DBA Data[Home] [Help]

PACKAGE BODY: APPS.MSD_WF

Source


1 PACKAGE BODY MSD_WF AS
2 /* $Header: msddpwfb.pls 120.2 2006/02/13 12:29:07 faliu noship $ */
3 
4 express_server varchar2(240);
5  DBName    varchar2(80);
6  CodeLoc   varchar2(80);
7  SharedLoc varchar2(80);
8  PlName    varchar2(30);
9  planID    varchar2(15);
10  Owner     varchar2(320);
11  DPAdmin   varchar2(320);
12  FixedDate varchar2(30);
13  g_owner   varchar2(340);
14  Master    varchar2(1);   --agb 02/15/02 is ODP Master controling cycle
15  gItemType varchar2(30);     -- noks 10/20/03 added for developers only,
16  gItemKey  varchar2(250);    -- to allow to debug code with private CODE.AW.
17 
18  gMaster_ItemKey varchar2(250);
19 
20 
21 -- connects to OES and run programs in OES and gets values back.
22 PROCEDURE DOEXPRESS (itemtype in varchar2,
23 		  itemkey  in varchar2,
24 		  actid    in number,
25 		  funcmode in varchar2,
26                   resultout   out NOCOPY varchar2)
27    IS
28     ActEntry     varchar2(16);
29     ActRetCode    varchar2(2000);
30     ActRetText   varchar2(2000);
31     ActRetVal    varchar2(2000);
32     ActRetErr    varchar2(2000);
33     thisrole     varchar2(320);
34     TempDate     date;
35     TxtDate      varchar2(16);   -- agb 06/14/00 to deal with ambiguous date
36     Process      varchar2(30);  -- agb 03/19/02 B2173260 added to wf.setactivity
37     Script       varchar(2000);
38 
39    BEGIN
40 
41 	gItemType := ItemType;
42  	gItemKey := ItemKey;
43 
44       IF (funcmode = 'RUN') THEN
45          resultout :='COMPLETE:N';
46        SELECT ACTIVITY_NAME, PROCESS_NAME INTO ActEntry, Process FROM WF_PROCESS_ACTIVITIES
47          WHERE INSTANCE_ID=actid;
48        SELECT TEXT_VALUE INTO thisrole FROM WF_ITEM_ATTRIBUTE_VALUES
49           WHERE ITEM_KEY=itemkey AND ITEM_TYPE=itemtype AND NAME='ODPROLE';
50        express_server:=wf_engine.GetItemAttrText(Itemtype => ItemType,
51 		       Itemkey => ItemKey,
52               	       aname => 'EXPCONN');
53 
54        -- new to indicate if ODP Master is governing Cycle
55        Master:=wf_engine.GetItemAttrText(Itemtype => ItemType,
56 		       Itemkey => ItemKey,
57   		       aname => 'ISMASTER');
58 
59        DBName:=wf_engine.GetItemAttrText(Itemtype => ItemType,
60 		       Itemkey => ItemKey,
61   		       aname => 'DBNAME');
62        DPAdmin:=wf_engine.GetItemAttrText(Itemtype => ItemType,
63 		       Itemkey => ItemKey,
64 		       aname => 'DPADMIN');
65        SharedLoc:=wf_engine.GetItemAttrText(Itemtype => ItemType,
66 	               Itemkey => ItemKey,
67  	  	       aname => 'SHAREDLOC');
68        CodeLoc:=wf_engine.GetItemAttrText(Itemtype => ItemType,
69 		       Itemkey => ItemKey,
70   	               aname => 'CODELOC');
71        PlanID:=wf_engine.GetItemAttrText(Itemtype => ItemType,
72 		       Itemkey => ItemKey,
73  	  	       aname => 'ODPPLAN');
74 
75 
76       -- call to wf.setactivity and get return values
77 
78       execute_dml(actentry, planid, dbname, SharedLoc, dpadmin, thisrole, itemkey, master, process,
79                   actretcode, actrettext, actretval, actreterr);
80 
81 
82 
83       if ActRetCode = 'Y' then
84          resultout :='COMPLETE:Y';
85       end if;
86 
87       if ActRetCode = 'MSG' then
88         -- corrected this name
89         if ActEntry = 'ODPSUBSTAT'
90            then
91             TxtDate := to_char(sysdate, 'YY MM DD HH24:MI');
92             TempDate := to_date(TxtDate, 'YY MM DD HH24:MI');
93             -- obsolete agb 6/14/00 TempDate := sysdate;
94             wf_engine.SetItemAttrDate(Itemtype => ItemType,
95 	  	   Itemkey => ItemKey,
96 		   aname => 'VALUE1',
97 		   avalue => TempDate);
98            end if;
99          resultout :='COMPLETE:MSG';
100       end if;
101 
102       if ActRetCode = 'CYCLE' then
103         -- corrected this name
104         if ActEntry = 'ODPSUBSTAT'
105            then
106             TxtDate := to_char(sysdate, 'YY MM DD HH24:MI');
107             TempDate := to_date(TxtDate, 'YY MM DD HH24:MI');
108             -- obsolete agb 6/14/00 TempDate := sysdate;
109             wf_engine.SetItemAttrDate(Itemtype => ItemType,
110 	  	   Itemkey => ItemKey,
111 		   aname => 'VALUE1',
112 		   avalue => TempDate);
113            end if;
114         resultout :='COMPLETE:CYCLE';
115       end if;
116 
117       if ActRetCode = 'BUSY' then
118          resultout :='COMPLETE:BUSY';
119       end if;
120       if ActRetCode = 'DONE' then
121          resultout :='COMPLETE:DONE';
122       end if;
123       if ActRetCode = 'END' then
124          resultout :='COMPLETE:END';
125       end if;
126     if ActRetCode = 'Y' then
127  	if ActEntry = 'ODPDIST'
128           then
129              wf_engine.SetItemAttrText(Itemtype => ItemType,
130       		    Itemkey => ItemKey,
131 		          aname => 'ASSIGNID',
132 		          avalue => ActRetVal);
133              wf_engine.SetItemAttrText(Itemtype => ItemType,
134 		          Itemkey => ItemKey,
135 		          aname => 'ASSIGNNAME',
136 		          avalue => ActRetText);
137            end if;
138 
139       end if;
140       if ActRetCode = 'N' then
141       wf_engine.SetItemAttrText(Itemtype => ItemType,
142 				   Itemkey => ItemKey,
143 				   aname => 'DPPROBLEM',
144 				   avalue => ActRetErr);
145       end if;
146 
147       return;
148 
149       END IF;
150 
151   exception
152    when others then
153      if instr(upper(SQLERRM), 'EXPRESS') > 0 or instr(upper(SQLERRM), 'SNAPI') > 0
154 	then
155          resultout :='COMPLETE:N';
156          wf_engine.SetItemAttrText(Itemtype => ItemType,
157 				   Itemkey => ItemKey,
158 				   aname => 'DPPROBLEM',
159 				   avalue => substr(SQLERRM, 1, 200));
160 
161 	   update msd_demand_plans
162 		    set DP_BUILD_ERROR_FLAG = 'YES'
163 		    where demand_plan_id = to_number(PlanID);
164 	   commit;
165 
166          return;
167 	else
168      	   WF_CORE.CONTEXT('MSD_WF', 'DOEXPRESS',
169     	   itemtype, itemkey, to_char(actid), funcmode);
170          raise;
171 	end if;
172 
173 end DOEXPRESS;
174 
175 -- Starts a Workflow process.
176 PROCEDURE STARTPRO (WorkflowProcess in varchar2,
177                       iteminput in varchar2,
178                       inputkey in varchar2,
179                       inowner  in varchar2,
180                       inrole   in varchar2,
181                       inplan   in varchar2,
182                       inCDate  in varchar2,
183 			    inCodeDB in varchar2)
184 
185 IS
186    itemtype varchar2(30);
187    itemkey varchar2(240);
188    owner varchar2(320);
189    CompDate date;
190 
191    userID number;
192    respID  number;
193    respApplID number;
194 
195 BEGIN
196    itemtype := iteminput;
197    itemkey := inputkey;
198    owner := inowner;
199    userID := fnd_global.user_id;
200    respID  := fnd_global.resp_id;
201    respApplID := fnd_global.resp_appl_id;
202 
203 
204    SELECT demand_plan_name, code_location, shared_db_prefix,
205     shared_db_location, express_connect_string INTO PlName,
206     CodeLoc, DBName, SharedLoc, express_server
207     from msd_demand_plans_v
208     where demand_plan_id=to_number(inPlan);
209 
210 
211    wf_engine.CreateProcess(ItemType => ItemType,
212                            itemKey => ItemKey,
213                            process => WorkflowProcess);
214    -- The sysinfo(user that launched the process or the Owner of the process.
215    -- This would be the demand planning administrator.
216    wf_engine.SetItemOwner(ItemType => ItemType,
217                          ItemKey => ItemKey,
218                          owner => owner);
219    wf_engine.SetItemAttrText(Itemtype => ItemType,
220 				   Itemkey => ItemKey,
221 				   aname => 'DPADMIN',
222 				   avalue => owner);
223    wf_engine.SetItemAttrText(Itemtype => ItemType,
224 				   Itemkey => ItemKey,
225 				   aname => 'ODPROLE',
226 				   avalue => inrole);
227    -- Plan ID!
228    wf_engine.SetItemAttrText(Itemtype => ItemType,
229 				   Itemkey => ItemKey,
230 				   aname => 'ODPPLAN',
231 				   avalue => inplan);
232    wf_engine.SetItemAttrText(Itemtype => ItemType,
233 				   Itemkey => ItemKey,
234 				   aname => 'PLNAME',
235 				   avalue => PlName);
236    wf_engine.SetItemAttrText(Itemtype => ItemType,
237 				   Itemkey => ItemKey,
238 				   aname => 'CODELOC',
239 				   avalue => CodeLoc);
240    wf_engine.SetItemAttrText(Itemtype => ItemType,
241 				   Itemkey => ItemKey,
242 				   aname => 'DBNAME',
243 				   avalue => DBName);
244    wf_engine.SetItemAttrText(Itemtype => ItemType,
245 				   Itemkey => ItemKey,
246 				   aname => 'SHAREDLOC',
247 				   avalue => SharedLoc);
248    wf_engine.SetItemAttrText(Itemtype => ItemType,
249 				   Itemkey => ItemKey,
250 				   aname => 'EXPCONN',
251 				   avalue => express_server);
252 
253    wf_engine.SetItemAttrText(Itemtype => ItemType,
254 				   Itemkey => ItemKey,
255 				   aname => 'CODEDB',
256 				   avalue => inCodeDB);
257 
258   wf_engine.SetItemAttrNumber(Itemtype => ItemType,
259 	      		   Itemkey => ItemKey,
260 	      		   aname => 'USER_ID',
261 	      		   avalue => userID);
262    wf_engine.SetItemAttrNumber(Itemtype => ItemType,
263 	      		   Itemkey => ItemKey,
264 	      		   aname => 'RESP_ID',
265 	      		   avalue => respID);
266    wf_engine.SetItemAttrNumber(Itemtype => ItemType,
267 	      		   Itemkey => ItemKey,
268 	      		   aname => 'RESP_APPL_ID',
269 	      		   avalue => respApplID);
270 
271    if WorkflowProcess = 'ODPSTDCOL'
272       then
273          CompDate:= to_date(inCDate, 'YY MM DD');
274          wf_engine.SetItemAttrDate(Itemtype => ItemType,
275 	 			   Itemkey => ItemKey,
276 				   aname => 'VALUE2',
277 				   avalue => CompDate);
278        end if;
279 
280     -- if fixed date for Distrbution or Standard Collection then set Wait to null.
281     if WorkflowProcess = 'ODPDISTPLANS'
282        then
283           select count(value) into FixedDate from v$parameter
284               where name like '%fixed_date%' AND length(VALUE) > 0;
285           if FixedDate > 0
286              then
287               wf_engine.SetItemAttrNumber(Itemtype => ItemType,
288 	      		   Itemkey => ItemKey,
289 	      		   aname => 'WAIT_RELATIVE_TIME',
290 	      		   avalue => NULL);
291           end if;
292      end if;
293 
294    commit;
295 
296    wf_engine.StartProcess(ItemType => ItemType,
297                          ItemKey => ItemKey);
298    return;
299    exception
300      when others then
301         WF_CORE.CONTEXT('MSD_WF', 'STARTPRO',
302          itemtype, itemkey);
303    raise;
304 end STARTPRO;
305 PROCEDURE LAUNCH (itemtype in varchar2,
306 		  itemkey  in varchar2,
307 		  actid    in number,
308 		  funcmode in varchar2,
309                   resultout   out NOCOPY varchar2)
310    IS
311     ActEntry     varchar2(16);
312     ActRetCode    varchar2(2000);
313     ActRetVal    varchar2(2000);
314     ActRetText   varchar2(2000);
315     ActRetErr    varchar2(2000);
316     thisrole     varchar2(320);
317     LaunchMgr    varchar2(12);
318     AttachDBName varchar2(240);
319     script       varchar2(2000);
320    BEGIN
321       IF (funcmode = 'RUN') THEN
322          resultout :='COMPLETE:N';
323        SELECT ACTIVITY_NAME INTO ActEntry FROM WF_PROCESS_ACTIVITIES
324          WHERE INSTANCE_ID=actid;
325        SELECT TEXT_VALUE INTO thisrole FROM WF_ITEM_ATTRIBUTE_VALUES
326           WHERE ITEM_KEY=itemkey AND ITEM_TYPE=itemtype AND NAME='ODPROLE';
327        --  Inital default is "CONTINUE". Values are CYCLE, DONE, LAUNCH
328    --  LAUNCH means Make the call to launch a sub process.
329    --  DONE  means all DB Assignments are complete.
330    --  CYCLE means keep processing.
331    --  This is set upon the start of the process.
332    --  This is set by MSD_WF.GOVERNOR.
333        LaunchMgr:=wf_engine.GetItemAttrText(Itemtype => ItemType,
334 				   Itemkey => ItemKey,
335 				   aname => 'LAUNCHMGR');
336        PlanID:=wf_engine.GetItemAttrText(Itemtype => ItemType,
337 				   Itemkey => ItemKey,
338   	              		   aname => 'ODPPLAN');
339       if LaunchMgr = 'CYCLE' or LaunchMgr = 'DONE'
340          then
341             resultout :='COMPLETE:Y';
342             return;
343          end if;
344  -- Call to Launch a process.
345     if LaunchMgr = 'LAUNCH'
346        then
347 
348 	 gItemType := ItemType;
349  	 gItemKey := ItemKey;
350 
351        express_server:=wf_engine.GetItemAttrText(Itemtype => ItemType,
352 				   Itemkey => ItemKey,
353   	  	   aname => 'EXPCONN');
354        DPAdmin:=wf_engine.GetItemAttrText(Itemtype => ItemType,
355 		       Itemkey => ItemKey,
356 		       aname => 'DPADMIN');
357        DBName:=wf_engine.GetItemAttrText(Itemtype => ItemType,
358 				   Itemkey => ItemKey,
359   	  	   aname => 'DBNAME');
360        SharedLoc:=wf_engine.GetItemAttrText(Itemtype => ItemType,
361 				   Itemkey => ItemKey,
362   	  	   aname => 'SHAREDLOC');
363        CodeLoc:=wf_engine.GetItemAttrText(Itemtype => ItemType,
364 				   Itemkey => ItemKey,
365   	  	   aname => 'CODELOC');
366 
367       execute_dml(actentry, planid, dbname, SharedLoc, dpadmin, thisrole, itemkey, master, '',
368                   actretcode, actrettext, actretval, actreterr);
369 
370      commit;
371 
372       if ActRetCode = 'Y' then
373          resultout :='COMPLETE:Y';
374       end if;
375  --     if ActRetCode = 'Y' then
376  --      wf_engine.SetItemAttrText(Itemtype => ItemType,
377  --				   Itemkey => ItemKey,
378  --				   aname => 'ODPBODY',
379  --				   avalue => ActRetText);
380  --     end if;
381      if ActRetCode = 'N' then
382       wf_engine.SetItemAttrText(Itemtype => ItemType,
383 				   Itemkey => ItemKey,
384 				   aname => 'DPPROBLEM',
385 				   avalue => ActRetErr);
386       end if;
387    return;
388    end if;
389   END IF;
390   exception
391    when others then
392      if instr(upper(SQLERRM), 'EXPRESS') > 0 or instr(upper(SQLERRM), 'SNAPI') > 0
393 	then
394          resultout :='COMPLETE:N';
395          wf_engine.SetItemAttrText(Itemtype => ItemType,
396 				   Itemkey => ItemKey,
397 				   aname => 'DPPROBLEM',
398 				   avalue => substr(SQLERRM, 1, 200));
399 
400 	   update msd_demand_plans
401 		    set DP_BUILD_ERROR_FLAG = 'YES'
402 		    where demand_plan_id = to_number(PlanID);
403 	   commit;
404 
405          return;
406 	else
407      	   WF_CORE.CONTEXT('MSD_WF', 'LAUNCH',
408     	   itemtype, itemkey, to_char(actid), funcmode, ActRetErr);
409          raise;
410 	end if;
411 
412 end LAUNCH;
413 
414 PROCEDURE GOVERNOR (itemtype in varchar2,
415 		  itemkey  in varchar2,
416 		  actid    in number,
417 		  funcmode in varchar2,
418                   resultout   out NOCOPY varchar2)
419    IS
420     ActEntry     varchar2(16);
421     ActRetCode    varchar2(2000);
422     ActRetText   varchar2(2000);
423     ActRetVal    varchar2(2000);
424     ActRetErr    varchar2(2000);
425     thisrole     varchar2(320);
426     PlanID       varchar2(200);
427 
428    BEGIN
429 
430 	gItemType := ItemType;
431  	gItemKey := ItemKey;
432 
433       IF (funcmode = 'RUN') THEN
434          resultout :='COMPLETE:N';
435        SELECT ACTIVITY_NAME INTO ActEntry FROM WF_PROCESS_ACTIVITIES
436          WHERE INSTANCE_ID=actid;
437        SELECT TEXT_VALUE INTO thisrole FROM WF_ITEM_ATTRIBUTE_VALUES
438           WHERE ITEM_KEY=itemkey AND ITEM_TYPE=itemtype AND NAME='ODPROLE';
439        express_server := wf_engine.GetItemAttrText(Itemtype => ItemType,
440 				   Itemkey => ItemKey,
441   	       aname => 'EXPCONN');
442        DPAdmin:=wf_engine.GetItemAttrText(Itemtype => ItemType,
443 		       Itemkey => ItemKey,
444 		       aname => 'DPADMIN');
445        DBName := wf_engine.GetItemAttrText(Itemtype => ItemType,
446 				   Itemkey => ItemKey,
447   	              		   aname => 'DBNAME');
448        SharedLoc := wf_engine.GetItemAttrText(Itemtype => ItemType,
449 				   Itemkey => ItemKey,
450   	              		   aname => 'SHAREDLOC');
451        CodeLoc := wf_engine.GetItemAttrText(Itemtype => ItemType,
452 				   Itemkey => ItemKey,
453   	              		   aname => 'CODELOC');
454 
455       -- call to wf.setactivity and get return values
456       execute_dml(actentry, planid, dbname, SharedLoc, DPAdmin, thisrole, itemkey, master, '',
457                   actretcode, actrettext, actretval, actreterr);
458    commit;
459 
460    -- This is the end. We are out.
461    -- I need Y/N/DONE as possible return values.
462       if ActRetCode = 'DONE' then
463          resultout :='COMPLETE:DONE';
464          return;
465       end if;
466    -- its time to launch another or contiue
467    -- ActRetVal should be either LAUNCH or CYCLE.
468       if ActRetCode = 'Y' then
469          wf_engine.setItemAttrText(Itemtype => ItemType,
470 			   Itemkey => ItemKey,
471 			   aname => 'LAUNCHMGR',
472 			   avalue => ActRetVal);
473          resultout :='COMPLETE:CYCLE';
474       end if;
475      if ActRetCode = 'N' then
476       wf_engine.SetItemAttrText(Itemtype => ItemType,
477 			   Itemkey => ItemKey,
478 			   aname => 'DPPROBLEM',
479   			   avalue => ActRetErr);
480      end if;
481    return;
482  END IF;
483  exception
484    when others then
485      if instr(upper(SQLERRM), 'EXPRESS') > 0 or instr(upper(SQLERRM), 'SNAPI') > 0
486 	then
487          resultout :='COMPLETE:N';
488          wf_engine.SetItemAttrText(Itemtype => ItemType,
489 				   Itemkey => ItemKey,
490 				   aname => 'DPPROBLEM',
491 				   avalue => substr(SQLERRM, 1, 200));
492 
493 	   planID:=wf_engine.GetItemAttrText(Itemtype => ItemType,
494 				   Itemkey => ItemKey,
495   	              		   aname => 'ODPPLAN');
496 	   update msd_demand_plans
497 		    set DP_BUILD_ERROR_FLAG = 'YES'
498 		    where demand_plan_id = to_number(planID);
499          commit;
500 
501          return;
502 	else
503      	   WF_CORE.CONTEXT('MSD_WF', 'GOVERNOR',
504          itemtype, itemkey, to_char(actid), funcmode, ActRetErr);
505          raise;
506 	end if;
507 end GOVERNOR;
508 
509 --========================================================================
510 --
511 -- StartConcProc
512 --
513 -- As of 11.5.10, this program directly launches the MSDWFBG concurrent program
514 -- instead of starting a workflow process.
515 --
516 -- itemtype - A valid item type from WF_ITEM_TYPES table (generally ODPCYCLE)
517 -- itemKey  - An ItemKey of the process whose Activity was deferred
518 --
519 
520 procedure StartConcProc(itemtype in varchar2,
521 	                itemkey in varchar2) is
522   l_ret number;
523 BEGIN
524   l_ret := fnd_request.submit_request('MSD', 'MSDWFBG',null,null,null,
525                                       ItemType, ItemKey,
526                                       chr(0),null,null,null,null,null,null,null,null,null,
527                                       null,null,null,null,null,null,null,null,null,null,
528                                       null,null,null,null,null,null,null,null,null,null,
529                                       null,null,null,null,null,null,null,null,null,null,
530                                       null,null,null,null,null,null,null,null,null,null,
531                                       null,null,null,null,null,null,null,null,null,null,
532                                       null,null,null,null,null,null,null,null,null,null,
533                                       null,null,null,null,null,null,null,null,null,null,
534                                       null,null,null,null,null,null,null,null,null,null,
535                                       null,null,null,null,null,null,null,null);
536   commit;
537 end StartConcProc;
538 
539 --========================================================================
540 
541 -- ConcLoop
542 --
543 -- Run Background Engine Program in the loop for each Deferred Activity
544 -- until the Process with Deferred Activities is not completed.
545 --
546 -- AGBLoop has to be used from SubmitCost Concurrent program
547 -- to complete deferred process.
548 --
549 -- IN
550 -- itemtype  - A valid item type from WF_ITEM_TYPES table.
551 -- itemkey   - A string generated from application object's primary key.
552 --
553 -- OUT
554 --   errbuf -  error message : process or PL/SQL error.
555 --   retcode - return code (0 = success, 2 = error).
556 --
557 
558  procedure ConcLoop(errbuf out NOCOPY varchar2,
559 		      retcode out NOCOPY number,
560 			itemtype in varchar2,
561 		      itemkey  in varchar2)
562 IS
563 
564  status_code varchar2(50);
565  seconds number;
566  result     varchar2(200);
567  deferred_found varchar2(3);
568  RootAct varchar2(30);
569 
570 BEGIN
571   seconds := 20;
572 
573   errbuf := ' ';
574   retcode := 0;
575 
576   status_code := 'NONE';
577   deferred_found := 'NO';
578 
579   --**********************
580   --agb Emerson 08/12/2003
581   select ROOT_ACTIVITY into RootAct
582   from WF_ITEMS_V
583   where item_type = 'ODPCYCLE' and item_key = itemkey;
584 
585 
586   -- run Background Engine Program in the loop for each Deferred
587   -- Activity until the Process with Deferred Activities is not completed.
588 
589   Loop
590 
591     --*************************************************
592     --agb Emerson 08/12/2003
593     -- moved sleep here to pace the loop at one minute
594     -- This should be more than sufficent
595 
596     dbms_lock.sleep(45);
597 
598     wf_engine.ItemStatus(itemType, itemkey, status_code, result);
599 
600     if RTRIM(status_code) = 'COMPLETE' then
601 	exit;
602     end if;
603 
604     if RootAct = 'ODPDISTPLANS' then
605          --*****************************************************
606          --  agb Emerson 08/12/2003
607          --  if this is the controling Distrbution process then just
608          --  do a call to background once a minute.  This will check the WAIT
609          --  and intiate any deferred thread for the distribtuion.
610 
611 	  wf_engine.Background(itemtype);
612     else
613 	--*****************************************************
614          --  agb inspired from Emerson mod 08/12/2003
615          --  This path WILL NOT be taken for distribution!
616          --  HERE if we find a deferrd activity waiting to be be
617          --  run by a background engine we will ONLY then call
618          --  wf_engine.Background(itemtype).  Note this is select is
619          --  itemkey specific.
620 
621     	  select distinct ACTIVITY_STATUS_CODE into status_code
622         from wf_item_activity_statuses_v
623  	  where  item_type = itemtype
624   	  and    item_key  = itemkey
625   	  and    ACTIVITY_STATUS_CODE = 'DEFERRED';
626 
627        if status_code = 'DEFERRED' then
628           deferred_found := 'YES';
629 
630 	    -- agb inspired from Emerson mod 08/12/2003
631           -- This should give time for the deferred item to be
632 	    -- in both WF status and on the deferred queue
633 	    dbms_lock.sleep(15);
634 	    wf_engine.Background(itemtype);
635 
636       end if;
637 
638    end if;
639 
640 end loop;
641 
642  return;
643 
644    exception
645 
646    when NO_DATA_FOUND then
647 	if deferred_found = 'YES' then
648  	   return;
649       else
650 	   WF_CORE.CONTEXT('MSD_WF', 'ConcLoop', itemtype, itemkey, ' NO_DATA_FOUND_BUN');
651          retcode := 2;
652     	   errbuf:=substr(sqlerrm, 1, 255);
653 	   raise;
654       end if;
655 
656    when others then
657         WF_CORE.CONTEXT('MSD_WF', 'ConcLoop', itemtype, itemkey);
658     	  retcode := 2;
659         errbuf:=substr(sqlerrm, 1, 255);
660 
661         raise;
662 
663 end ConcLoop;
664 
665 --========================================================================
666 --
667 -- RunConcLoop
668 --
669 -- Concurrent program that is used to run WF Background Engine in the looop
670 -- to complete each deferred activity for particular WF Process(ItemType/ItemKey).
671 --
672 -- This program has to be run from Standard Submit Concurrent Program Activity.
673 --
674 -- IN
675 -- itemtype  	- A valid item type from WF_ITEM_TYPES table.
676 -- cost_itemkey   - Item key of the process whose activities were deferred.
677 --
678 -- OUT
679 --   errbuf -  error message : process or PL/SQL error.
680 --   retcode - return code (0 = success, 2 = error).
681 --
682 
683 procedure RunConcLoop(errbuf out NOCOPY varchar2,
684                       retcode out NOCOPY number,
685 			    ItemType in varchar2,
686                       cost_ItemKey in varchar2)
687 
688     IS
689     retText     varchar2(200);
690     planName varchar2(100);
691     dispMesg varchar2(200);
692 
693 BEGIN
694 
695 
696 	errbuf := ' ';
697 
698       MSD_WF.ConcLoop(errbuf, retcode, itemtype, cost_ItemKey);
699 
700 
701 	return;
702 
703    exception
704    when others then
705     retcode :='2';
706     errbuf:=substr(sqlerrm, 1, 255);
707 
708 
709      raise;
710 
711 end RunConcLoop;
712 
713 --========================================================================
714 -- SetColDate
715 --
716 --  WF proc to set the number of days to run the Standard Collection.
717 --
718 -- IN Standard  parameters supplied by WF engine:
719 -- itemtype , itemkey, actid, funcmode
720 --
721 -- OUT
722 --   resultout  'COMPLETE:N' for failure, 'COMPLETE:Y'  for success
723 --
724 procedure  SetColDate (itemtype in varchar2,
725 		  itemkey  in varchar2,
726 		  actid    in number,
727 		  funcmode in varchar2,
728               resultout   out NOCOPY varchar2)
729    IS
730     TempDate     date;
731     TxtDate      varchar2(16);
732     NumDays      number;
733 
734    BEGIN
735 
736       IF (funcmode = 'RUN') THEN
737          resultout :='COMPLETE:N';
738 
739 
740          NumDays:=wf_engine.GetItemAttrNumber(Itemtype => ItemType,
741 		       Itemkey => ItemKey,
742  	  	       aname => 'NUMDAYS');
743 
744         TempDate := sysdate + NumDays;
745         TxtDate := to_char(TempDate, 'YY MM DD HH24:MI');
746         TempDate := to_date(TxtDate, 'YY MM DD HH24:MI');
747         wf_engine.SetItemAttrDate(Itemtype => ItemType,
748 	 			   Itemkey => ItemKey,
749 				   aname => 'VALUE2',
750 				   avalue => TempDate);
751 
752 	  wf_engine.SetItemAttrText(Itemtype => ItemType,
753 				   Itemkey => ItemKey,
754 				   aname => 'SETUPLDREF',
755 				   avalue => 'NO');
756 
757          resultout :='COMPLETE:Y';
758 
759   END IF;
760 
761   exception
762    when others then
763      WF_CORE.CONTEXT('MSD_WF', 'SetColDate', itemtype, itemkey, to_char(actid), funcmode);
764      raise;
765 end SetColDate;
766 --========================================================================
767 -- SetUpldDate
768 --
769 --  WF proc to set the number of days to run the Upload Process.
770 --
771 -- IN
772 -- Standard  parameters supplied by WF engine:
773 -- itemtype , itemkey, actid, funcmode
774 --
775 -- OUT
776 --   resultout  'COMPLETE:N' for failure, 'COMPLETE:Y'  for success
777 --
778 procedure  SetUpldDate (itemtype in varchar2,
779 		  itemkey  in varchar2,
780 		  actid    in number,
781 		  funcmode in varchar2,
782               resultout   out NOCOPY varchar2)
783    IS
784     TempDate     date;
785     TxtDate      varchar2(16);
786     NumDays      number;
787     DelayUpldRef_flag varchar(3);
788 
789    BEGIN
790 
791       IF (funcmode = 'RUN') THEN
792          resultout :='COMPLETE:N';
793 
794       TxtDate := to_char(sysdate, 'YY MM DD HH24:MI');
795      	TempDate := to_date(TxtDate, 'YY MM DD HH24:MI');
796      	-- obsolete agb 6/14/00 TempDate := sysdate;
797      	wf_engine.SetItemAttrDate(Itemtype => ItemType,
798   	    	Itemkey => ItemKey,
799 	    	aname => 'VALUE1',
800 	    	avalue => TempDate);
801 
802 	-- the Delay Reference value must be loaded only once
803 	-- when UploadDelay process just started
804 	DelayUpldRef_flag := wf_engine.GetItemAttrText(Itemtype => ItemType,
805 		       Itemkey => ItemKey,
806  	  	       aname => 'SETUPLDREF');
807 
808 	IF (DelayUpldRef_flag <> 'YES') Then
809       	NumDays:=wf_engine.GetItemAttrNumber(Itemtype => ItemType,
810 		       Itemkey => ItemKey,
811  	  	       aname => 'DELAYDAYS');
812 
813        	TempDate := sysdate + NumDays;
814        	TxtDate := to_char(TempDate, 'YY MM DD HH24:MI');
815        	TempDate := to_date(TxtDate, 'YY MM DD HH24:MI');
816        	wf_engine.SetItemAttrDate(Itemtype => ItemType,
817 	 			   Itemkey => ItemKey,
818 				   aname => 'VALUE2',
819 				   avalue => TempDate);
820 		wf_engine.SetItemAttrText(Itemtype => ItemType,
821 				   Itemkey => ItemKey,
822 				   aname => 'SETUPLDREF',
823 				   avalue => 'YES');
824 	END IF;
825 
826          resultout :='COMPLETE:Y';
827 
828   END IF;
829 
830   exception
831    when others then
832      WF_CORE.CONTEXT('MSD_WF', 'SetUpldDate', itemtype, itemkey, to_char(actid), funcmode);
833      raise;
834 end SetUpldDate;
835 
836 --========================================================================
837 -- StartMaster
838 --
839 -- Concurrent program that is used to run the ODP master WF process
840 --
841 --
842 -- IN
843 -- PlanName	              - A valid plan name from msd_demand_plans_v
844 -- NumDays_to_collect     -  Number of days to run the collection
845 -- OUT
846 --   errbuf -  error message : process or PL/SQL error.
847 --   retcode - return code (0 = success, 2 = error).
848 --
849 procedure StartMaster(errbuf out NOCOPY varchar2,
850                       retcode out NOCOPY number,
851       	          PlanName in varchar2,
852 			    NumDays_to_collect in varchar2,
853 			    NumDays_to_delayUpld in varchar2)
854 
855    IS
856 
857    retText     	varchar2(200);
858    dispMesg 	varchar2(200);
859    itemtype 	varchar2(8);
860    workflowProcess varchar2(11);
861 
862    owner 	varchar2(320);
863    instcode 	varchar2(3);
864    org 		varchar2(8);
865    PlanID   	varchar2(16);
866    itemkey 	varchar2(240);
867    numDaysToCol   number;
868    EngItemKey     varchar2(240);
869    DelayDaysToUpld   number;
870    codeDBName     varchar2(20);
871 
872    userID number;
873    respID  number;
874    respApplID number;
875 
876  BEGIN
877    itemtype := 'ODPCYCLE';
878    workflowProcess := 'ODPAUTOMATE';
879    owner := fnd_global.user_name;
880    userID := fnd_global.user_id;
881    respID := fnd_global.resp_id;
882    respApplID := fnd_global.resp_appl_id;
883 
884 
885     errbuf := ' ';
886 
887 -- Get needed plan information
888 SELECT demand_plan_id, code_location, shared_db_prefix, shared_db_location, express_connect_string      INTO PlanID, CodeLoc, DBName, SharedLoc, express_server
889 from msd_demand_plans_v
890 where demand_plan_name=PlanName;
891 
892 -- Get organiztion code and instance
893 SELECT msc_trading_partners.organization_code, msc_apps_instances.instance_code
894  INTO org, instcode
895  FROM msc_trading_partners, msc_apps_instances, msd_demand_plans_v
896  WHERE PlanID = msd_demand_plans_v.DEMAND_PLAN_ID AND
897  msd_demand_plans_v.ORGANIZATION_ID = msc_trading_partners.sr_tp_id
898  and msd_demand_plans_v.sr_instance_id  = msc_trading_partners.sr_instance_id
899  and msc_trading_partners.partner_type = 3
900  AND  msd_demand_plans_v.SR_INSTANCE_ID = msc_apps_instances.instance_id;
901 
902 --get MSD code database name
903 select fnd_profile.value('MSD_CODE_AW') into codeDBName from dual;
904 
905 codeDBName := nvl(codeDBName, 'ODPCODE');
906 
907 numDaysToCol := to_number(NumDays_to_collect);
908 DelayDaysToUpld := to_number(NumDays_to_delayUpld);
909 
910 -- Set item key
911 --org  := orgcode || ':' || instcode;
912 itemKey := org || '-' || PlanName || '-' || to_char( sysdate, 'MM/DD/YYYY-HH24:MI:SS') || '-' || workflowprocess;
913 
914 gItemType := ItemType;
915 gItemKey  := itemKey;
916 
917 -- Create WF Automate process instance
918     wf_engine.CreateProcess(ItemType => ItemType,
919                          itemKey => ItemKey,
920                          process => WorkflowProcess);
921 
922 -- setup attributes for Master Automation process
923 wf_engine.SetItemAttrText(Itemtype => ItemType,
924 			  Itemkey => ItemKey,
925 			  aname => 'CODEDB',
926 			  avalue => codeDBName);
927 
928 wf_engine.SetItemAttrNumber(Itemtype => ItemType,
929 	      		   Itemkey => ItemKey,
930 	      		   aname => 'USER_ID',
931 	      		   avalue => userID);
932    wf_engine.SetItemAttrNumber(Itemtype => ItemType,
933 	      		   Itemkey => ItemKey,
934 	      		   aname => 'RESP_ID',
935 	      		   avalue => respID);
936    wf_engine.SetItemAttrNumber(Itemtype => ItemType,
937 	      		   Itemkey => ItemKey,
938 	      		   aname => 'RESP_APPL_ID',
939 	      		   avalue => respApplID);
940 
941 -- This should be the demand planning administrator.
942     wf_engine.SetItemOwner(ItemType => ItemType,
943                          ItemKey => ItemKey,
944                          owner => owner);
945 -- Sets new attribute Is OPD Master running.
946     wf_engine.SetItemAttrText(Itemtype => ItemType,
947 				   Itemkey => ItemKey,
948 				   aname => 'ISMASTER',
949 				   avalue => 'Y');
950    wf_engine.SetItemAttrText(Itemtype => ItemType,
951 				   Itemkey => ItemKey,
952 				   aname => 'DPADMIN',
953 				   avalue => owner);
954    wf_engine.SetItemAttrText(Itemtype => ItemType,
955 				   Itemkey => ItemKey,
956 				   aname => 'ODPROLE',
957 				   avalue => owner);
958    -- Plan ID!
959    wf_engine.SetItemAttrText(Itemtype => ItemType,
960 				   Itemkey => ItemKey,
961 				   aname => 'ODPPLAN',
962 				   avalue => PlanID);
963    wf_engine.SetItemAttrText(Itemtype => ItemType,
964 				   Itemkey => ItemKey,
965 				   aname => 'PLNAME',
966 				   avalue => PlanName);
967    wf_engine.SetItemAttrText(Itemtype => ItemType,
968 				   Itemkey => ItemKey,
969 				   aname => 'CODELOC',
970 				   avalue => CodeLoc);
971    wf_engine.SetItemAttrText(Itemtype => ItemType,
972 				   Itemkey => ItemKey,
973 				   aname => 'DBNAME',
974 				   avalue => DBName);
975    wf_engine.SetItemAttrText(Itemtype => ItemType,
976 				   Itemkey => ItemKey,
977 				   aname => 'SHAREDLOC',
978 				   avalue => SharedLoc);
979    wf_engine.SetItemAttrText(Itemtype => ItemType,
980 				   Itemkey => ItemKey,
981 				   aname => 'EXPCONN',
982 				   avalue => express_server);
983 -- set NumDays to collect
984  wf_engine.SetItemAttrNumber(Itemtype => ItemType,
985 				   Itemkey => ItemKey,
986 				   aname =>  'NUMDAYS',
987 				   avalue => NumDaysToCol);
988 -- set DelayDays to Upload
989  wf_engine.SetItemAttrNumber(Itemtype => ItemType,
990 				   Itemkey => ItemKey,
991 				   aname =>  'DELAYDAYS',
992 				   avalue => DelayDaysToUpld);
993 
994 -- Now that all is created and set START the PROCESS!
995    wf_engine.StartProcess(ItemType => ItemType,
996                           ItemKey => ItemKey);
997    commit;
998 
999 -- Start background engine for this process.
1000    MSD_WF.StartConcProc('ODPCYCLE', Itemkey);
1001    commit;
1002 
1003    return;
1004 
1005    exception
1006    when others then
1007     retcode :='2';
1008     errbuf:=substr(sqlerrm, 1, 255);
1009      raise;
1010 
1011 end StartMaster;
1012 --=============================================================================
1013 
1014 procedure setowner(p_owner in varchar2) is
1015 begin
1016 g_owner := p_owner;
1017 end;
1018 
1019 --==============================================================================
1020 
1021 /*
1022   This procedure will attach the ODPCODE aw, construct a call to WF.SETACTIVITY
1023   and retrieve return values and codes.
1024 */
1025 procedure execute_dml(p_actentry varchar2, p_planid varchar2, p_dbname varchar2,
1026                      p_SharedLoc varchar2, p_owner varchar2, p_role varchar2, p_itemkey varchar2,
1027                       p_master varchar2, p_process varchar2,
1028                       p_retcode out NOCOPY varchar2, p_rettext out NOCOPY varchar2,
1029                       p_retval out NOCOPY varchar2, p_reterr out NOCOPY varchar2) is
1030   script varchar2(4000);
1031   code_aw varchar2(50);
1032   user_id  number;
1033   resp_id  number;
1034   respAppl_id number;
1035   bFailed  boolean;
1036 
1037   master_type varchar2(50);
1038   show_log_title varchar2(50);
1039 
1040 
1041 
1042 begin
1043 
1044   code_aw :=wf_engine.GetItemAttrText(Itemtype => gItemType,
1045 		       Itemkey => gItemKey,
1046  	  	       aname => 'CODEDB');
1047 
1048   user_id:=wf_engine.GetItemAttrNumber(Itemtype => gItemType,
1049        					 Itemkey => gItemKey,
1050        					 aname => 'USER_ID');
1051 
1052   resp_id:=wf_engine.GetItemAttrNumber(Itemtype => gItemType,
1053 	       				   Itemkey => gItemKey,
1054   	       				   aname => 'RESP_ID');
1055 
1056   respAppl_id:=wf_engine.GetItemAttrNumber(Itemtype => gItemType,
1057 	       					 Itemkey => gItemKey,
1058   	       					 aname => 'RESP_APPL_ID');
1059   -- get attributes to manage S&OP Master Automation Process
1060 
1061   master_type := wf_engine.GetItemAttrText(Itemtype => gItemType,
1062 		       			     Itemkey => gItemKey,
1063  	  	       			     aname => 'MASTER_TYPE');
1064   show_log_title := wf_engine.GetItemAttrText(Itemtype => gItemType,
1065 		       			     Itemkey => gItemKey,
1066  	  	       			     aname => 'SHOW_LOG_TITLE');
1067 
1068   fnd_global.apps_initialize(user_id, resp_id, respAppl_id);
1069 
1070 
1071   script := 'aw attach ap' || 'ps.' || code_aw || ' ro; ';
1072 
1073   if master_type = 'SOP' then
1074     script := script || 'SOP.MASTER = ''Y''; ';
1075     script := script || 'SHOW.LOG.TITLE = ''' || show_log_title || ''';';
1076   end if;
1077 
1078   script := script ||
1079             'CALL WF.SETACTIVITY('''|| p_ActEntry || ''', '''|| p_PlanID ||''',  '''||
1080                                        p_DBName ||''', '''|| p_SharedLoc ||''', '''|| p_owner ||''',  '''||
1081                                        p_role ||''',  '''|| p_ItemKey ||''',  '''||
1082                                        p_Master ||''', ''' || p_process || ''', ''' || code_aw || '''); ' ||
1083              'activity.retcode = activity.formula; ';
1084   begin
1085     bFailed := false;
1086     msd_common_utilities.dbms_aw_interp_silent(script);
1087 
1088     exception
1089       when others then
1090         p_RetCode := 'N';
1091         bFailed := true;
1092   end;
1093 
1094   if not(bFailed) then
1095     p_RetCode := trim(both fnd_global.local_chr(10) from dbms_lob.substr(msd_common_utilities.dbms_aw_interp('shw activity.retcode'), 2000));
1096   end if;
1097 
1098   p_RetText := trim(both fnd_global.local_chr(10) from dbms_lob.substr(msd_common_utilities.dbms_aw_interp('shw activity.text'), 2000));
1099   p_RetVal  := trim(both fnd_global.local_chr(10) from dbms_lob.substr(msd_common_utilities.dbms_aw_interp('shw activity.retval'), 2000));
1100   p_RetErr  := trim(both fnd_global.local_chr(10) from dbms_lob.substr(msd_common_utilities.dbms_aw_interp('shw activity.error'), 2000));
1101 script := '';
1102 
1103    -- detach any aws if they are still attached
1104    msd_common_utilities.detach_all_aws;
1105 
1106 end execute_dml;
1107 
1108 -- ========================================================================
1109 -- SET_ATTRIBUTES
1110 --
1111 --  set WF Attributes.  Currently just argument1.  Will add more as needed.
1112 --
1113 -- IN
1114 --   Standard parameters supplied by WF engine: itemtype , itemkey, actid, funcmode
1115 --
1116 -- OUT
1117 --   resultout 'COMPLETE' for success
1118 --
1119 
1120 procedure SET_ATTRIBUTES(itemtype in varchar2,
1121  		  		itemkey  in varchar2,
1122  		  		actid    in number,
1123  		  		funcmode in varchar2,
1124                		resultout   out NOCOPY varchar2)
1125 
1126     IS
1127 
1128      BEGIN
1129 
1130         IF (funcmode = 'RUN') THEN
1131            	  wf_engine.SetItemAttrText(Itemtype => ItemType,
1132  						   Itemkey => ItemKey,
1133  				   		   aname => 'ARG1',
1134  				   		   avalue => ItemKey);
1135 
1136          	resultout := 'COMPLETE';
1137        END IF;
1138        return;
1139 
1140     exception
1141     when others then
1142       WF_CORE.CONTEXT('MSD_WF', 'SET_ATTRIBUTES', itemtype, itemkey, to_char(actid), funcmode);
1143       raise;
1144 
1145  end SET_ATTRIBUTES;
1146 
1147 
1148 --================================================================================
1149 -- DISTRIBUTE
1150 --
1151 --  A concurrent program that connects to OES and runs ODPWF.DISTRIBUTE in Express.
1152 --  Gets values back through EPS.
1153 -- IN one argument:
1154 --  itemkey
1155 --
1156 -- OUT
1157 --   standard for concurrent program: errbuf, retcode: 0,1 ,2.
1158 --
1159 
1160 PROCEDURE DISTRIBUTE (errbuf out NOCOPY varchar2,
1161                       retcode out NOCOPY number,
1162 	                itemkey  in varchar2)
1163 
1164     IS
1165 
1166      ActEntry     varchar2(16);
1167      ActRetCode    varchar2(2000);
1168      ActRetText   varchar2(2000);
1169      ActRetVal    varchar2(2000);
1170      ActRetErr    varchar2(2000);
1171      thisrole     varchar2(320);
1172      Process      varchar2(30);
1173      itemType     varchar2(10);
1174 
1175 BEGIN
1176 
1177 -- This is only run for assignment distibution.
1178 	 itemType := 'ODPCYCLE';
1179        ActEntry := 'ODPDIST';
1180        Process := 'ODPDISTPRC';
1181 
1182 	 gItemType := ItemType;
1183  	 gItemKey := ItemKey;
1184 
1185        SELECT TEXT_VALUE INTO thisrole FROM WF_ITEM_ATTRIBUTE_VALUES
1186            WHERE ITEM_KEY=itemkey AND ITEM_TYPE=itemtype AND NAME='ODPROLE';
1187 
1188        express_server:=wf_engine.GetItemAttrText(Itemtype => ItemType,
1189  		       					Itemkey => ItemKey,
1190           							aname => 'EXPCONN');
1191 
1192          -- new to indicate if ODP Master is governing Cycle
1193         Master:=wf_engine.GetItemAttrText(Itemtype => ItemType,
1194  		       				Itemkey => ItemKey,
1195    		       				aname => 'ISMASTER');
1196 
1197         DBName:=wf_engine.GetItemAttrText(Itemtype => ItemType,
1198  		       				Itemkey => ItemKey,
1199    		       				aname => 'DBNAME');
1200 
1201         DPAdmin:=wf_engine.GetItemAttrText(Itemtype => ItemType,
1202  		       				Itemkey => ItemKey,
1203  		       				aname => 'DPADMIN');
1204 
1205         SharedLoc:=wf_engine.GetItemAttrText(Itemtype => ItemType,
1206  	               				   Itemkey => ItemKey,
1207 					  	  	   aname => 'SHAREDLOC');
1208 
1209         CodeLoc:=wf_engine.GetItemAttrText(Itemtype => ItemType,
1210  		       				Itemkey => ItemKey,
1211    	               				aname => 'CODELOC');
1212 
1213         PlanID:=wf_engine.GetItemAttrText(Itemtype => ItemType,
1214  		       				Itemkey => ItemKey,
1215   	  	       				aname => 'ODPPLAN');
1216 
1217  	-- call to wf.setactivity and get return values
1218       execute_dml(actentry, planid, dbname, SharedLoc, dpadmin, thisrole, itemkey, master, process,
1219                   ActRetCode, ActRetText, ActRetVal, ActRetErr);
1220 
1221 
1222       if ActRetCode = 'Y' then
1223 
1224 	retcode :='0';
1225         wf_engine.SetItemAttrText(Itemtype => ItemType,
1226        	  	    			Itemkey => ItemKey,
1227  		    				aname => 'ASSIGNID',
1228  		    				avalue => ActRetVal);
1229 
1230         wf_engine.SetItemAttrText(Itemtype => ItemType,
1231  		    				Itemkey => ItemKey,
1232  		    				aname => 'ASSIGNNAME',
1233  		    				avalue => ActRetText);
1234         end if;
1235 
1236       if ActRetCode = 'N' then
1237         wf_engine.SetItemAttrText(Itemtype => ItemType,
1238  		   				Itemkey => ItemKey,
1239  		   				aname => 'DPPROBLEM',
1240  		   				avalue => ActRetErr);
1241 	retcode :='2';
1242       end if;
1243 
1244       commit;
1245 
1246 
1247       return;
1248 
1249      exception
1250     	when others then
1251       	retcode :='2';
1252       	errbuf:=substr(sqlerrm, 1, 255);
1253 
1254      if instr(upper(SQLERRM), 'EXPRESS') > 0 or instr(upper(SQLERRM), 'SNAPI') > 0
1255  	then
1256          wf_engine.SetItemAttrText(Itemtype => ItemType,
1257  				   Itemkey => ItemKey,
1258  				   aname => 'DPPROBLEM',
1259  				   avalue => substr(SQLERRM, 1, 200));
1260 
1261          commit;
1262          return;
1263      end if;
1264 
1265   end DISTRIBUTE;
1266 
1267 -- ========================================================================
1268 -- EXECUTE_DML2
1269 --
1270 --  This program is running by Purge.
1271 --  It's identical to the EXECUTE_DML, but always uses ODPCODE only.
1272 --  It doesn't care about CODEDB attribute .
1273 --
1274 
1275 procedure execute_dml2(p_actentry varchar2, p_planid varchar2, p_dbname varchar2,
1276                       p_SharedLoc varchar2, p_owner varchar2, p_role varchar2, p_itemkey varchar2,
1277                       p_master varchar2, p_process varchar2,
1278                       p_retcode out NOCOPY varchar2, p_rettext out NOCOPY varchar2,
1279                       p_retval out NOCOPY varchar2, p_reterr out NOCOPY varchar2) is
1280   script varchar2(4000);
1281   code_aw varchar2(50);
1282 
1283 begin
1284 
1285   code_aw := 'odpcode';
1286 
1287   -- because of the GSCC error "Hard-coded Schema name 'apps',
1288   -- the different notation is used
1289   --script := 'aw attach apps.odpcode'   ||' ro; ';
1290 
1291   script := 'aw attach ap' || 'ps.odpcode'   ||' ro; ';
1292 
1293   script := script ||
1294             'CALL WF.SETACTIVITY('''|| p_ActEntry || ''', '''|| p_PlanID ||''',  '''||
1295                                        p_DBName ||''', '''|| p_SharedLoc ||''', '''|| p_owner ||''',  '''||
1296                                        p_role ||''',  '''|| p_ItemKey ||''',  '''||
1297                                        p_Master ||''', ''' || p_process || ''', ''' || code_aw || '''); ' ||
1298              'activity.retcode = activity.formula';
1299 
1300   --insert into msd_temp values(script);
1301   msd_common_utilities.dbms_aw_interp_silent(script);
1302 
1303   p_RetCode := trim(both fnd_global.local_chr(10) from dbms_lob.substr(msd_common_utilities.dbms_aw_interp('shw activity.retcode'), 2000));
1304   p_RetText := trim(both fnd_global.local_chr(10) from dbms_lob.substr(msd_common_utilities.dbms_aw_interp('shw activity.text'), 2000));
1305   p_RetVal  := trim(both fnd_global.local_chr(10) from dbms_lob.substr(msd_common_utilities.dbms_aw_interp('shw activity.retval'), 2000));
1306   p_RetErr  := trim(both fnd_global.local_chr(10) from dbms_lob.substr(msd_common_utilities.dbms_aw_interp('shw activity.error'), 2000));
1307 script := '';
1308 
1309 
1310 end execute_dml2;
1311 
1312 --================================================================================
1313 end MSD_WF;