DBA Data[Home] [Help]

PACKAGE BODY: APPS.CLN_ACK_PO_PKG

Source


4    TYPE t_line_num_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
1 PACKAGE BODY CLN_ACK_PO_PKG AS
2 /* $Header: CLNACKPB.pls 120.2 2006/03/27 00:34:33 kkram noship $ */
3    l_debug_level        NUMBER := to_number(nvl(fnd_profile.value('CLN_DEBUG_LEVEL'), '5'));
5    l_line_num_tab t_line_num_tab;
6 
7 --  Package
8 --      CLN_ACK_PO_PKG
9 --
10 --  Purpose
11 --      Body of package CLN_ACK_PO_PKG.
12 --
13 --  History
14 --      May-14-2002        Rahul Krishan         Created
15 
16    -- Name
17    --    IS_ALREADY_PROCESSED_LINE
18    -- Purpose
19    --    Checks whether a line is already processed or not
20    -- Arguments
21    --   PO Line Num
22 
23 
24       FUNCTION IS_ALREADY_PROCESSED_LINE(
25          p_line_num             IN  VARCHAR2)
26          RETURN BOOLEAN
27       IS
28            i           binary_integer;
29       BEGIN
30          IF (l_Debug_Level <= 2) THEN
31                  cln_debug_pub.Add('ENTERING PROCESS_ORDER_HEADER,p_requestor:' || p_line_num, 2);
32          END IF;
33 
34            i := l_line_num_tab.first();
35            while i is not null loop
36              IF (l_Debug_Level <= 1) THEN
37                     cln_debug_pub.Add('next element:' || l_line_num_tab(i), 1);
38              END IF;
39              IF (l_line_num_tab(i) = p_line_num ) THEN
40                 IF (l_Debug_Level <= 2) THEN
41                        cln_debug_pub.Add('EXITING PROCESS_ORDER_HEADER:Line is duplicate', 1);
42                 END IF;
43                 RETURN TRUE;
44              END IF;
45              i := l_line_num_tab.next(i);
46            end loop;
47            l_line_num_tab(l_line_num_tab.count()+1) := p_line_num;
48            IF (l_Debug_Level <= 2) THEN
49                  cln_debug_pub.Add('EXITING PROCESS_ORDER_HEADER:Line is not duplicate', 1);
50            END IF;
51            RETURN FALSE;
52       END;
53 
54 
55    -- Name
56    --    RAISE_UPDATE_EVENT
57    -- Purpose
58    --    This is the public procedure which raises an event to update collaboration passing these parameters so
59    --    obtained.This procedure actually requires only three input parameters viz. p_coll_id, p_org_ref
60    --    p_msg_text, p_internal_control_number but due to previous coding and its dependencies,
61    --    the signature of this procedure is left as it is.The previously used code is simply commented out.
62    --    This procedure is called from PROCESS_HEADER_LINES.
63    --
64    -- Arguments
65    --
66    -- Notes
67    --    No specific notes.
68 
69    PROCEDURE RAISE_UPDATE_EVENT(
70          x_return_status                OUT NOCOPY VARCHAR2,
71          x_msg_data                     OUT NOCOPY VARCHAR2,
72          p_coll_id                      IN  NUMBER,
73          p_doc_status                   IN  VARCHAR2,
74          p_org_ref                      IN  VARCHAR2,
75          p_disposition                  IN  VARCHAR2,
76          p_msg_text                     IN  VARCHAR2,
77          p_internal_control_number      IN  VARCHAR2 )
78 
79    IS
80          l_cln_ch_parameters            wf_parameter_list_t;
81          l_event_key                    NUMBER;
82          l_rosettanet_check_required    VARCHAR2(10);
83          l_error_code                   NUMBER;
84          l_error_msg                    VARCHAR2(255);
85          l_debug_mode                   VARCHAR2(255);
86          l_msg_data                     VARCHAR2(255);
87 
88    BEGIN
89          -- Sets the debug mode to be FILE
90          --l_debug_mode := cln_debug_pub.Set_Debug_Mode('FILE');
91          IF (l_Debug_Level <= 2) THEN
92                  cln_debug_pub.Add('-------- ENTERING RAISE_UPDATE_EVENT -----------', 2);
93          END IF;
94 
95          --  Initialize API return status to success
96          x_return_status := FND_API.G_RET_STS_SUCCESS;
97          l_msg_data      := 'Update event successfully raised';
98 
99          FND_MESSAGE.SET_NAME('CLN','CLN_CH_EVENT_RAISED');
100          FND_MESSAGE.SET_TOKEN('EVENT','Update');
101          x_msg_data := FND_MESSAGE.GET;
102 
103          SELECT  cln_generic_s.nextval INTO l_event_key FROM dual;
104 
105          IF (l_Debug_Level <= 1) THEN
106                  cln_debug_pub.Add('----------- PARAMETERS OBTAINED ----------', 1);
107                  cln_debug_pub.Add('Collaboration ID            ---- '||p_coll_id, 1);
108                  cln_debug_pub.Add('Document Status             ---- '||p_doc_status, 1);
109                  cln_debug_pub.Add('Disposition                 ---- '||p_disposition, 1);
110                  cln_debug_pub.Add('Originator Reference (SO Number) ---- '||p_org_ref, 1);
114                  cln_debug_pub.Add('----------- SETTING DEFAULT VALUES ----------', 1);
111                  cln_debug_pub.Add('Message Text                ---- '||p_msg_text, 1);
112                  cln_debug_pub.Add('Internal Control Number     ---- '||p_internal_control_number, 1);
113                  cln_debug_pub.Add('------------------------------------------', 1);
115          END IF;
116          l_rosettanet_check_required  :=        'TRUE'          ;
117 
118          l_cln_ch_parameters := wf_parameter_list_t();
119          IF (l_Debug_Level <= 1) THEN
120                  cln_debug_pub.Add('-------- SETTING EVENT PARAMETERS -----------', 1);
121          END IF;
122          WF_EVENT.AddParameterToList('COLLABORATION_ID', p_coll_id, l_cln_ch_parameters);
123          WF_EVENT.AddParameterToList('DOCUMENT_STATUS', p_doc_status, l_cln_ch_parameters);
124          WF_EVENT.AddParameterToList('DISPOSITION', p_disposition, l_cln_ch_parameters);
125          WF_EVENT.AddParameterToList('ORIGINATOR_REFERENCE', p_org_ref, l_cln_ch_parameters);
126          WF_EVENT.AddParameterToList('MESSAGE_TEXT', p_msg_text, l_cln_ch_parameters);
127          WF_EVENT.AddParameterToList('ROSETTANET_CHECK_REQUIRED',l_rosettanet_check_required,l_cln_ch_parameters);
128          WF_EVENT.AddParameterToList('XMLG_INTERNAL_CONTROL_NUMBER',p_internal_control_number,l_cln_ch_parameters);
129          WF_EVENT.AddParameterToList('PARTNER_DOCUMENT_NO',p_org_ref,l_cln_ch_parameters);
130          IF (l_Debug_Level <= 1) THEN
131                  cln_debug_pub.Add('-------- EVENT PARAMETERS SET-----------', 1);
132                  cln_debug_pub.Add('Workflow event- oracle.apps.cln.ch.collaboration.update', 1);
133          END IF;
134 
135          WF_EVENT.Raise('oracle.apps.cln.ch.collaboration.update',l_event_key, NULL, l_cln_ch_parameters, NULL);
136          IF (l_Debug_Level <= 2) THEN
137                  cln_debug_pub.Add('----------- EXITING RAISE_UPDATE_EVENT ------------', 2);
138          END IF;
139 
140 
141    EXCEPTION
142          WHEN FND_API.G_EXC_ERROR THEN
143             l_error_code        := SQLCODE;
144             l_error_msg         := SQLERRM;
145             x_return_status     := FND_API.G_RET_STS_ERROR ;
146             x_msg_data          := l_error_code||' : '||l_error_msg;
147             IF (l_Debug_Level <= 6) THEN
148                     cln_debug_pub.Add('Error:' || l_error_code || ':' || l_error_msg, 6);
149                     cln_debug_pub.Add('----------- ERROR :EXITING RAISE_UPDATE_EVENT ------------', 6);
150             END IF;
151 
152          WHEN OTHERS THEN
153             l_error_code    := SQLCODE;
154             l_error_msg     := SQLERRM;
155             x_return_status := FND_API.G_RET_STS_ERROR ;
156             FND_MESSAGE.SET_NAME('CLN','CLN_CH_UNEXPECTED_ERROR');
157             FND_MESSAGE.SET_TOKEN('ERRORCODE',l_error_code);
158             FND_MESSAGE.SET_TOKEN('ERRORMSG',l_error_msg);
159             x_msg_data      := FND_MESSAGE.GET;
160             IF (l_Debug_Level <= 6) THEN
161                     cln_debug_pub.Add('Unexpected Error:' || l_error_code || ':' || l_error_msg, 6);
162                     cln_debug_pub.Add('----------- ERROR :EXITING RAISE_UPDATE_EVENT ------------', 2);
163             END IF;
164 
165    END RAISE_UPDATE_EVENT;
166 
167 
168 
169 
170    -- Name
171    --    RAISE_ADD_MSG_EVENT
172    -- Purpose
173    --    This is the public procedure which is used to raise an event that add messages into collaboration history passing
174    --    these parameters so obtained.This procedure is called
175    --    from PROCESS_HEADER_LINES.
176    --
177    -- Arguments
178    --
179    -- Notes
180    --    No specific notes.
181 
182    PROCEDURE RAISE_ADD_MSG_EVENT(
183          x_return_status                OUT NOCOPY VARCHAR2,
184          x_msg_data                     OUT NOCOPY VARCHAR2,
185          p_coll_id                      IN  NUMBER,
186          p_ref1                         IN  VARCHAR2,
187          p_ref2                         IN  VARCHAR2,
188          p_ref3                         IN  VARCHAR2,
189          p_ref4                         IN  VARCHAR2,
190          p_ref5                         IN  VARCHAR2,
191          p_dtl_msg                      IN  VARCHAR2,
192          p_internal_control_number      IN  VARCHAR2 )
193 
194    IS
195          l_cln_ch_parameters            wf_parameter_list_t;
196          l_event_key                    NUMBER;
197          l_error_code                   NUMBER;
198          l_error_msg                    VARCHAR2(255);
199          l_debug_mode                   VARCHAR2(255);
200          l_msg_data                     VARCHAR2(255);
201 
202    BEGIN
203          -- Sets the debug mode to be FILE
204          --l_debug_mode := cln_debug_pub.Set_Debug_Mode('FILE');
205          IF (l_Debug_Level <= 2) THEN
206                  cln_debug_pub.Add('-------- ENTERING RAISE_ADD_MSG_EVENT ------------', 2);
207          END IF;
208 
209          --  Initialize API return status to success
210          x_return_status := FND_API.G_RET_STS_SUCCESS;
211          l_msg_data     := 'Add Messages successfully raised';
212 
213          FND_MESSAGE.SET_NAME('CLN','CLN_CH_EVENT_RAISED');
214          FND_MESSAGE.SET_TOKEN('EVENT','Add Messages');
215          x_msg_data := FND_MESSAGE.GET;
216 
217 
218          SELECT  cln_generic_s.nextval INTO l_event_key FROM dual;
219 
220          IF (l_Debug_Level <= 1) THEN
221                  cln_debug_pub.Add('----------- PARAMETERS OBTAINED ----------',1);
222                  cln_debug_pub.Add('Collaboration ID            ---- '||p_coll_id, 1);
223                  cln_debug_pub.Add('Reference 1                 ---- '||p_ref1,1);
224                  cln_debug_pub.Add('Reference 2                 ---- '||p_ref2,1);
225                  cln_debug_pub.Add('Reference 3                 ---- '||p_ref3,1);
229                  cln_debug_pub.Add('Internal Control Number     ---- '||p_internal_control_number, 1);
226                  cln_debug_pub.Add('Reference 4                 ---- '||p_ref4,1);
227                  cln_debug_pub.Add('Reference 5                 ---- '||p_ref5,1);
228                  cln_debug_pub.Add('Detail Message              ---- '||p_dtl_msg,1);
230                  cln_debug_pub.Add('------------------------------------------',1);
231          END IF;
232 
233 
234          l_cln_ch_parameters := wf_parameter_list_t();
235          IF (l_Debug_Level <= 1) THEN
236                  cln_debug_pub.Add('---------- SETTING WORKFLOW PARAMETERS---------', 1);
237          END IF;
238          WF_EVENT.AddParameterToList('REFERENCE_ID1',p_ref1,l_cln_ch_parameters);
239          WF_EVENT.AddParameterToList('REFERENCE_ID2',p_ref2,l_cln_ch_parameters);
240          WF_EVENT.AddParameterToList('REFERENCE_ID3',p_ref3,l_cln_ch_parameters);
241          WF_EVENT.AddParameterToList('REFERENCE_ID4',p_ref4,l_cln_ch_parameters);
242          WF_EVENT.AddParameterToList('REFERENCE_ID5',p_ref5,l_cln_ch_parameters);
243          WF_EVENT.AddParameterToList('DETAIL_MESSAGE',p_dtl_msg,l_cln_ch_parameters);
244          WF_EVENT.AddParameterToList('COLLABORATION_ID', p_coll_id, l_cln_ch_parameters);
245          WF_EVENT.AddParameterToList('DOCUMENT_TYPE', 'ACKNOWLEDGE_PO', l_cln_ch_parameters);
246          WF_EVENT.AddParameterToList('DOCUMENT_DIRECTION', 'IN', l_cln_ch_parameters);
247          WF_EVENT.AddParameterToList('COLLABORATION_POINT', 'APPS', l_cln_ch_parameters);
248          WF_EVENT.AddParameterToList('XMLG_INTERNAL_CONTROL_NUMBER',p_internal_control_number,l_cln_ch_parameters);
249          IF (l_Debug_Level <= 1) THEN
250                  cln_debug_pub.Add('----------------------------------------------', 1);
251                  cln_debug_pub.Add('Workflow event- oracle.apps.cln.ch.collaboration.addmessage', 1);
252          END IF;
253 
254          WF_EVENT.Raise('oracle.apps.cln.ch.collaboration.addmessage',l_event_key, NULL, l_cln_ch_parameters, NULL);
255          IF (l_Debug_Level <= 2) THEN
256                  cln_debug_pub.Add('--------- EXITING RAISE_ADD_MSG_EVENT -------------', 2);
257          END IF;
258 
259 
260    EXCEPTION
261          WHEN FND_API.G_EXC_ERROR THEN
262             x_return_status :=FND_API.G_RET_STS_ERROR ;
263             IF (l_Debug_Level <= 5) THEN
264                     cln_debug_pub.Add('Error:' || x_msg_data, 4);
265                     cln_debug_pub.Add('--------- ERROR :EXITING RAISE_ADD_MSG_EVENT -------------', 2);
266             END IF;
267 
268          WHEN OTHERS THEN
269             l_error_code        := SQLCODE;
270             l_error_msg         := SQLERRM;
271             x_return_status     :=FND_API.G_RET_STS_ERROR ;
272             FND_MESSAGE.SET_NAME('CLN','CLN_CH_UNEXPECTED_ERROR');
273             FND_MESSAGE.SET_TOKEN('ERRORCODE',l_error_code);
274             FND_MESSAGE.SET_TOKEN('ERRORMSG',l_error_msg);
275             x_msg_data          :=FND_MESSAGE.GET;
276             IF (l_Debug_Level <= 2) THEN
280 
277                     cln_debug_pub.Add('Error:' || l_error_code || ':' || l_error_msg, 4);
278                     cln_debug_pub.Add('--------- ERROR :EXITING RAISE_ADD_MSG_EVENT -------------', 2);
279             END IF;
281    END RAISE_ADD_MSG_EVENT;
282 
283 
284 
285 
286   -- Name
287   --   PROCESS_HEADER
288   -- Purpose
289   --    The main purpose of this procedure is to check whether the collaboration exists for
290   --    for a particular reference id or not
291   --
292   -- Arguments
293   --
294   -- Notes
295   --   No specific notes
296 
297 
298  PROCEDURE PROCESS_HEADER(
299         x_return_status             OUT NOCOPY VARCHAR2,
303         p_po_number                 IN  VARCHAR2,
300         x_msg_data                  OUT NOCOPY VARCHAR2,
301         p_ref_id                    IN  VARCHAR2,
302         p_sender_component          IN  VARCHAR2,
304         p_release_number            IN  NUMBER,
305         p_revision_number           IN  NUMBER,
306         p_ackcode_header            IN  NUMBER,
307         p_note                      IN  LONG,
308         p_requestor                 IN  VARCHAR2,
309         p_int_cont_num              IN  VARCHAR2,
310         p_request_origin            IN  VARCHAR2,
311         p_tp_header_id              IN  NUMBER,
312         p_tp_id                     OUT NOCOPY VARCHAR2,
313         p_tp_site_id                OUT NOCOPY VARCHAR2,
314         x_cln_required              OUT NOCOPY VARCHAR2,
315         x_collaboration_type        OUT NOCOPY VARCHAR2,
316         x_coll_id                   OUT NOCOPY NUMBER,
317         x_notification_code         OUT NOCOPY VARCHAR2,
318         x_notification_status       OUT NOCOPY VARCHAR2,
319         x_return_status_tp          OUT NOCOPY VARCHAR2,
320         x_call_po_apis              OUT NOCOPY VARCHAR2 )
321 
322  IS
323         l_error_code                NUMBER;
324         l_txn_id                    NUMBER;
325         l_error_msg                 VARCHAR2(255);
326         l_msg_data                  VARCHAR2(255);
327         l_debug_mode                VARCHAR2(255);
328         l_update_reqd               BOOLEAN;
329         l_action                    VARCHAR2(255);
330         l_po_type                   VARCHAR2(50);
331         l_request_type              VARCHAR2(50);
332         l_error_id                  NUMBER;
333         l_error_status              VARCHAR2(1000);
334         l_tp_id                     NUMBER;
335         l_tp_site_id                NUMBER;
336         l_call_po_apis              VARCHAR2(10);
337         l_po_ackcode                NUMBER;
338 
339  BEGIN
340 
341         -- Sets the debug mode to be FILE
342         --l_debug_mode :=cln_debug_pub.Set_Debug_Mode('FILE');
343 
344         IF (l_Debug_Level <= 1) THEN
345                 cln_debug_pub.Add('############################################################',1);
346                 cln_debug_pub.Add('###############   START OF XGM DEBUG FILE  #################',1);
347                 cln_debug_pub.Add('############################################################',1);
348         END IF;
349 
350         IF (l_Debug_Level <= 2) THEN
351                 cln_debug_pub.Add('---- Entering PROCESS_HEADER API ----- ', 2);
352         END IF;
353 
354         -- Standard Start of API savepoint
355         SAVEPOINT   CHECK_COLLABORATION_PUB;
356 
357         -- Initialize API return status to success
358         x_return_status := FND_API.G_RET_STS_SUCCESS;
359         l_msg_data      := 'ACKPO Header successfully consumed';
360         l_call_po_apis  := 'YES';
361         x_cln_required  := 'TRUE';
362 
363 
364         -- Parameters received
365         IF (l_Debug_Level <= 1) THEN
366                 cln_debug_pub.Add('----- PARAMETERS RECEIVED ------- ',1);
367                 cln_debug_pub.Add('Status received          - '||x_return_status,1);
368                 cln_debug_pub.Add('Message received         - '||x_msg_data,1);
369                 cln_debug_pub.Add('Reference ID             - '||p_ref_id,1);
370                 cln_debug_pub.Add('Sender Component         - '||p_sender_component,1);
371                 cln_debug_pub.Add('PO Number                - '||p_po_number,1);
372                 cln_debug_pub.Add('Release Number           - '||p_release_number,1);
373                 cln_debug_pub.Add('Revision Number          - '||p_revision_number,1);
374                 cln_debug_pub.Add('Ackcode at header level  - '||p_ackcode_header,1);
375                 cln_debug_pub.Add('Note                     - '||p_note,1);
376                 cln_debug_pub.Add('CLN reqd                 - '||x_cln_required,1);
377                 cln_debug_pub.Add('p_tp_header_id           - '|| p_tp_header_id, 1);
378                 cln_debug_pub.Add('Requestor                - '||p_requestor,1);
379                 cln_debug_pub.Add('Internal Ctrl Number     - '||p_int_cont_num,1);
380                 cln_debug_pub.Add('Request Origin           - '||p_request_origin,1);
381                 cln_debug_pub.Add('----------------------------------',1);
382         END IF;
383 
384         l_line_num_tab.delete;-- Initialize array of PO lines
385 
386 
387         -- Check whether collaboration can be created/upadted based on Profile, Protocol value
388         CLN_CH_COLLABORATION_PKG.IS_UPDATE_REQUIRED(
389             x_return_status             =>        x_return_status,
390             x_msg_data                  =>        x_msg_data,
391             p_doc_dir                   =>        'IN',
392             p_xmlg_transaction_type     =>        null,
393             p_xmlg_transaction_subtype  =>        null,
394             p_tr_partner_type           =>        null,
395             p_tr_partner_id             =>        null,
396             p_tr_partner_site           =>        null,
397             p_sender_component          =>        p_sender_component,
398             x_update_reqd               =>        l_update_reqd);
399 
400         IF (x_return_status <> 'S') THEN
401              FND_MESSAGE.SET_NAME('CLN','CLN_CH_REQD_CRITERIA_FAIL');
402              x_msg_data         := FND_MESSAGE.GET;
403              l_msg_data         :='Failed to verify the required criteria for updating/creating.collaboration';
404              x_coll_id          :=null;
405              x_cln_required     :='FALSE';
406              RAISE FND_API.G_EXC_ERROR;
407         ELSE
408              IF (l_update_reqd <> TRUE) THEN
409                 x_cln_required  := 'FALSE';
410                 x_coll_id       :=  null;
411              END IF;
412         END IF;
413 
417                         cln_debug_pub.Add('Defaulting Collaboration Type to ACKNOWLEDGE_PO',1);
414         IF (x_cln_required <>'TRUE')THEN
415                 IF (l_Debug_Level <= 1) THEN
416                         cln_debug_pub.Add('CLN history need not be updated',1);
418                 END IF;
419                 x_collaboration_type    :=      'ACKNOWLEDGE_PO';
420         END IF;
421         -- Getting Collaboration ID for the Application Refernce ID
422         IF (x_cln_required = 'TRUE')THEN
423                 IF p_ref_id IS NULL THEN
424                      IF (l_Debug_Level <= 1) THEN
425                              cln_debug_pub.Add('Application Reference ID is null',1);
426                      END IF;
427                      FND_MESSAGE.SET_NAME('CLN','CLN_CH_PARAM_NULL');
428                      FND_MESSAGE.SET_TOKEN('PARAM','Application reference ID');
429                      x_coll_id       :=  null;
430                      x_msg_data      := FND_MESSAGE.GET;
431                      l_msg_data      :='Application reference ID is null';
432                      RAISE FND_API.G_EXC_ERROR;
433                 END IF;
434 
435                 IF (l_Debug_Level <= 1) THEN
436                         cln_debug_pub.Add('Application Reference ID is not null',1);
437                 END IF;
438 
439                 BEGIN
440                      SELECT COLLABORATION_ID,COLLABORATION_TYPE
441                      INTO x_coll_id,x_collaboration_type
442                      FROM CLN_COLL_HIST_HDR
443                      WHERE APPLICATION_REFERENCE_ID     =      p_ref_id;
444                 EXCEPTION
445                      WHEN NO_DATA_FOUND THEN
446                          FND_MESSAGE.SET_NAME('CLN','CLN_CH_REFID_NOT_FOUND');
447                          FND_MESSAGE.SET_TOKEN('PARAM','Application reference ID');
448                          FND_MESSAGE.SET_TOKEN('REFID',p_ref_id);
449                          x_msg_data   := FND_MESSAGE.GET;
450                          x_coll_id       :=  null;
451                          l_msg_data   :='Collaboration Not Found For Application reference ID :'||p_ref_id;
452                       RAISE FND_API.G_EXC_ERROR;
453                 END;
454                 IF (l_Debug_Level <= 1) THEN
455                         cln_debug_pub.Add('Collaboration ID retrieved as   : '||x_coll_id,1);
456                         cln_debug_pub.Add('Collaboration Type retrieved as : '||x_collaboration_type,1);
457                 END IF;
458         END IF;
459 
460 
461         IF (l_Debug_Level <= 1) THEN
462                 cln_debug_pub.Add('Getting Trading partner details using TP_HEADER_ID',1);
463         END IF;
464 
465         BEGIN
466              SELECT  PARTY_ID, PARTY_SITE_ID
467              INTO    l_tp_id, l_tp_site_id
468              FROM    ECX_TP_HEADERS
469              WHERE   TP_HEADER_ID = p_tp_header_id;
470         EXCEPTION
471              WHEN NO_DATA_FOUND THEN
472                  IF (l_Debug_Level <= 2) THEN
473                          cln_debug_pub.Add('TP details not found for the TP Header ID = '||p_tp_header_id,2);
474                  END IF;
475         END;
476 
477         IF (l_Debug_Level <= 2) THEN
478                 cln_debug_pub.Add('Trading Partner ID       - '||l_tp_id,1);
479                 cln_debug_pub.Add('Trading Partner Site ID  - '||l_tp_site_id,1);
480         END IF;
481 
482         p_tp_id                 := l_tp_id;
483         p_tp_site_id            := l_tp_site_id;
484 
485         IF (x_collaboration_type = 'CANCEL_ORDER' OR x_collaboration_type = 'SUPP_CHANGE_ORDER') THEN
486                 l_call_po_apis  := 'NO';
487                 IF (l_Debug_Level <= 2) THEN
488                         cln_debug_pub.Add('PO APIs should not be called....',1);
489                 END IF;
490         END IF;
491 
492 
493         IF (l_call_po_apis = 'YES') THEN
494                 IF (l_Debug_Level <= 2) THEN
495                         cln_debug_pub.Add('--- Calling PO_CHG_REQUEST_GRP.initialize_chn_ack_inbound ----- ',1);
496                 END IF;
497                 PO_CHG_REQUEST_GRP.initialize_chn_ack_inbound (
498                         p_requestor             => p_requestor,
499                         p_int_cont_num          => p_int_cont_num,
500                         p_request_origin        => p_request_origin,
501                         p_tp_id                 => l_tp_id,
502                         p_tp_site_id            => l_tp_site_id,
503                         x_error_id              => l_error_id,
504                         x_error_status          => l_error_status);
505 
506                 IF (l_Debug_Level <= 2) THEN
507                         cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
508                         cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
509                 END IF;
510 
511                 -- If initialize_chn_ack_inbound errored out
512                 IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
513                      x_msg_data  :=   l_error_status;
514                      l_msg_data  :=   l_error_status;
515                      RAISE FND_API.G_EXC_ERROR;
516                 END IF;
517                 IF (l_Debug_Level <= 2) THEN
518                         cln_debug_pub.Add('PO_CHG_REQUEST_GRP.initialize_chn_ack_inbound returned Success',1);
519                 END IF;
520          END IF;
521 
522         l_action := x_collaboration_type;
523 
524         IF (x_collaboration_type <>  'ACKNOWLEDGE_PO') THEN
525                 BEGIN
526                         IF((p_ackcode_header = 1) and (x_collaboration_type <> 'ORDER')) OR (p_ackcode_header not in (0,1,2,3)) THEN
527                             FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_INVALID_TAG_VALUE');
528                             FND_MESSAGE.SET_TOKEN('TAG','ACKHEADER/ACKCODE');
532                         END IF;
529                             x_msg_data  :=FND_MESSAGE.GET;
530                             l_msg_data  :='Invalid value for ACKHEADER/ACKCODE tag.';
531                             RAISE FND_API.G_EXC_ERROR;
533 
534                         SELECT meaning INTO l_action FROM fnd_lookups
535                         WHERE lookup_code = x_collaboration_type AND lookup_type = 'CLN_COLLABORATION_TYPE';
536                         cln_debug_pub.Add('Collaboration Type found as  - '||l_action,1);
537 
538                 EXCEPTION
539                         WHEN NO_DATA_FOUND THEN
540                              l_msg_data := 'Collaboration Type not found for the lookup_code as ORDER and lookup_type as CLN_COLLABORATION_TYPE ';
541                              FND_MESSAGE.SET_NAME('CLN','CLN_CH_COLLABORATION_TYPE_NOT');
542                              FND_MESSAGE.SET_TOKEN('TYPE','CLN_COLLABORATION_TYPE');
543                              FND_MESSAGE.SET_TOKEN('CODE',l_action);
544                              x_msg_data := FND_MESSAGE.GET;
548                 l_action := 'Acknowledge PO';
545                              RAISE FND_API.G_EXC_ERROR;
546                 END;
547         ELSE
549         END IF;
550 
551         IF (l_Debug_Level <= 2) THEN
552                 cln_debug_pub.Add('Action is set as                : '||l_action,1);
553                 cln_debug_pub.Add('Return status is                : '||x_return_status,1);
554         END IF;
555 
556         -- get the sequence number for Transaction id.
557         select  cln_generic_s.NEXTVAL INTO l_txn_id FROM DUAL;
558         IF (l_Debug_Level <= 2) THEN
559                 cln_debug_pub.Add('Transaction ID                  :' || l_txn_id, 1);
560         END IF;
561 
562         -- Find the Request Type
563         IF p_ackcode_header = 1 THEN
564              l_request_type := 'CHANGE';
565         ELSE
566              l_request_type := 'ACKNOWLEDGE';
567         END IF;
568         IF (l_Debug_Level <= 2) THEN
569                 cln_debug_pub.Add('PO Request Type is              : ' || l_request_type,1);
570         END IF;
571 
572         -- Identify PO Type based on release number
573         l_po_type := 'STANDARD';
574 
575         IF (p_release_number IS NOT NULL AND p_release_number > 0) THEN
576              l_po_type := 'RELEASE';
577         END IF;
578         IF (l_Debug_Level <= 2) THEN
579                 cln_debug_pub.Add('PO Type is                      : ' || l_po_type,1);
580                 cln_debug_pub.Add('--- Calling PO_CHG_REQUEST_GRP.validate_header ----- ',1);
581         END IF;
582 
583 
584         IF (l_call_po_apis = 'YES') THEN
585             -- should not be called for 3A9 and 3A7 Response
586             PO_CHG_REQUEST_GRP.validate_header (
587                p_requestor               => p_requestor,
588                p_int_cont_num            => p_int_cont_num,
589                p_request_origin          => p_request_origin,
590                p_request_type            => l_request_type,
591                p_tp_id                   => l_tp_id,
592                p_tp_site_id              => l_tp_site_id,
593                p_po_number               => p_po_number,
594                p_release_number          => p_release_number,
595                p_po_type                 => l_po_type,
596                -- Should not pass revision number
597                p_revision_num            => NULL,
598                x_error_id_in             => l_error_id,
599                x_error_status_in         => l_error_status,
600                x_error_id_out            => l_error_id,
601                x_error_status_out        => l_error_status);
602 
603             IF (l_Debug_Level <= 2) THEN
604                     cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
605                     cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
606             END IF;
607 
608             -- If validate header errored out
609             IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
610                 x_msg_data  :=   l_error_status;
611                 l_msg_data  :=   l_error_status;
612                 RAISE FND_API.G_EXC_ERROR;
613             END IF;
614             IF (l_Debug_Level <= 2) THEN
615                     cln_debug_pub.Add('PO_CHG_REQUEST_GRP.validate_header returned Success',1);
616             END IF;
617         END IF;
618 
619         IF (l_call_po_apis = 'YES') THEN  -- should not be called for 3A9 and 3A8 Response
620             IF (l_request_type = 'ACKNOWLEDGE') THEN
621                     IF (l_Debug_Level <= 2) THEN
622                             cln_debug_pub.Add('--- Calling PO_CHG_REQUEST_GRP.acknowledge_po ----- ',1);
623                     END IF;
624                     IF p_ackcode_header = 3 THEN    --If pending treat it as accept
625                        l_po_ackcode := 0;
626                     ELSE
630                          p_requestor            => p_requestor,     -- Change requester or the acknowledging username
627                        l_po_ackcode := p_ackcode_header;
628                     END IF;
629                     PO_CHG_REQUEST_GRP.acknowledge_po(
631                          p_int_cont_num         => p_int_cont_num,  -- ECX's ICN. Used for integrity of request
632                          p_request_type         => 'ACKNOWLEDGE',  -- ??'ACKNOWLEDGE'
633                          p_tp_id                => l_tp_id,         -- vendor_id
634                          p_tp_site_id           => l_tp_site_id,    -- vendor_site_id
635                          p_po_number            => p_po_number,     -- PO # of the PO being modified or the Blanket's PO #
636                          p_release_number       => p_release_number,-- Release number if the PO Type is release or null
637                          p_po_type              => l_po_type,       -- PO Type??  -- RELEASE for release, STANDARD for others.
638                          p_revision_num         => NULL,            -- Revision number of the PO or the release
639                          p_ack_code             => l_po_ackcode,    -- 0 for accept/peding and 2 reject
640                          p_ack_reason           => p_note,          --  comments
641                          x_error_id             => l_error_id,      -- The error id will be 2, errors will go to the TP sysadmin
642                          x_error_status         => l_error_status   -- Error message
643                      );
644 
645                      IF (l_Debug_Level <= 2) THEN
646                              cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
647                              cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
648                      END IF;
649 
650                      IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
651                          x_msg_data  :=   l_error_status;
652                          l_msg_data  :=   l_error_status;
653                          RAISE FND_API.G_EXC_ERROR;
654                      END IF;
655 
656                 END IF;
657         END IF;
658 
659         IF (p_ackcode_header = 0) or (p_ackcode_header = 3) THEN -- Pending is treated as accepted
660                 x_notification_code   := 'ACKPO_01';
661         ELSIF (p_ackcode_header = 1) THEN
662                 x_notification_code   := 'ACKPO_03';
663         ELSIF (p_ackcode_header = 2) THEN
664                 x_notification_code   := 'ACKPO_02';
665         END IF;
666 
667         x_notification_status := 'SUCCESS';
668         x_return_status_tp    := '00';
669         x_call_po_apis        :=  l_call_po_apis;
670 
671         IF (l_Debug_Level <= 2) THEN
672                 cln_debug_pub.Add('Notification Code set as     :'||x_notification_code,1);
673                 cln_debug_pub.Add('Notification Status set as   :'||x_notification_status,1);
674                 cln_debug_pub.Add('Return Status set as         :'||x_notification_code,1);
675         END IF;
676 
677         IF (l_Debug_Level <= 2) THEN
678                 cln_debug_pub.Add('---- Exiting PROCESS_HEADER API ----- ', 2);
679         END IF;
680 
681  -- Exception Handling
682  EXCEPTION
683 
684         WHEN FND_API.G_EXC_ERROR THEN
685              x_return_status    := FND_API.G_RET_STS_ERROR ;
689              FND_MESSAGE.SET_TOKEN('REVNUM',p_revision_number);
686              FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_ERROR');
687              FND_MESSAGE.SET_TOKEN('PONUM',p_po_number);
688              FND_MESSAGE.SET_TOKEN('RELNUM',p_release_number);
690              FND_MESSAGE.SET_TOKEN('MSG',x_msg_data);
691              x_msg_data         := FND_MESSAGE.GET;
692              x_call_po_apis     := 'NO';
693 
694              IF (l_Debug_Level <= 5) THEN
695                      cln_debug_pub.Add(l_msg_data,4);
696                      cln_debug_pub.Add('---- ERROR :Exiting PROCESS_HEADER  API ----- ', 2);
697              END IF;
698 
699 
700         WHEN OTHERS THEN
701              l_error_code       :=SQLCODE;
702              l_error_msg        :=SQLERRM;
703              x_return_status    :=FND_API.G_RET_STS_UNEXP_ERROR ;
704              FND_MESSAGE.SET_NAME('CLN','CLN_CH_UNEXPECTED_ERROR');
705              FND_MESSAGE.SET_TOKEN('ERRORCODE',l_error_code);
706              FND_MESSAGE.SET_TOKEN('ERRORMSG',l_error_msg);
707              x_msg_data         :=FND_MESSAGE.GET;
708              x_call_po_apis     := 'NO';
709 
710              FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_ERROR');
711              FND_MESSAGE.SET_TOKEN('PONUM',p_po_number);
712              FND_MESSAGE.SET_TOKEN('RELNUM',p_release_number);
713              FND_MESSAGE.SET_TOKEN('REVNUM',p_revision_number);
714              FND_MESSAGE.SET_TOKEN('MSG',x_msg_data);
715              x_msg_data         := FND_MESSAGE.GET;
716              l_msg_data         :='Unexpected Error -'||l_error_code||' : '||l_error_msg;
717              IF (l_Debug_Level <= 5) THEN
718                      cln_debug_pub.Add(l_msg_data,6);
719                      cln_debug_pub.Add('---- ERROR :Exiting PROCESS_HEADER API ----- ', 2);
720              END IF;
721 
722  END PROCESS_HEADER;
723 
724 
725 
726 
727     -- Name
728     --   PROCESS_HEADER_LINES
729     -- Purpose
730     --   The main purpose of this procedure is to provide a sequence of actions that
731     --   need to be taken to consume the Acknowledgement depending upon the ACKCODE
732     --   value at the header level and on the Collaboration Type.
733     -- Arguments
734     --
735     -- Notes
736     --   No specific notes.
737 
738   PROCEDURE PROCESS_HEADER_LINES(
739          x_return_status             IN OUT NOCOPY VARCHAR2,
740          x_msg_data                  IN OUT NOCOPY VARCHAR2,
741          p_requestor                 IN VARCHAR2,
742          p_po_number                 IN VARCHAR2,
743          p_release_number            IN NUMBER,
744          p_revision_number           IN NUMBER,
745          p_line_number               IN NUMBER,
746          p_previous_line_number      IN OUT NOCOPY NUMBER,
747          p_shipment_number           IN NUMBER,
748          p_new_quantity              IN NUMBER,
749          p_po_quantity_uom           IN VARCHAR2,
750          p_po_price_currency         IN VARCHAR2,
751          p_po_price_uom              IN VARCHAR2,
752          p_new_price                 IN NUMBER,
753          p_ackcode_header            IN NUMBER,
754          p_ackcode_line              IN NUMBER,
755          p_coll_id                   IN NUMBER,
756          p_new_promised_date         IN DATE,
757          p_collaboration_type        IN VARCHAR2,
758          p_org_ref                   IN VARCHAR2,
759          p_cln_required              IN VARCHAR2,
760          p_internal_control_number   IN VARCHAR2,
761          p_supplier_part_number      IN VARCHAR2,
762          p_so_num                    IN VARCHAR2,
763          p_so_line_num               IN NUMBER,
764          p_so_line_status            IN VARCHAR2,
765          p_reason                    IN VARCHAR2,
766          p_tp_id                     IN VARCHAR2,
767          p_tp_site_id                IN VARCHAR2,
768          p_msg_dtl_screen            IN OUT NOCOPY VARCHAR2,
769          p_msg_txt_lines             IN OUT NOCOPY VARCHAR2,
770          p_if_collaboration_updated  IN OUT NOCOPY VARCHAR2,
771          -- Additional parameters added for new Change_PO API to
772          -- support split lines and cancellation at header and schedule level.
773          p_supp_doc_ref              IN VARCHAR2 DEFAULT NULL,
774          p_supp_line_ref             IN VARCHAR2 DEFAULT NULL,
775          p_supplier_shipment_ref     IN VARCHAR2 DEFAULT NULL,
776          p_parent_shipment_number    IN VARCHAR2 DEFAULT NULL)
777   IS
778          l_error_code                NUMBER;
779          l_error_msg                 VARCHAR2(255);
780          l_msg_data                  VARCHAR2(255);
781          l_debug_mode                VARCHAR2(255);
782          l_return_code               NUMBER;
783          l_return_status             VARCHAR2(255);
784          l_msg_txt_lines             VARCHAR2(2000);
785          l_disposition               VARCHAR2(255);
786          l_return_status_tp          VARCHAR2(255);
787          l_dtl_status                VARCHAR2(255);
788          l_txn_id                    NUMBER;
789          l_po_type                   VARCHAR2(50);
790          l_error_id                  NUMBER;
791          l_error_status              VARCHAR2(1000);
792 
793 
794   BEGIN
795 
796          -- Sets the debug mode to be FILE
797          --l_debug_mode           := cln_debug_pub.Set_Debug_Mode('FILE');
798 
799          IF (l_Debug_Level <= 2) THEN
800                  cln_debug_pub.Add('----- Entering PROCESS_HEADER_LINES API ------- ',2);
801          END IF;
802 
803          l_msg_txt_lines        := p_msg_txt_lines;
804 
805          IF(p_ackcode_header = 0) THEN
809          ELSIF(p_ackcode_header = 2) THEN
806             l_disposition            := 'ACCEPTED';
807          ELSIF (p_ackcode_header = 1) THEN
808             l_disposition            := 'ACCEPTED';
810             l_disposition            := 'REJECTED';
811          ELSIF (p_ackcode_header = 3) THEN
812             l_disposition            := 'PENDING';
813          END IF;
814 
815          l_msg_data     := 'ACKPO successfully consumed for PO : '||p_po_number||' with Line : '||p_line_number;
816 
817          -- Parameters received
818          IF (l_Debug_Level <= 1) THEN
819                  cln_debug_pub.Add('----- PARAMETERS RECEIVED ------- ',1);
820                  cln_debug_pub.Add('Status received          - '||x_return_status,1);
821                  cln_debug_pub.Add('Message received         - '||x_msg_data,1);
822                  cln_debug_pub.Add('PO Number                - '||p_po_number,1);
823                  cln_debug_pub.Add('Release Number           - '||p_release_number,1);
824                  cln_debug_pub.Add('Revision Number          - '||p_revision_number,1);
825                  cln_debug_pub.Add('Previous Line  Number    - '||p_previous_line_number,1);
826                  cln_debug_pub.Add('Line  Number             - '||p_line_number,1);
827                  cln_debug_pub.Add('Shipment Number          - '||p_shipment_number,1);
828                  cln_debug_pub.Add('New Quantity             - '||p_new_quantity,1);
829                  cln_debug_pub.Add('New Price                - '||p_new_price,1);
830                  cln_debug_pub.Add('Promised Date            - '||p_new_promised_date,1);
831                  cln_debug_pub.Add('Ackcode at header level  - '||p_ackcode_header,1);
832                  cln_debug_pub.Add('Ackcode at line level    - '||p_ackcode_line,1);
833                  cln_debug_pub.Add('Collaboration Type       - '||p_collaboration_type,1);
834                  cln_debug_pub.Add('Originator Reference     - '||p_org_ref,1);
835                  cln_debug_pub.Add('Collaboration ID         - '||p_coll_id,1);
836                  cln_debug_pub.Add('Detail Header Message    - '||p_msg_dtl_screen,1);
837                  cln_debug_pub.Add('Detail Line Message      - '||p_msg_txt_lines,1);
838                  cln_debug_pub.Add('Internal Control Number  - '||p_internal_control_number,1);
839                  cln_debug_pub.Add('Collaboration Updated    - '||p_if_collaboration_updated,1);
840                  cln_debug_pub.Add('Disposition              - '||l_disposition,1);
841                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
842                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
843                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
844                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
845                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
846                  cln_debug_pub.Add('----------------------------------',1);
847          END IF;
848 
849          -- get the sequence number for Transaction id.
850          select  cln_generic_s.NEXTVAL INTO l_txn_id FROM DUAL;
851          IF (l_Debug_Level <= 1) THEN
852                  cln_debug_pub.Add('Transaction ID:' || l_txn_id, 1);
853          END IF;
854 
855          -- Identify PO Type based on release number
856 
857          l_po_type := 'STANDARD';
858 
859          IF (p_release_number IS NOT NULL AND p_release_number > 0) THEN
860              l_po_type := 'RELEASE';
861          END IF;
862          cln_debug_pub.Add('PO Type is           : ' || l_po_type,1);
863 
864 
865          IF((p_ackcode_header = 1 and p_ackcode_line = 1) AND ((p_collaboration_type = 'ORDER') or (p_collaboration_type = 'ACKNOWLEDGE_PO'))) THEN
866                 IF l_po_type = 'RELEASE' THEN
867                     IF (l_Debug_Level <= 1) THEN
868                             cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.store_supplier_request API For PO Release',1);
869                     END IF;
870                     PO_CHG_REQUEST_GRP.store_supplier_request (
871                           p_requestor         => p_requestor,
872                           p_int_cont_num      => p_internal_control_number,
873                           p_request_type      => 'CHANGE',
874                           p_tp_id             => p_tp_id,
875                           p_tp_site_id        => p_tp_site_id,
876                           p_level             => 'SHIPMENT',
877                           p_po_number         => p_po_number,
878                           p_release_number    => p_release_number,
879                           p_po_type           => 'RELEASE',
880                           -- Should not pass revision nmumber, it keeps changing
881                           p_revision_num      => NULL,
882                           p_line_num          => p_line_number,
883                           p_reason            => p_reason,
884                           p_shipment_num      => p_shipment_number,
885                           p_quantity          => p_new_quantity,
886                           p_quantity_uom      => p_po_quantity_uom,
887                           p_price             => p_new_price,
888                           p_price_currency    => p_po_price_currency,
889                           p_price_uom         => p_po_price_uom,
890                           p_promised_date     => p_new_promised_date,
891                           p_supplier_part_num => p_supplier_part_number,
892                           p_so_number         => p_so_num,
893                           p_so_line_number    => p_so_line_num,
894                           p_ack_type          => 'MODIFICATION',
895                           x_error_id_in       => l_error_id,
896                           x_error_status_in   => l_error_status,
897                           x_error_id_out      => l_error_id,
898                           x_error_status_out  => l_error_status/*,
899                           -- Supplier Line Reference added for new Change_PO API to
903                           p_supplier_line_ref => p_supp_line_ref,
900                           -- support split lines and cancellation at header and schedule level.
901                           p_parent_shipment_number  => p_parent_shipment_number,
902                           p_supplier_doc_ref  => p_supp_doc_ref,
904                           p_supplier_shipment_ref => p_supplier_shipment_ref*/);
905 
906 
907 
908                       IF (l_Debug_Level <= 1) THEN
909                               cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
910                       END IF;
911                       IF (l_Debug_Level <= 1) THEN
912                               cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
913                       END IF;
914 
915                       IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
916                          x_msg_data  :=   l_error_status;
917                          l_msg_data  :=   l_error_status;
918                          RAISE FND_API.G_EXC_ERROR;
919                       END IF;
920 
921                 ELSE
922 
923                     IF (l_Debug_Level <= 1) THEN
924                             cln_debug_pub.Add('Previous and new line number are not same..',1);
925                     END IF;
926                     IF (p_previous_line_number <> p_line_number) THEN
927                         IF (l_Debug_Level <= 1) THEN
928                                 cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.store_supplier_request API For Standard PO',1);
929                                 cln_debug_pub.Add('Call is at Line Level......',1);
930                         END IF;
931                         p_previous_line_number          :=  p_line_number;
932 
933                         IF IS_ALREADY_PROCESSED_LINE(p_line_number) THEN
934                               -- Nothing to do since the changes happens only once per each po line
935                               -- Collaboration history too is not updated
936                               IF (l_Debug_Level <= 1) THEN
937                                       cln_debug_pub.Add('Since this an already processed line, Nothing to do', 1);
938                               END IF;
939                               RETURN;
940                         END IF;
941 
942                         IF l_error_id IS NULL OR l_error_id = 0 THEN
943                            PO_CHG_REQUEST_GRP.store_supplier_request (
944                                   p_requestor         => p_requestor,
945                                   p_int_cont_num      => p_internal_control_number,
946                                   p_request_type      => 'CHANGE',
947                                   p_tp_id             => p_tp_id,
948                                   p_tp_site_id        => p_tp_site_id,
949                                   p_level             => 'LINE',
950                                   p_po_number         => p_po_number,
951                                   p_release_number    => p_release_number,
952                                   p_po_type           => 'STANDARD',
953                                   p_revision_num      => NULL,
954                                   p_line_num          => p_line_number,
955                                   p_reason            => p_reason,
956                                   p_shipment_num      => p_shipment_number,
957                                   p_quantity          => NULL,
958                                   p_quantity_uom      => NULL,
959                                   p_price             => p_new_price,
960                                   p_price_currency    => p_po_price_currency,
961                                   p_price_uom         => p_po_price_uom,
962                                   p_promised_date     => NULL,
963                                   p_supplier_part_num => p_supplier_part_number,
964                                   p_so_number         => p_so_num,
965                                   p_so_line_number    => p_so_line_num,
966                                   p_ack_type          => 'MODIFICATION',
967                                   x_error_id_in       => l_error_id,
968                                   x_error_status_in   => l_error_status,
969                                   x_error_id_out      => l_error_id,
970                                   x_error_status_out  => l_error_status/*,
971                                   -- Supplier Line Reference added for new Change_PO API to
972                                   -- support split lines and cancellation at header and schedule level.
973                                   p_parent_shipment_number  => p_parent_shipment_number,
974                                   p_supplier_doc_ref  => p_supp_doc_ref,
975                                   p_supplier_line_ref => p_supp_line_ref,
976                                   p_supplier_shipment_ref => p_supplier_shipment_ref*/);
977 
978 
979                             IF (l_Debug_Level <= 1) THEN
980                                     cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
981                                     cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
982                             END IF;
983                          END IF;
984                      END IF;
985 
986                     IF (l_Debug_Level <= 1) THEN
987                             cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.store_supplier_request API For Standard PO',1);
988                             cln_debug_pub.Add('Call is at Shipment Line Level......',1);
989                     END IF;
990                     PO_CHG_REQUEST_GRP.store_supplier_request (
991                           p_requestor         => p_requestor,
992                           p_int_cont_num      => p_internal_control_number,
993                           p_request_type      => 'CHANGE',
994                           p_tp_id             => p_tp_id,
995                           p_tp_site_id        => p_tp_site_id,
996                           p_level             => 'SHIPMENT',
1000                           p_revision_num      => NULL,
997                           p_po_number         => p_po_number,
998                           p_release_number    => p_release_number,
999                           p_po_type           => 'STANDARD',
1001                           p_line_num          => p_line_number,
1002                           p_reason            => p_reason,
1003                           p_shipment_num      => p_shipment_number,
1004                           p_quantity          => p_new_quantity,
1005                           p_quantity_uom      => p_po_quantity_uom,
1006                           p_price             => NULL,
1007                           p_price_currency    => NULL,
1008                           p_price_uom         => NULL,
1009                           p_promised_date     => p_new_promised_date,
1010                           p_supplier_part_num => p_supplier_part_number,
1011                           p_so_number         => p_so_num,
1012                           p_so_line_number    => p_so_line_num,
1013                           p_ack_type          => 'MODIFICATION',
1014                           x_error_id_in       => l_error_id,
1015                           x_error_status_in   => l_error_status,
1016                           x_error_id_out      => l_error_id,
1017                           x_error_status_out  => l_error_status/*,
1018                           -- Supplier Line Reference added for new Change_PO API to
1019                           -- support split lines and cancellation at header and schedule level.
1020                           p_parent_shipment_number  => p_parent_shipment_number,
1021                           p_supplier_doc_ref  => p_supp_doc_ref,
1022                           p_supplier_line_ref => p_supp_line_ref,
1023                           p_supplier_shipment_ref => p_supplier_shipment_ref*/);
1024 
1025 
1026                     IF (l_Debug_Level <= 1) THEN
1027                             cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
1028                             cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
1029                     END IF;
1030 
1031                     IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
1032                          x_msg_data  :=   l_error_status;
1033                          l_msg_data  :=   l_error_status;
1034                          RAISE FND_API.G_EXC_ERROR;
1035                     END IF;
1036 
1037                 END IF;
1038 
1039                 IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
1040                      x_msg_data  :=   l_error_status;
1041                      l_msg_data  :=   l_error_status;
1042                      RAISE FND_API.G_EXC_ERROR;
1043                 END IF;
1044 
1045     /*
1046                 IF l_error_id IS NULL OR l_error_id = 0 THEN
1047                     cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.process_supplier_request API',1);
1048 
1049                     PO_CHG_REQUEST_GRP.process_supplier_request (
1050                        p_int_cont_num      => p_internal_control_number,
1051                        x_error_id_in       => l_error_id,
1052                        x_error_status_in   => l_error_status,
1053                        x_error_id_out      => l_error_id,
1054                        x_error_status_out  => l_error_status
1055                     );
1056 
1057                     cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
1058                     cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
1059                 END IF;
1060      */
1061          END IF;
1062 
1063          IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
1064                x_msg_data  :=   l_error_status;
1065                l_msg_data  :=   l_error_status;
1066                RAISE FND_API.G_EXC_ERROR;
1067          END IF;
1068 
1069 
1070         IF ((p_cln_required = 'TRUE') AND (p_if_collaboration_updated = 'FALSE'))THEN
1071                 IF (l_Debug_Level <= 1) THEN
1072                         cln_debug_pub.Add('Call to Raise Update Event.....',1);
1073                 END IF;
1074                 RAISE_UPDATE_EVENT(
1075                       x_return_status                => x_return_status,
1076                       x_msg_data                     => x_msg_data,
1077                       p_coll_id                      => p_coll_id,
1078                       p_doc_status                   => 'SUCCESS',
1079                       p_org_ref                      => p_org_ref,
1080                       p_disposition                  => l_disposition,
1081                       p_msg_text                     => p_msg_dtl_screen,
1082                       p_internal_control_number      => p_internal_control_number );
1083 
1084                  IF(x_return_status <> 'S')THEN
1085                          p_if_collaboration_updated  := 'ERROR';
1086                          l_msg_data := 'Error in RAISE_UPDATE_EVENT API';
1087                          RAISE FND_API.G_EXC_ERROR;
1088                  END IF;
1089                  p_if_collaboration_updated      :=  'TRUE';
1090         END IF;
1091 
1092         IF(p_cln_required = 'TRUE') THEN
1093                  IF p_ackcode_line = 0 THEN
1094                         l_dtl_status          := 'Accepted';
1095                  ELSIF p_ackcode_line = 1 THEN
1096                         l_dtl_status          := 'Accepted With Changes';
1097                  ELSIF p_ackcode_line = 2 THEN
1098                         l_dtl_status          := 'Rejected';
1099                  ELSIF p_ackcode_line = 3 THEN
1100                         l_dtl_status          := 'Pending';
1101                  END IF;
1102 
1103                  IF (l_Debug_Level <= 1) THEN
1104                          cln_debug_pub.Add('Call to Raise Message Event.....',1);
1105                  END IF;
1106                  RAISE_ADD_MSG_EVENT(
1107                          x_return_status        => x_return_status,
1111                          p_ref2                 => p_line_number,
1108                          x_msg_data             => x_msg_data,
1109                          p_coll_id              => p_coll_id,
1110                          p_ref1                 => l_dtl_status,
1112                          p_ref3                 => p_shipment_number,
1113                          p_ref4                 => p_org_ref,
1114                          p_ref5                 => null,
1115                          p_dtl_msg              => l_msg_txt_lines,
1116                          p_internal_control_number      => p_internal_control_number );
1117 
1118                  IF(x_return_status <> 'S')THEN
1119                          p_if_collaboration_updated  := 'ERROR';
1120                          l_msg_data := 'Error in RAISE_ADD_MSG_EVENT API';
1121                          RAISE FND_API.G_EXC_ERROR;
1122                  END IF;
1123 
1124                  FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_CONSUMED');
1125                  FND_MESSAGE.SET_TOKEN('PONUM',p_po_number);
1126                  x_msg_data           :=  FND_MESSAGE.GET;
1127         END IF;
1128 
1129         --p_msg_dtl_screen              :=  NULL;
1130         p_msg_txt_lines                 :=  NULL;
1131         x_return_status                 :=  FND_API.G_RET_STS_SUCCESS;
1132 
1133         IF (l_Debug_Level <= 1) THEN
1134                 cln_debug_pub.Add(l_msg_data,1);
1135         END IF;
1136         IF (l_Debug_Level <= 2) THEN
1137                 cln_debug_pub.Add('------- Exiting PROCESS_HEADER_LINES API --------- ',2);
1138         END IF;
1139 
1140   -- Exception Handling
1141   EXCEPTION
1142 
1143          WHEN FND_API.G_EXC_ERROR THEN
1144               x_return_status           := FND_API.G_RET_STS_ERROR ;
1145               FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_ERROR');
1146               FND_MESSAGE.SET_TOKEN('PONUM',p_po_number);
1147               FND_MESSAGE.SET_TOKEN('RELNUM',p_release_number);
1148               FND_MESSAGE.SET_TOKEN('REVNUM',p_revision_number);
1149               FND_MESSAGE.SET_TOKEN('MSG',x_msg_data);
1150               x_msg_data         := FND_MESSAGE.GET;
1151               IF (l_Debug_Level <= 5) THEN
1152                       cln_debug_pub.Add(l_msg_data,4);
1153                       cln_debug_pub.Add('------- ERROR :Exiting PROCESS_HEADER_LINES API --------- ',2);
1154               END IF;
1155 
1156 
1157          WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1158               l_error_code              :=SQLCODE;
1159               l_error_msg               :=SQLERRM;
1160               x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
1161               l_msg_data                :=l_error_code||' : '||l_error_msg;
1162               IF (l_Debug_Level <= 5) THEN
1163                       cln_debug_pub.Add(l_msg_data,6);
1164                       cln_debug_pub.Add('------- ERROR :Exiting PROCESS_HEADER_LINES API --------- ',2);
1165               END IF;
1166 
1167          WHEN OTHERS THEN
1168               l_error_code              :=SQLCODE;
1169               l_error_msg               :=SQLERRM;
1170               x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
1171               FND_MESSAGE.SET_NAME('CLN','CLN_CH_UNEXPECTED_ERROR');
1172               FND_MESSAGE.SET_TOKEN('ERRORCODE',l_error_code);
1173               FND_MESSAGE.SET_TOKEN('ERRORMSG',l_error_msg);
1174               x_msg_data :=FND_MESSAGE.GET;
1175               l_msg_data         :='Unexpected Error in PROCESS_HEADER_LINES   -'||l_error_code||' : '||l_error_msg;
1176               IF (l_Debug_Level <= 5) THEN
1177                       cln_debug_pub.Add(l_msg_data,6);
1178                       cln_debug_pub.Add('------- ERROR :Exiting PROCESS_HEADER_LINES API --------- ',2);
1179               END IF;
1180 
1181  END PROCESS_HEADER_LINES;
1182 
1183 
1184    -- Name
1185    --   LOAD_CHANGES
1186    -- Purpose
1187    --   Call Process Supplier Request of Update_PO API to
1188    --   load all changes in to interface tables
1189    -- Arguments
1190    --   Internal Control Number
1191    -- Notes
1192    --   No Specific Notes
1193 
1194       PROCEDURE LOAD_CHANGES(
1195          p_call_po_apis                 IN  VARCHAR2,
1196          p_internal_ctrl_num            IN  VARCHAR2,
1197          p_requestor                    IN  VARCHAR2,
1198          p_request_origin               IN  VARCHAR2,
1199          p_tp_id                        IN  VARCHAR2,
1200          p_tp_site_id                   IN  VARCHAR2,
1201          x_return_status                IN OUT NOCOPY VARCHAR2,
1202          x_msg_data                     IN OUT NOCOPY VARCHAR2 )
1203       IS
1204          l_return_status                VARCHAR2(1000);
1205          l_return_msg                   VARCHAR2(2000);
1206          l_debug_mode                   VARCHAR2(300);
1207          l_error_code                   NUMBER;
1208          l_error_msg                    VARCHAR2(2000);
1209          l_error_id                     NUMBER;
1210          l_error_status                 VARCHAR2(1000);
1211          l_msg_data                     VARCHAR2(1000);
1212          l_errored_msg                  VARCHAR2(1000);
1213          l_errored_code                 NUMBER;
1214 
1215       BEGIN
1216 
1217          -- Sets the debug mode to be FILE
1218          --l_debug_mode           := cln_debug_pub.Set_Debug_Mode('FILE');
1219          l_error_id             := 0;
1220 
1221          IF (l_Debug_Level <= 2) THEN
1222                  cln_debug_pub.Add('----- Entering LOAD_CHANGES API ------- ',2);
1223          END IF;
1224 
1225          l_msg_data     := 'Changes in PO successfully loaded';
1226 
1227          -- Parameters received
1228          IF (l_Debug_Level <= 1) THEN
1229                  cln_debug_pub.Add('----- PARAMETERS RECEIVED ------- ',1);
1230                  cln_debug_pub.Add('Call PO APIs             - '||p_call_po_apis,1);
1234                  cln_debug_pub.Add('Trading Partner ID       - '||p_tp_id,1);
1231                  cln_debug_pub.Add('Internal Control Number  - '||p_internal_ctrl_num,1);
1232                  cln_debug_pub.Add('Requestor                - '||p_requestor,1);
1233                  cln_debug_pub.Add('Request Origin           - '||p_request_origin,1);
1235                  cln_debug_pub.Add('Trading Partner Site ID  - '||p_tp_site_id,1);
1236                  cln_debug_pub.Add('Return status got        - '||x_return_status,1);
1237                  cln_debug_pub.Add('Return msg got           - '||x_msg_data,1);
1238                  cln_debug_pub.Add('----------------------------------',1);
1239          END IF;
1240 
1241 
1242          IF p_call_po_apis <> 'YES' THEN
1243                 RETURN;
1244          END IF;
1245 
1246          IF x_return_status = 'S' THEN
1247                 IF (l_Debug_Level <= 1) THEN
1248                         cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.process_supplier_request API',1);
1249                 END IF;
1250 
1251                 PO_CHG_REQUEST_GRP.process_supplier_request (
1252                       p_int_cont_num      => p_internal_ctrl_num,
1253                       x_error_id_in       => l_error_id,
1254                       x_error_status_in   => l_error_status,
1255                       x_error_id_out      => l_error_id,
1256                       x_error_status_out  => l_error_status
1257                 );
1258 
1259                 IF (l_Debug_Level <= 1) THEN
1260                         cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
1261                         cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
1262                 END IF;
1263 
1264                 IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
1265                       x_msg_data     :=   l_error_status;
1266                       l_msg_data     :=   l_error_status;
1267                       l_errored_msg  :=   l_error_status;
1268                       l_errored_code :=   0;
1269                 END IF;
1270          END IF;
1271 
1272          IF (l_Debug_Level <= 1) THEN
1273                  cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.windup_chn_ack_inbound API',1);
1274          END IF;
1275 
1276 
1277          -- we have to call this even in case of error.
1278          PO_CHG_REQUEST_GRP.windup_chn_ack_inbound (
1279                 p_requestor             => p_requestor,
1280                 p_int_cont_num          => p_internal_ctrl_num,
1281                 p_request_origin        => p_request_origin,
1282                 p_tp_id                 => p_tp_id,
1283                 p_tp_site_id            => p_tp_site_id,
1284                 x_error_id_in           => l_error_id,
1285                 x_error_status_in       => l_error_status,
1286                 x_error_id_out          => l_error_id,
1287                 x_error_status_out      => l_error_status
1288          );
1289 
1290          IF (l_Debug_Level <= 1) THEN
1291                  cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
1292                  cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
1293          END IF;
1294 
1295 	 -- Whatever be the status of PO_CHG_REQUEST_GRP.windup_chn_ack_inbound API,
1296 	 -- we are returning back the failure incase the initial code returned was error.
1297 	 -- This code is deliberately called after the API call.
1298 	 IF x_return_status <> 'S' THEN
1299 	       l_msg_data  := x_msg_data;
1300 	       RAISE FND_API.G_EXC_ERROR;
1301 	 END IF;
1302 
1303 	 IF ( l_errored_code = 0 ) THEN
1304                x_msg_data  := l_errored_msg;
1305                RAISE FND_API.G_EXC_ERROR;
1306 	 END IF;
1307 
1308          IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
1309                 x_msg_data  := l_error_status;
1310                 l_msg_data  := l_error_status;
1311                 RAISE FND_API.G_EXC_ERROR;
1312          END IF;
1313 
1314          x_return_status        := 'S';
1315 
1316          IF (l_Debug_Level <= 1) THEN
1317                  cln_debug_pub.Add(l_msg_data,1);
1318          END IF;
1319          IF (l_Debug_Level <= 2) THEN
1320                  cln_debug_pub.Add('----- EXITING LOAD_CHANGES WITH SUCCESS-----', 2);
1321          END IF;
1322 
1323          EXCEPTION
1324                 WHEN FND_API.G_EXC_ERROR THEN
1325                      x_return_status           := FND_API.G_RET_STS_ERROR ;
1326                      IF (l_Debug_Level <= 5) THEN
1327                              cln_debug_pub.Add(l_msg_data,4);
1328                              cln_debug_pub.Add('------- ERROR :Exiting LOAD_CHANGES API --------- ',2);
1329                      END IF;
1330 
1331                 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1332                      l_error_code              :=SQLCODE;
1333                      l_error_msg               :=SQLERRM;
1334                      x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
1335                      l_msg_data                :=l_error_code||' : '||l_error_msg;
1336                      IF (l_Debug_Level <= 5) THEN
1337                              cln_debug_pub.Add(l_msg_data,5);
1338                              cln_debug_pub.Add('------- ERROR :Exiting LOAD_CHANGES API --------- ',2);
1339                      END IF;
1340 
1341                 WHEN OTHERS THEN
1342                      l_error_code              :=SQLCODE;
1343                      l_error_msg               :=SQLERRM;
1344                      x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
1345                      FND_MESSAGE.SET_NAME('CLN','CLN_CH_UNEXPECTED_ERROR');
1346                      FND_MESSAGE.SET_TOKEN('ERRORCODE',l_error_code);
1347                      FND_MESSAGE.SET_TOKEN('ERRORMSG',l_error_msg);
1348                      x_msg_data :=FND_MESSAGE.GET;
1349                      l_msg_data         :='Unexpected Error in LOAD_CHANGES   -'||l_error_code||' : '||l_error_msg;
1353                      END IF;
1350                      IF (l_Debug_Level <= 5) THEN
1351                              cln_debug_pub.Add(l_msg_data,5);
1352                              cln_debug_pub.Add('------- ERROR :Exiting LOAD_CHANGES API --------- ',2);
1354       END LOAD_CHANGES;
1355 
1356 
1357   -- Name
1358   --   ACKPO_ERROR_HANDLER
1359   -- Purpose
1360   --
1361   -- Arguments
1362   --
1363   -- Notes
1364   --   No specific notes.
1365 
1366   PROCEDURE ACKPO_ERROR_HANDLER(
1367          x_return_status             IN OUT NOCOPY VARCHAR2,
1368          x_msg_data                  IN OUT NOCOPY VARCHAR2,
1369          p_po_number                 IN VARCHAR2,
1370          p_org_ref                   IN VARCHAR2,
1371          p_coll_id                   IN NUMBER,
1372          p_internal_control_number   IN VARCHAR2,
1373          x_notification_code         OUT NOCOPY VARCHAR2,
1374          x_notification_status       OUT NOCOPY VARCHAR2,
1375          x_return_status_tp          OUT NOCOPY VARCHAR2,
1376          p_cln_required              IN VARCHAR2 )
1377 
1378   IS
1379         l_error_code                NUMBER;
1380         l_error_msg                 VARCHAR2(2000);
1381         l_debug_mode                VARCHAR2(255);
1382         l_msg_data                  VARCHAR2(255);
1383         l_doc_status                VARCHAR2(255);
1384         l_msg_dtl_screen            VARCHAR2(2000);
1385         l_coll_status               VARCHAR2(255);
1386         l_msg_buffer                VARCHAR2(2000);
1387 
1388   BEGIN
1389 
1390         -- Sets the debug mode to be FILE
1391         --l_debug_mode :=cln_debug_pub.Set_Debug_Mode('FILE');
1392 
1393         IF (l_Debug_Level <= 2) THEN
1394                 cln_debug_pub.Add('------ Entering ACKPO_ERROR_HANDLER API ------ ', 2);
1395         END IF;
1396 
1397         -- Initialize API return status to success
1398         l_msg_data :='Parameters set to their correct values when the return status is ERROR';
1399 
1400         -- Parameters received
1401         IF (l_Debug_Level <= 1) THEN
1402                 cln_debug_pub.Add('------  Parameters Received   ------ ', 1);
1403                 cln_debug_pub.Add('Return Status                        - '||x_return_status,1);
1404                 cln_debug_pub.Add('Message Data                         - '||x_msg_data,1);
1405                 cln_debug_pub.Add('PO Number                            - '||p_po_number,1);
1406                 cln_debug_pub.Add('Originator Reference                 - '||p_org_ref,1);
1407                 cln_debug_pub.Add('Collaboration ID                     - '||p_coll_id,1);
1408                 cln_debug_pub.Add('Internal Control Number              - '||p_internal_control_number,1);
1409                 cln_debug_pub.Add('CLN Required                         - '||p_cln_required,1);
1410                 cln_debug_pub.Add('------------------------------------- ', 1);
1411 
1412                 cln_debug_pub.Add('Rollback all previous changes....',1);
1413         END IF;
1414         ROLLBACK TO CHECK_COLLABORATION_PUB;
1415 
1416         IF (p_coll_id  IS NULL) THEN --If not null take action will be done
1417              CLN_NP_PROCESSOR_PKG.NOTIFY_ADMINISTRATOR(x_msg_data);
1418              l_msg_data  :=  'Collaboration ID is null. Moving out of ERROR HANDLER API.';
1419 ----Changes made for rnet messages
1420 
1421 ---             RAISE  FND_API.G_EXC_ERROR;
1422 
1423 ----Changes made for rnet messages
1424         END IF;
1425 
1426 
1427         -- if collaboration id is null, then skip this API.
1428         IF (l_Debug_Level <= 1) THEN
1429                 cln_debug_pub.Add('------ERROR status------',1);
1430         END IF;
1431         FND_MESSAGE.SET_NAME('CLN','CLN_CH_ERROR_PO_UPDATION');
1432         FND_MESSAGE.SET_TOKEN('POID',p_po_number);
1433         l_error_msg           :=  FND_MESSAGE.GET;
1434         l_error_msg           :=  l_error_msg || '--- Detail Error:' ||x_msg_data;
1435         x_notification_code   := 'ACKPO_04';
1436         x_notification_status := 'ERROR';
1437         x_return_status_tp    := '99';
1438 
1439 
1440         IF (l_Debug_Level <= 1) THEN
1441                 cln_debug_pub.Add('-----Parameters set ------ ',1);
1442                 cln_debug_pub.Add('Msg for collaboration detail         - '||l_error_msg,1);
1443                 cln_debug_pub.Add('--------------------------------------------------',1);
1444         END IF;
1445 
1446         l_msg_buffer := x_msg_data;-- preserving the error message
1447 
1448         IF(p_cln_required = 'TRUE') THEN
1449                 IF (l_Debug_Level <= 1) THEN
1450                         cln_debug_pub.Add('------Calling RAISE_UPDATE_EVENT with ERROR status------',1);
1451                 END IF;
1452                 RAISE_UPDATE_EVENT(
1453                         x_return_status                         => x_return_status,
1454                         x_msg_data                              => x_msg_data,
1455                         p_coll_id                               => p_coll_id,
1456                         p_doc_status                            => 'ERROR',
1457                         p_org_ref                               => p_org_ref,
1458                         p_disposition                           => NULL,
1459                         p_msg_text                              => l_error_msg,
1460                         p_internal_control_number               => p_internal_control_number );
1461 
1462                 IF(x_return_status <> 'S')THEN
1463                         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1464                 END IF;
1465 
1466                 x_msg_data := l_msg_buffer; -- restoring the actual error msg.
1467 
1468          END IF;
1469 
1470          IF (l_Debug_Level <= 1) THEN
1471                  cln_debug_pub.Add(l_msg_data,1);
1472          END IF;
1473          IF (l_Debug_Level <= 2) THEN
1477 
1474                  cln_debug_pub.Add('------- Exiting ACKPO_ERROR_HANDLER API --------- ',2);
1475          END IF;
1476 
1478 
1479   -- Exception Handling
1480   EXCEPTION
1481 
1482          WHEN FND_API.G_EXC_ERROR THEN
1483               x_return_status           := FND_API.G_RET_STS_ERROR ;
1484               IF (l_Debug_Level <= 5) THEN
1485                       cln_debug_pub.Add(l_msg_data,4);
1486                       cln_debug_pub.Add('------- ERROR :Exiting ACKPO_ERROR_HANDLER API --------- ',2);
1487               END IF;
1488 
1489          WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1490               l_error_code              :=SQLCODE;
1491               l_error_msg               :=SQLERRM;
1492               x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
1493               l_msg_data                :=l_error_code||' : '||l_error_msg;
1494               IF (l_Debug_Level <= 5) THEN
1495                       cln_debug_pub.Add(l_msg_data,6);
1496                       cln_debug_pub.Add('------- ERROR :Exiting ACKPO_ERROR_HANDLER API --------- ',2);
1497               END IF;
1498 
1499          WHEN OTHERS THEN
1500               l_error_code              :=SQLCODE;
1501               l_error_msg               :=SQLERRM;
1502               x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
1503               FND_MESSAGE.SET_NAME('CLN','CLN_CH_UNEXPECTED_ERROR');
1504               FND_MESSAGE.SET_TOKEN('ERRORCODE',l_error_code);
1505               FND_MESSAGE.SET_TOKEN('ERRORMSG',l_error_msg);
1506               x_msg_data :=FND_MESSAGE.GET;
1507               l_msg_data         :='Unexpected Error in ACKPO_ERROR_HANDLER   -'||l_error_code||' : '||l_error_msg;
1508               IF (l_Debug_Level <= 5) THEN
1509                       cln_debug_pub.Add(l_msg_data,6);
1510                       cln_debug_pub.Add('------- ERROR :Exiting ACKPO_ERROR_HANDLER API --------- ',2);
1511               END IF;
1512 
1513   END ACKPO_ERROR_HANDLER;
1514 
1515 
1516 
1517     -- Name
1518     --   PROCESS_HEADER_LINES
1519     -- Purpose
1520     --   This procedure is called from the Rosettanet XGMs.
1521     --   This procedure is used to process the headers level.
1522     -- Arguments
1523     --
1524     -- Notes
1525     --   No specific notes.
1526 
1527 PROCEDURE PROCESS_HEADER_RN(
1528         x_return_status             OUT NOCOPY VARCHAR2,
1529         x_msg_data                  OUT NOCOPY VARCHAR2,
1530         p_sender_component          IN  VARCHAR2,
1531         p_po_number                 IN  VARCHAR2,
1532         p_release_number            IN  NUMBER,
1533         p_revision_number           IN  NUMBER,
1534         p_ackcode_header            IN  NUMBER,
1535         p_note                      IN  LONG,
1536         p_requestor                 IN  VARCHAR2,
1537         p_int_cont_num              IN  VARCHAR2,
1538         p_request_origin            IN  VARCHAR2,
1539         p_tp_header_id              IN  NUMBER,
1540         p_collaboration_type        IN  VARCHAR2,
1541         p_tp_id                     OUT NOCOPY VARCHAR2,
1542         p_tp_site_id                OUT NOCOPY VARCHAR2,
1543         x_cln_required              OUT NOCOPY VARCHAR2,
1544         x_notification_code         OUT NOCOPY VARCHAR2,
1545         x_notification_status       OUT NOCOPY VARCHAR2,
1546         x_return_status_tp          OUT NOCOPY VARCHAR2,
1547         x_call_po_apis              OUT NOCOPY VARCHAR2 )
1548 
1549  IS
1550         l_error_code                NUMBER;
1551         l_txn_id                    NUMBER;
1552         l_error_msg                 VARCHAR2(255);
1553         l_msg_data                  VARCHAR2(255);
1554         l_debug_mode                VARCHAR2(255);
1555         l_update_reqd               BOOLEAN;
1556         l_action                    VARCHAR2(255);
1557         l_po_type                   VARCHAR2(50);
1558         l_request_type              VARCHAR2(50);
1559         l_error_id                  NUMBER;
1560         l_error_status              VARCHAR2(1000);
1561         l_tp_id                     NUMBER;
1562         l_tp_site_id                NUMBER;
1563         l_call_po_apis              VARCHAR2(10);
1564         l_po_ackcode                NUMBER;
1565 
1566  BEGIN
1567 
1568         -- Sets the debug mode to be FILE
1569         --l_debug_mode :=cln_debug_pub.Set_Debug_Mode('FILE');
1570 
1571         IF (l_Debug_Level <= 1) THEN
1572                 cln_debug_pub.Add('############################################################',1);
1573                 cln_debug_pub.Add('###############   START OF XGM DEBUG FILE  #################',1);
1574                 cln_debug_pub.Add('############################################################',1);
1575         END IF;
1576 
1577         IF (l_Debug_Level <= 2) THEN
1578                 cln_debug_pub.Add('---- Entering PROCESS_HEADER API ----- ', 2);
1579         END IF;
1580 
1581         -- Standard Start of API savepoint
1582         SAVEPOINT   CHECK_COLLABORATION_PUB;
1583 
1584         -- Initialize API return status to success
1585         x_return_status := FND_API.G_RET_STS_SUCCESS;
1586         l_msg_data      := 'ACKPO Header successfully consumed';
1587         l_call_po_apis  := 'YES';
1588         x_cln_required  := 'TRUE';
1589 
1590 
1591         -- Parameters received
1592         IF (l_Debug_Level <= 1) THEN
1593                 cln_debug_pub.Add('----- PARAMETERS RECEIVED ------- ',1);
1594                 cln_debug_pub.Add('Status received          - '||x_return_status,1);
1595                 cln_debug_pub.Add('Message received         - '||x_msg_data,1);
1596                 cln_debug_pub.Add('Sender Component         - '||p_sender_component,1);
1597                 cln_debug_pub.Add('PO Number                - '||p_po_number,1);
1598                 cln_debug_pub.Add('Release Number           - '||p_release_number,1);
1602                 cln_debug_pub.Add('CLN reqd                 - '||x_cln_required,1);
1599                 cln_debug_pub.Add('Revision Number          - '||p_revision_number,1);
1600                 cln_debug_pub.Add('Ackcode at header level  - '||p_ackcode_header,1);
1601                 cln_debug_pub.Add('Note                     - '||p_note,1);
1603                 cln_debug_pub.Add('p_tp_header_id           - '|| p_tp_header_id, 1);
1604                 cln_debug_pub.Add('Requestor                - '||p_requestor,1);
1605                 cln_debug_pub.Add('Internal Ctrl Number     - '||p_int_cont_num,1);
1606                 cln_debug_pub.Add('Request Origin           - '||p_request_origin,1);
1607                 cln_debug_pub.Add('Collaboration Type           - '||p_collaboration_type,1);
1608                 cln_debug_pub.Add('----------------------------------',1);
1609         END IF;
1610 
1611         l_line_num_tab.delete;-- Initialize array of PO lines
1612 
1613 
1614         -- Check whether collaboration can be created/upadted based on Profile, Protocol value
1615         CLN_CH_COLLABORATION_PKG.IS_UPDATE_REQUIRED(
1616             x_return_status             =>        x_return_status,
1617             x_msg_data                  =>        x_msg_data,
1618             p_doc_dir                   =>        'IN',
1619             p_xmlg_transaction_type     =>        null,
1620             p_xmlg_transaction_subtype  =>        null,
1621             p_tr_partner_type           =>        null,
1622             p_tr_partner_id             =>        null,
1623             p_tr_partner_site           =>        null,
1624             p_sender_component          =>        p_sender_component,
1625             x_update_reqd               =>        l_update_reqd);
1626 
1627         IF (x_return_status <> 'S') THEN
1628              FND_MESSAGE.SET_NAME('CLN','CLN_CH_REQD_CRITERIA_FAIL');
1629              x_msg_data         := FND_MESSAGE.GET;
1630              l_msg_data         :='Failed to verify the required criteria for updating/creating.collaboration';
1631             -- x_coll_id          :=null;
1632              x_cln_required     :='FALSE';
1633              RAISE FND_API.G_EXC_ERROR;
1634         ELSE
1635              IF (l_update_reqd <> TRUE) THEN
1636                 x_cln_required  := 'FALSE';
1637                -- x_coll_id       :=  null;
1638              END IF;
1639         END IF;
1640 
1641        /* IF (x_cln_required <>'TRUE')THEN
1642                 IF (l_Debug_Level <= 1) THEN
1643                         cln_debug_pub.Add('CLN history need not be updated',1);
1644                         cln_debug_pub.Add('Defaulting Collaboration Type to ACKNOWLEDGE_PO',1);
1645                 END IF;
1646                 x_collaboration_type    :=      'ACKNOWLEDGE_PO';
1647         END IF;
1648        */
1649 
1650 
1651         IF (l_Debug_Level <= 1) THEN
1652                 cln_debug_pub.Add('Getting Trading partner details using TP_HEADER_ID',1);
1653         END IF;
1654 
1655         BEGIN
1656              SELECT  PARTY_ID, PARTY_SITE_ID
1657              INTO    l_tp_id, l_tp_site_id
1658              FROM    ECX_TP_HEADERS
1659              WHERE   TP_HEADER_ID = p_tp_header_id;
1660         EXCEPTION
1661              WHEN NO_DATA_FOUND THEN
1662                  IF (l_Debug_Level <= 2) THEN
1663                          cln_debug_pub.Add('TP details not found for the TP Header ID = '||p_tp_header_id,2);
1664                  END IF;
1665         END;
1666 
1667         IF (l_Debug_Level <= 2) THEN
1668                 cln_debug_pub.Add('Trading Partner ID       - '||l_tp_id,1);
1669                 cln_debug_pub.Add('Trading Partner Site ID  - '||l_tp_site_id,1);
1670         END IF;
1671 
1672         p_tp_id                 := l_tp_id;
1673         p_tp_site_id            := l_tp_site_id;
1674 
1675 
1676         IF (l_call_po_apis = 'YES') THEN
1677                 IF (l_Debug_Level <= 2) THEN
1678                         cln_debug_pub.Add('--- Calling PO_CHG_REQUEST_GRP.initialize_chn_ack_inbound ----- ',1);
1679                 END IF;
1680                 PO_CHG_REQUEST_GRP.initialize_chn_ack_inbound (
1681                         p_requestor             => p_requestor,
1682                         p_int_cont_num          => p_int_cont_num,
1683                         p_request_origin        => p_request_origin,
1684                         p_tp_id                 => l_tp_id,
1685                         p_tp_site_id            => l_tp_site_id,
1686                         x_error_id              => l_error_id,
1687                         x_error_status          => l_error_status);
1688 
1689                 IF (l_Debug_Level <= 2) THEN
1690                         cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
1691                         cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
1692                 END IF;
1693 
1694                 -- If initialize_chn_ack_inbound errored out
1695                 IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
1696                      x_msg_data  :=   l_error_status;
1697                      l_msg_data  :=   l_error_status;
1698                      RAISE FND_API.G_EXC_ERROR;
1699                 END IF;
1700                 IF (l_Debug_Level <= 2) THEN
1701                         cln_debug_pub.Add('PO_CHG_REQUEST_GRP.initialize_chn_ack_inbound returned Success',1);
1702                 END IF;
1703          END IF;
1704 
1705         l_action := p_collaboration_type;
1706 
1707         IF (p_collaboration_type <>  'ACKNOWLEDGE_PO') THEN
1708                 BEGIN
1709                         IF((p_ackcode_header = 1) and (p_collaboration_type <> 'ORDER')) OR (p_ackcode_header not in (0,1,2,3)) THEN
1710                             FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_INVALID_TAG_VALUE');
1711                             FND_MESSAGE.SET_TOKEN('TAG','ACKHEADER/ACKCODE');
1712                             x_msg_data  :=FND_MESSAGE.GET;
1716 
1713                             l_msg_data  :='Invalid value for ACKHEADER/ACKCODE tag.';
1714                             RAISE FND_API.G_EXC_ERROR;
1715                         END IF;
1717                         SELECT meaning INTO l_action FROM fnd_lookups
1718                         WHERE lookup_code = p_collaboration_type AND lookup_type = 'CLN_COLLABORATION_TYPE';
1719                         cln_debug_pub.Add('Collaboration Type found as  - '||l_action,1);
1720 
1721                 EXCEPTION
1722                         WHEN NO_DATA_FOUND THEN
1723                              l_msg_data := 'Collaboration Type not found for the lookup_code as ORDER and lookup_type as CLN_COLLABORATION_TYPE ';
1724                              FND_MESSAGE.SET_NAME('CLN','CLN_CH_COLLABORATION_TYPE_NOT');
1725                              FND_MESSAGE.SET_TOKEN('TYPE','CLN_COLLABORATION_TYPE');
1726                              FND_MESSAGE.SET_TOKEN('CODE',l_action);
1727                              x_msg_data := FND_MESSAGE.GET;
1728                              RAISE FND_API.G_EXC_ERROR;
1729                 END;
1730         ELSE
1731                 l_action := 'Acknowledge PO';
1732         END IF;
1733 
1734         IF (l_Debug_Level <= 2) THEN
1735                 cln_debug_pub.Add('Action is set as                : '||l_action,1);
1736                 cln_debug_pub.Add('Return status is                : '||x_return_status,1);
1737         END IF;
1738 
1739         -- get the sequence number for Transaction id.
1740         select  cln_generic_s.NEXTVAL INTO l_txn_id FROM DUAL;
1741         IF (l_Debug_Level <= 2) THEN
1742                 cln_debug_pub.Add('Transaction ID                  :' || l_txn_id, 1);
1743         END IF;
1744 
1745         -- Find the Request Type
1746         IF p_ackcode_header = 1 THEN
1747              l_request_type := 'CHANGE';
1748         ELSE
1749              l_request_type := 'ACKNOWLEDGE';
1750         END IF;
1751         IF (l_Debug_Level <= 2) THEN
1752                 cln_debug_pub.Add('PO Request Type is              : ' || l_request_type,1);
1753         END IF;
1754 
1755         -- Identify PO Type based on release number
1756         l_po_type := 'STANDARD';
1757 
1758         IF (p_release_number IS NOT NULL AND p_release_number > 0) THEN
1759              l_po_type := 'RELEASE';
1760         END IF;
1761         IF (l_Debug_Level <= 2) THEN
1762                 cln_debug_pub.Add('PO Type is                      : ' || l_po_type,1);
1763                 cln_debug_pub.Add('--- Calling PO_CHG_REQUEST_GRP.validate_header ----- ',1);
1764         END IF;
1765 
1766 
1767         IF (l_call_po_apis = 'YES') THEN
1768             -- should not be called for 3A9 and 3A7 Response
1769             PO_CHG_REQUEST_GRP.validate_header (
1770                p_requestor               => p_requestor,
1771                p_int_cont_num            => p_int_cont_num,
1772                p_request_origin          => p_request_origin,
1773                p_request_type            => l_request_type,
1774                p_tp_id                   => l_tp_id,
1775                p_tp_site_id              => l_tp_site_id,
1776                p_po_number               => p_po_number,
1777                p_release_number          => p_release_number,
1778                p_po_type                 => l_po_type,
1779                -- Should not pass revision number
1780                p_revision_num            => NULL,
1781                x_error_id_in             => l_error_id,
1782                x_error_status_in         => l_error_status,
1783                x_error_id_out            => l_error_id,
1784                x_error_status_out        => l_error_status);
1785 
1786             IF (l_Debug_Level <= 2) THEN
1787                     cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
1788                     cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
1789             END IF;
1790 
1791             -- If validate header errored out
1792             IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
1793                 x_msg_data  :=   l_error_status;
1794                 l_msg_data  :=   l_error_status;
1795                 RAISE FND_API.G_EXC_ERROR;
1796             END IF;
1797             IF (l_Debug_Level <= 2) THEN
1798                     cln_debug_pub.Add('PO_CHG_REQUEST_GRP.validate_header returned Success',1);
1799             END IF;
1800         END IF;
1801 
1802         IF (l_call_po_apis = 'YES') THEN  -- should not be called for 3A9 and 3A8 Response
1803             IF (l_request_type = 'ACKNOWLEDGE') THEN
1804                     IF (l_Debug_Level <= 2) THEN
1805                             cln_debug_pub.Add('--- Calling PO_CHG_REQUEST_GRP.acknowledge_po ----- ',1);
1806                     END IF;
1807                     IF p_ackcode_header = 3 THEN    --If pending treat it as accept
1808                        l_po_ackcode := 0;
1809                     ELSE
1810                        l_po_ackcode := p_ackcode_header;
1811                     END IF;
1812                     PO_CHG_REQUEST_GRP.acknowledge_po(
1813                          p_requestor            => p_requestor,     -- Change requester or the acknowledging username
1814                          p_int_cont_num         => p_int_cont_num,  -- ECX's ICN. Used for integrity of request
1815                          p_request_type         => 'ACKNOWLEDGE',  -- ??'ACKNOWLEDGE'
1816                          p_tp_id                => l_tp_id,         -- vendor_id
1817                          p_tp_site_id           => l_tp_site_id,    -- vendor_site_id
1818                          p_po_number            => p_po_number,     -- PO # of the PO being modified or the Blanket's PO #
1819                          p_release_number       => p_release_number,-- Release number if the PO Type is release or null
1820                          p_po_type              => l_po_type,       -- PO Type??  -- RELEASE for release, STANDARD for others.
1821                          p_revision_num         => NULL,            -- Revision number of the PO or the release
1825                          x_error_status         => l_error_status   -- Error message
1822                          p_ack_code             => l_po_ackcode,    -- 0 for accept/peding and 2 reject
1823                          p_ack_reason           => p_note,          --  comments
1824                          x_error_id             => l_error_id,      -- The error id will be 2, errors will go to the TP sysadmin
1826                      );
1827 
1828                      IF (l_Debug_Level <= 2) THEN
1829                              cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
1830                              cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
1831                      END IF;
1832 
1833                      IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
1834                          x_msg_data  :=   l_error_status;
1835                          l_msg_data  :=   l_error_status;
1836                          RAISE FND_API.G_EXC_ERROR;
1837                      END IF;
1838 
1839                 END IF;
1840         END IF;
1841 
1842         IF (p_ackcode_header = 0) or (p_ackcode_header = 3) THEN -- Pending is treated as accepted
1843                 x_notification_code   := 'ACKPO_01';
1844         ELSIF (p_ackcode_header = 1) THEN
1845                 x_notification_code   := 'ACKPO_03';
1846         ELSIF (p_ackcode_header = 2) THEN
1847                 x_notification_code   := 'ACKPO_02';
1848         END IF;
1849 
1850         x_notification_status := 'SUCCESS';
1851         x_return_status_tp    := '00';
1852         x_call_po_apis        :=  l_call_po_apis;
1853 
1854         IF (l_Debug_Level <= 2) THEN
1855                 cln_debug_pub.Add('Notification Code set as     :'||x_notification_code,1);
1856                 cln_debug_pub.Add('Notification Status set as   :'||x_notification_status,1);
1857                 cln_debug_pub.Add('Return Status set as         :'||x_notification_code,1);
1858         END IF;
1859 
1860         IF (l_Debug_Level <= 2) THEN
1861                 cln_debug_pub.Add('---- Exiting PROCESS_HEADER API ----- ', 2);
1862         END IF;
1863 
1864  -- Exception Handling
1865  EXCEPTION
1866 
1867         WHEN FND_API.G_EXC_ERROR THEN
1868              x_return_status    := FND_API.G_RET_STS_ERROR ;
1869              FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_ERROR');
1870              FND_MESSAGE.SET_TOKEN('PONUM',p_po_number);
1871              FND_MESSAGE.SET_TOKEN('RELNUM',p_release_number);
1872              FND_MESSAGE.SET_TOKEN('REVNUM',p_revision_number);
1873              FND_MESSAGE.SET_TOKEN('MSG',x_msg_data);
1874              x_msg_data         := FND_MESSAGE.GET;
1875              x_call_po_apis     := 'NO';
1876 
1877              IF (l_Debug_Level <= 5) THEN
1878                      cln_debug_pub.Add(l_msg_data,4);
1879                      cln_debug_pub.Add('---- ERROR :Exiting PROCESS_HEADER  API ----- ', 2);
1880              END IF;
1881 
1882 
1883         WHEN OTHERS THEN
1884              l_error_code       :=SQLCODE;
1885              l_error_msg        :=SQLERRM;
1886              x_return_status    :=FND_API.G_RET_STS_UNEXP_ERROR ;
1887              FND_MESSAGE.SET_NAME('CLN','CLN_CH_UNEXPECTED_ERROR');
1888              FND_MESSAGE.SET_TOKEN('ERRORCODE',l_error_code);
1889              FND_MESSAGE.SET_TOKEN('ERRORMSG',l_error_msg);
1890              x_msg_data         :=FND_MESSAGE.GET;
1891              x_call_po_apis     := 'NO';
1892 
1893              FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_ERROR');
1894              FND_MESSAGE.SET_TOKEN('PONUM',p_po_number);
1895              FND_MESSAGE.SET_TOKEN('RELNUM',p_release_number);
1896              FND_MESSAGE.SET_TOKEN('REVNUM',p_revision_number);
1897              FND_MESSAGE.SET_TOKEN('MSG',x_msg_data);
1898              x_msg_data         := FND_MESSAGE.GET;
1899              l_msg_data         :='Unexpected Error -'||l_error_code||' : '||l_error_msg;
1900              IF (l_Debug_Level <= 5) THEN
1901                      cln_debug_pub.Add(l_msg_data,6);
1902                      cln_debug_pub.Add('---- ERROR :Exiting PROCESS_HEADER API ----- ', 2);
1903              END IF;
1904 
1905  END PROCESS_HEADER_RN;
1906 
1907 
1908 
1909 
1910     -- Name
1911     --   PROCESS_HEADER_LINES
1912     -- Purpose
1913     --   This procedure is called from RosettaNet xgms.
1914     --   The main purpose of this procedure is to provide a sequence of actions that
1915     --   need to be taken to consume the Acknowledgement depending upon the ACKCODE
1916     --   value at the header level and on the Collaboration Type.
1917     -- Arguments
1918     --
1919     -- Notes
1920     --   No specific notes.
1921 
1922   PROCEDURE PROCESS_HEADER_LINES_RN(
1923          x_return_status             IN OUT NOCOPY VARCHAR2,
1924          x_msg_data                  IN OUT NOCOPY VARCHAR2,
1925          p_requestor                 IN VARCHAR2,
1926          p_po_number                 IN VARCHAR2,
1927          p_release_number            IN NUMBER,
1928          p_revision_number           IN NUMBER,
1929          p_line_number               IN NUMBER,
1930          p_previous_line_number      IN OUT NOCOPY NUMBER,
1931          p_shipment_number           IN NUMBER,
1932          p_new_quantity              IN NUMBER,
1933          p_po_quantity_uom           IN VARCHAR2,
1934          p_po_price_currency         IN VARCHAR2,
1935          p_po_price_uom              IN VARCHAR2,
1936          p_new_price                 IN NUMBER,
1937          p_ackcode_header            IN NUMBER,
1938          p_ackcode_line              IN NUMBER,
1939          p_coll_id                   IN NUMBER,
1940          p_new_promised_date         IN DATE,
1941          p_collaboration_type        IN VARCHAR2,
1942          p_org_ref                   IN VARCHAR2,
1943          p_cln_required              IN VARCHAR2,
1944          p_internal_control_number   IN VARCHAR2,
1948          p_so_line_status            IN VARCHAR2,
1945          p_supplier_part_number      IN VARCHAR2,
1946          p_so_num                    IN VARCHAR2,
1947          p_so_line_num               IN NUMBER,
1949          p_reason                    IN VARCHAR2,
1950          p_tp_id                     IN VARCHAR2,
1951          p_tp_site_id                IN VARCHAR2,
1952          p_msg_dtl_screen            IN OUT NOCOPY VARCHAR2,
1953          p_msg_txt_lines             IN OUT NOCOPY VARCHAR2,
1954          p_if_collaboration_updated  IN OUT NOCOPY VARCHAR2,
1955          -- Additional parameters added for new Change_PO API to
1956          -- support split lines and cancellation at header and schedule level.
1957          p_supp_doc_ref              IN VARCHAR2 DEFAULT NULL,
1958          p_supp_line_ref             IN VARCHAR2 DEFAULT NULL,
1959          p_supplier_shipment_ref     IN VARCHAR2 DEFAULT NULL,
1960          p_parent_shipment_number    IN VARCHAR2 DEFAULT NULL)
1961   IS
1962          l_error_code                NUMBER;
1963          l_error_msg                 VARCHAR2(255);
1964          l_msg_data                  VARCHAR2(255);
1965          l_debug_mode                VARCHAR2(255);
1966          l_return_code               NUMBER;
1967          l_return_status             VARCHAR2(255);
1968          l_msg_txt_lines             VARCHAR2(2000);
1969          l_disposition               VARCHAR2(255);
1970          l_return_status_tp          VARCHAR2(255);
1971          l_dtl_status                VARCHAR2(255);
1972          l_txn_id                    NUMBER;
1973          l_po_type                   VARCHAR2(50);
1974          l_error_id                  NUMBER;
1975          l_error_status              VARCHAR2(1000);
1976 
1977 
1978   BEGIN
1979 
1980          -- Sets the debug mode to be FILE
1981          --l_debug_mode           := cln_debug_pub.Set_Debug_Mode('FILE');
1982 
1983          IF (l_Debug_Level <= 2) THEN
1984                  cln_debug_pub.Add('----- Entering PROCESS_HEADER_LINES API ------- ',2);
1985          END IF;
1986 
1987          l_msg_txt_lines        := p_msg_txt_lines;
1988 
1989          IF(p_ackcode_header = 0) THEN
1990             l_disposition            := 'ACCEPTED';
1991          ELSIF (p_ackcode_header = 1) THEN
1992             l_disposition            := 'ACCEPTED';
1993          ELSIF(p_ackcode_header = 2) THEN
1994             l_disposition            := 'REJECTED';
1995          ELSIF (p_ackcode_header = 3) THEN
1996             l_disposition            := 'PENDING';
1997          END IF;
1998 
1999          l_msg_data     := 'ACKPO successfully consumed for PO : '||p_po_number||' with Line : '||p_line_number;
2000 
2001          -- Parameters received
2002          IF (l_Debug_Level <= 1) THEN
2003                  cln_debug_pub.Add('----- PARAMETERS RECEIVED ------- ',1);
2004                  cln_debug_pub.Add('Status received          - '||x_return_status,1);
2005                  cln_debug_pub.Add('Message received         - '||x_msg_data,1);
2006                  cln_debug_pub.Add('PO Number                - '||p_po_number,1);
2007                  cln_debug_pub.Add('Release Number           - '||p_release_number,1);
2008                  cln_debug_pub.Add('Revision Number          - '||p_revision_number,1);
2009                  cln_debug_pub.Add('Previous Line  Number    - '||p_previous_line_number,1);
2010                  cln_debug_pub.Add('Line  Number             - '||p_line_number,1);
2011                  cln_debug_pub.Add('Shipment Number          - '||p_shipment_number,1);
2012                  cln_debug_pub.Add('New Quantity             - '||p_new_quantity,1);
2013                  cln_debug_pub.Add('New Price                - '||p_new_price,1);
2014                  cln_debug_pub.Add('Promised Date            - '||p_new_promised_date,1);
2015                  cln_debug_pub.Add('Ackcode at header level  - '||p_ackcode_header,1);
2016                  cln_debug_pub.Add('Ackcode at line level    - '||p_ackcode_line,1);
2017                  cln_debug_pub.Add('Collaboration Type       - '||p_collaboration_type,1);
2018                  cln_debug_pub.Add('Originator Reference     - '||p_org_ref,1);
2019                  cln_debug_pub.Add('Collaboration ID         - '||p_coll_id,1);
2020                  cln_debug_pub.Add('Detail Header Message    - '||p_msg_dtl_screen,1);
2021                  cln_debug_pub.Add('Detail Line Message      - '||p_msg_txt_lines,1);
2022                  cln_debug_pub.Add('Internal Control Number  - '||p_internal_control_number,1);
2023                  cln_debug_pub.Add('Collaboration Updated    - '||p_if_collaboration_updated,1);
2024                  cln_debug_pub.Add('Disposition              - '||l_disposition,1);
2025                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
2026                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
2027                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
2028                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
2029                  cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
2030                  cln_debug_pub.Add('----------------------------------',1);
2031          END IF;
2032 
2033          -- get the sequence number for Transaction id.
2034          select  cln_generic_s.NEXTVAL INTO l_txn_id FROM DUAL;
2035          IF (l_Debug_Level <= 1) THEN
2036                  cln_debug_pub.Add('Transaction ID:' || l_txn_id, 1);
2037          END IF;
2038 
2039          -- Identify PO Type based on release number
2040 
2041          l_po_type := 'STANDARD';
2042 
2043          IF (p_release_number IS NOT NULL AND p_release_number > 0) THEN
2044              l_po_type := 'RELEASE';
2045          END IF;
2046          cln_debug_pub.Add('PO Type is           : ' || l_po_type,1);
2047 
2048 
2049          IF((p_ackcode_header = 1 and p_ackcode_line = 1) AND ((p_collaboration_type = 'ORDER') or (p_collaboration_type = 'ACKNOWLEDGE_PO'))) THEN
2050                 IF l_po_type = 'RELEASE' THEN
2054                     PO_CHG_REQUEST_GRP.store_supplier_request (
2051                     IF (l_Debug_Level <= 1) THEN
2052                             cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.store_supplier_request API For PO Release',1);
2053                     END IF;
2055                           p_requestor         => p_requestor,
2056                           p_int_cont_num      => p_internal_control_number,
2057                           p_request_type      => 'CHANGE',
2058                           p_tp_id             => p_tp_id,
2059                           p_tp_site_id        => p_tp_site_id,
2060                           p_level             => 'SHIPMENT',
2061                           p_po_number         => p_po_number,
2062                           p_release_number    => p_release_number,
2063                           p_po_type           => 'RELEASE',
2064                           -- Should not pass revision nmumber, it keeps changing
2065                           p_revision_num      => NULL,
2066                           p_line_num          => p_line_number,
2067                           p_reason            => p_reason,
2068                           p_shipment_num      => p_shipment_number,
2069                           p_quantity          => p_new_quantity,
2070                           p_quantity_uom      => p_po_quantity_uom,
2071                           p_price             => p_new_price,
2072                           p_price_currency    => p_po_price_currency,
2073                           p_price_uom         => p_po_price_uom,
2074                           p_promised_date     => p_new_promised_date,
2075                           p_supplier_part_num => p_supplier_part_number,
2076                           p_so_number         => p_so_num,
2077                           p_so_line_number    => p_so_line_num,
2078                           p_ack_type          => 'MODIFICATION',
2079                           x_error_id_in       => l_error_id,
2080                           x_error_status_in   => l_error_status,
2081                           x_error_id_out      => l_error_id,
2082                           x_error_status_out  => l_error_status/*,
2083                           -- Supplier Line Reference added for new Change_PO API to
2084                           -- support split lines and cancellation at header and schedule level.
2085                           p_parent_shipment_number  => p_parent_shipment_number,
2086                           p_supplier_doc_ref  => p_supp_doc_ref,
2087                           p_supplier_line_ref => p_supp_line_ref,
2088                           p_supplier_shipment_ref => p_supplier_shipment_ref*/);
2089 
2090 
2091 
2092                       IF (l_Debug_Level <= 1) THEN
2093                               cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
2094                       END IF;
2095                       IF (l_Debug_Level <= 1) THEN
2096                               cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
2097                       END IF;
2098 
2099                       IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
2100                          x_msg_data  :=   l_error_status;
2101                          l_msg_data  :=   l_error_status;
2102                          RAISE FND_API.G_EXC_ERROR;
2103                       END IF;
2104 
2105                 ELSE
2106 
2107                     IF (l_Debug_Level <= 1) THEN
2108                             cln_debug_pub.Add('Previous and new line number are not same..',1);
2109                     END IF;
2110                     IF (p_previous_line_number <> p_line_number) THEN
2111                         IF (l_Debug_Level <= 1) THEN
2112                                 cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.store_supplier_request API For Standard PO',1);
2113                                 cln_debug_pub.Add('Call is at Line Level......',1);
2114                         END IF;
2115                         p_previous_line_number          :=  p_line_number;
2116 
2117                         IF IS_ALREADY_PROCESSED_LINE(p_line_number) THEN
2118                               -- Nothing to do since the changes happens only once per each po line
2119                               -- Collaboration history too is not updated
2120                               IF (l_Debug_Level <= 1) THEN
2121                                       cln_debug_pub.Add('Since this an already processed line, Nothing to do', 1);
2122                               END IF;
2123                               RETURN;
2124                         END IF;
2125 
2126                         IF l_error_id IS NULL OR l_error_id = 0 THEN
2127                            PO_CHG_REQUEST_GRP.store_supplier_request (
2128                                   p_requestor         => p_requestor,
2129                                   p_int_cont_num      => p_internal_control_number,
2130                                   p_request_type      => 'CHANGE',
2131                                   p_tp_id             => p_tp_id,
2132                                   p_tp_site_id        => p_tp_site_id,
2133                                   p_level             => 'LINE',
2134                                   p_po_number         => p_po_number,
2135                                   p_release_number    => p_release_number,
2136                                   p_po_type           => 'STANDARD',
2137                                   p_revision_num      => NULL,
2138                                   p_line_num          => p_line_number,
2139                                   p_reason            => p_reason,
2140                                   p_shipment_num      => p_shipment_number,
2141                                   p_quantity          => NULL,
2142                                   p_quantity_uom      => NULL,
2143                                   p_price             => p_new_price,
2144                                   p_price_currency    => p_po_price_currency,
2145                                   p_price_uom         => p_po_price_uom,
2146                                   p_promised_date     => NULL,
2150                                   p_ack_type          => 'MODIFICATION',
2147                                   p_supplier_part_num => p_supplier_part_number,
2148                                   p_so_number         => p_so_num,
2149                                   p_so_line_number    => p_so_line_num,
2151                                   x_error_id_in       => l_error_id,
2152                                   x_error_status_in   => l_error_status,
2153                                   x_error_id_out      => l_error_id,
2154                                   x_error_status_out  => l_error_status/*,
2155                                   -- Supplier Line Reference added for new Change_PO API to
2156                                   -- support split lines and cancellation at header and schedule level.
2157                                   p_parent_shipment_number  => p_parent_shipment_number,
2158                                   p_supplier_doc_ref  => p_supp_doc_ref,
2159                                   p_supplier_line_ref => p_supp_line_ref,
2160                                   p_supplier_shipment_ref => p_supplier_shipment_ref*/);
2161 
2162 
2163                             IF (l_Debug_Level <= 1) THEN
2164                                     cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
2165                                     cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
2166                             END IF;
2167                          END IF;
2168                      END IF;
2169 
2170                     IF (l_Debug_Level <= 1) THEN
2171                             cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.store_supplier_request API For Standard PO',1);
2172                             cln_debug_pub.Add('Call is at Shipment Line Level......',1);
2173                     END IF;
2174                     PO_CHG_REQUEST_GRP.store_supplier_request (
2175                           p_requestor         => p_requestor,
2176                           p_int_cont_num      => p_internal_control_number,
2177                           p_request_type      => 'CHANGE',
2178                           p_tp_id             => p_tp_id,
2179                           p_tp_site_id        => p_tp_site_id,
2180                           p_level             => 'SHIPMENT',
2181                           p_po_number         => p_po_number,
2182                           p_release_number    => p_release_number,
2183                           p_po_type           => 'STANDARD',
2184                           p_revision_num      => NULL,
2185                           p_line_num          => p_line_number,
2186                           p_reason            => p_reason,
2187                           p_shipment_num      => p_shipment_number,
2188                           p_quantity          => p_new_quantity,
2189                           p_quantity_uom      => p_po_quantity_uom,
2190                           p_price             => NULL,
2191                           p_price_currency    => NULL,
2192                           p_price_uom         => NULL,
2193                           p_promised_date     => p_new_promised_date,
2194                           p_supplier_part_num => p_supplier_part_number,
2195                           p_so_number         => p_so_num,
2196                           p_so_line_number    => p_so_line_num,
2197                           p_ack_type          => 'MODIFICATION',
2198                           x_error_id_in       => l_error_id,
2199                           x_error_status_in   => l_error_status,
2200                           x_error_id_out      => l_error_id,
2201                           x_error_status_out  => l_error_status/*,
2202                           -- Supplier Line Reference added for new Change_PO API to
2203                           -- support split lines and cancellation at header and schedule level.
2204                           p_parent_shipment_number  => p_parent_shipment_number,
2205                           p_supplier_doc_ref  => p_supp_doc_ref,
2206                           p_supplier_line_ref => p_supp_line_ref,
2207                           p_supplier_shipment_ref => p_supplier_shipment_ref*/);
2208 
2209 
2210                     IF (l_Debug_Level <= 1) THEN
2211                             cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
2212                             cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
2213                     END IF;
2214 
2215                     IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
2216                          x_msg_data  :=   l_error_status;
2217                          l_msg_data  :=   l_error_status;
2218                          RAISE FND_API.G_EXC_ERROR;
2219                     END IF;
2220 
2221                 END IF;
2222 
2223                 IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
2224                      x_msg_data  :=   l_error_status;
2225                      l_msg_data  :=   l_error_status;
2226                      RAISE FND_API.G_EXC_ERROR;
2227                 END IF;
2228 
2229     /*
2230                 IF l_error_id IS NULL OR l_error_id = 0 THEN
2231                     cln_debug_pub.Add('Calling PO_CHG_REQUEST_GRP.process_supplier_request API',1);
2232 
2233                     PO_CHG_REQUEST_GRP.process_supplier_request (
2234                        p_int_cont_num      => p_internal_control_number,
2235                        x_error_id_in       => l_error_id,
2236                        x_error_status_in   => l_error_status,
2237                        x_error_id_out      => l_error_id,
2238                        x_error_status_out  => l_error_status
2239                     );
2240 
2241                     cln_debug_pub.Add('ERROR ID             : ' || l_error_id,1);
2242                     cln_debug_pub.Add('ERROR STATUS         : ' || l_error_status,1);
2243                 END IF;
2244      */
2245          END IF;
2246 
2247          IF l_error_id IS NOT NULL AND l_error_id <> 0 THEN
2248                x_msg_data  :=   l_error_status;
2249                l_msg_data  :=   l_error_status;
2253 
2250                RAISE FND_API.G_EXC_ERROR;
2251          END IF;
2252 
2254         IF ((p_cln_required = 'TRUE') AND (p_if_collaboration_updated = 'FALSE'))THEN
2255                 IF (l_Debug_Level <= 1) THEN
2256                         cln_debug_pub.Add('Call to Raise Update Event.....',1);
2257                 END IF;
2258                 RAISE_UPDATE_EVENT(
2259                       x_return_status                => x_return_status,
2260                       x_msg_data                     => x_msg_data,
2261                       p_coll_id                      => p_coll_id,
2262                       p_doc_status                   => 'SUCCESS',
2263                       p_org_ref                      => p_org_ref,
2264                       p_disposition                  => l_disposition,
2265                       p_msg_text                     => p_msg_dtl_screen,
2266                       p_internal_control_number      => p_internal_control_number );
2267 
2268                  IF(x_return_status <> 'S')THEN
2269                          p_if_collaboration_updated  := 'ERROR';
2270                          l_msg_data := 'Error in RAISE_UPDATE_EVENT API';
2271                          RAISE FND_API.G_EXC_ERROR;
2272                  END IF;
2273                  p_if_collaboration_updated      :=  'TRUE';
2274         END IF;
2275 
2276         IF(p_cln_required = 'TRUE') THEN
2277                  IF p_ackcode_line = 0 THEN
2278                         l_dtl_status          := 'Accepted';
2279                  ELSIF p_ackcode_line = 1 THEN
2280                         l_dtl_status          := 'Accepted With Changes';
2281                  ELSIF p_ackcode_line = 2 THEN
2282                         l_dtl_status          := 'Rejected';
2283                  ELSIF p_ackcode_line = 3 THEN
2284                         l_dtl_status          := 'Pending';
2285                  END IF;
2286 
2287                  IF (l_Debug_Level <= 1) THEN
2288                          cln_debug_pub.Add('Call to Raise Message Event.....',1);
2289                  END IF;
2290                  RAISE_ADD_MSG_EVENT(
2291                          x_return_status        => x_return_status,
2292                          x_msg_data             => x_msg_data,
2293                          p_coll_id              => p_coll_id,
2294                          p_ref1                 => l_dtl_status,
2295                          p_ref2                 => p_line_number,
2296                          p_ref3                 => p_shipment_number,
2297                          p_ref4                 => p_org_ref,
2298                          p_ref5                 => null,
2299                          p_dtl_msg              => l_msg_txt_lines,
2300                          p_internal_control_number      => p_internal_control_number );
2301 
2302                  IF(x_return_status <> 'S')THEN
2303                          p_if_collaboration_updated  := 'ERROR';
2304                          l_msg_data := 'Error in RAISE_ADD_MSG_EVENT API';
2305                          RAISE FND_API.G_EXC_ERROR;
2306                  END IF;
2307 
2308                  FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_CONSUMED');
2309                  FND_MESSAGE.SET_TOKEN('PONUM',p_po_number);
2310                  x_msg_data           :=  FND_MESSAGE.GET;
2311         END IF;
2312 
2313         --p_msg_dtl_screen              :=  NULL;
2314         p_msg_txt_lines                 :=  NULL;
2315         x_return_status                 :=  FND_API.G_RET_STS_SUCCESS;
2316 
2317         IF (l_Debug_Level <= 1) THEN
2318                 cln_debug_pub.Add(l_msg_data,1);
2319         END IF;
2320         IF (l_Debug_Level <= 2) THEN
2321                 cln_debug_pub.Add('------- Exiting PROCESS_HEADER_LINES API --------- ',2);
2322         END IF;
2323 
2324   -- Exception Handling
2325   EXCEPTION
2326 
2327          WHEN FND_API.G_EXC_ERROR THEN
2328               x_return_status           := FND_API.G_RET_STS_ERROR ;
2329               FND_MESSAGE.SET_NAME('CLN','CLN_CH_ACKPO_ERROR');
2330               FND_MESSAGE.SET_TOKEN('PONUM',p_po_number);
2331               FND_MESSAGE.SET_TOKEN('RELNUM',p_release_number);
2332               FND_MESSAGE.SET_TOKEN('REVNUM',p_revision_number);
2333               FND_MESSAGE.SET_TOKEN('MSG',x_msg_data);
2334               x_msg_data         := FND_MESSAGE.GET;
2335               IF (l_Debug_Level <= 5) THEN
2336                       cln_debug_pub.Add(l_msg_data,4);
2337                       cln_debug_pub.Add('------- ERROR :Exiting PROCESS_HEADER_LINES API --------- ',2);
2338               END IF;
2339 
2340 
2341          WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2342               l_error_code              :=SQLCODE;
2343               l_error_msg               :=SQLERRM;
2344               x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
2345               l_msg_data                :=l_error_code||' : '||l_error_msg;
2346               IF (l_Debug_Level <= 5) THEN
2347                       cln_debug_pub.Add(l_msg_data,6);
2348                       cln_debug_pub.Add('------- ERROR :Exiting PROCESS_HEADER_LINES API --------- ',2);
2349               END IF;
2350 
2351          WHEN OTHERS THEN
2352               l_error_code              :=SQLCODE;
2353               l_error_msg               :=SQLERRM;
2354               x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
2355               FND_MESSAGE.SET_NAME('CLN','CLN_CH_UNEXPECTED_ERROR');
2356               FND_MESSAGE.SET_TOKEN('ERRORCODE',l_error_code);
2357               FND_MESSAGE.SET_TOKEN('ERRORMSG',l_error_msg);
2358               x_msg_data :=FND_MESSAGE.GET;
2359               l_msg_data         :='Unexpected Error in PROCESS_HEADER_LINES   -'||l_error_code||' : '||l_error_msg;
2360               IF (l_Debug_Level <= 5) THEN
2364 
2361                       cln_debug_pub.Add(l_msg_data,6);
2362                       cln_debug_pub.Add('------- ERROR :Exiting PROCESS_HEADER_LINES API --------- ',2);
2363               END IF;
2365  END PROCESS_HEADER_LINES_RN;
2366 
2367 
2368 
2369 
2370     -- Name
2371     --   CLN_GET_PO_ACK_CODE_RN
2372     -- Purpose
2373     --   This procedure is called from RosettaNet XGMs.
2374     --   This procedure is used to get the ACK_CODE fro ack_reason_code and ack_status_code
2375     -- Arguments
2376     --
2377     -- Notes
2378     --   No specific notes.
2379 
2380 PROCEDURE CLN_GET_PO_ACK_CODE_RN (
2381          p_po_ack_reason_code   IN VARCHAR2,
2382          p_po_status_code       IN VARCHAR2,
2383          x_po_ack_code          OUT NOCOPY VARCHAR2) IS
2384 BEGIN
2385         IF (l_Debug_Level <= 2) THEN
2386                 cln_debug_pub.Add('---- Entering CLN_GET_PO_AKC_CODE_RN API ----- ', 2);
2387         END IF;
2388 
2389         IF (l_Debug_Level <= 1) THEN
2390                 cln_debug_pub.Add('----- PARAMETERS RECEIVED ------- ',1);
2391                 cln_debug_pub.Add('PO Ack Reason Code received          - '||p_po_ack_reason_code,1);
2392                 cln_debug_pub.Add('PO Status Code received         - '||p_po_status_code,1);
2393         END IF;
2394 
2395         IF (p_po_ack_reason_code = 'Accept with changes' AND p_po_status_code = 'Accept')  THEN
2396         x_po_ack_code := 1;
2397         ELSIF  ( p_po_status_code = 0)  THEN
2398         x_po_ack_code :=  0;
2399         ELSIF  ( p_po_status_code = 2)  THEN
2400         x_po_ack_code :=  2;
2401         ELSIF  ( p_po_status_code = 3)  THEN
2402         x_po_ack_code :=  3;
2403         END IF;
2404 
2405 
2406 		IF (l_Debug_Level <= 2) THEN
2407                 cln_debug_pub.Add('---- Exiting CLN_GET_PO_AKC_CODE_RN API ----- ', 2);
2408         END IF;
2409 
2410 END CLN_GET_PO_ACK_CODE_RN;
2411 
2412 
2413   PROCEDURE UPDATE_COLL_FOR_HDR_ONLY_MSG(
2414          x_return_status             IN OUT NOCOPY VARCHAR2,
2415          x_msg_data                  IN OUT NOCOPY VARCHAR2,
2416          p_ackcode_header            IN NUMBER,
2417          p_ackcode_line              IN NUMBER,
2418          p_coll_id                   IN NUMBER,
2419          p_org_ref                   IN VARCHAR2,
2420          p_cln_required              IN VARCHAR2,
2421          p_internal_control_number   IN VARCHAR2,
2422          p_so_num                    IN VARCHAR2,
2423          p_message                   IN OUT NOCOPY VARCHAR2,
2424          p_if_collaboration_updated  IN OUT NOCOPY VARCHAR2)
2425   IS
2426          l_error_code                NUMBER;
2427          l_error_msg                 VARCHAR2(255);
2428          l_msg_data                  VARCHAR2(255);
2429          l_debug_mode                VARCHAR2(255);
2430          l_return_code               NUMBER;
2431          l_return_status             VARCHAR2(255);
2432          l_disposition               VARCHAR2(255);
2433          l_error_id                  NUMBER;
2434          l_error_status              VARCHAR2(1000);
2435 
2436 
2437   BEGIN
2438 
2439 	 IF (l_Debug_Level <= 2) THEN
2440 		 cln_debug_pub.Add('----- Entering UPDATE_COLL_FOR_HDR_ONLY_MSG API ------- ',2);
2441 	 END IF;
2442 	 IF (l_Debug_Level <= 1) THEN
2443 		 cln_debug_pub.Add('----- PARAMETERS RECEIVED ------- ',1);
2444 		 cln_debug_pub.Add('Status received          - '||x_return_status,1);
2445 		 cln_debug_pub.Add('Message received         - '||x_msg_data,1);
2446 		 cln_debug_pub.Add('Ackcode at header level  - '||p_ackcode_header,1);
2447 		 cln_debug_pub.Add('Originator Reference     - '||p_org_ref,1);
2448 		 cln_debug_pub.Add('Collaboration ID         - '||p_coll_id,1);
2449 		 cln_debug_pub.Add('Detail Header Message    - '||p_message,1);
2450 		 cln_debug_pub.Add('Internal Control Number  - '||p_internal_control_number,1);
2451 		 cln_debug_pub.Add('Collaboration Updated    - '||p_if_collaboration_updated,1);
2452 		 cln_debug_pub.Add('CLN reqd                 - '||p_cln_required,1);
2453 		 cln_debug_pub.Add('----------------------------------',1);
2454 	 END IF;
2455 	 IF ((p_cln_required = 'TRUE') AND (p_if_collaboration_updated = 'FALSE'))THEN
2456 
2457 		 IF(p_ackcode_header = 0) THEN
2458 		    l_disposition            := 'ACCEPTED';
2459 		 ELSIF (p_ackcode_header = 1) THEN
2460 		    l_disposition            := 'ACCEPTED';
2461 		 ELSIF(p_ackcode_header = 2) THEN
2462 		    l_disposition            := 'REJECTED';
2463 		 ELSIF (p_ackcode_header = 3) THEN
2464 		    l_disposition            := 'PENDING';
2465 		 END IF;
2466 
2467 
2468 
2469 		 -- Identify PO Type based on release number
2470 
2471                 IF (l_Debug_Level <= 1) THEN
2472                         cln_debug_pub.Add('Call to Raise Update Event.....',1);
2473                 END IF;
2474                 RAISE_UPDATE_EVENT(
2475                       x_return_status                => x_return_status,
2476                       x_msg_data                     => x_msg_data,
2477                       p_coll_id                      => p_coll_id,
2478                       p_doc_status                   => 'SUCCESS',
2479                       p_org_ref                      => p_org_ref,
2480                       p_disposition                  => l_disposition,
2481                       p_msg_text                     => p_message,
2482                       p_internal_control_number      => p_internal_control_number );
2483 
2484                  IF(x_return_status <> 'S')THEN
2485                          p_if_collaboration_updated  := 'ERROR';
2486                          l_msg_data := 'Error in RAISE_UPDATE_EVENT API';
2487                          RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2488                  END IF;
2489                  p_if_collaboration_updated      :=  'TRUE';
2490         END IF;
2491 
2495         END IF;
2492         x_return_status                 :=  FND_API.G_RET_STS_SUCCESS;
2493         IF (l_Debug_Level <= 1) THEN
2494                 cln_debug_pub.Add(l_msg_data,1);
2496         IF (l_Debug_Level <= 2) THEN
2497                 cln_debug_pub.Add('------- Exiting UPDATE_COLL_FOR_HDR_ONLY_MSG API --------- ',2);
2498         END IF;
2499 
2500   -- Exception Handling
2501   EXCEPTION
2502 
2503 
2504          WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2505               l_error_code              :=SQLCODE;
2506               l_error_msg               :=SQLERRM;
2507               x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
2508               l_msg_data                :=l_error_code||' : '||l_error_msg;
2509               IF (l_Debug_Level <= 5) THEN
2510                       cln_debug_pub.Add(l_msg_data,6);
2511                       cln_debug_pub.Add('------- ERROR :Exiting UPDATE_COLL_FOR_HDR_ONLY_MSG API --------- ',2);
2512               END IF;
2513 
2514          WHEN OTHERS THEN
2515               l_error_code              :=SQLCODE;
2516               l_error_msg               :=SQLERRM;
2517               x_return_status           :=FND_API.G_RET_STS_UNEXP_ERROR ;
2518               FND_MESSAGE.SET_NAME('CLN','CLN_CH_UNEXPECTED_ERROR');
2519               FND_MESSAGE.SET_TOKEN('ERRORCODE',l_error_code);
2520               FND_MESSAGE.SET_TOKEN('ERRORMSG',l_error_msg);
2521               x_msg_data :=FND_MESSAGE.GET;
2522               l_msg_data         :='Unexpected Error in UPDATE_COLL_FOR_HDR_ONLY_MSG   -'||l_error_code||' : '||l_error_msg;
2523               IF (l_Debug_Level <= 5) THEN
2524                       cln_debug_pub.Add(l_msg_data,6);
2525                       cln_debug_pub.Add('------- ERROR :Exiting UPDATE_COLL_FOR_HDR_ONLY_MSG API --------- ',2);
2526               END IF;
2527 
2528  END UPDATE_COLL_FOR_HDR_ONLY_MSG;
2529 
2530 END CLN_ACK_PO_PKG;