DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_DOCUMENT_UPDATE_GRP

Source


1 PACKAGE BODY PO_DOCUMENT_UPDATE_GRP AS
2 /* $Header: POXGCPOB.pls 120.5.12020000.2 2013/02/10 12:35:30 vegajula ship $*/
3 
4 -- Read the profile option that enables/disables the debug log
5 g_fnd_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
6 
7 g_pkg_name CONSTANT VARCHAR2(30) := 'PO_DOCUMENT_UPDATE_GRP';
8 g_module_prefix  CONSTANT VARCHAR2(40) := 'po.plsql.' || g_pkg_name || '.';
9 
10 -- <PO_CHANGE_API FPJ START>
11 -- In file version 115.3, added an overloaded update_document procedure that
12 -- takes in changes as a PO_CHANGES_REC_TYPE object. This allows the caller to
13 -- request changes to multiple lines, shipments, and distributions at once.
14 
15 -------------------------------------------------------------------------------
16 --Start of Comments
17 --Name: update_document
18 --Function:
19 --  Validates and applies the requested changes and any derived
20 --  changes to the Purchase Order, Purchase Agreement, or Release.
21 --Notes:
22 --  For details, see the comments in the package body for
23 --  PO_DOCUMENT_UPDATE_PVT.update_document.
24 --End of Comments
25 -------------------------------------------------------------------------------
26 PROCEDURE update_document (
27   p_api_version            IN NUMBER,
28   p_init_msg_list          IN VARCHAR2,
29   x_return_status          OUT NOCOPY VARCHAR2,
30   p_changes                IN OUT NOCOPY PO_CHANGES_REC_TYPE,
31   p_run_submission_checks  IN VARCHAR2,
32   p_launch_approvals_flag  IN VARCHAR2,
33   p_buyer_id               IN NUMBER,
34   p_update_source          IN VARCHAR2,
35   p_override_date          IN DATE,
36   x_api_errors             OUT NOCOPY PO_API_ERRORS_REC_TYPE,
37   p_approval_background_flag IN VARCHAR2,
38   p_mass_update_releases   IN VARCHAR2, -- Bug 3373453
39   p_req_chg_initiator      IN VARCHAR2 DEFAULT NULL --Bug 14549341
40 ) IS
41   l_api_name     CONSTANT VARCHAR(30) := 'UPDATE_DOCUMENT';
42   l_api_version  CONSTANT NUMBER := 1.0;
43 BEGIN
44   -- Standard API initialization:
45   IF NOT FND_API.Compatible_API_Call ( l_api_version, p_api_version,
46                                        l_api_name, g_pkg_name ) THEN
47     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
48   END IF;
49 
50   IF (FND_API.to_boolean(p_init_msg_list)) THEN
51     FND_MSG_PUB.initialize;
52   END IF;
53 
54   PO_DOCUMENT_UPDATE_PVT.update_document(
55     p_api_version => 1.0,
56     p_init_msg_list => p_init_msg_list,
57     x_return_status => x_return_status,
58     p_changes => p_changes,
59     p_run_submission_checks => p_run_submission_checks,
60     p_launch_approvals_flag => p_launch_approvals_flag,
61     p_buyer_id => p_buyer_id,
62     p_update_source => p_update_source,
63     p_override_date => p_override_date,
64     x_api_errors => x_api_errors,
65     p_approval_background_flag => p_approval_background_flag,
66     p_mass_update_releases => p_mass_update_releases,
67     p_req_chg_initiator => p_req_chg_initiator --Bug 14549341
68   );
69 
70 EXCEPTION
71   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
72     -- Add the errors on the API message list to x_api_errors.
73     PO_DOCUMENT_UPDATE_PVT.add_message_list_errors (
74       p_api_errors => x_api_errors,
75       x_return_status => x_return_status
76     );
77     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
78   WHEN OTHERS THEN
79     -- Add the unexpected error to the API message list.
80     PO_DEBUG.handle_unexp_error ( p_pkg_name => g_pkg_name,
81                                   p_proc_name => l_api_name );
82     -- Add the errors on the API message list to x_api_errors.
83     PO_DOCUMENT_UPDATE_PVT.add_message_list_errors (
84       p_api_errors => x_api_errors,
85       x_return_status => x_return_status
86     );
87     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
88 END update_document;
89 -- <PO_CHANGE_API FPJ END>
90 
91 -- START Forward declarations for package private procedures:
92 FUNCTION check_mandatory_params (
93   p_api_errors                  IN OUT NOCOPY PO_API_ERRORS_REC_TYPE,
94   p_po_number                   VARCHAR2,
95   p_revision_number             NUMBER,
96   p_line_number                 NUMBER,
97   p_new_quantity                NUMBER,
98   p_new_price                   NUMBER,
99   p_new_promised_date           DATE,
100   p_new_need_by_date            DATE,
101   p_launch_approvals_flag       VARCHAR2,
102   p_secondary_qty               NUMBER,
103   p_preferred_grade             VARCHAR2
104 ) RETURN NUMBER;
105 -- END Forward declarations for package private procedures
106 
107 
108 
109 -- <PO_CHANGE_API FPJ>
110 -- In file version 115.3, removed the P_INTERFACE_TYPE and P_TRANSACTION_ID
111 -- parameters from UPDATE_DOCUMENT and added an X_API_ERRORS parameter, because
112 -- the PO Change API will no longer write error messages to the
113 -- PO_INTERFACE_ERRORS table. Instead, it will return all of the errors
114 -- in the x_api_errors object.
115 
116 -------------------------------------------------------------------------------
117 --Start of Comments
118 --Name: update_document
119 --Function:
120 --  Validates and applies the requested changes and any derived
121 --  changes to the Purchase Order or Release.
122 --Pre-reqs:
123 --  The Applications context must be set before calling this API - i.e.:
124 --    FND_GLOBAL.apps_initialize ( user_id => <user ID>,
125 --                                 resp_id => <responsibility ID>,
126 --                                 resp_appl_id => 201 );
127 --Notes:
128 --  This procedure is for backward compatibility only. New callers should use
129 --  the overloaded UPDATE_DOCUMENT procedure above, which takes in changes
130 --  as a PO_CHANGES_REC_TYPE object.
131 --End of Comments
132 -------------------------------------------------------------------------------
133 PROCEDURE update_document (
134   p_PO_NUMBER                   IN      VARCHAR2,
135   p_RELEASE_NUMBER              IN      NUMBER,
136   p_REVISION_NUMBER             IN      NUMBER,
137   p_LINE_NUMBER                 IN      NUMBER,
138   p_SHIPMENT_NUMBER             IN      NUMBER,
139   p_NEW_QUANTITY                IN      NUMBER,
140   p_NEW_PRICE                   IN      NUMBER,
141   p_NEW_PROMISED_DATE           IN      DATE,
142   p_NEW_NEED_BY_DATE            IN      DATE,
143   p_LAUNCH_APPROVALS_FLAG       IN      VARCHAR2,
144   p_UPDATE_SOURCE               IN      VARCHAR2,
145   p_OVERRIDE_DATE               IN      DATE,
146   p_VERSION                     IN      NUMBER,
147   x_result                      IN OUT NOCOPY   NUMBER,
148   x_api_errors                  OUT NOCOPY PO_API_ERRORS_REC_TYPE,
149   p_BUYER_NAME                  IN VARCHAR2  default NULL, /* Bug:2986718 */
150  -- <INVCONV R12 START>
151   p_secondary_qty               IN NUMBER ,
152   p_preferred_grade             IN VARCHAR2
153   -- <INVCONV R12 END>
154 ) IS
155 
156   l_api_version CONSTANT NUMBER := 2.0;
157   l_api_name    CONSTANT VARCHAR2(50) := 'UPDATE_DOCUMENT';
158 
159   -- <PO_CHANGE_API FPJ START>
160   CURSOR l_po_header_csr (p_po_number VARCHAR2) IS
161     select  po_header_id, revision_num,
162             NVL(authorization_status, 'INCOMPLETE'), type_lookup_code
163     from    po_headers
164     where   segment1 = p_PO_NUMBER
165     and     type_lookup_code IN ('STANDARD', 'BLANKET', 'PLANNED');
166 
167   CURSOR l_po_release_csr (p_po_header_id NUMBER, p_release_number NUMBER) IS
168     select  po_release_id, revision_num,
169             NVL(authorization_status, 'INCOMPLETE'), release_type
170     from    po_releases
171     where   po_header_id = p_po_header_id
172     and     release_num = p_RELEASE_NUMBER;
173 
174   CURSOR l_po_line_csr (p_po_header_id NUMBER, p_line_number NUMBER) IS
175     select  po_line_id
176     from    po_lines
177     where   po_header_id = p_po_header_id
178     and     line_num = p_LINE_NUMBER;
179 
180   CURSOR l_po_shipment_csr (p_po_line_id NUMBER, p_shipment_number NUMBER) IS
181     select  line_location_id
182     from    po_line_locations
183     where   po_line_id = p_po_line_id
184     and     shipment_num = p_SHIPMENT_NUMBER;
185 
186   CURSOR l_release_shipment_csr (p_po_release_id NUMBER, p_po_line_id NUMBER,
187                                  p_shipment_number NUMBER) IS
188     select  line_location_id
189     from    po_line_locations
190     where   po_line_id = p_po_line_id
191     and     po_release_id = p_po_release_id
192     and     shipment_num = p_SHIPMENT_NUMBER;
193 
194   l_header_table_name    VARCHAR2(30);
195   l_changes              PO_CHANGES_REC_TYPE;
196   l_new_shipment_price   PO_LINE_LOCATIONS.price_override%TYPE;
197   l_po_header_id         PO_HEADERS.po_header_id%TYPE;
198   l_po_release_id        PO_RELEASES.po_release_id%TYPE;
199   l_po_line_id           PO_LINES.po_line_id%TYPE;
200   l_line_location_id     PO_LINE_LOCATIONS.line_location_id%TYPE;
201   l_revision_num         PO_HEADERS.revision_num%TYPE;
202   l_authorization_status PO_HEADERS.authorization_status%TYPE;
203   l_document_subtype     PO_HEADERS.type_lookup_code%TYPE;
204   l_launch_approvals_flag VARCHAR2(1);
205   l_shipment_count       NUMBER;
206   l_buyer_id             PO_HEADERS.agent_id%TYPE;
207 
208   l_return_status        VARCHAR2(1);
209   l_secondary_quantity   PO_LINES.SECONDARY_QUANTITY%TYPE := p_secondary_qty;  -- <INVCONV R12>
210   l_preferred_grade      MTL_GRADES.grade_Code%TYPE := p_preferred_grade;      -- <INVCONV R12>
211 
212   l_progress             VARCHAR2(3) := '000';
213   -- <PO_CHANGE_API FPJ END>
214   l_message_name        fnd_new_messages.message_name%TYPE;   -- <INVCONV R12>
215 
216 BEGIN
217 
218   IF (g_fnd_debug = 'Y') THEN
219     IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
220       FND_LOG.string( FND_LOG.LEVEL_PROCEDURE, g_module_prefix || l_api_name,
221                     'Entering ' || l_api_name );
222     END IF;
223   END IF;
224 
225   x_result := 1;
226 
227   IF NOT FND_API.Compatible_API_Call ( l_api_version, p_VERSION,
228                                        l_api_name, g_pkg_name ) THEN
229     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
230   END IF;
231 
232   FND_MSG_PUB.initialize;
233 
234   -- <PO_CHANGE_API FPJ START>
235   -- Moved the following logic from the private API (PO_DOCUMENT_UPDATE_PVT)
236   -- to the group API, because the private API now takes changes as a
237   -- PO_CHANGES_REC_TYPE object instead of individual procedure arguments.
238 
239   l_progress := '010';
240 
241   -- Verify that the caller passed in values for all the required parameters.
242   IF (check_mandatory_params (
243         x_api_errors, p_po_number, p_revision_number, p_line_number,
244         p_new_quantity, p_new_price, p_new_promised_date, p_new_need_by_date,
245         p_launch_approvals_flag,
246         p_secondary_qty,p_preferred_grade ) = 0)      -- <INVCONV R12>
247   THEN
248     x_result := 0;
249     RETURN;
250   END IF;
251 
252   l_progress := '020';
253 
254   -- Obtain the PO_HEADER_ID.
255   OPEN l_po_header_csr (p_po_number);
256   FETCH l_po_header_csr
257   INTO l_po_header_id, l_revision_num,
258        l_authorization_status, l_document_subtype;
259 
260   IF (l_po_header_csr%NOTFOUND) THEN
261     PO_DOCUMENT_UPDATE_PVT.add_error (
262       p_api_errors => x_api_errors,
263       x_return_status => l_return_status,
264       p_message_name => 'PO_INVALID_DOC_IDS',
265       p_table_name => 'PO_HEADERS',
266       p_column_name => 'PO_HEADER_ID'
267     );
268     x_result := 0;
269     CLOSE l_po_header_csr;
270     RETURN;
271   END IF; -- l_po_header_csr%NOTFOUND
272   CLOSE l_po_header_csr;
273 
274   l_progress := '030';
275 
276   -- Obtain the PO_RELEASE_ID if needed.
277   IF (p_release_number is not null) THEN
278     OPEN l_po_release_csr (l_po_header_id, p_release_number);
279     FETCH l_po_release_csr
280     INTO l_po_release_id, l_revision_num,
281          l_authorization_status, l_document_subtype;
282 
283     if (l_po_release_csr%NOTFOUND) then
284       PO_DOCUMENT_UPDATE_PVT.add_error (
285         p_api_errors => x_api_errors,
286         x_return_status => l_return_status,
287         p_message_name => 'PO_CHNG_INVALID_RELEASE_NUM',
288         p_table_name => 'PO_RELEASES',
289         p_column_name => 'PO_RELEASE_ID'
290       );
291       x_result := 0;
292       CLOSE l_po_release_csr;
293       RETURN;
294     END IF; -- l_po_release_csr%NOTFOUND
295     CLOSE l_po_release_csr;
296   END IF;
297 
298   l_progress := '040';
299 
300      --<INVCONV R12 START>
301      IF (l_preferred_grade IS NOT NULL OR
302          l_secondary_quantity IS NOT NULL) THEN
303         l_message_name := 'PO_CHNG_SECGRD_NOTSUPPORTED_PB';
304      ELSE
305         l_message_name := 'PO_CHNG_WRONG_DOC_TYPE';
306      END IF;
307      --<INVCONV R12 END>
308 
309   -- Check if the document is one of the supported types.
310   IF (l_po_release_id IS NULL) THEN -- PO/PA
311     l_header_table_name := 'PO_HEADERS';
312     IF l_document_subtype NOT IN ('STANDARD', 'PLANNED') THEN
313       PO_DOCUMENT_UPDATE_PVT.add_error (
314         p_api_errors => x_api_errors,
315         x_return_status => l_return_status,
316         p_message_name => l_message_name,    -- <INVCONV R12>
317         p_table_name => l_header_table_name,
318         p_column_name => 'TYPE_LOOKUP_CODE'
319       );
320       x_result := 0;
321       RETURN;
322     END IF; -- l_document_subtype
323   ELSE -- Release
324     l_header_table_name := 'PO_RELEASES';
325     IF l_document_subtype NOT IN ('SCHEDULED', 'BLANKET') THEN
326       PO_DOCUMENT_UPDATE_PVT.add_error (
327         p_api_errors => x_api_errors,
328         x_return_status => l_return_status,
329         p_message_name =>  l_message_name,   -- <INVCONV R12>
330         p_table_name => l_header_table_name,
331         p_column_name => 'RELEASE_TYPE'
332       );
333       x_result := 0;
334       RETURN;
335     END IF; -- l_document_subtype
336   END IF; -- l_po_release_id
337 
338   l_progress := '050';
339 
340   -- Check if the document is in a supported status.
341   -- Bug#4156064: allow changing of PO with incomplete status also
342   IF l_authorization_status NOT IN ('APPROVED', 'REQUIRES REAPPROVAL', 'INCOMPLETE') THEN
343     PO_DOCUMENT_UPDATE_PVT.add_error (
344       p_api_errors => x_api_errors,
345       x_return_status => l_return_status,
346       p_message_name => 'PO_ALL_DOC_CANNOT_BE_OPENED',
347       p_table_name => l_header_table_name,
348       p_column_name => 'AUTHORIZATION_STATUS'
349     );
350     x_result := 0;
351     RETURN;
352   END IF; -- l_authorization_status
353 
354   l_progress := '060';
355 
356   -- Verify that the passed in revision equals the current revision.
357   IF (l_revision_num <> p_revision_number) THEN
358     PO_DOCUMENT_UPDATE_PVT.add_error (
359       p_api_errors => x_api_errors,
360       x_return_status => l_return_status,
361       p_message_name => 'PO_CHNG_REVISION_NOT_MATCH',
362       p_table_name => l_header_table_name,
363       p_column_name => 'REVISION_NUM'
364     );
365     x_result := 0;
366     RETURN;
367   END IF; -- l_revision_num
368 
369   -- Create an empty change object for this document.
370   l_changes := PO_CHANGES_REC_TYPE.create_object (
371     p_po_header_id => l_po_header_id,
372     p_po_release_id => l_po_release_id
373   );
374 
375   l_progress := '070';
376 
377   -- Obtain the PO_LINE_ID.
378   OPEN l_po_line_csr (l_po_header_id, p_line_number);
379   FETCH l_po_line_csr INTO l_po_line_id;
380 
381   IF (l_po_line_csr%NOTFOUND) THEN
382     PO_DOCUMENT_UPDATE_PVT.add_error (
383       p_api_errors => x_api_errors,
384       x_return_status => l_return_status,
385       p_message_name => 'PO_CHNG_INVALID_LINE_NUM',
386       p_table_name => 'PO_LINES',
387       p_column_name => 'PO_LINE_ID'
388     );
389     x_result := 0;
390     CLOSE l_po_line_csr;
391     RETURN;
392   END IF;
393   CLOSE l_po_line_csr;
394 
395   -- Add the line or shipment changes to the change object.
396   IF (p_shipment_number IS NULL) THEN -- Line-level change
397 
398     l_progress := '080';
399 
400     IF (p_new_promised_date IS NOT NULL) THEN
401       -- Lines do not have promised date.
402       PO_DOCUMENT_UPDATE_PVT.add_error (
403         p_api_errors => x_api_errors,
404         x_return_status => l_return_status,
405         p_message_name => 'PO_CHNG_NO_DATE_CHANGE_LINE',
406         p_table_name => 'PO_LINES',
407         p_column_name => 'PROMISED_DATE'
408       );
409       x_result := 0;
410       RETURN;
411     END IF; -- p_new_promised_date
412 
413     IF (p_new_need_by_date IS NOT NULL) THEN
414       -- Lines do not have need by date.
415       PO_DOCUMENT_UPDATE_PVT.add_error (
416         p_api_errors => x_api_errors,
417         x_return_status => l_return_status,
418         p_message_name => 'PO_CHNG_NO_NEED_DATE_ON_LINE',
419         p_table_name => 'PO_LINES',
420         p_column_name => 'NEED_BY_DATE'
421       );
422       x_result := 0;
423       RETURN;
424     END IF; -- p_new_need_by_date
425 
426 
427     -- Add a line change.
428     l_changes.line_changes.add_change (
429       p_po_line_id => l_po_line_id,
430       p_quantity => p_new_quantity,
431       p_unit_price => p_new_price,
432       p_secondary_quantity => l_secondary_quantity,   -- <INVCONV R12>
433       p_preferred_grade  => l_preferred_grade         -- <INVCONV R12>
434     );
435 
436   ELSE -- Shipment-level change
437 
438     l_progress := '090';
439 
440     -- Obtain the LINE_LOCATION_ID.
441     IF (p_release_number IS NULL) THEN -- PO or PA
442       OPEN l_po_shipment_csr (l_po_line_id, p_shipment_number);
443       FETCH l_po_shipment_csr INTO l_line_location_id;
444 
445       IF (l_po_shipment_csr%NOTFOUND) THEN
446         PO_DOCUMENT_UPDATE_PVT.add_error (
447           p_api_errors => x_api_errors,
448           x_return_status => l_return_status,
449           p_message_name => 'PO_CHNG_INVALID_SHIPMENT_NUM',
450           p_table_name => 'PO_LINE_LOCATIONS',
451           p_column_name => 'LINE_LOCATION_ID'
452         );
453         x_result := 0;
454         CLOSE l_po_shipment_csr;
455         RETURN;
456       END IF; -- l_po_shipment_csr%NOTFOUND
457       CLOSE l_po_shipment_csr;
458 
459     ELSE -- Releases
460       OPEN l_release_shipment_csr (l_po_release_id, l_po_line_id,
461                                    p_shipment_number);
462       FETCH l_release_shipment_csr INTO l_line_location_id;
463 
464       IF (l_release_shipment_csr%NOTFOUND) THEN
465         PO_DOCUMENT_UPDATE_PVT.add_error (
466           p_api_errors => x_api_errors,
467           x_return_status => l_return_status,
468           p_message_name => 'PO_CHNG_INVALID_SHIPMENT_NUM',
469           p_table_name => 'PO_LINE_LOCATIONS',
470           p_column_name => 'LINE_LOCATION_ID'
471         );
472         x_result := 0;
473         CLOSE l_release_shipment_csr;
474         RETURN;
475       END IF; -- l_release_shipment_csr%NOTFOUND
476       CLOSE l_release_shipment_csr;
477 
478     END IF; -- p_release_number
479 
480     l_progress := '100';
481 
482     -- Shipments of standard/planned POs do not have prices.
483     -- However, for backward compatibility, if the caller requests
484     -- a shipment price change, we will automatically convert it
485     -- to a line price change if the line has only one shipment.
486     IF (p_release_number IS NULL)
487        AND (l_document_subtype IN ('STANDARD', 'PLANNED'))
488        AND (p_new_price IS NOT NULL) THEN
489 
490       -- SQL What: Returns the number of shipments on this line.
491       SELECT count(*)
492       INTO l_shipment_count
493       FROM po_line_locations
494       WHERE po_line_id = l_po_line_id
495       AND shipment_type = l_document_subtype;
496 
497       IF (l_shipment_count > 1) THEN
498         -- Do not allow shipment price changes if the line has
499         -- multiple shipments.
500         PO_DOCUMENT_UPDATE_PVT.add_error (
501           p_api_errors => x_api_errors,
502           x_return_status => l_return_status,
503           p_message_name => 'PO_CHNG_PO_NO_SHIP_PRICE',
504           p_table_name => 'PO_LINE_LOCATIONS',
505           p_column_name => 'PRICE_OVERRIDE'
506         );
507         x_result := 0;
508         RETURN;
509       END IF;
510 
511       -- Convert this shipment price change to a line price change.
512       l_changes.line_changes.add_change (
513         p_po_line_id => l_po_line_id,
514         p_unit_price => p_new_price
515       );
516       l_new_shipment_price := NULL; -- Do not add a shipment price change.
517     ELSE -- not a standard or planned PO
518       l_new_shipment_price := p_new_price;
519     END IF; -- standard or planned PO with new price
520 
521     l_progress := '110';
522 
523     -- Add a shipment change.
524 
525     l_changes.shipment_changes.add_change (
526       p_po_line_location_id => l_line_location_id,
527       p_quantity => p_new_quantity,
528       p_price_override => l_new_shipment_price,
529       p_promised_date => p_new_promised_date,
530       p_need_by_date => p_new_need_by_date,
531       p_preferred_grade => l_preferred_grade,       -- <INVCONV R12>
532       p_secondary_quantity => l_secondary_quantity  -- <INVCONV R12>
533     );
534 
535   END IF; -- p_shipment_number
536 
537   l_progress := '120';
538 
539   -- Convert the launch approvals flag from Y/N to FND_API true/false.
540   IF (p_launch_approvals_flag = 'Y') THEN
541     l_launch_approvals_flag := FND_API.G_TRUE;
542   ELSE
543     l_launch_approvals_flag := FND_API.G_FALSE;
544   END IF;
545 
546   l_progress := '130';
547 
548   -- Derive the buyer ID from the buyer name.
549   IF ( p_BUYER_NAME IS NOT NULL) THEN
550     l_buyer_id := PO_AGENTS_SV1.derive_agent_id(p_BUYER_NAME);
551     IF (l_buyer_id IS NULL) then -- could not find a buyer
552       PO_DOCUMENT_UPDATE_PVT.add_error (
553         p_api_errors => x_api_errors,
554         x_return_status => l_return_status,
555         p_message_name => 'PO_PDOI_DERV_ERROR',
556         p_column_name => 'P_BUYER_NAME',
557         p_token_name1 => 'COLUMN_NAME',
558         p_token_value1 => 'P_BUYER_NAME',
559         p_token_name2 => 'VALUE',
560         p_token_value2 => p_buyer_name
561       );
562       x_result := 0;
563       RETURN;
564     END IF;
565   END IF;
566 
567   l_progress := '150';
568 
569   -- Call the private PO Change API to derive, validate, and apply the changes.
570   PO_DOCUMENT_UPDATE_PVT.update_document(
571     p_api_version => 1.0,
572     p_init_msg_list => FND_API.G_TRUE,
573     x_return_status => l_return_status,
574     p_changes => l_changes,
575     p_run_submission_checks => FND_API.G_FALSE,
576     p_launch_approvals_flag => l_launch_approvals_flag,
577     p_buyer_id => l_buyer_id,
578     p_update_source => p_update_source,
579     p_override_date => p_override_date,
580     x_api_errors => x_api_errors
581   );
582 
583   IF (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
584     x_result := 1;
585   ELSE
586     x_result := 0;
587   END IF;
588 
589   l_progress := '150';
590 
591 EXCEPTION
592   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
593     -- Add the errors on the API message list to x_api_errors.
594     PO_DOCUMENT_UPDATE_PVT.add_message_list_errors (
595       p_api_errors => x_api_errors,
596       x_return_status => l_return_status
597     );
598     x_result := 0;
599   WHEN OTHERS THEN
600     -- Add the unexpected error to the API message list.
601     PO_DEBUG.handle_unexp_error ( p_pkg_name => g_pkg_name,
602                                   p_proc_name => l_api_name,
603                                   p_progress => l_progress );
604     -- Add the errors on the API message list to x_api_errors.
605     PO_DOCUMENT_UPDATE_PVT.add_message_list_errors (
606       p_api_errors => x_api_errors,
607       x_return_status => l_return_status
608     );
609     x_result := 0;
610 -- <PO_CHANGE_API FPJ END>
611 END update_document;
612 
613 -- <PO_CHANGE_API FPJ START>
614 -- In file version 115.3, moved this procedure from the private API
615 -- (PO_DOCUMENT_UPDATE_PVT) to the group API, because the private API
616 -- now takes changes as a PO_CHANGES_REC_TYPE object, not as individual
617 -- procedure arguments.
618 
619 -------------------------------------------------------------------------------
620 --Start of Comments
621 --Name: check_mandatory_params
622 --Function:
623 --  Checks that the caller has passed in values for the required parameters.
624 --  Returns 1 if all of the required parameters have non-NULL values,
625 --  0 otherwise.
626 --End of Comments
627 -------------------------------------------------------------------------------
628 FUNCTION check_mandatory_params (
629   p_api_errors                  IN OUT NOCOPY PO_API_ERRORS_REC_TYPE,
630   p_po_number                   VARCHAR2,
631   p_revision_number             NUMBER,
632   p_line_number                 NUMBER,
633   p_new_quantity                NUMBER,
634   p_new_price                   NUMBER,
635   p_new_promised_date           DATE,
636   p_new_need_by_date            DATE,
637   p_launch_approvals_flag       VARCHAR2,
638   p_secondary_qty               NUMBER ,   -- <INVCONV R12>
639   p_preferred_grade             VARCHAR2   -- <INVCONV R12>
640 ) RETURN NUMBER IS
641   l_api_name    CONSTANT VARCHAR2(50) := 'CHECK_MANDATORY_PARAMS';
642   l_return_status VARCHAR2(1);
643 BEGIN
644   IF (g_fnd_debug = 'Y') THEN
645      IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
646         FND_LOG.string( FND_LOG.LEVEL_PROCEDURE, g_module_prefix || l_api_name,
647                     'Entering ' || l_api_name );
648      END IF;
649   END IF;
650 
651   if (p_PO_NUMBER is null) then
652     PO_DOCUMENT_UPDATE_PVT.add_error (
653       p_api_errors => p_api_errors,
654       x_return_status => l_return_status,
655       p_message_name => 'PO_ALL_CNL_PARAM_NULL',
656       p_column_name => 'P_PO_NUMBER'
657     );
658     return 0;
659   end if;
660 
661   if (p_REVISION_NUMBER is null) then
662     PO_DOCUMENT_UPDATE_PVT.add_error (
663       p_api_errors => p_api_errors,
664       x_return_status => l_return_status,
665       p_message_name => 'PO_ALL_CNL_PARAM_NULL',
666       p_column_name => 'P_REVISION_NUMBER'
667     );
668     return 0;
669   end if;
670 
671   IF (NVL(p_LAUNCH_APPROVALS_FLAG,'N') NOT IN ('Y', 'N')) THEN
672     PO_DOCUMENT_UPDATE_PVT.add_error (
673       p_api_errors => p_api_errors,
674       x_return_status => l_return_status,
675       p_message_name => 'PO_CHNG_INVALID_LAUNCH_FLAG',
676       p_column_name => 'P_LAUNCH_APPROVALS_FLAG');
677     return 0;
678   END IF;
679 
680   IF (p_LINE_NUMBER IS NULL) THEN
681     PO_DOCUMENT_UPDATE_PVT.add_error (
682       p_api_errors => p_api_errors,
683       x_return_status => l_return_status,
684       p_message_name => 'PO_ALL_CNL_PARAM_NULL',
685       p_column_name => 'P_LINE_NUMBER'
686     );
687     return 0;
688   END IF;
689 
690   --<INVCONV R12 START>
691   /*
692   ===============================================================
693    check if secondary and preferred grade are not passed.
694    we want to make sure API runs even if we just pass secondary
695    or preferred grade
696   ===============================================================
697   */
698   g_process_param_chge_only := 'N';
699 
700   IF (p_new_quantity IS NULL AND p_new_price IS NULL
701       AND p_new_promised_date IS NULL AND p_new_need_by_date IS NULL) THEN
702 
703     /* check if process attributes are null */
704 
705     IF (p_secondary_qty IS NULL AND p_preferred_grade IS NULL) THEN
706        PO_DOCUMENT_UPDATE_PVT.add_error (
707         p_api_errors => p_api_errors,
708         x_return_status => l_return_status,
709         p_message_name => 'PO_CHNG_ONE_INPUT_REQUIRED');
710        return 0;
711     ELSE
712        g_process_param_chge_only := 'Y';  -- <INVCONV R12>
713     END IF;
714   END IF;
715 
716   --<INVCONV R12 END>
717 
718   return 1;
719 
720 EXCEPTION
721   WHEN OTHERS THEN
722     PO_DEBUG.handle_unexp_error ( p_pkg_name => g_pkg_name,
723                                   p_proc_name => l_api_name );
724     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
725 END check_mandatory_params;
726 -- <PO_CHANGE_API FPJ END>
727 
728 -- Bug 3605355 START
729 -------------------------------------------------------------------------------
730 --Start of Comments
731 --Name: launch_po_approval_wf
732 --Function:
733 --  Launches the Document Approval workflow for the given document.
734 --Note:
735 -- For details, see the package body comments for
736 -- PO_DOCUMENT_UPDATE_PVT.launch_po_approval_wf.
737 --End of Comments
738 -------------------------------------------------------------------------------
739 PROCEDURE launch_po_approval_wf (
740   p_api_version           IN NUMBER,
741   p_init_msg_list         IN VARCHAR2,
742   x_return_status         OUT NOCOPY VARCHAR2,
743   p_document_id           IN NUMBER,
744   p_document_type         IN PO_DOCUMENT_TYPES_ALL_B.document_type_code%TYPE,
745   p_document_subtype      IN PO_DOCUMENT_TYPES_ALL_B.document_subtype%TYPE,
746   p_preparer_id           IN NUMBER,
747   p_approval_background_flag IN VARCHAR2,
748   p_mass_update_releases  IN VARCHAR2
749 ) IS
750   l_proc_name CONSTANT VARCHAR2(30) := 'LAUNCH_PO_APPROVAL_WF';
751   l_api_version CONSTANT NUMBER := 1.0;
752   l_progress VARCHAR2(3) := '000';
753 BEGIN
754   x_return_status := FND_API.G_RET_STS_SUCCESS;
755 
756   -- Standard API initialization:
757   IF NOT FND_API.compatible_api_call (
758            p_current_version_number => l_api_version,
759            p_caller_version_number => p_api_version,
760            p_api_name => l_proc_name,
761            p_pkg_name => g_pkg_name ) THEN
762     RAISE FND_API.g_exc_unexpected_error;
763   END IF;
764 
765   IF (FND_API.to_boolean(p_init_msg_list)) THEN
766     FND_MSG_PUB.initialize();
767   END IF;
768 
769   l_progress := '010';
770 
771   PO_DOCUMENT_UPDATE_PVT.launch_po_approval_wf (
772     p_api_version => 1.0,
773     p_init_msg_list => FND_API.G_FALSE,
774     x_return_status => x_return_status,
775     p_document_id => p_document_id,
776     p_document_type => p_document_type,
777     p_document_subtype => p_document_subtype,
778     p_preparer_id => p_preparer_id,
779     p_approval_background_flag => p_approval_background_flag,
780     p_mass_update_releases => p_mass_update_releases,
781     p_retroactive_price_change => NULL
782   );
783 EXCEPTION
784   WHEN FND_API.g_exc_unexpected_error THEN
785     PO_DEBUG.handle_unexp_error ( p_pkg_name => g_pkg_name,
786                                   p_proc_name => l_proc_name,
787                                   p_progress => l_progress );
788     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
789   WHEN OTHERS THEN
790     PO_DEBUG.handle_unexp_error ( p_pkg_name => g_pkg_name,
791                                   p_proc_name => l_proc_name,
792                                   p_progress => l_progress );
793     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
794 END launch_po_approval_wf;
795 -- Bug 3605355 END
796 
797 END PO_DOCUMENT_UPDATE_GRP;