DBA Data[Home] [Help]

PACKAGE BODY: APPS.FND_MLS_REQUEST

Source


1 package body FND_MLS_REQUEST as
5 
2 /* $Header: AFMLSUBB.pls 120.15 2011/12/21 23:14:26 ckclark ship $ */
3 
4 
6 /*
7 ** GEN_ERROR (Internal)
8 **
9 ** Return error message for unexpected sql errors
10 */
11 function GEN_ERROR(routine in varchar2,
12 	           errcode in number,
13 	           errmsg in varchar2) return varchar2 is
14 begin
15     fnd_message.set_name('FND', 'SQL_PLSQL_ERROR');
16     fnd_message.set_token('ROUTINE', routine);
17     fnd_message.set_token('ERRNO', errcode);
18     fnd_message.set_token('REASON', errmsg);
19     return substr( fnd_message.get, 1, 240);
20 end;
21 
22 /*
23 ** FNDMLSUB
24 **
25 ** MLS master program.
26 **
27 */
28 procedure FNDMLSUB  (errbuf            out nocopy varchar2,
29                      retcode           out nocopy number,
30                      appl_id           in number,
31                      prog_id           in number,
32 		     use_func          in varchar2 default 'N') is
33 
34 cursor run_req_info(appl_id number, prog_id number, parent_id number) is
35   select a.application_short_name,
36          cp.concurrent_program_name,
37          r.request_set_program_id,
38          r.application_id,
39          r.concurrent_program_id,
40 	  r.description,
41          r.number_of_copies,
42          r.printer,
43          r.print_style,
44          r.save_output_flag,
45          argument1, argument2, argument3, argument4, argument5,
46          argument6, argument7, argument8, argument9, argument10,
47          argument11, argument12, argument13, argument14, argument15,
48          argument16, argument17, argument18, argument19, argument20,
49          argument21, argument22, argument23, argument24, argument25,
50          argument26, argument27, argument28, argument29, argument30,
51          argument31, argument32, argument33, argument34, argument35,
52          argument36, argument37, argument38, argument39, argument40,
53          argument41, argument42, argument43, argument44, argument45,
54          argument46, argument47, argument48, argument49, argument50,
55          argument51, argument52, argument53, argument54, argument55,
56          argument56, argument57, argument58, argument59, argument60,
57          argument61, argument62, argument63, argument64, argument65,
58          argument66, argument67, argument68, argument69, argument70,
59          argument71, argument72, argument73, argument74, argument75,
60          argument76, argument77, argument78, argument79, argument80,
61          argument81, argument82, argument83, argument84, argument85,
62 
63          argument86, argument87, argument88, argument89, argument90,
64          argument91, argument92, argument93, argument94, argument95,
65          argument96, argument97, argument98, argument99, argument100,
66          r.org_id
67     from fnd_run_requests r,
68          fnd_concurrent_programs cp, fnd_application a
69    where r.parent_request_id = parent_id
70      and a.application_id = r.application_id
71      and cp.application_id = r.application_id
72      and cp.concurrent_program_id = r.concurrent_program_id
73    order by r.request_set_program_id;
74 
75   cursor mls_requests( parent_req_id number ) is
76      select nls_language, nls_territory, numeric_characters
77        from fnd_run_req_languages
78       where parent_request_id = parent_req_id;
79 
80   cursor mls_req_printers(parent_req_id number,
81                              set_program_id number,
82 			     language varchar2) is
83     select arguments printer, number_of_copies
84       from fnd_run_req_pp_actions
85      where parent_request_id = parent_req_id
86        and request_set_program_id = set_program_id
87        and action_type = 1
88        and (nls_language = language
89            or nls_language is null)
90      order by sequence;
91 
92   cursor mls_req_notifications(parent_req_id number,
93                                   set_program_id number,
94 				  language varchar2) is
95     select arguments notify
96       from fnd_run_req_pp_actions
97      where parent_request_id = parent_req_id
98        and request_set_program_id = set_program_id
99        and action_type = 2
100        and (nls_language = language
101            or nls_language is null)
102      order by sequence;
103 
104   cursor mls_req_layouts(parent_req_id number,
105                              set_program_id number,
106 			     language varchar2) is
107     select argument1, argument2, argument3, argument4, argument5
108       from fnd_run_req_pp_actions
109      where parent_request_id = parent_req_id
110        and request_set_program_id = set_program_id
111        and action_type = 6
112        and (nls_language = language
113            or nls_language is null)
114      order by sequence;
115 
116   cursor mls_function_req_layouts(parent_req_id number,
117                                  set_program_id number) is
118     select argument1, argument2, argument5
119       from fnd_run_req_pp_actions
120      where parent_request_id = parent_req_id
121        and request_set_program_id = set_program_id
122        and action_type = 6
123      order by sequence;
124 
125 
126   cursor mls_req_delivery(parent_req_id number,
127                                   set_program_id number,
128 				  language varchar2) is
129     select argument1, argument2, argument3, argument4, argument5,
130 	   argument6, argument7, argument8, argument9, argument10
131       from fnd_run_req_pp_actions
132      where parent_request_id = parent_req_id
133        and request_set_program_id = set_program_id
137      order by sequence;
134        and action_type in (7, 8)
135        and (nls_language = language
136            or nls_language is null)
138 
139   TYPE lang_record_type is record
140 	(lang_code     varchar2(4),
141 	 terr_code     varchar2(4),
142 	 nc_code       varchar2(2),
143 	 nls_language  varchar2(30),
144 	 nls_territory varchar2(30),
145          numeric_characters varchar2(2));
146 
147   TYPE lang_tab_type is table of lang_record_type
148 	index by binary_integer;
149 
150   TYPE req_record_type is record
151 	( req_id       number(15));
152 
153   TYPE req_tab_type is table of req_record_type
154 	index by binary_integer;
155 
156   P_LANG lang_tab_type;
157   P_REQ  req_tab_type;
158 
159   req_id            number;
160   error             boolean         default FALSE;
161   req_data          varchar2(240);  /* State of last FNDMLSUB run.     */
162   has_reqs          boolean         default FALSE;
163   funct             varchar2(61);  /* Function string */
164   fcursor           varchar2(75);  /* Cursor string for dbms_sql */
165   cid               number;        /* Cursor ID for dbms_sql */
166   dummy             number;
167   printer           varchar2(30);
168   copies            number;
169   parent_id         number;
170   func_outcome      varchar2(240) := '';
171   function_id       number;
172   function_appl_id  number;
173   nls_comp	    varchar2(1);
174   P_LCOUNT	    number;
175   endloc	    number;
176   endloc1	    number;
177   endloc2	    number;
178   startloc          number;
179   chkstrloc         number;
180   i 		    number;
181   current_outcome   varchar2(1);
182   request_error     boolean := FALSE;
183   request_warning   boolean := FALSE;
184   outcome_meaning   varchar2(240);
185   req_info_line     varchar2(100) := '';
186   UserProgramName   varchar2(240);  /*  Concurrent Program associated with the request */
187   /* xml project */
188   t_app_name        varchar2(50);
189   t_code            varchar2(80);
190   t_language        varchar2(2);
191   t_territory       varchar2(2);
192   t_format          varchar2(6);
193 
194   parent_nls_lang   varchar2(30);
195   parent_nls_terr   varchar2(30);
196   parent_nls_char   varchar2(2);
197   nls_char_spaces   varchar2(2);
198 
199   iso_lang          varchar2(2);
200   iso_terr          varchar2(2);
201   l_description     varchar2(240);
202 
203 begin
204   /* if use language function then get list of languages from that function
205      and submit the requests for those languages */
206 
207   P_LCOUNT	:= 0;
208   parent_id 	:= fnd_global.conc_request_id;
209 
210   /* Get state from last run if any. */
211   req_data := fnd_conc_global.request_data;
212 
213   /* Is this the first run? */
214   if (req_data is null) then
215 /*
216  * CODE FOLDED : Begining
217  */
218 
219   if ( use_func = 'Y') then
220   /* Get  function for program if any.
221    * Also, set up function globals.
222    */
223      begin
224         select execution_file_name,
225                p.mls_executable_id, p.mls_executable_app_id,
226 	       p.nls_compliant, P.User_Concurrent_Program_Name
227           into funct,
228                function_id, function_appl_id,
229 	       nls_comp, UserProgramName
230           from fnd_concurrent_programs_vl p, fnd_executables e
231          where p.application_id = appl_id
232            and p.concurrent_program_id = prog_id
233        	   and e.executable_id(+) = p.mls_executable_id
234            and e.application_id(+) = p.mls_executable_app_id;
235 
236      exception
237           when NO_DATA_FOUND then
238              fnd_message.set_name('FND','CONC-Missing program');
239       	     errbuf := substr(fnd_message.get,1, 240);
240              retcode := 2;
241           return;
242      end;
243 
244 
245      /* Initialize the request information to access by the language function
246        */
247      fnd_request_info.initialize;
248 
249      fnd_file.put_line(fnd_file.log,
250 	'+---------------------------------------------------------------------------+');
251      fnd_message.set_name('FND', 'CONC-Before lang function');
252      fnd_message.set_token('FUNCTION', funct);
253      fnd_file.put_line(fnd_file.log, fnd_message.get || '  : ' ||
254 				     to_char(sysdate,'DD-MON-YYYY HH24:MI:SS'));
255 
256      fcursor := 'begin :r := '||funct||'; end;';
257      begin
258         cid := dbms_sql.open_cursor;
259         dbms_sql.parse(cid, fcursor, dbms_sql.v7);
260         dbms_sql.bind_variable(cid, ':r', func_outcome, 240);
261         dummy := dbms_sql.execute(cid);
262         dbms_sql.variable_value(cid, ':r', func_outcome);
263         dbms_sql.close_cursor(cid);
264      exception
265         when others then
266           errbuf := gen_error(funct, SQLCODE, SQLERRM);
267           retcode := 2;
268           return;
269      end;
270 
271      fnd_message.set_name('FND', 'CONC-After lang function');
272      fnd_message.set_token('VALUE', func_outcome );
273 
274      fnd_file.put_line(fnd_file.log, fnd_message.get || '  : ' ||
275 				     to_char(sysdate,'DD-MON-YYYY HH24:MI:SS'));
276      fnd_file.put_line(fnd_file.log,
277 	'+---------------------------------------------------------------------------+');
278 
279      /* Parse func_outcome to get nls_languages  */
280      startloc := 1;
281      endloc   := 1;
282      P_LCOUNT   := 0;
283 
284      -- Fix for BUG 1207108
285      -- Language function associated with [PROGRAM] determined no data exists
286      -- for the given set of parameters
287 
291        fnd_message.set_token('PROGRAM', UserProgramName);
288      if (func_outcome is null ) then
289        fnd_file.put_line(fnd_file.log, fnd_message.get);
290        fnd_message.set_name('FND', 'CONC-MLS no data');
292        errbuf := substr(fnd_message.get, 1, 240);
293        retcode := 1;
294        return;
295      end if;
296 
297      -- 12.1  NEW MLS Function Str with optional territory and num char
298      chkstrloc := instr( func_outcome, ':', 1 );
299 
300      if ( chkstrloc = 0 ) then
301         -- Process for original MLS Functionality for lang code only
302         if ( func_outcome is not null ) then
303         loop
304    	   endloc := instr( func_outcome, ',', startloc );
305 	   P_LCOUNT := P_LCOUNT + 1;
306 	   if ( endloc = 0 ) then
307               P_LANG(P_LCOUNT).lang_code := LTRIM(RTRIM( substr( func_outcome, startloc,
308 							 length(func_outcome) -
309 							   startloc + 1
310 							)
311 						    )
312 						);
313               P_LANG(P_LCOUNT).terr_code := null;
314               P_LANG(P_LCOUNT).nc_code := null;
315               exit;
316 	   else
317 	      P_LANG(P_LCOUNT).lang_code := LTRIM(RTRIM( substr( func_outcome, startloc,
318 							 endloc - startloc
319 							)
320 						    )
321 						);
322               P_LANG(P_LCOUNT).terr_code := null;
323               P_LANG(P_LCOUNT).nc_code := null;
324 	   end if;
325            startloc := endloc + 1;
326         end loop;
327         end if;
328      else
329 
330         -- Process for MLS Functionality for lang code with
331         -- optional territory and numeric characters
332         loop
333    	   endloc := instr( func_outcome, ';', startloc );
334 	   P_LCOUNT := P_LCOUNT + 1;
335 	   if ( endloc = 0 ) then
336               endloc1 := instr( func_outcome, ':', startloc );
337               P_LANG(P_LCOUNT).lang_code :=
338                     LTRIM(RTRIM( substr( func_outcome, startloc, endloc1 - startloc) ));
339 
340               endloc2 := instr( func_outcome, ':', endloc1 + 1 );
341               P_LANG(P_LCOUNT).terr_code :=
342                     LTRIM(RTRIM( substr( func_outcome, endloc1 + 1, endloc2 - (endloc1 + 1) )));
343 
344               P_LANG(P_LCOUNT).nc_code :=
345                     LTRIM(RTRIM( substr( func_outcome, endloc2 + 1, length(func_outcome) - endloc2 + 1 )));
346               exit;
347 	   else
348               endloc1 := instr( func_outcome, ':', startloc );
349               P_LANG(P_LCOUNT).lang_code :=
350                     LTRIM(RTRIM( substr( func_outcome, startloc, endloc1 - startloc) ));
351 
352               endloc2 := instr( func_outcome, ':', endloc1 + 1 );
353               P_LANG(P_LCOUNT).terr_code :=
354                     LTRIM(RTRIM( substr( func_outcome, endloc1 + 1, endloc2 - (endloc1 + 1) )));
355 
356               P_LANG(P_LCOUNT).nc_code :=
357                     LTRIM(RTRIM( substr( func_outcome, endloc2 + 1, endloc - (endloc2 + 1) )));
358 	   end if;
359            startloc := endloc + 1;
360         end loop;
361      end if;
362 
363      /* select lang, terr, num char from parent req id */
364      begin
365         select nls_language, nls_territory, nls_numeric_characters
366           into parent_nls_lang, parent_nls_terr, parent_nls_char
367           from fnd_concurrent_requests
368          where request_id =  parent_id;
369         exception
370            when NO_DATA_FOUND then
371               fnd_message.set_name('FND','CONC-Missing Request');
372               fnd_message.set_token('ROUTINE', 'FND_MLS_REQUEST.FNDMLSUB');
373               fnd_message.set_token('REQUEST', to_char(parent_id));
374               errbuf := fnd_message.get;
375               retcode := 2;
376            return;
377      end;
378 
379      /* get nls_language and nls_territory for each language_code  */
380      -- 12.1  NEW MLS Function Str with optional territory and num char
381      -- Use the New Str if present otherwise keep as before
382      for i in 1..P_LCOUNT loop
383         /* if program is nls_compliant then use the default territory from
384            fnd_languages, otherwise use user environment */
385         if ( nls_comp  = 'Y' ) then
386            if (chkstrloc = 0 ) then
387  	      begin
388 		   select nls_language, nls_territory
389 		     into P_LANG(i).nls_language, P_LANG(i).nls_territory
390 		     from fnd_languages
391 		    where language_code = P_LANG(i).lang_code;
392 	      exception
393 		   when no_data_found then
394                       fnd_message.set_name('FND', 'CONC-Invalid Language Code');
395 		      fnd_message.set_token('LANG', P_LANG(i).lang_code);
396 		      errbuf := substr(fnd_message.get, 1, 240);
397 		      retcode := 2;
398 		      return;
399 	      end;
400            else
401               if ( P_LANG(i).terr_code is NULL ) then
402                  begin
403                       select nls_language, nls_territory
404                         into P_LANG(i).nls_language, P_LANG(i).nls_territory
405                         from fnd_languages
406                        where language_code = P_LANG(i).lang_code;
407                  exception
408                       when no_data_found then
409                          fnd_message.set_name('FND', 'CONC-Invalid LangTerr Code');
410                          fnd_message.set_token('LANG', P_LANG(i).lang_code);
411 		         fnd_message.set_token('TERR', P_LANG(i).terr_code);
412                          errbuf := substr(fnd_message.get, 1, 240);
413                          retcode := 2;
414                          return;
415                  end;
416               else
417  	         begin
421 		       where language_code = P_LANG(i).lang_code
418 		      select nls_language, b.nls_territory
419 		        into P_LANG(i).nls_language, P_LANG(i).nls_territory
420 		        from fnd_languages a, fnd_territories b
422                          and territory_code = P_LANG(i).terr_code;
423 	         exception
424 		      when no_data_found then
425                          fnd_message.set_name('FND', 'CONC-Invalid LangTerr Code');
426 		         fnd_message.set_token('LANG', P_LANG(i).lang_code);
427 		         fnd_message.set_token('TERR', P_LANG(i).terr_code);
428 		         errbuf := substr(fnd_message.get, 1, 240);
429 		         retcode := 2;
430 		         return;
431 	         end;
432               end if;
433 
434            end if;
435 	else
436 	   /* use territory from the user environment which is parent_id's
437 	      nls_territory */
438            -- 12.1  NEW MLS Function Str with optional territory and num char
439            -- Use the New Str if present otherwise keep as before
440            begin
441 		select nls_language
442 		  into P_LANG(i).nls_language
443 		  from fnd_languages
444 		 where language_code = P_LANG(i).lang_code;
445 	   exception
446 		when no_data_found then
447                    fnd_message.set_name('FND', 'CONC-Invalid Language Code');
448 		   fnd_message.set_token('LANG', P_LANG(i).lang_code);
449 		   errbuf := substr(fnd_message.get, 1, 240);
450 		   retcode := 2;
451 		   return;
452 	   end;
453 
454            if ( chkstrloc = 0 ) then
455               P_LANG(i).nls_territory := fnd_request_info.get_territory;
456            else
457 
458               if ( P_LANG(i).terr_code is NULL ) then
459                  P_LANG(i).nls_territory := fnd_request_info.get_territory;
460               else
461                  begin
462                    select nls_territory
463                      into P_LANG(i).nls_territory
464                      from fnd_territories
465                     where territory_code = P_LANG(i).terr_code;
466                  exception
467                       when no_data_found then
468                          fnd_message.set_name('FND', 'CONC-Invalid Territory Code');
469                          fnd_message.set_token('TERR', P_LANG(i).terr_code);
470                          errbuf := substr(fnd_message.get, 1, 240);
471                          retcode := 2;
472                          return;
473                  end;
474               end if;
475            end if;
476 
477 	end if;
478 
479         -- 12.1  NEW MLS Function Str with optional territory and num char
480         -- Use the New Str if present otherwise keep as before
481         if ( chkstrloc = 0 ) then
482            /* Determine Numeric Character value to use */
483            if (parent_nls_lang = P_LANG(i).nls_language) then
484               P_LANG(i).nls_territory := parent_nls_terr;
485               P_LANG(i).numeric_characters := parent_nls_char;
486            else
487               P_LANG(i).numeric_characters := NULL;
488            end if;
489         else
490            if (parent_nls_lang = P_LANG(i).nls_language) then
491               P_LANG(i).nls_territory := parent_nls_terr;
492            end if;
493            if ( P_LANG(i).nc_code is NULL ) then
494               if (parent_nls_lang = P_LANG(i).nls_language) then
495                  P_LANG(i).numeric_characters := parent_nls_char;
496               else
497                  P_LANG(i).numeric_characters := NULL;
498               end if;
499            else
500               P_LANG(i).numeric_characters := P_LANG(i).nc_code;
501            end if;
502         end if;
503 
504      end loop;
505 
506   else          /* not using the language function */
507      for req in mls_requests(parent_id) loop
508 	P_LCOUNT := P_LCOUNT + 1;
509 	P_LANG(P_LCOUNT).nls_language := req.nls_language;
510 	P_LANG(P_LCOUNT).nls_territory := req.nls_territory;
511         /* NLS Project - Set the numeric characters  */
512         P_LANG(P_LCOUNT).numeric_characters := req.numeric_characters;
513      end loop;
514   end if;      /* use_func    */
515 
516 
517   -- 12.1  NEW MLS Function Str with optional territory and num char
518   if ( chkstrloc = 0 ) then
519      fnd_message.set_name('FND', 'CONC-About submitted requests');
520   else
521      fnd_message.set_name('FND', 'CONC-About submitted req full');
522   end if;
523   fnd_file.put_line(fnd_file.log, fnd_message.get);
524 
525   /* process all the requests   */
526   begin
527     /* using cursor for loop for easy coding. run_req_info will return
528        only one row  */
529     for req in run_req_info(appl_id, prog_id, parent_id) loop
530 
531       for ind in 1..P_LCOUNT loop
532 
533         /* set the language and territory and numeric characters for this request
534            all individual requests are protected against updates */
535         /* NLS Project - added numeric character */
536         /* 4079398 - Check the numeric character for single character; if so,
537                      Add a space for set options to pass the new Numeric Characters */
538         if (length(P_LANG(ind).numeric_characters) = 1) then
539            nls_char_spaces := substr(P_LANG(ind).numeric_characters,1,1)||' ';
540         else
541            nls_char_spaces := P_LANG(ind).numeric_characters;
542         end if;
543 
544 	if ( not fnd_request.set_options(
545 				implicit => 'NO',
546 				protected => 'YES',
547 				language  => P_LANG(ind).nls_language,
548 				territory => P_LANG(ind).nls_territory,
549                                 datagroup => '',
550                                 numeric_characters =>  nls_char_spaces )) then
554 	   return;
551 	   errbuf  := substr(fnd_message.get, 1, 240);
552 	   retcode := 2;
553 	   rollback;
555 	end if;
556 
557         /* set the print pp actions for this request  */
558         open mls_req_printers(parent_id, 0, P_LANG(ind).nls_language);
559 
560         fetch mls_req_printers into printer, copies;
561 
562         if (mls_req_printers%found) then
563           if (not fnd_request.set_print_options(
564                               printer => printer,
565                               style => req.print_style,
566                               copies => copies,
567                               save_output => (req.save_output_flag = 'Y'),
568                               print_together => NULL))
569           then
570             errbuf := substr(fnd_message.get, 1, 240);
571             retcode := 2;
572             close mls_req_printers;
573             rollback;
574             return;
575           end if;
576 
577           fetch mls_req_printers into printer, copies;
578           while (mls_req_printers%found) loop
579             if (not fnd_request.add_printer(
580                               printer => printer,
581                               copies => copies)) then
582               errbuf := substr(fnd_message.get, 1, 240);
583               retcode := 2;
584               close mls_req_printers;
585               rollback;
586               return;
587             end if;
588             fetch mls_req_printers into printer, copies;
589           end loop;
590         else
591           if (not fnd_request.set_print_options(
592                               printer => null,
593                               style => req.print_style,
594                               copies => 0,
595                               save_output => (req.save_output_flag = 'Y'),
596                               print_together => NULL))
597           then
598             errbuf := substr(fnd_message.get, 1, 240);
599             retcode := 2;
600             close mls_req_printers;
601             rollback;
602             return;
603           end if;
604         end if;
605         close mls_req_printers;
606 
607         /* set notification pp actions for this request */
608         for notify_rec in mls_req_notifications
609                             (parent_id, req.request_set_program_id,
610 				P_LANG(ind).nls_language) loop
611           if (not fnd_request.add_notification(
612                               user=>notify_rec.notify)) then
613             errbuf := substr(fnd_message.get, 1, 240);
614             retcode := 2;
615             rollback;
616             return;
617           end if;
618         end loop;
619 
620         /* Determine if an MLS Function is associated with this prog_id */
621         /* If so, then use iso_language and iso_territory to add to     */
622         /* layout for each language that is in the MLS Function.        */
623         if (function_id is not NULL) then
624            open mls_function_req_layouts(parent_id, 0);
625            fetch mls_function_req_layouts into t_app_name,
626                                                t_code,
627                                                t_format;
628 
629            /* Change the language and terr */
630            select iso_language, iso_territory
631              into t_language, t_territory
632              from fnd_languages
633             where nls_language = P_LANG(ind).nls_language;
634 
635            -- 12.1  NEW MLS Function Str with optional territory and num char
636            if ( chkstrloc > 0 ) then
637               if ( P_LANG(ind).terr_code is NOT NULL ) then
638                  begin
639                    select nls_territory
640                      into P_LANG(ind).nls_territory
641                      from fnd_territories
642                     where territory_code = P_LANG(ind).terr_code;
643                  exception
644                       when no_data_found then
645                          fnd_message.set_name('FND', 'CONC-Invalid Territory Code');
646                          fnd_message.set_token('TERR', P_LANG(ind).terr_code);
647                          errbuf := substr(fnd_message.get, 1, 240);
648                          retcode := 2;
649                          return;
650                  end;
651                  t_territory := UPPER(P_LANG(ind).terr_code);
652               end if;
653            end if;
654 
655            t_language := lower(t_language);
656 
657            while (mls_function_req_layouts%found) loop
658              if (not fnd_request.add_layout(
659                                  t_app_name,
660                                  t_code,
661                                  t_language,
662                                  t_territory,
663                                  t_format)) then
664                errbuf := substr(fnd_message.get, 1, 240);
665                retcode := 2;
666                close mls_function_req_layouts;
667                rollback;
668                return;
669              end if;
670              fetch mls_function_req_layouts into t_app_name,
671                                                  t_code,
672                                                  t_format;
673            end loop;
674            close mls_function_req_layouts;
675         else
676            /* set the layout pp actions for this request  */
677            open mls_req_layouts(parent_id, 0, P_LANG(ind).nls_language);
678 
679            fetch mls_req_layouts into t_app_name,
680                                       t_code,
681                                       t_language,
682                                       t_territory,
686              if (not fnd_request.add_layout(
683                                       t_format;
684 
685            while (mls_req_layouts%found) loop
687                                  t_app_name,
688                                  t_code,
689                                  t_language,
690                                  t_territory,
691                                  t_format)) then
692                errbuf := substr(fnd_message.get, 1, 240);
693                retcode := 2;
694                close mls_req_layouts;
695                rollback;
696                return;
697              end if;
698              fetch mls_req_layouts into t_app_name,
699                                         t_code,
700                                         t_language,
701                                         t_territory,
702                                         t_format;
703            end loop;
704            close mls_req_layouts;
705         end if;
706 
707 
708 	/* set delivery pp actions for this request */
709         for delivery_rec in mls_req_delivery
710                             (parent_id, req.request_set_program_id,
711 				P_LANG(ind).nls_language) loop
712           if (not fnd_request.add_delivery_option(
713                                                   delivery_rec.argument1,
714                                                   delivery_rec.argument2,
715 						  delivery_rec.argument3,
716 						  delivery_rec.argument4,
717 						  delivery_rec.argument5,
718 						  delivery_rec.argument6,
719 						  delivery_rec.argument7,
720 						  delivery_rec.argument8,
721 						  delivery_rec.argument9,
722 						  delivery_rec.argument10
723 						  )) then
724             errbuf := substr(fnd_message.get, 1, 240);
725             retcode := 2;
726             rollback;
727             return;
728           end if;
729         end loop;
730 
731 
732         fnd_request.internal(critical => null, type=>'C');
733 
734         fnd_request.set_org_id(req.org_id);
735 
736 
737 
738         -- Prepend the ISO language and territory to the request description
739 
740         -- Get ISO language, default territory
741 	select ISO_LANGUAGE, ISO_TERRITORY
742 	  into iso_lang, iso_terr
743           from fnd_languages
744 	where nls_language = P_LANG(ind).nls_language;
745 
746         -- If a territory was specified, use it
747         -- else use the default for the language
748         if P_LANG(ind).nls_territory is not null then
749 	    select territory_code
750               into iso_terr
751 	      from fnd_territories
752               where nls_territory = P_LANG(ind).nls_territory
753 	      and obsolete_flag = 'N';
754 	end if;
755 
756 	if req.description is null then
757 	   l_description := iso_lang || '-' || iso_terr || ':';
758 	else
759 	   l_description := substr(iso_lang || '-' || iso_terr || ': ' || req.description, 1, 240);
760         end if;
761 
762 
763         req_id := fnd_request.submit_request(
764                       req.application_short_name, req.concurrent_program_name,
765                       l_description, NULL, TRUE,
766                       req.argument1, req.argument2, req.argument3,
767                       req.argument4, req.argument5, req.argument6,
768                       req.argument7, req.argument8, req.argument9,
769                       req.argument10, req.argument11, req.argument12,
770                       req.argument13, req.argument14, req.argument15,
771                       req.argument16, req.argument17, req.argument18,
772                       req.argument19, req.argument20, req.argument21,
773                       req.argument22, req.argument23, req.argument24,
774                       req.argument25, req.argument26, req.argument27,
775                       req.argument28, req.argument29, req.argument30,
776                       req.argument31, req.argument32, req.argument33,
777                       req.argument34, req.argument35, req.argument36,
778                       req.argument37, req.argument38, req.argument39,
779                       req.argument40, req.argument41, req.argument42,
780                       req.argument43, req.argument44, req.argument45,
781                       req.argument46, req.argument47, req.argument48,
782                       req.argument49, req.argument50, req.argument51,
783                       req.argument52, req.argument53, req.argument54,
784                       req.argument55, req.argument56, req.argument57,
785                       req.argument58, req.argument59, req.argument60,
786                       req.argument61, req.argument62, req.argument63,
787                       req.argument64, req.argument65, req.argument66,
788                       req.argument67, req.argument68, req.argument69,
789                       req.argument70, req.argument71, req.argument72,
790                       req.argument73, req.argument74, req.argument75,
791                       req.argument76, req.argument77, req.argument78,
792                       req.argument79, req.argument80, req.argument81,
793                       req.argument82, req.argument83, req.argument84,
797                       req.argument94, req.argument95, req.argument96,
794                       req.argument85, req.argument86, req.argument87,
795                       req.argument88, req.argument89, req.argument90,
796                       req.argument91, req.argument92, req.argument93,
798                       req.argument97, req.argument98, req.argument99,
799                       req.argument100);
800         if (req_id = 0) then
801           errbuf := substr(fnd_message.get, 1, 240);
802           retcode := 2;
803           return;
804         end if;
805         has_reqs := TRUE;
806 
807         /* prepare the req_data to be set after submission of all req's */
808 	if ( req_data is null ) then
809 	   req_data := to_char(req_id);
810 	else
811            req_data := req_data || ',' || to_char(req_id);
812 	end if;
813 
814         -- 12.1  NEW MLS Function Str with optional territory and num char
815         /* print the submitted request in log file  */
816         if ( chkstrloc = 0 ) then
817            req_info_line := '     ' || RPAD(to_char(req_id),15) || P_LANG(ind).nls_language;
818         else
819            req_info_line := '     ' || RPAD(to_char(req_id),15) || RPAD(P_LANG(ind).nls_language,31)||RPAD(P_LANG(ind).nls_territory,31)||P_LANG(ind).nc_code;
820         end if;
821 	fnd_file.put_line(fnd_file.log, req_info_line);
822       end loop;
823 
824     end loop;   /* run_req_info  */
825 
826 
827     if ( has_reqs = FALSE ) then
828        fnd_message.set_name('FND', 'CONC-MLS has no requests');
829        errbuf := substr(fnd_message.get, 1, 240);
830        retcode := 2;
831     else
832        fnd_conc_global.set_req_globals(
833                         conc_status => 'PAUSED',
834                         request_data => req_data);
835     end if;
836 
837   end;
838 
839 /*
840  * CODE FOLDED: ENDS
841  */
842 
843   else   /* program was restarted */
844 
845      P_LCOUNT := 0;
846      startloc := 1;
847      endloc   := 1;
848 
849      loop
850 	endloc := instr( req_data, ',', startloc );
851 	P_LCOUNT := P_LCOUNT + 1;
852 	if ( endloc = 0 ) then
853 	   P_REQ(P_LCOUNT).req_id := to_number( substr( req_data, startloc,
854 					                length(req_data) -
855                                                         startloc + 1
856 							)
857 						);
858            exit;
859 	else
860 	   P_REQ(P_LCOUNT).req_id := to_number( substr( req_data, startloc,
861 							endloc - startloc
862 							)
863 						);
864 	end if;
865         startloc := endloc + 1;
866      end loop;
867 
868      /* print the header for completed request status */
869      fnd_message.set_name('FND', 'CONC-About completed requests');
870      fnd_file.put_line(fnd_file.log, fnd_message.get);
871 
872      for ind in 1..P_LCOUNT loop
873 	begin
874            select decode(status_code, 'C', 'S', 'G', 'W', 'E')
875              into current_outcome
876              from fnd_concurrent_requests
877             where request_id = P_REQ(ind).req_id;
878 
879            if ( current_outcome = 'E' ) then
880 		request_error := TRUE;
881 	   elsif ( current_outcome = 'W' ) then
882 		request_warning := TRUE;
883 	   end if;
884 
885         exception
886            when NO_DATA_FOUND then
887               fnd_message.set_name('FND','CONC-Missing Request');
888               fnd_message.set_token('ROUTINE', 'FND_MLS_REQUEST.FNDMLSUB');
889               fnd_message.set_token('REQUEST', to_char(P_REQ(ind).req_id));
890               errbuf := fnd_message.get;
891               retcode := 2;
892            return;
893         end;
894 
895         select meaning
896           into outcome_meaning
897           from fnd_lookups
898          where lookup_type = 'CP_SET_OUTCOME'
899            and lookup_code = current_outcome;
900 
901        req_info_line := '     '||RPAD(to_char(P_REQ(ind).req_id),15) || outcome_meaning;
902        fnd_file.put_line(fnd_file.log, req_info_line);
903 
904      end loop;
905 
906      if ( request_error ) then
907 	retcode := 2;
908      elsif ( request_warning ) then
909 	retcode := 1;
910      else
911 	retcode := 0;
912      end if;
913 
914       /* Get final outcome meaning */
915       select meaning
916         into outcome_meaning
917         from fnd_lookups
918        where lookup_type = 'CP_SET_OUTCOME'
919          and lookup_code = decode(retcode,2,'E',1,'W','S');
920 
921       fnd_message.set_name('FND', 'CONC-mls Completed');
922       fnd_message.set_token('OUTCOME', outcome_meaning);
923       errbuf := substr(fnd_message.get, 1, 240);
924 
925   end if;  /* req_data */
926 
927 end FNDMLSUB;
928 
929 
930 
931 function standard_languages return varchar2 is
932    cursor langs_c is
933       select language_code
934         from fnd_languages
935        where installed_flag in ('B','I')
936              order by language_id;
937    lang_str   varchar2(240);
938    ret_val    varchar2(240);
939 begin
940    lang_str := null;
941 
942    for langs in langs_c loop
943 	select concat ( lang_str, langs.language_code || ',')
944 	  into lang_str
945           from dual;
946    end loop;
947 
948    if ( length( lang_str) > 0) then
949        ret_val := substr(lang_str, 1, length(lang_str) - 1);
950    else
951        ret_val := null;
952    end if;
953 
954    return (ret_val);
955 
956 end;
957 
958 
959 end FND_MLS_REQUEST;