DBA Data[Home] [Help]

PACKAGE BODY: APPS.XDPCORE

Source


1 PACKAGE BODY XDPCORE AS
2 /* $Header: XDPCOREB.pls 120.1 2005/06/15 22:36:52 appldev  $ */
3 
4 
5 /****
6  All Private Procedures for the Package
7 ****/
8 /***
9 Procedure EnqueuePendingQueue(itemtype in varchar2,
10                               itemkey  in varchar2);
11 ***/
12 Function GetOrderType(itemtype in varchar2,
13                       itemkey  in varchar2,
14                       actid    in number) return varchar2;
15 
16 Function GetOrderSource(itemtype in varchar2,
17                         itemkey  in varchar2,
18                         actid    in number) return varchar2;
19 
20 Function IsOANeeded(itemtype in varchar2,
21                     itemkey  in varchar2,
22                     actid    in number) return varchar2;
23 
24 Procedure LaunchOrderAnalyzer(itemtype in varchar2,
25                               itemkey  in varchar2,
26                               actid    in number);
27 
28 Procedure ResumeSDP(itemtype  in varchar2,
29                     itemkey   in varchar2,
30                     actid     in number,
31                     funcmode  in varchar2,
32                     resultout OUT NOCOPY varchar2);
33 
34 Function HandleOtherWFFuncmode (funcmode in varchar2) return varchar2;
35 
36 type RowidArrayType is table of rowid index by binary_integer;
37 
38 
39 
40 /***********************************************
41 * END of Private Procedures/Function Definitions
42 ************************************************/
43 
44 
45 -- StartWfProcess
46 -- Generic Procedure which starts up a  workflow process.
47 -- Used to Start Main Order Provisioning Process
48 
49 Procedure StartWfProcess ( ItemType     in VARCHAR2,
50                            ItemKey      in VARCHAR2,
51                            OrderID      in number,
52                            WorkflowProcess VARCHAR2,
53                            Caller       in VARCHAR2) is
54 
55  x_Progress                     VARCHAR2(2000);
56 
57 begin
58 
59   IF  ( ItemType is NOT NULL ) AND
60       ( ItemKey is NOT NULL )  AND
61       (OrderID is NOT NULL) then
62 
63 	wf_engine.CreateProcess( ItemType => ItemType,
64  				 ItemKey  => ItemKey,
65 				 process  => WorkflowProcess);
66 	--   *****
67 	-- Initialize workflow item attributes below
68 	--   *****
69 
70         wf_engine.SetItemAttrNumber(ItemType => ItemType,
71                                     ItemKey  => ItemKey,
72                                     aname    => 'ORDER_ID',
73                                     avalue   => OrderID);
74 
75 	wf_engine.StartProcess(itemtype => ItemType,
76 			       itemkey  => ItemKey);
77   ELSE
78      /* Set the Error Message */
79      x_ErrMsg := 'Got Null value';
80      RAISE e_NullValueException;
81   END IF;
82 
83 EXCEPTION
84      WHEN e_NullValueException then
85 
86           x_Progress := 'XDPCORE.StartWfProcess: Cannot Start Workflow process with null values for Itemtype: '
87                  || NVL(itemtype, 'NULL') || ' Itemkey: ' || NVL(itemkey, 'NULL') || ' OrderID ' || NVL(OrderID,  'NULL')
88                  || ' Process: ' || NVL(WorkflowProcess, 'NULL');
89 
90           wf_core.context('XDPCORE', 'StartWfProcess', itemtype, itemkey, x_Progress);
91           raise;
92      WHEN OTHERS THEN
93           wf_core.context('XDPCORE', 'StartWfProcess', itemtype, itemkey, null, null);
94           raise;
95 END StartWfProcess;
96 
97 
98 
99 
100 -- StartInitOrderProcess Process
101 -- Creates and Starts the OA process
102 
103 Procedure StartInitOrderProcess ( OrderID in number)
104 
105 IS
106 
107  x_Progress   VARCHAR2(2000);
108  Itemtype     VARCHAR2(8);
109  itemkey      VARCHAR2(240);
110  process      VARCHAR2(80);
111 
112 BEGIN
113 
114   if OrderID is NOT NULL then
115 
116     SELECT to_char(XDP_WF_ITEMKEY_S.NEXTVAL)
117       INTO itemkey
118       FROM dual;
119 
120     ItemType := 'XDPPROV';
121     itemkey  := to_char(OrderID) || '-INIT-' || itemkey;
122 
123      process := 'INIT_PROCESS_ORDER';
124 
125 	wf_engine.CreateProcess( ItemType => ItemType,
126 			 	 ItemKey  => ItemKey,
127 				 process  => process);
128 	--   *****
129 	-- Initialize workflow item attributes below
130 	--   *****
131 
132         wf_engine.SetItemAttrNumber(ItemType => ItemType,
133                                     ItemKey  => ItemKey,
134                                     aname    => 'ORDER_ID',
135                                     avalue   => OrderID);
136 
137 	wf_engine.StartProcess(itemtype        => ItemType,
138 				itemkey        => ItemKey);
139   else
140       /* Set the Error Message */
141       x_Progress := 'Got Null value';
142       RAISE e_NullValueException;
143    end if;
144 
145 exception
146 when others then
147    wf_core.context('XDPCORE', 'StartInitOrderProcess', itemtype, itemkey, null, x_progress);
148    raise;
149 end StartInitOrderProcess;
150 
151 
152 
153 
154 
155 -- StartORUProcess Process
156 -- Creates and Starts the Order Resubmission process
157 
158 Procedure StartORUProcess ( ResubmissionJobID in number,
159                             Itemtype         OUT NOCOPY varchar2,
160                             itemkey          OUT NOCOPY varchar2)
161 
162 IS
163 
164  x_Progress   VARCHAR2(2000);
165  l_ErrCode    NUMBER;
166  l_ErrStr     VARCHAR2(4000);
167  process      VARCHAR2(80);
168 
169  e_AddAttributeException exception;
170 
171 BEGIN
172 
173   IF ResubmissionJobID is NOT NULL then
174 
175     SELECT to_char(XDP_WF_ITEMKEY_S.NEXTVAL)
176       INTO itemkey
177       FROM dual;
178 
179     ItemType := 'XDPPROV';
180     itemkey  := to_char(ResubmissionJobID) || '-ORU-' || itemkey;
181 
182      process := 'ORDER_RESUBMISSION_PROCESS';
183 
184 
185 	wf_engine.CreateProcess( ItemType => ItemType,
186 				 ItemKey  => ItemKey,
187 				 process  => process);
188 	--   *****
189 	-- Initialize workflow item attributes below
190 	--   *****
191 
192         CheckNAddItemAttrNumber (itemtype  => itemtype,
193                                  itemkey   => itemkey,
194                                  AttrName  => 'RESUBMISSION_JOB_ID',
195                                  AttrValue => ResubmissionJobID,
196                                  ErrCode   => l_ErrCode,
197                                  ErrStr    => l_ErrStr);
198 
199     if l_ErrCode <> 0 then
200        x_progress := 'In XDPCORE.StartORUProcess. Error when adding RESUBMISSION_JOB_ID attribute. ';
201        raise e_AddAttributeException;
202     end if;
203 
204 	wf_engine.StartProcess(itemtype => ItemType,
205 				itemkey => ItemKey);
206   else
207       /* Set the Error Message */
208       x_Progress := 'Got Null value';
209       RAISE e_NullValueException;
210    end if;
211 
212 exception
213 when others then
214    wf_core.context('XDPCORE', 'StartORUProcess', itemtype, itemkey, null, x_progress);
215    raise;
216 end StartORUProcess;
217 
218 
219 -- StartOA Process
220 -- Creates and Starts the OA process
221 
222 Procedure StartOAProcess ( OrderID in number)
223 
224 is
225 
226  x_Progress VARCHAR2(2000);
227  Itemtype   VARCHAR2(8);
228  itemkey    VARCHAR2(240);
229  process    VARCHAR2(80);
230 
231 BEGIN
232 
233   if OrderID is NOT NULL then
234 
235     SELECT to_char(XDP_WF_ITEMKEY_S.NEXTVAL)
236       INTO itemkey
237       FROM dual;
238 
239     ItemType := 'XDPPROV';
240     itemkey  := to_char(OrderID) || '-OA-' || itemkey;
241 
242      process := 'PROV_PROCESS';
243 
244 	wf_engine.CreateProcess( ItemType => ItemType,
245 				 ItemKey  => ItemKey,
246 				 process  => process);
247 	--   *****
248 	-- Initialize workflow item attributes below
249 	--   *****
250 
251         wf_engine.SetItemAttrNumber(ItemType => ItemType,
252                                     ItemKey  => ItemKey,
253                                     aname    => 'ORDER_ID',
254                                     avalue   => OrderID);
255 
256 	wf_engine.StartProcess(itemtype        => ItemType,
257 				itemkey        => ItemKey);
258   else
259       /* Set the Error Message */
260       x_Progress := 'Got Null value';
261       RAISE e_NullValueException;
262    end if;
263 
264 exception
265 when others then
266    wf_core.context('XDPCORE', 'StartOAProcess', itemtype, itemkey, null, x_progress);
267    raise;
268 end StartOAProcess;
269 
270 
271 
272 
273 
274 
275 -- CreateOrderProcess
276 -- then creates the Main Order Process which the Order processor Dequer starts off
277 --
278 Procedure CreateOrderProcess (OrderID   in number,
279                               ItemType OUT NOCOPY VARCHAR2,
280                               ItemKey  OUT NOCOPY VARCHAR2 )
281 
282 is
283 
284  x_Progress  VARCHAR2(2000);
285 
286 begin
287 
288     SELECT to_char(XDP_WF_ITEMKEY_S.NEXTVAL)
289       INTO itemkey
290       FROM dual;
291 
292     ItemType := 'XDPPROV';
293     itemkey  := to_char(OrderID) || '-MAIN-' || itemkey;
294 
295     wf_engine.CreateProcess( ItemType => ItemType,
296                              ItemKey  => ItemKey,
297                              process  => 'MAIN_ORDER_PROCESS');
298 
299 	--   *****
300 	-- Initialize workflow item attributes below
301 	--   *****
302 
303      wf_engine.SetItemAttrNumber(ItemType => ItemType,
304                                  ItemKey  => ItemKey,
305                                  aname    => 'ORDER_ID',
306                                  avalue   => OrderID);
307 
308 
309 exception
310 when others then
311    x_progress := 'XDPCORE.CreateOrderProcess. Unhandled Excepton: ' || SUBSTR(SQLERRM, 1, 1500);
312    wf_core.context('XDPCORE', 'CreateOrderProcess', itemtype, itemkey, null, x_progress);
313    raise;
314 end CreateOrderProcess;
315 
316 
317 
318 
319 --  IS_OA_NEEDED
320 --   Resultout
321 --     yes/no
322 --
323 -- Your Description here: This procedure determines if the Order Analyzer is
324 --			  to Process the current Order
325 
326 
327 Procedure IS_OA_NEEDED (itemtype        in varchar2,
328                         itemkey         in varchar2,
329 			actid           in number,
330 			funcmode        in varchar2,
331 			resultout       OUT NOCOPY varchar2 ) IS
332 
333 
334  x_Progress                     VARCHAR2(2000);
335  l_Result varchar2(1);
336 
337 BEGIN
338 
339 -- RUN mode - normal process execution
340 --
341 	IF (funcmode = 'RUN') THEN
342 
343                 l_Result  := IsOANeeded(itemtype, itemkey ,actid);
344 		resultout := 'COMPLETE:' || l_Result;
345                 return;
346         ELSE
347                 resultout := HandleOtherWFFuncmode(funcmode);
348                 return;
349         END IF;
350 
351 
352 EXCEPTION
353 WHEN OTHERS THEN
354  wf_core.context('XDPCORE', 'IS_OA_NEEDED', itemtype, itemkey, to_char(actid), funcmode);
355  raise;
356 END IS_OA_NEEDED;
357 
358 
359 
360 
361 
362 
363 --  LAUNCH_ORDER_ANALYZER
364 --   Resultout
365 --     Activity Performed   - Activity was completed without any errors
366 --
367 -- Your Description here:
368 
369 Procedure LAUNCH_ORDER_ANALYZER (itemtype  in varchar2,
370 			         itemkey   in varchar2,
371 			         actid     in number,
372 			         funcmode  in varchar2,
373 			         resultout OUT NOCOPY varchar2 ) IS
374 
375  x_Progress   VARCHAR2(2000);
376 
377 BEGIN
378 -- RUN mode - normal process execution
379 --
380 	IF (funcmode = 'RUN') THEN
381                 LaunchOrderAnalyzer(itemtype, itemkey, actid);
382 		resultout := 'COMPLETE:ACTIVITY_PERFORMED';
383                 return;
384         ELSE
385                 resultout := HandleOtherWFFuncmode(funcmode);
386                 return;
387         END IF;
388 
389 EXCEPTION
390 WHEN OTHERS THEN
391  wf_core.context('XDPCORE', 'LAUNCH_ORDER_ANALYZER', itemtype, itemkey, to_char(actid), funcmode);
392  raise;
393 END LAUNCH_ORDER_ANALYZER;
394 
395 
396 --  SET_ORDER_STATUS_TO_HOLD
397 --   Resultout
398 --     Activity Performed   - Activity was completed without any errors
399 --
400 -- Your Description here:
401 
402 Procedure SET_ORDER_STATUS_TO_HOLD (itemtype  in varchar2,
403 			            itemkey   in varchar2,
404 			            actid     in number,
405 			            funcmode  in varchar2,
406 			            resultout OUT NOCOPY varchar2 ) IS
407 
408  x_Progress  VARCHAR2(2000);
409 
410 BEGIN
411 -- RUN mode - normal process execution
412 --
413         IF (funcmode = 'RUN') THEN
414 --      <your procedure here>
415                 resultout := 'COMPLETE:<result>';
416                 return;
417         ELSE
418                 resultout := HandleOtherWFFuncmode(funcmode);
419                 return;
420         END IF;
421 
422 EXCEPTION
423 WHEN OTHERS THEN
424  wf_core.context('XDPCORE', 'SET_ORDER_STATUS_TO_HOLD', itemtype, itemkey, to_char(actid), funcmode);
425  raise;
426 END SET_ORDER_STATUS_TO_HOLD;
427 
428 
429 --  ENQUEUE_PENDING_QUEUE
430 --   Resultout
431 --     Activity Performed   - Activity was completed without any errors
432 --
433 -- Your Description here:
434 /*****
435 
436 Procedure ENQUEUE_PENDING_QUEUE (itemtype  in varchar2,
437 		 	         itemkey   in varchar2,
438 			         actid     in number,
439 			         funcmode  in varchar2,
440 			         resultout OUT NOCOPY varchar2 ) IS
441 
442  x_Progress   VARCHAR2(2000);
443 
444 BEGIN
445 -- RUN mode - normal process execution
446 --
447         IF (funcmode = 'RUN') THEN
448                 EnqueuePendingQueue(itemtype, itemkey);
449                 resultout := 'COMPLETE:ACTIVITY_PERFORMED';
450                 return;
451         ELSE
452                 resultout := HandleOtherWFFuncmode(funcmode);
453                 return;
454         END IF;
455 
456 EXCEPTION
457 WHEN OTHERS THEN
458  wf_core.context('XDPCORE', 'ENQUEUE_PENDING_QUEUE', itemtype, itemkey, to_char(actid), funcmode);
459  raise;
460 END ENQUEUE_PENDING_QUEUE;
461 
462 ****/
463 
464 
465 
466 --  WHAT_SOURCE
467 --   Resultout
468 --     Activity Performed   - Activity was completed without any errors
469 --
470 -- Your Description here:
471 
472 Procedure WHAT_SOURCE (itemtype  in varchar2,
473 		       itemkey   in varchar2,
474 		       actid     in number,
475 		       funcmode  in varchar2,
476 		       resultout OUT NOCOPY varchar2 ) IS
477 
478  x_Progress  VARCHAR2(2000);
479  l_Result    VARCHAR2(40);
480 
481 BEGIN
482 
483 -- RUN mode - normal process execution
484 --
485         IF (funcmode = 'RUN') THEN
486                 l_Result := GetOrderSource(itemtype, itemkey , actid);
487                 resultout := 'COMPLETE:' || l_Result;
488                 return;
489         ELSE
490                 resultout := HandleOtherWFFuncmode(funcmode);
491                 return;
492         END IF;
493 
494 EXCEPTION
495 WHEN OTHERS THEN
496  wf_core.context('XDPCORE', 'WHAT_SOURCE', itemtype, itemkey, to_char(actid), funcmode);
497  raise;
498 END WHAT_SOURCE;
499 
500 
501 
502 --  ORDER_TYPE
503 --   Resultout
504 --     Activity Performed   - Activity was completed without any errors
505 --
506 -- Your Description here:
507 
508 Procedure ORDER_TYPE (itemtype  in varchar2,
509 		      itemkey   in varchar2,
510 		      actid     in number,
511 		      funcmode  in varchar2,
512 		      resultout OUT NOCOPY varchar2 ) IS
513 
514  x_Progress   VARCHAR2(2000);
515  l_Result     VARCHAR2(40);
516 
517 BEGIN
518 
519 -- RUN mode - normal process execution
520 --
521         IF (funcmode = 'RUN') THEN
522                 l_Result := GetOrderType(itemtype, itemkey, actid);
523                 resultout := 'COMPLETE:' || l_Result;
524                 return;
525         ELSE
526                 resultout := HandleOtherWFFuncmode(funcmode);
527                 return;
528         END IF;
529 
530 EXCEPTION
531 WHEN OTHERS THEN
532  wf_core.context('XDPCORE', 'ORDER_TYPE', itemtype, itemkey, to_char(actid), funcmode);
533  raise;
534 END ORDER_TYPE;
535 
536 
537 
538 --  RESUME_SDP
539 --   Resultout
540 --     Activity Performed   - Activity was completed without any errors
541 --
542 -- Your Description here: Put the Order requiring Order Analyzer into the
543 --			  Order Analyzer Queue for processing.
544 
545 Procedure RESUME_SDP (itemtype   in varchar2,
546                       itemkey    in varchar2,
547                       actid      in number,
548                       funcmode   in varchar2,
549                       resultout  OUT NOCOPY varchar2 ) IS
550 
551  x_Progress VARCHAR2(2000);
552 
553 BEGIN
554 -- RUN mode - normal process execution
555 --
556 	IF (funcmode = 'RUN') THEN
557                 ResumeSDP(itemtype, itemkey, actid, funcmode,resultout);
558 		resultout := 'COMPLETE';
559                 return;
560         ELSE
561                 resultout := HandleOtherWFFuncmode(funcmode);
562                 return;
563         END IF;
564 
565 EXCEPTION
566 WHEN OTHERS THEN
567  wf_core.context('XDPCORE', 'RESUME_SDP', itemtype, itemkey, to_char(actid), funcmode);
568  raise;
569 END RESUME_SDP;
570 
571 
572 Procedure OP_START (itemtype  in varchar2,
573                     itemkey   in varchar2,
574                     actid     in number,
575                     funcmode  in varchar2,
576                     resultout OUT NOCOPY varchar2 ) IS
577 
578 BEGIN
579 
580   null;
581 
582 EXCEPTION
583 
584      WHEN OTHERS THEN
585           wf_core.context('XDPCORE', 'OP_START', itemtype, itemkey, to_char(actid), funcmode);
586           raise;
587 END OP_START;
588 
589 Procedure OP_END (itemtype  in varchar2,
590                   itemkey   in varchar2,
591                   actid     in number,
592                   funcmode  in varchar2,
593                   resultout OUT NOCOPY varchar2 ) IS
594 
595 BEGIN
596   null;
597 EXCEPTION
598 WHEN OTHERS THEN
599  wf_core.context('XDPCORE', 'OP_END', itemtype, itemkey, to_char(actid), funcmode);
600  raise;
601 END OP_END;
602 
603 
604 /****
605  All the Private Functions
606 ****/
607 
608 Function HandleOtherWFFuncmode( funcmode in varchar2) return varchar2
609 is
610 resultout    VARCHAR2(30);
611 x_Progress   VARCHAR2(2000);
612 
613 begin
614 
615         IF (funcmode = 'CANCEL') THEN
616                 resultout := 'COMPLETE';
617         END IF;
618 
619         IF (funcmode = 'RESPOND') THEN
620                 resultout := 'COMPLETE';
621         END IF;
622 
623         IF (funcmode = 'FORWARD') THEN
624                 resultout := 'COMPLETE';
625         END IF;
626 
627         IF (funcmode = 'TRANSFER') THEN
628                 resultout := 'COMPLETE';
629         END IF;
630 
631         IF (funcmode = 'TIMEOUT') THEN
632                 resultout := 'COMPLETE';
633         END IF;
634 
635         IF (funcmode = 'others') THEN
636                 resultout := 'COMPLETE';
637         END IF;
638 
639 
640         return resultout;
641 
642 end;
643 
644 
645 
646 /******
647 
648 PROCEDURE EnqueuePendingQueue (itemtype IN VARCHAR2,
649                                itemkey  IN VARCHAR2)
650 IS
651 
652  l_OrderID          NUMBER;
653  l_ErrCode          NUMBER;
654  l_ErrStr           VARCHAR2(2000);
655  x_progress         VARCHAR2(2000);
656  e_EnqueueException EXCEPTION;
657 
658 BEGIN
659 
660  l_OrderID := wf_engine.GetItemAttrNumber(itemtype => itemtype,
661                                           itemkey  => itemkey,
662                                           aname    => 'ORDER_ID');
663 
664  UPDATE xdp_order_headers
665   SET state             = 'WAIT',
666       last_update_date  = sysdate,
667       last_updated_by   = fnd_global.user_id,
668       last_update_login = fnd_global.login_id
669  WHERE order_id = l_orderid
670    AND state    = 'PREPROCESS';
671 
672  UPDATE xdp_order_line_items
673   SET state = 'WAIT',
674       last_update_date  = sysdate,
675       last_updated_by   = fnd_global.user_id,
676       last_update_login = fnd_global.login_id
677  WHERE order_id = l_orderid
678    AND state    = 'PREPROCESS';
679 
680  XDP_AQ_UTILITIES.Pending_Order_EQ( p_order_id          => l_OrderID,
681                                     p_prov_date         => sysdate,
682                                     p_priority          => 100,
683                                     p_return_code       => l_ErrCode,
684                                     p_error_description => l_ErrStr);
685 
686  IF l_ErrCode <> 0 then
687     x_Progress := 'XDPCORE.EnqueuePendingQueue. Error when enqueuing into the Pending Order Queue. Error: ' || SUBSTR(l_ErrStr, 1, 1500);
688     raise e_EnqueueException;
689  END IF;
690 
691 EXCEPTION
692     WHEN e_EnqueueException THEN
693          wf_core.context('XDPCORE', 'EnqueuePendingQueue',itemtype,itemkey, null,x_progress);
694          raise;
695     WHEN others THEN
696          x_progress := 'XDPCORE.EnqueuePendingQueue. Unhandled Exception: ' || SUBSTR(SQLERRM, 1, 1500);
697          wf_core.context('XDPCORE', 'EnqueuePendingQueue',itemtype,itemkey, null,x_progress);
698          raise;
699 END EnqueuePendingQueue;
700 *******/
701 
702 PROCEDURE ResumeSDP (itemtype   IN VARCHAR2,
703                      itemkey    IN VARCHAR2,
704                      actid      IN NUMBER,
705                      funcmode   IN VARCHAR2,
706                      resultout OUT NOCOPY VARCHAR2)
707 IS
708  x_progress VARCHAR2(2000);
709  l_Status   VARCHAR2(40);
710 
711 
712  l_wi_instance_id number;
713  l_error_code number;
714 
715  e_deregister_exception exception;
716 BEGIN
717  --
718  -- The next line is commented out as l_Status is not used in this context.
719  -- Commenting out this line allows us to remove attribue WORKITEM_STATUS in
720  -- the workflow activity 'complete workitem and update status'
721  -- Bug 1224293
722  -- Anping Wang
723  -- 12/21/2000
724 
725  -- Bug 1790288
726  -- Once the Work Item completes all the waiting Events and Timers must be
727  -- Expired
728  -- Raja 5/30/2001
729 
730  l_wi_instance_id := wf_engine.GetItemAttrNumber(itemtype => ResumeSDP.itemtype,
731 					         itemkey => ResumeSDP.itemkey,
732 					         aname => 'WORKITEM_INSTANCE_ID');
733 
734  xnp_timer_standard.deregister_for_workitem(p_workitem_instance_id => l_wi_instance_id,
735 					    x_error_code => l_error_code,
736 					    x_error_message => x_progress);
737 
738  if (l_error_code <> 0 ) then
739 	raise e_deregister_exception;
740  end if;
741 
742  xnp_event.deregister_for_workitem(p_workitem_instance_id => l_wi_instance_id,
743 				   x_error_code => l_error_code,
744 				   x_error_message => x_progress);
745 
746  if (l_error_code <> 0 ) then
747 	raise e_deregister_exception;
748  end if;
749 
750  /* Call API to Set Workitem Status */
751 
752  XDPSTATUS.SetWorkitemStatus(ResumeSDP.itemtype, ResumeSDP.itemkey);
753 
754 
755 -- WF_STANDARD.CONTINUEFLOW(itemtype, itemkey, actid, funcmode,resultout);
756  XDP_UTILITIES.CONTINUEFLOW(itemtype, itemkey);
757 
758 
759 
760 EXCEPTION
761      WHEN e_deregister_exception then
762           x_progress := 'XDPCORE.ResumeSDP. Error when Deregistering Timers and Callback Events' || SUBSTR(x_progress, 1, 1800);
763           wf_core.context('XDPCORE', 'ResumeSDP', itemtype, itemkey, to_char(actid), x_progress);
764 	  raise;
765      WHEN others THEN
766           x_progress := 'XDPCORE.ResumeSDP. Unhandled Exception: ' || SUBSTR(SQLERRM, 1, 1500);
767           wf_core.context('XDPCORE', 'ResumeSDP', itemtype, itemkey, to_char(actid), x_progress);
768 	  raise;
769 END ResumeSDP;
770 
771 
772 
773 FUNCTION GetOrderType (itemtype IN VARCHAR2,
774                        itemkey  IN VARCHAR2,
775                        actid    IN NUMBER) RETURN VARCHAR2
776 
777 IS
778 
779  x_progress  VARCHAR2(2000);
780  l_OrderType VARCHAR2(40);
781 
782 BEGIN
783 
784  l_OrderType := 'NORMAL';
785 
786  return l_OrderType;
787 
788 
789 EXCEPTION
790      WHEN others THEN
791           x_progress := 'XDPCORE.GetOrderType. Unhandled Exception: ' || SUBSTR(SQLERRM, 1, 1500);
792           wf_core.context('XDPCORE', 'GetOrderType', itemtype, itemkey, to_char(actid), x_progress);
793 END GetOrderType;
794 
795 
796 
797 
798 FUNCTION GetOrderSource (itemtype IN VARCHAR2,
799                          itemkey  IN VARCHAR2,
800                          actid    IN NUMBER) RETURN VARCHAR2
801 
802 IS
803 
804  x_progress    VARCHAR2(2000);
805  l_OrderSource VARCHAR2(40);
806 
807 BEGIN
808 
809  l_OrderSource := 'PROV';
810 
811  return l_OrderSource;
812 
813 
814 EXCEPTION
815      WHEN others THEN
816           x_progress := 'XDPCORE.GetOrderSource. Unhandled Exception: ' || SUBSTR(SQLERRM, 1, 1500);
817           wf_core.context('XDPCORE', 'GetOrderSource', itemtype, itemkey, to_char(actid), x_progress);
818 END GetOrderSource;
819 
820 
821 FUNCTION IsOANeeded (itemtype IN VARCHAR2,
822                      itemkey  IN VARCHAR2,
823                      actid    IN NUMBER) RETURN VARCHAR2
824 
825 IS
826 
827  x_progress VARCHAR2(2000);
828  l_OAFlag   VARCHAR2(40);
829 
830 BEGIN
831 
832  l_OAFlag := wf_engine.GetActivityAttrText(itemtype => IsOANeeded.itemtype,
833                                            itemkey  => IsOANeeded.itemkey,
834                                            actid    => actid,
835                                            aname    => 'IS_OA_REQUIRED');
836 
837  return l_OAFlag;
838 
839 
840 EXCEPTION
841      WHEN others THEN
842           x_progress := 'XDPCORE.IsOANeeded. Unhandled Exception: ' || SUBSTR(SQLERRM, 1, 1500);
843           wf_core.context('XDPCORE', 'IsOANeeded', itemtype, itemkey, to_char(actid), x_progress);
844 END IsOANeeded;
845 
846 
847 PROCEDURE LaunchOrderAnalyzer (itemtype IN VARCHAR2,
848                                itemkey  IN VARCHAR2,
849                                actid    IN NUMBER)
850 
851 IS
852 
853  x_progress VARCHAR2(2000);
854 
855 BEGIN
856 
857 /*
858    XDP_ANALYZER.AnalyzeOrder;
859 */
860    null;
861 
862 EXCEPTION
863      WHEN others THEN
864           x_progress := 'XDPCORE.LaunchOrderAnalyzer. Unhandled Exception: ' || SUBSTR(SQLERRM, 1, 1500);
865           wf_core.context('XDPCORE', 'LaunchOrderAnalyzer', itemtype, itemkey, to_char(actid), x_progress);
866 END LaunchOrderAnalyzer;
867 
868 
869 
870 
871 PROCEDURE SEND_NOTIFICATION (role         IN VARCHAR2,
872                              msg_type     IN VARCHAR2,
873                              msg_name     IN VARCHAR2,
874                              due_date     IN VARCHAR2,
875                              itemtype     IN VARCHAR2,
876                              itemkey      IN VARCHAR2,
877                              actid        IN NUMBER,
878                              priority in number default 100,
879                              OrderID in number default null,
880                              WIInstanceID IN NUMBER DEFAULT NULL,
881                              FAInstanceID IN NUMBER DEFAULT NULL,
882                              notifID     OUT NOCOPY NUMBER)
883 IS
884 
885  l_context   VARCHAR2(2000);
886  x_Progress  VARCHAR2(2000);
887 
888 BEGIN
889 
890  l_context := SEND_NOTIFICATION.itemtype || ':' || SEND_NOTIFICATION.itemkey || ':' || to_char(SEND_NOTIFICATION.actid);
891 
892 
893  notifID := wf_notification.SEND(role,
894                                  msg_type,
895                                  msg_name,
896                                  due_date,
897                                  'wf_engine.cb',
898                                  l_context,
899                                  null,
900                                  priority);
901 
902 EXCEPTION
903      WHEN others THEN
904           wf_core.context('XDPCORE', 'SEND_NOTIFICATION',null,null, null,null);
905           raise;
906 END SEND_NOTIFICATION;
907 
908 
909 
910 PROCEDURE CheckNAddItemAttrText(itemtype  IN VARCHAR2,
911                                 itemkey   IN VARCHAR2,
912                                 AttrName  IN VARCHAR2,
913                                 AttrValue IN VARCHAR2,
914                                 ErrCode  OUT NOCOPY NUMBER,
915                                 ErrStr   OUT NOCOPY VARCHAR2)
916 IS
917  l_AttrFound NUMBER := 0;
918  l_Dummy     VARCHAR2(4000);
919  x_Progress  VARCHAR2(2000);
920 
921 BEGIn
922 
923   ErrCode := 0;
924   ErrStr := null;
925 
926   BEGIN
927 
928        l_Dummy := wf_engine.GetItemAttrText (itemtype => CheckNAddItemAttrText.itemtype,
929                                              itemkey  => CheckNAddItemAttrText.itemkey,
930                                              aname    => AttrName);
931 
932           l_AttrFound := 1;
933 
934           wf_engine.SetItemAttrText(itemtype => CheckNAddItemAttrText.itemtype,
935                                     itemkey  => CheckNAddItemAttrText.itemkey,
936                                     aname    => AttrName,
937                                     avalue   => AttrValue);
938 
939           return;
940 
941   EXCEPTION
942        WHEN others THEN
943         -- dbms_output.put_line(SQLCODE);
944         IF SQLCODE = -20002 THEN
945            l_AttrFound := 0;
946            wf_core.clear;
947         ELSE
948            RAISE;
949         END IF;
950   END;
951 
952 
953       IF l_AttrFound = 0 THEN
954 
955          wf_engine.AddItemAttr(itemtype => CheckNAddItemAttrText.itemtype,
956                                itemkey  => CheckNAddItemAttrText.itemkey,
957                                aname    => AttrName);
958 
959           wf_engine.SetItemAttrText(itemtype => CheckNAddItemAttrText.itemtype,
960                                     itemkey  => CheckNAddItemAttrText.itemkey,
961                                     aname    => AttrName,
962                                     avalue   => AttrValue);
963           return;
964       END IF;
965 
966 EXCEPTION
967      WHEN others THEN
968           ErrCode := SQLCODE;
969           ErrStr := SQLERRM;
970 END CheckNAddItemAttrText;
971 
972 
973 PROCEDURE CheckNAddItemAttrNumber(itemtype  IN VARCHAR2,
974                                   itemkey   IN VARCHAR2,
975                                   AttrName  IN VARCHAR2,
976                                   AttrValue IN NUMBER,
977                                   ErrCode  OUT NOCOPY NUMBER,
978                                   ErrStr   OUT NOCOPY VARCHAR2)
979 IS
980  l_AttrFound NUMBER := 0;
981  l_Dummy     NUMBER;
982  x_Progress  VARCHAR2(2000);
983 
984 BEGIN
985 
986   ErrCode := 0;
987   ErrStr := null;
988 
989   BEGIN
990 
991        l_Dummy := wf_engine.GetItemAttrNumber (itemtype => CheckNAddItemAttrNumber.itemtype,
992                                                itemkey  => CheckNAddItemAttrNumber.itemkey,
993                                                aname    => AttrName);
994 
995           l_AttrFound := 1;
996 
997           wf_engine.SetItemAttrNumber(itemtype => CheckNAddItemAttrNumber.itemtype,
998                                       itemkey  => CheckNAddItemAttrNumber.itemkey,
999                                       aname    => AttrName,
1000                                       avalue   => AttrValue);
1001 
1002           return;
1003 
1004   EXCEPTION
1005        WHEN others THEN
1006         -- dbms_output.put_line(SQLCODE);
1007 
1008         IF SQLCODE = -20002 then
1009            l_AttrFound := 0;
1010            wf_core.clear;
1011         ELSE
1012            RAISE;
1013         END IF;
1014   END;
1015 
1016 
1017       If l_AttrFound = 0 then
1018 
1019          wf_engine.AddItemAttr(itemtype => CheckNAddItemAttrNumber.itemtype,
1020                                itemkey  => CheckNAddItemAttrNumber.itemkey,
1021                                aname    => AttrName);
1022 
1023           wf_engine.SetItemAttrNumber(itemtype => CheckNAddItemAttrNumber.itemtype,
1024                                       itemkey => CheckNAddItemAttrNumber.itemkey,
1025                                       aname => AttrName,
1026                                       avalue => AttrValue);
1027           return;
1028       end if;
1029 
1030 EXCEPTION
1031      WHEN others THEN
1032           ErrCode := SQLCODE;
1033           ErrStr := SQLERRM;
1034 END CheckNAddItemAttrNumber;
1035 
1036 
1037 
1038 PROCEDURE CheckNAddItemAttrDate(itemtype  IN VARCHAR2,
1039                                 itemkey   IN VARCHAR2,
1040                                 AttrName  IN VARCHAR2,
1041                                 AttrValue IN dATE,
1042                                 ErrCode  OUT NOCOPY NUMBER,
1043                                 ErrStr   OUT NOCOPY VARCHAR2)
1044 IS
1045  l_AttrFound NUMBER := 0;
1046  l_Dummy     DATE;
1047  x_Progress  VARCHAR2(2000);
1048 
1049 BEGIN
1050 
1051   ErrCode := 0;
1052   ErrStr := null;
1053 
1054   BEGIN
1055 
1056        l_Dummy := wf_engine.GetItemAttrDate (itemtype => CheckNAddItemAttrDate.itemtype,
1057                                              itemkey  => CheckNAddItemAttrDate.itemkey,
1058                                              aname    => AttrName);
1059 
1060           l_AttrFound := 1;
1061 
1062           wf_engine.SetItemAttrDate(itemtype => CheckNAddItemAttrDate.itemtype,
1063                                     itemkey  => CheckNAddItemAttrDate.itemkey,
1064                                     aname    => AttrName,
1065                                     avalue   => AttrValue);
1066 
1067           return;
1068 
1069   EXCEPTION
1070       WHEN others THEN
1071         -- dbms_output.put_line(SQLCODE);
1072         IF SQLCODE = -20002 then
1073            l_AttrFound := 0;
1074            wf_core.clear;
1075         ELSE
1076            RAISE;
1077         END IF;
1078   END;
1079 
1080 
1081       IF l_AttrFound = 0 THEN
1082 
1083          wf_engine.AddItemAttr(itemtype => CheckNAddItemAttrDate.itemtype,
1084                                itemkey  => CheckNAddItemAttrDate.itemkey,
1085                                aname    => AttrName);
1086 
1087           wf_engine.SetItemAttrDate(itemtype => CheckNAddItemAttrDate.itemtype,
1088                                     itemkey  => CheckNAddItemAttrDate.itemkey,
1089                                     aname    => AttrName,
1090                                     avalue   => AttrValue);
1091           return;
1092       END IF;
1093 
1094 EXCEPTION
1095      WHEN others THEN
1096           ErrCode := SQLCODE;
1097           ErrStr := SQLERRM;
1098 END CheckNAddItemAttrDate;
1099 
1100 --This procedure creates the child process and sets the parent child
1101 --relationship along with the label of wait flow activity in parent
1102 -- bug fix for bug #2269403
1103 Procedure CreateNAddAttrNParentLabel(itemtype in varchar2,
1104                               itemkey in varchar2,
1105                               processname in varchar2,
1106                               parentitemtype in varchar2,
1107                               parentitemkey in varchar2,
1108                               waitflowLabel in varchar2,
1109                               OrderID in number,
1110                               LineitemID in number,
1111                               WIInstanceID in number,
1112                               FAInstanceID in number)
1113 IS
1114 
1115 l_NameArray Wf_Engine.NameTabTyp;
1116 l_ValueNumArray Wf_Engine.NumTabTyp;
1117 l_ErrCode number;
1118 l_ErrDescription varchar2(800);
1119 
1120 
1121 
1122 l_index number := 1;
1123 begin
1124 
1125         wf_engine.CreateProcess(itemtype => CreateNAddAttrNParentLabel.itemtype,
1126                                 itemkey => CreateNAddAttrNParentLabel.itemkey,
1127                                 process => processname);
1128 
1129 -- Only set its parent when it has one
1130         IF CreateNAddAttrNParentLabel.parentitemkey IS NOT NULL THEN
1131             wf_engine.SetItemParent(itemtype => CreateNAddAttrNParentLabel.itemtype,
1132                                 itemkey => CreateNAddAttrNParentLabel.itemkey,
1133                                 parent_itemtype => CreateNAddAttrNParentLabel.parentitemtype,
1134                                 parent_itemkey => CreateNAddAttrNParentLabel.parentitemkey,
1135                                 parent_context => CreateNAddAttrNParentLabel.waitflowlabel );
1136         END IF;
1137 
1138 		if OrderID is not null then
1139 			l_NameArray(l_index) := 'ORDER_ID';
1140 			l_ValueNumArray(l_index) := OrderID;
1141 
1142 			l_index := l_index + 1;
1143 		end if;
1144 
1145 		if LineItemID is not null  then
1146 			l_NameArray(l_index) := 'LINE_ITEM_ID';
1147 			l_ValueNumArray(l_index) := LineItemID;
1148 
1149                         l_index := l_index + 1;
1150 		end if;
1151 
1152 		if WIInstanceID is not null  then
1153 			l_NameArray(l_index) := 'WORKITEM_INSTANCE_ID';
1154 			l_ValueNumArray(l_index) := WIInstanceID;
1155 
1156 			l_index := l_index + 1;
1157 		end if;
1158 
1159 		if FAInstanceID is not null then
1160 			l_NameArray(l_index) := 'FA_INSTANCE_ID';
1161 			l_ValueNumArray(l_index) := FAInstanceID;
1162 		end if;
1163 
1164 
1165 		if l_index > 1 then
1166           BEGIN
1167 			wf_engine.SetItemAttrNumberArray
1168 					(itemtype => CreateNAddAttrNParentLabel.itemtype,
1169 					 itemkey  => CreateNAddAttrNParentLabel.itemKey,
1170 					 aname => l_NameArray,
1171 					 avalue => l_ValueNumArray);
1172                  EXCEPTION
1173 
1174                    WHEN OTHERS THEN
1175                        -- skilaru 01/10/2002
1176                        -- We get into this exception block only when the USER DEFINED Item type
1177                        -- does not contain any of the static Item attributes ORDER_ID, LINE_ITEM_ID,
1178                        -- WORKITEM_INSTANCE_ID, FA_INSTANCE_ID. We will go ahead and set them (IF THEY
1179                        -- ARE NOT DEFINED) dynamically for the User Defined Workflows.
1180 
1181 
1182 		             if OrderID is not null then
1183                        CheckNAddItemAttrNumber (itemtype => CreateNAddAttrNParentLabel.itemtype,
1184                                                 itemkey => CreateNAddAttrNParentLabel.itemKey,
1185                                                 AttrName => 'ORDER_ID',
1186                                                 AttrValue => OrderID,
1187                                                 ErrCode => l_ErrCode,
1188                                                 ErrStr => l_ErrDescription);
1189 
1190 
1191 		             end if;
1192 		             if LineItemID is not null  then
1193                        CheckNAddItemAttrNumber (itemtype => CreateNAddAttrNParentLabel.itemtype,
1194                                                 itemkey => CreateNAddAttrNParentLabel.itemKey,
1195                                                 AttrName => 'LINE_ITEM_ID',
1196                                                 AttrValue => LineItemID,
1197                                                 ErrCode => l_ErrCode,
1198                                                 ErrStr => l_ErrDescription);
1199 
1200 		             end if;
1201 		             if WIInstanceID is not null  then
1202                        CheckNAddItemAttrNumber (itemtype => CreateNAddAttrNParentLabel.itemtype,
1203                                                 itemkey => CreateNAddAttrNParentLabel.itemKey,
1204                                                 AttrName => 'WORKITEM_INSTANCE_ID',
1205                                                 AttrValue => WIInstanceID,
1206                                                 ErrCode => l_ErrCode,
1207                                                 ErrStr => l_ErrDescription);
1208 
1209 		             end if;
1210 		             if FAInstanceID is not null then
1211                        CheckNAddItemAttrNumber (itemtype => CreateNAddAttrNParentLabel.itemtype,
1212                                                 itemkey => CreateNAddAttrNParentLabel.itemKey,
1213                                                 AttrName => 'FA_INSTANCE_ID',
1214                                                 AttrValue => FAInstanceID,
1215                                                 ErrCode => l_ErrCode,
1216                                                 ErrStr => l_ErrDescription);
1217 		             end if;
1218           END;
1219 		end if;
1220 end CreateNAddAttrNParentLabel;
1221 
1222 
1223 
1224 Procedure CreateAndAddAttrNum(itemtype 		IN VARCHAR2,
1225 			      itemkey 		IN VARCHAR2,
1226 			      processname 	IN VARCHAR2,
1227 			      parentitemtype 	IN VARCHAR2,
1228 			      parentitemkey 	IN VARCHAR2,
1229 			      OrderID 		IN NUMBER,
1230 			      LineitemID 	IN NUMBER,
1231 			      WIInstanceID 	IN NUMBER,
1232 			      FAInstanceID 	IN NUMBER)
1233 
1234 IS
1235 
1236 l_NameArray Wf_Engine.NameTabTyp;
1237 l_ValueNumArray Wf_Engine.NumTabTyp;
1238 l_ErrCode number;
1239 l_ErrDescription varchar2(800);
1240 
1241 
1242 
1243 l_index number := 1;
1244 begin
1245 
1246         wf_engine.CreateProcess(itemtype => CreateAndAddAttrNum.itemtype,
1247                                 itemkey => CreateAndAddAttrNum.itemkey,
1248                                 process => processname);
1249 
1250 -- Only set its parent when it has one
1251         IF CreateAndAddAttrNum.parentitemkey IS NOT NULL THEN
1252             wf_engine.SetItemParent(itemtype => CreateAndAddAttrNum.itemtype,
1253                                 itemkey => CreateAndAddAttrNum.itemkey,
1254                                 parent_itemtype => CreateAndAddAttrNum.parentitemtype,
1255                                 parent_itemkey => CreateAndAddAttrNum.parentitemkey,
1256                                 parent_context => null);
1257         END IF;
1258 
1259 		if OrderID is not null then
1260 			l_NameArray(l_index) := 'ORDER_ID';
1261 			l_ValueNumArray(l_index) := OrderID;
1262 
1263 			l_index := l_index + 1;
1264 		end if;
1265 
1266 		if LineItemID is not null  then
1267 			l_NameArray(l_index) := 'LINE_ITEM_ID';
1268 			l_ValueNumArray(l_index) := LineItemID;
1269 
1270                         l_index := l_index + 1;
1271 		end if;
1272 
1273 		if WIInstanceID is not null  then
1274 			l_NameArray(l_index) := 'WORKITEM_INSTANCE_ID';
1275 			l_ValueNumArray(l_index) := WIInstanceID;
1276 
1277 			l_index := l_index + 1;
1278 		end if;
1279 
1280 		if FAInstanceID is not null then
1281 			l_NameArray(l_index) := 'FA_INSTANCE_ID';
1282 			l_ValueNumArray(l_index) := FAInstanceID;
1283 		end if;
1284 
1285 
1286 		if l_index > 1 then
1287           BEGIN
1288 			wf_engine.SetItemAttrNumberArray
1289 					(itemtype => CreateAndAddAttrNum.itemtype,
1290 					 itemkey  => CreateAndAddAttrNum.itemKey,
1291 					 aname => l_NameArray,
1292 					 avalue => l_ValueNumArray);
1293                  EXCEPTION
1294 
1295                    WHEN OTHERS THEN
1296                        -- skilaru 01/10/2002
1297                        -- We get into this exception block only when the USER DEFINED Item type
1298                        -- does not contain any of the static Item attributes ORDER_ID, LINE_ITEM_ID,
1299                        -- WORKITEM_INSTANCE_ID, FA_INSTANCE_ID. We will go ahead and set them (IF THEY
1300                        -- ARE NOT DEFINED) dynamically for the User Defined Workflows.
1301 
1302 
1303 		             if OrderID is not null then
1304                        CheckNAddItemAttrNumber (itemtype => CreateAndAddAttrNum.itemtype,
1305                                                 itemkey => CreateAndAddAttrNum.itemKey,
1306                                                 AttrName => 'ORDER_ID',
1307                                                 AttrValue => OrderID,
1308                                                 ErrCode => l_ErrCode,
1309                                                 ErrStr => l_ErrDescription);
1310 
1311 
1312 		             end if;
1313 		             if LineItemID is not null  then
1314                        CheckNAddItemAttrNumber (itemtype => CreateAndAddAttrNum.itemtype,
1315                                                 itemkey => CreateAndAddAttrNum.itemKey,
1316                                                 AttrName => 'LINE_ITEM_ID',
1317                                                 AttrValue => LineItemID,
1318                                                 ErrCode => l_ErrCode,
1319                                                 ErrStr => l_ErrDescription);
1320 
1321 		             end if;
1322 		             if WIInstanceID is not null  then
1323                        CheckNAddItemAttrNumber (itemtype => CreateAndAddAttrNum.itemtype,
1324                                                 itemkey => CreateAndAddAttrNum.itemKey,
1325                                                 AttrName => 'WORKITEM_INSTANCE_ID',
1326                                                 AttrValue => WIInstanceID,
1327                                                 ErrCode => l_ErrCode,
1328                                                 ErrStr => l_ErrDescription);
1329 
1330 		             end if;
1331 		             if FAInstanceID is not null then
1332                        CheckNAddItemAttrNumber (itemtype => CreateAndAddAttrNum.itemtype,
1333                                                 itemkey => CreateAndAddAttrNum.itemKey,
1334                                                 AttrName => 'FA_INSTANCE_ID',
1335                                                 AttrValue => FAInstanceID,
1336                                                 ErrCode => l_ErrCode,
1337                                                 ErrStr => l_ErrDescription);
1338 		             end if;
1339           END;
1340 		end if;
1341 
1342 end CreateAndAddAttrNum;
1343 
1344 
1345 Procedure START_FA_RESUBMIT_PROCESS( p_fe_id                IN NUMBER,
1346                                     p_start_date           IN DATE ,
1347                                     p_end_date             IN DATE,
1348                                     p_resubmission_job_id  IN NUMBER,
1349                                     x_error_code          OUT NOCOPY NUMBER,
1350                                     x_error_message       OUT NOCOPY VARCHAR2) IS
1351 
1352 l_fa_instance_id NUMBER;
1353 l_item_key       VARCHAR2(240);
1354 l_item_type      VARCHAR2(240);
1355 
1356 CURSOR c_fa IS
1357        SELECT fr.workitem_instance_id ,
1358               fr.fulfillment_action_id,
1359               fr.fa_instance_id
1360          FROM xdp_fa_runtime_list fr
1361         WHERE fr.fe_id = p_fe_id
1362           AND fr.status_code IN ('SUCCESS','SUCCESS_WITH_OVERRIDE')
1363           AND fr.completion_date >= p_start_date
1364           AND fr.completion_date <= NVL(p_end_date , sysdate)
1365           AND fr.resubmission_job_id IS NULL ;
1366 
1367 BEGIN
1368 
1369      -- Resubmit FA
1370 
1371      FOR c_fa_rec IN c_fa
1372          LOOP
1373             l_fa_instance_id := XDP_ENG_UTIL.RESUBMIT_FA
1374                                      ( p_resubmission_job_id => p_resubmission_job_id,
1375                                        p_resub_fa_instance_id => c_fa_rec.fa_instance_id );
1376 
1377          END LOOP ;
1378 
1379      -- Start ORU Process
1380 
1381             STARTORUPROCESS
1382                        (resubmissionjobid => p_resubmission_job_id,
1383                         itemtype          => l_item_type,
1384                         itemkey           => l_item_key );
1385 
1386      COMMIT;
1387 
1388 EXCEPTION
1389      WHEN others THEN
1390           x_error_code := -191266;
1391           FND_MESSAGE.SET_NAME('XDP', 'XDP_API_WHEN_OTHERS');
1392           FND_MESSAGE.SET_TOKEN('API_NAME', 'XDPCORE.START_RESUBMITT_PROCESS');
1393           FND_MESSAGE.SET_TOKEN('ERROR_STRING', SQLERRM);
1394           x_error_message := FND_MESSAGE.GET;
1395           RAISE ;
1396 END START_FA_RESUBMIT_PROCESS;
1397 
1398 Procedure START_RESUBMISSION_CHANNELS( p_fe_id              IN NUMBER,
1399                                        p_channels_reqd      IN NUMBER,
1400                                        p_usage_code         IN VARCHAR2,
1401                                        x_channels_started  OUT NOCOPY NUMBER,
1402                                        x_error_code        OUT NOCOPY NUMBER,
1403                                        x_error_message     OUT NOCOPY VARCHAR2) IS
1404 
1405 l_channels_to_start   NUMBER := 0;
1406 l_current_channels    NUMBER;
1407 l_channel_started     NUMBER;
1408 e_exception           EXCEPTION;
1409 l_error_code          NUMBER;
1410 l_error_message       VARCHAR2(240);
1411 
1412 CURSOR c_channel(channel_count IN NUMBER) IS
1413        SELECT channel_name,
1414               adapter_status ,
1415               seq_in_fe
1416          FROM xdp_adapter_reg
1417         WHERE fe_id = p_fe_id
1418           AND usage_code = p_usage_code
1419           AND rownum = channel_count
1420         ORDER BY seq_in_fe ;
1421 
1422 BEGIN
1423           if( FND_LOG.LEVEL_PROCEDURE >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then --Fix Bug: 4256771, dputhiye, 28 Apr 05
1424               FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,'XDPCORE.START_RESUBMISSION_CHANNELS',
1425                                                  'P_FE_ID is '||p_fe_id||
1426                                                  '   P_CHANNEL_REQD is '||p_channels_reqd||
1427                                                  '  P_USAGE_CODE is '||p_usage_code);
1428 	  end if;
1429 
1430           SELECT count(*)
1431             INTO l_current_channels
1432             FROM xdp_adapter_reg
1433            WHERE fe_id      = p_fe_id
1434              AND usage_code = p_usage_code ;
1435 
1436           IF p_channels_reqd >= l_current_channels THEN
1437              l_channels_to_start := l_current_channels ;
1438           ELSIF p_channels_reqd < l_current_channels THEN
1439              l_channels_to_start := p_channels_reqd ;
1440           END IF ;
1441 
1442           l_channel_started := 0 ;
1443 
1444           FOR c_channel_rec IN c_channel(l_channels_to_start)
1445               LOOP
1446                  IF c_channel_rec.adapter_status NOT IN ('IDLE','BUSY') THEN
1447 
1448                     XDP_ADAPTER.START_ADAPTER
1449                             (p_channelname  => c_channel_rec.channel_name,
1450                              p_retcode      => l_error_code ,
1451                              p_errbuf       => l_error_message );
1452 
1453                     IF l_error_code <> 0 THEN
1454                        RAISE e_exception ;
1455                     ELSE
1456                        l_channel_started := l_channel_started + 1 ;
1457                     END IF ;
1458                  ELSE
1459                     null ;
1460                  END IF ;
1461 
1462               END LOOP ;
1463               COMMIT;
1464 
1465              x_channels_started := l_channel_started ;
1466              if( FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL ) then --Fix Bug: 4256771, dputhiye, 28 Apr 05
1467                  FND_LOG.STRING(fnd_log.level_statement,'XDPCORE.START_RESUBMISSION_CHANNELS',
1468                                                     ' No. Of Channels Required '||p_channels_reqd ||
1469                                                     ' No Of Channel Started '||x_channels_started);
1470 	     end if;
1471 EXCEPTION
1472      WHEN e_exception THEN
1473           x_error_code := l_error_code ;
1474           x_error_message := l_error_message ;
1475           rollback;
1476           RAISE ;
1477 
1478      WHEN others THEN
1479           x_error_code := -191266;
1480           FND_MESSAGE.SET_NAME('XDP', 'XDP_API_WHEN_OTHERS');
1481           FND_MESSAGE.SET_TOKEN('API_NAME', 'XDPCORE.START_RESUBMISSION_CHANNELS');
1482           FND_MESSAGE.SET_TOKEN('ERROR_STRING', SQLERRM);
1483           x_error_message := FND_MESSAGE.GET;
1484           RAISE ;
1485 END START_RESUBMISSION_CHANNELS ;
1486 
1487 
1488 --
1489 -- Context
1490 --   set procedure context (for stack trace)
1491 -- IN
1492 --   pkg_name   - package name
1493 --   proc_name  - procedure/function name
1494 --   arg1       - first IN argument
1495 --   argn       - n'th IN argument
1496 -- EXCEPTIONS
1497 --   none
1498 --
1499 procedure Context(pkg_name  in varchar2,
1500                   proc_name in varchar2,
1501                   arg1      in varchar2 default '*none*',
1502                   arg2      in varchar2 default '*none*',
1503                   arg3      in varchar2 default '*none*',
1504                   arg4      in varchar2 default '*none*',
1505                   arg5      in varchar2 default '*none*',
1506                   arg6      in varchar2 default '*none*',
1507                   arg7      in varchar2 default '*none*',
1508                   arg8      in varchar2 default '*none*',
1509                   arg9      in varchar2 default '*none*',
1510                   arg10     in varchar2 default '*none*') is
1511 
1512     buf varchar2(32000);
1513 begin
1514     -- Start with package and proc name.
1515     buf := wf_core.newline||pkg_name||'.'||proc_name||'(';
1516 
1517     -- Add all defined args.
1518     if (arg1 <> '*none*') then
1519       buf := substrb(buf||arg1, 1, 32000);
1520     end if;
1521     if (arg2 <> '*none*') then
1522       buf := substrb(buf||', '||arg2, 1, 32000);
1523     end if;
1524     if (arg3 <> '*none*') then
1525       buf := substrb(buf||', '||arg3, 1, 32000);
1526     end if;
1527     if (arg4 <> '*none*') then
1528       buf := substrb(buf||', '||arg4, 1, 32000);
1529     end if;
1530     if (arg5 <> '*none*') then
1531       buf := substrb(buf||', '||arg5, 1, 32000);
1532     end if;
1533     if (arg6 <> '*none*') then
1534       buf := substrb(buf||',' ||arg6, 1, 32000);
1535     end if;
1536     if (arg7 <> '*none*') then
1537       buf := substrb(buf||', '||arg7, 1, 32000);
1538     end if;
1539     if (arg8 <> '*none*') then
1540       buf := substrb(buf||', '||arg8, 1, 32000);
1541     end if;
1542     if (arg9 <> '*none*') then
1543       buf := substrb(buf||', '||arg9, 1, 32000);
1544     end if;
1545     if (arg10 <> '*none*') then
1546       buf := substrb(buf||', '||arg10, 1, 32000);
1547     end if;
1548 
1549     buf := substrb(buf||')', 1, 32000);
1550 
1551     -- Concatenate to the error_stack buffer
1552     xdpcore.error_stack := substrb(xdpcore.error_stack||buf, 1, 32000);
1553 
1554 end Context;
1555 
1556 Procedure error_context (object_type in varchar2,
1557 		        object_key in varchar2,
1558 			error_name in varchar2,
1559 			error_message in varchar2)
1560 is
1561 
1562 begin
1563 
1564   xdpcore.business_error := 'Y';
1565   xdpcore.object_type := object_type;
1566   xdpcore.object_key := object_key;
1567   xdpcore.error_name := error_name;
1568   xdpcore.error_message := error_message;
1569 
1570 end error_context;
1571 
1572 function is_business_error return varchar2
1573 is
1574 begin
1575   return (NVL(xdpcore.business_error,'N'));
1576 
1577 end is_business_error;
1578 
1579 procedure Clear is
1580 begin
1581   xdpcore.business_error := 'N';
1582   xdpcore.object_type := '';
1583   xdpcore.object_key := '';
1584   xdpcore.error_name := '';
1585   xdpcore.error_number := '';
1586   xdpcore.error_message := '';
1587   xdpcore.error_stack := '';
1588 
1589 end Clear;
1590 
1591 
1592 -- Get_Error
1593 --   Return current error info and clear error stack.
1594 --   Returns null if no current error.
1595 -- OUT
1596 --   error_name - error name - varchar2(30)
1597 --   error_message - substituted error message - varchar2(2000)
1598 --   error_stack - error call stack, truncated if needed  - varchar2(2000)
1599 -- EXCEPTIONS
1600 --   none
1601 --
1602 procedure Get_Error(object_type OUT NOCOPY varchar2,
1603 		    object_key OUT NOCOPY varchar2,
1604 		    err_name OUT NOCOPY varchar2,
1605 		    err_message OUT NOCOPY varchar2,
1606                     err_stack OUT NOCOPY varchar2)
1607 is
1608 begin
1609   object_type := xdpcore.object_type;
1610   object_key := xdpcore.object_key;
1611   err_name := xdpcore.error_name;
1612   err_message := xdpcore.error_message;
1613   err_stack := xdpcore.error_stack;
1614   xdpcore.clear;
1615 end Get_Error;
1616 
1617 
1618 --
1619 -- Raise
1620 --   Raise an exception to the caller
1621 -- IN
1622 --   none
1623 -- EXCEPTIONS
1624 --   Raises an a user-defined (20002) exception with the error message.
1625 --
1626 procedure Raise(err_number in number default -20001,
1627 		err_message in varchar2 default null)
1628 is
1629 begin
1630   xdpcore.error_number := err_number;
1631 
1632   if (xdpcore.error_number = -20001) then
1633     xdpcore.error_message := substrb(to_char(sqlcode)||
1634                                      ': '||sqlerrm, 1, 2000);
1635   elsif (xdpcore.error_number is not null) then
1636     xdpcore.error_message := substrb(to_char(xdpcore.error_number)||
1637                                      ': '||err_message, 1, 2000);
1638   end if;
1639 
1640   -- Raise the error
1641   raise_application_error(err_number, xdpcore.error_message);
1642 
1643 exception
1644   when others then
1645     raise;
1646 end Raise;
1647 
1648 End XDPCORE;