DBA Data[Home] [Help]

PACKAGE BODY: APPS.ECX_OUTBOUND

Source


1 PACKAGE BODY ecx_outbound as
2 -- $Header: ECXOUBXB.pls 120.14 2011/03/14 09:38:30 jmaddila ship $
3 
4 l_procedure          PLS_INTEGER := ecx_debug.g_procedure;
5 l_statement          PLS_INTEGER := ecx_debug.g_statement;
6 l_unexpected         PLS_INTEGER := ecx_debug.g_unexpected;
7 l_procedureEnabled   boolean     := ecx_debug.g_procedureEnabled;
8 l_statementEnabled   boolean     := ecx_debug.g_statementEnabled;
9 l_unexpectedEnabled  boolean     := ecx_debug.g_unexpectedEnabled;
10 
11 TYPE l_stack is table of pls_integer index by binary_integer;
12 i_stack		l_stack;
13 
14 /**
15 stage 10 - Pre-Processing
16 stage 20 - In-Processing
17 stage 30 - Post-Processing
18 **/
19 
20 procedure move_from_source_to_target
21 	(
22 	i_target_level	IN	pls_integer
23 	)
24 is
25 
26 i_method_name   varchar2(2000) := 'ecx_outbound.move_from_source_to_target';
27 i	pls_integer;
28 begin
29 if (l_procedureEnabled) then
30   ecx_debug.push(i_method_name);
31 end if;
32 if(l_statementEnabled) then
33   ecx_debug.log(l_statement,'i_target_level',i_target_level,i_method_name);
34 end if;
35 /**
36 Move the Values from Source to the Target
37 **/
38 
39 for i in ecx_utils.g_target_levels(i_target_level).file_start_pos..ecx_utils.g_target_levels(i_target_level).file_end_pos
40 loop
41 	/** Do a Clean up for the Target **/
42 	ecx_utils.g_target(i).value := null;
43 
44         /** Change required for Clob Support -- 2263729 ***/
45 	ecx_utils.g_target(i).clob_value := null;
46 	ecx_utils.g_target(i).clob_length := null;
47         ecx_utils.g_target(i).is_clob := null;
48 
49 	if ecx_utils.g_target(i).map_attribute_id is not null
50 	then
51             /** Change required for Clob Support -- 2263729 **/
52             if (ecx_utils.g_source(ecx_utils.g_target(i).map_attribute_id).data_type  = 112) Then
53                 ecx_utils.g_target(i).clob_length :=  ecx_utils.g_source(ecx_utils.g_target(i).map_attribute_id).clob_length;
54                 ecx_utils.g_target(i).is_clob     :=  ecx_utils.g_source(ecx_utils.g_target(i).map_attribute_id).is_clob;
55 
56                if (ecx_utils.g_target(i).is_clob = 'Y')
57                Then
58 
59                 ecx_utils.g_target(i).clob_value  :=  ecx_utils.g_source(ecx_utils.g_target(i).map_attribute_id).clob_value;
60                else
61 		ecx_utils.g_target(i).value :=
62 			ecx_utils.g_source(ecx_utils.g_target(i).map_attribute_id).value;
63                end if;
64             else
65                ecx_utils.g_target(i).value :=
66                         ecx_utils.g_source(ecx_utils.g_target(i).map_attribute_id).value;
67 	    end if;
68  	end if;
69 
70        	/** If the value is null then assign the target default value
71 	If ecx_utils.g_target(i).value is null
72 	then
73 	        ecx_utils.g_target(i).value := ecx_utils.g_target(i).default_value;
74 	End if;
75 	if(l_statementEnabled) then
76           ecx_debug.log(l_statement, ecx_utils.g_target(i).attribute_name,ecx_utils.g_target(i).value,
77 	               i_method_name);
78 	end if;
79 	End if;
80 	**/
81 
82 	If ecx_utils.g_target(i).clob_value is not null Then
83 	     if(l_statementEnabled) then
84 		ecx_debug.log(l_statement,i||'=>'||ecx_utils.g_target(i).parent_attribute_id||'=>'||
85 		             ecx_utils.g_target(i).attribute_type||'=>'||
86 	                     ecx_utils.g_target(i).attribute_name,ecx_utils.g_target(i).clob_value,
87 			     i_method_name);
88              end if;
89 	else
90         	-- if clob_value is null this means that it is varchar2
91 	       /** If the value is null then assign the target default value **/
92 	        If ecx_utils.g_target(i).value is null
93 	        then
94 		        ecx_utils.g_target(i).value := ecx_utils.g_target(i).default_value;
95 	        End if;
96 		if(l_statementEnabled) then
97 	          ecx_debug.log(l_statement,i||'=>'||ecx_utils.g_target(i).parent_attribute_id||'=>'||
98 		             ecx_utils.g_target(i).attribute_type||'=>'||
99 	                     ecx_utils.g_target(i).attribute_name,ecx_utils.g_target(i).value,
100 			     i_method_name);
101                 end if;
102         End If;
103 end loop;
104 if (l_procedureEnabled) then
105   ecx_debug.pop(i_method_name);
106 end if;
107 exception
108 when others then
109         if(l_unexpectedEnabled) then
110           ecx_debug.log(l_unexpected,'ECX','ECX_PROGRAM_ERROR',i_method_name,'PROGRESS_LEVEL',
111 	             'ECX_OUTBOUND.MOVE_FROM_SOURCE_TO_TARGET');
112           ecx_debug.log(l_unexpected,'ECX','ECX_ERROR_MESSAGE',i_method_name,'ERROR_MESSAGE',SQLERRM);
113         end if;
114 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.MOVE_FROM_SOURCE_TO_TARGET');
115 	if(l_unexpectedEnabled) then
116          ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_OUTBOUND.MOVE_FROM_SOURCE_TO_TARGET',
117 	               i_method_name);
118 	end if;
119 	if (l_procedureEnabled) then
120 	  ecx_debug.pop(i_method_name);
121 	end if;
122         raise ecx_utils.PROGRAM_EXIT;
123 end move_from_source_to_target;
124 
125 procedure processTarget
126 	(
127 	i_target	in	pls_integer
128 	)
129 is
130 i_method_name   varchar2(2000) := 'ecx_outbound.processtarget';
131 i_init_msg_list		varchar2(20);
132 i_simulate		varchar2(20);
133 i_validation_level	varchar2(20);
134 i_commit		varchar2(20);
135 i_return_status		varchar2(20);
136 i_msg_count		varchar2(20);
137 i_msg_data		varchar2(2000);
138 
139 begin
140 
141 if (l_procedureEnabled) then
142   ecx_debug.push(i_method_name);
143 end if;
144 if(l_statementEnabled) then
145   ecx_debug.log(l_statement,'i_target',i_target,i_method_name);
146 end if;
147 
148 	-- don't need t execute stage 10, level 0 action for target as this is
149 	-- already done in the initilization phase
150         if (i_target <> 0)
151         then
152 	   -- Pre-Processing Stage for Target
153            ecx_actions.execute_stage_data ( 10, i_target, 'T');
154         end if;
155 
156 	/** Move the Values from Source to the Target **/
157 	move_from_source_to_target(i_target);
158 
159 	-- In Processing Stage for Target
160 	   ecx_actions.execute_stage_data ( 20, i_target, 'T');
161 
162 	ecx_print_local.print_new_level
163 		(
164 		i_target,
165 		ecx_utils.g_target_levels(i_target).dtd_node_index
166 		);
167 
168         if (i_target <> 0)
169         then
170 	   -- Post Processing Stage for Target
171 	   ecx_actions.execute_stage_data ( 30, i_target, 'T');
172         end if;
173 if (l_procedureEnabled) then
174   ecx_debug.pop(i_method_name);
175 end if;
176 
177 exception
178 when ecx_utils.program_exit then
179         ecx_debug.pop('ECX_OUTBOUND.processTarget');
180         raise ecx_utils.program_exit;
181 when others then
182         if(l_unexpectedEnabled) then
183           ecx_debug.log(l_unexpected,'ECX','ECX_PROGRAM_ERROR',i_method_name,'PROGRESS_LEVEL',
184 	             'ECX_OUTBOUND.PROCESSTARGET');
185           ecx_debug.log(l_unexpected,'ECX','ECX_ERROR_MESSAGE',i_method_name,'ERROR_MESSAGE',SQLERRM);
186         end if;
187 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.PROCESSTARGET');
188 	if(l_unexpectedEnabled) then
189 	  ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_OUTBOUND.PROCESSTARGET',
190 	               i_method_name);
191         end if;
192 	if (l_procedureEnabled) then
193 	  ecx_debug.pop(i_method_name);
194 	end if;
195         raise ecx_utils.PROGRAM_EXIT;
196 end processTarget;
197 
198 procedure process_data
199 	(
200 	i		IN	pls_integer,
201 	i_stage		in	pls_integer ,
202 	i_next		IN	pls_integer
203 	)
204 is
205 
206         i_method_name   varchar2(2000) := 'ecx_outbound.process_data';
207 	i_init_msg_list         varchar2(20);
208 	i_simulate              varchar2(20);
209 	i_validation_level      varchar2(20);
210 	i_commit                varchar2(20);
211 	i_return_status         varchar2(20);
212 	i_msg_count             varchar2(20);
213 	i_msg_data	        varchar2(2000);
214         j                       pls_integer;
215 begin
216 if (l_procedureEnabled) then
217   ecx_debug.push(i_method_name);
218 end if;
219 if(l_statementEnabled) then
220   ecx_debug.log(l_statement,'i',i,i_method_name);
221   ecx_debug.log(l_statement,'i_stage',i_stage,i_method_name);
222   ecx_debug.log(l_statement,'i_next',i_next,i_method_name);
223 end if;
224 
225 if i < 0
226 then
227         if (l_procedureEnabled) then
228 	  ecx_debug.pop(i_method_name);
229 	end if;
230 	return;
231 end if;
232 
233 if i_stage = 10
234 then
235 
236 	/** Should clean up the Current Source and the down levels first**/
237 	for k in i..ecx_utils.g_source_levels.last
238 	loop
239 		for j in ecx_utils.g_source_levels(k).file_start_pos..ecx_utils.g_source_levels(k).file_end_pos
240        		loop
241 			if ecx_utils.g_source(j).default_value is null
242 			then
243        				ecx_utils.g_source(j).value := null;
244                                 ecx_utils.g_source(j).clob_value := null;
245                                 ecx_utils.g_source(j).is_clob    := null;
246                                 ecx_utils.g_source(j).clob_length := null;
247 			else
248        				ecx_utils.g_source(j).value := ecx_utils.g_source(j).default_value;
249 			end if;
250 			if(l_statementEnabled) then
251    			  ecx_debug.log(l_statement,'Source '||ecx_utils.g_source(j).attribute_name,
252 			               ecx_utils.g_source(j).value,i_method_name);
253 			end if;
254 		end loop;
255 	end loop;
256 
257          -- For level 0 this is already done in the initialization
258          if (i <> 0)
259          then
260 	   /** Execute the pre-processing for the Source **/
261             ecx_actions.execute_stage_data (i_stage, i, 'S');
262          end if;
263 end if;
264 
265 if i_stage = 20
266 then
267 	-- Perform Code Conversion
268 	ecx_code_conversion_pvt.populate_plsql_tbl_with_extval
269 		(
270 		p_api_version_number 	=> 1.0,
271 		p_init_msg_list		=> i_init_msg_list,
272 		p_simulate		=> i_simulate,
273 		p_commit		=> i_commit,
274 		p_validation_level	=> i_validation_level,
275 		p_return_status		=> i_return_status,
276 		p_msg_count		=> i_msg_count,
277 		p_msg_data		=> i_msg_data,
278 		p_level			=> i,
279 		p_tbl			=> ecx_utils.g_source,
280 		p_tp_id			=> ecx_utils.g_rec_tp_id,
281 		p_standard_id		=> ecx_utils.g_standard_id
282 		);
283 
284 	--Check the Status of the Code Conversion API and take appropriate action.
285 	IF 	(
286 		i_return_status = ecx_code_conversion_pvt.G_RET_STS_ERROR OR
287 		i_return_status is NULL OR
288 		i_return_status = ecx_code_conversion_pvt.G_RET_STS_UNEXP_ERROR
289 		)
290 	THEN
291 	        if(l_statementEnabled) then
292                      ecx_debug.log(l_statement,'ECX','ECX_PROGRAM_ERROR',i_method_name,'PROGRESS_LEVEL',
293 	                         'ECX_OUTBOUND.PROCESS_DATA');
294 		     ecx_debug.log(l_statement,'ECX','EC_CODE_CONVERSION_FAILED',i_method_name,'LEVEL',i);
295 		 end if;
296 		ecx_utils.i_ret_code := 2;
297 		RAISE ecx_utils.PROGRAM_EXIT;
298 	END IF;
299 
300 	/** Execute the In-processing for the Source **/
301         ecx_actions.execute_stage_data (i_stage, i, 'S');
302 
303 	for j in ecx_utils.g_source_levels(i).first_target_level .. ecx_utils.g_source_levels(i).last_target_level
304 	loop
305 		/** Initialize the Target **/
306 	        for k in ecx_utils.g_target_levels(j).file_start_pos..ecx_utils.g_target_levels(j).file_end_pos
307         	loop
308 			if ecx_utils.g_target(k).default_value is null
309 			then
310            			ecx_utils.g_target(k).value := null;
311                                /** Change required for Clob Support -- 2263729 ***/
312            			ecx_utils.g_target(k).clob_value := null;
313            			ecx_utils.g_target(k).clob_length := null;
314                                 ecx_utils.g_target(k).is_clob := null;
315 			else
316            			ecx_utils.g_target(k).value := ecx_utils.g_target(k).default_value;
317 			end if;
318 			if(l_statementEnabled) then
319 	   		  ecx_debug.log(l_statement,'target '||ecx_utils.g_target(k).attribute_name,
320 			               ecx_utils.g_target(k).value,i_method_name);
321 	                end if;
322 		end loop;
323 	   end loop;
324 
325 	   /** Check for Collapsion. Do depth checking for Collapsion only **/
326 	   if(l_statementEnabled) then
327 	     ecx_debug.log(l_statement,'Previous Level',i,i_method_name);
328 	     ecx_debug.log(l_statement,'Current Level',i_next,i_method_name);
329            end if;
330 
331 	   if ( ecx_utils.g_source_levels(i).last_source_level -
332 		ecx_utils.g_source_levels(i).first_source_level > 0 )
333 	   then
334 		if i_next > i
335 		then
336 			if 	( i_next >= ecx_utils.g_source_levels(i).first_source_level )
337 				and
338 				( i_next <= ecx_utils.g_source_levels(i).last_source_level )
339 			then
340 			        if(l_statementEnabled) then
341 				  ecx_debug.log(l_statement,'Skipping Source',i,i_method_name);
342 				 end if;
343 			else
344 				processTarget(ecx_utils.g_source_levels(i).first_target_level);
345 			end if;
346 		end if;
347 
348 		if i_next <= i
349 		then
350 				processTarget(ecx_utils.g_source_levels(i).first_target_level);
351 		end if;
352 	   else
353 		/** Else Expansion or 1-1 mapping **/
354 		for j in ecx_utils.g_source_levels(i).first_target_level .. ecx_utils.g_source_levels(i).last_target_level
355 		loop
356 			processTarget(j);
357 	end loop;
358      end if;
359 end if;
360 
361 if i_stage = 30
362 then
363          -- For level 0 this will be done in the end
364          if (i <> 0)
365          then
366 	    /** Execute the Post-processing for the Source **/
367            ecx_actions.execute_stage_data (30, i, 'S');
368         end if;
369 
370         /*
371         Before doing a stage 30 for level we need to print any remaning discontinuous elements
372         for this level. This way if another occurrance of this level arrives the data for the
373         discontinuous elements will be printed before it gets overwritten.
374         */
375 
376         -- for all the target levels mapped to this source level print the discont elements
377         j := ecx_utils.g_source_levels(i).last_target_level;
378 	if (l_statementEnabled) then
379           ecx_debug.log(l_statement,'last target level', ecx_utils.g_source_levels(i).last_target_level,i_method_name);
380           ecx_debug.log(l_statement, 'first target level', ecx_utils.g_source_levels(i).first_target_level,
381 	               i_method_name);
382 	end if;
383         while (j >= ecx_utils.g_source_levels(i).first_target_level)
384         loop
385                 ecx_print_local.print_discont_elements(ecx_print_local.last_printed + 1,
386                           ecx_utils.g_target_levels(j).file_end_pos,
387                           ecx_utils.g_target(ecx_utils.g_target_levels(j).file_start_pos).attribute_id,
388                                 j);
389                 j := j - 1;
390 	end loop;
391 end if;
392 
393 if (l_procedureEnabled) then
394   ecx_debug.pop(i_method_name);
395 end if;
396 exception
397 when ecx_utils.program_exit then
398         if (l_procedureEnabled) then
399           ecx_debug.pop(i_method_name);
400 	end if;
401         raise ecx_utils.program_exit;
402 when others then
403 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.PROCESS_DATA');
404 	if(l_unexpectedEnabled) then
405 	  ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_OUTBOUND.PROCESS_DATA',i_method_name);
406 	end if;
407 	if (l_procedureEnabled) then
408 		ecx_debug.pop(i_method_name);
409         end if;
410 	raise ecx_utils.program_exit;
411 end process_data;
412 
413 
414 procedure print_stack
415 is
416 i_method_name   varchar2(2000) := 'ecx_outbound.print_stack';
417 begin
418 
419         if(l_statementEnabled) then
420            ecx_debug.log(l_statement,'Stack Status','====',i_method_name);
421 	end if;
422 	for i in 1..i_stack.COUNT
423 	loop
424 	        if(l_statementEnabled) then
425                    ecx_debug.log(l_statement,i_stack(i),i_method_name);
426 		end if;
427 	end loop;
428 exception
429 when others then
430 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.PRINT_STACK');
431 	if(l_unexpectedEnabled) then
432            ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_OUTBOUND.PRINT_STACK',i_method_name);
433         end if;
434 	raise ecx_utils.program_exit;
435 end print_stack;
436 
437 procedure pop
438 	(
439 	i_next	in	pls_integer
440 	)
441 is
442 i_method_name   varchar2(2000) := 'ecx_outbound.pop';
443 
444 begin
445 if (l_procedureEnabled) then
446   ecx_debug.push(i_method_name );
447 end if;
448 if(l_statementEnabled) then
449   ecx_debug.log(l_statement,'i_next',i_next,i_method_name);
450   print_stack;
451 end if;
452 
453 	if i_stack.COUNT = 0
454 	then
455 	        if(l_statementEnabled) then
456                   ecx_debug.log(l_statement,'Stack Error. Nothing to pop','xxxxx',i_method_name);
457 		end if;
458 		if (l_procedureEnabled) then
459 		  ecx_debug.pop(i_method_name);
460 		end if;
461 		return;
462 	end if;
463 
464 	/** Post Process and then pop. **/
465 	process_data(i_stack(i_stack.COUNT),30,i_next);
466 
467 	i_stack.delete(i_stack.COUNT);
468 
469 	if(l_statementEnabled) then
470 		print_stack;
471 	end if;
472 if (l_procedureEnabled) then
473   ecx_debug.pop(i_method_name );
474 end if;
475 exception
476 when ecx_utils.program_exit then
477         if (l_procedureEnabled) then
478            ecx_debug.pop(i_method_name);
479         end if;
480         raise ecx_utils.program_exit;
481 when others then
482 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.POP');
483 	if(l_unexpectedEnabled) then
484 	  ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_OUTBOUND.POP',i_method_name);
485 	end if;
486 	if (l_procedureEnabled) then
487           ecx_debug.pop(i_method_name);
488         end if;
489 	raise ecx_utils.program_exit;
490 end pop;
491 
492 procedure push
493 	(
494 	i	in	pls_integer
495 	)
496 is
497 
498 i_method_name   varchar2(2000) := 'ecx_outbound.push';
499 begin
500 if (l_procedureEnabled) then
501   ecx_debug.push(i_method_name);
502 end if;
503 	if(l_statementEnabled) then
504 	  ecx_debug.log(l_statement,i,i_method_name);
505 	  print_stack;
506 	end if;
507 
508 	if i_stack.COUNT = 0
509 	then
510 		-- Nothing on the Stack. Push the value
511 		i_stack(i_stack.COUNT+1):=i;
512 
513 		/** pre stage processing **/
514 		process_data(i_stack(i_stack.COUNT),10,i);
515 
516 		if(l_statementEnabled) then
517 			print_stack;
518 		end if;
519 
520 		if (l_procedureEnabled) then
521 		  ecx_debug.pop(i_method_name);
522 		end if;
523 
524 		return;
525 	end if;
526 
527 	if i > i_stack(i_stack.COUNT)
528 	then
529 		/** In stage processing **/
530 		process_data(i_stack(i_stack.COUNT),20,i);
531 
532 		-- Push
533 		i_stack(i_stack.COUNT+1):=i;
534 
535 		/** pre stage processing **/
536 		process_data(i_stack(i_stack.COUNT),10,i);
537 
538 		if(l_statementEnabled) then
539 			print_stack;
540 		end if;
541 
542 		if (l_procedureEnabled) then
543 		  ecx_debug.pop(i_method_name);
544 		end if;
545 		return;
546 	end if;
547 
548 	if i = i_stack(i_stack.COUNT)
549 	then
550 		/** In-Processing and then pop the Top Entry. **/
551 		process_data(i_stack(i_stack.COUNT),20,i);
552 		pop(i);
553 	end if;
554 
555 	if i_stack.COUNT <> 0
556 	then
557 		if i < i_stack(i_stack.COUNT)
558 		then
559 
560 			/** In-Processing and then pop the Top Entry. **/
561 			process_data(i_stack(i_stack.COUNT),20,i);
562 			pop(i);
563 
564 			/** Pop The rest of the Elements **/
565 			while ( i <= i_stack(i_stack.COUNT) )
566 			loop
567 				pop(i);
568 				exit when i_stack.COUNT = 0;
569 			end loop;
570 
571 		end if;
572 	end if;
573 
574 	-- Push the value
575 	i_stack(i_stack.COUNT+1):=i;
576 	/** pre stage processing **/
577 	process_data(i_stack(i_stack.COUNT),10,i);
578 
579 
580 	if(l_statementEnabled) then
581 		print_stack;
582 	end if;
583 
584 if (l_procedureEnabled) then
585 	ecx_debug.pop(i_method_name);
586 end if;
587 exception
588 when ecx_utils.program_exit then
589         if (l_procedureEnabled) then
590           ecx_debug.pop(i_method_name);
591 	end if;
592         raise ecx_utils.program_exit;
593 when others then
594 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.PUSH');
595 	if(l_unexpectedEnabled) then
596           ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_OUTBOUND.PUSH',i_method_name);
597 	end if;
598 	if (l_procedureEnabled) then
599 	  ecx_debug.pop(i_method_name);
600 	end if;
601 	raise ecx_utils.program_exit;
602 end push;
603 
604 
605 procedure popall
606 is
607 i_method_name   varchar2(2000) := 'ecx_outbound.popall';
608 begin
609 if (l_procedureEnabled) then
610   ecx_debug.push(i_method_name );
611 end if;
612 	/** In-Process the last Level on the Stack **/
613 	if i_stack.COUNT <> 0
614 	then
615 		process_data(i_stack(i_stack.COUNT),20,0);
616 	end if;
617 
618 	if(l_statementEnabled) then
619 		print_stack;
620 	end if;
621 
622 	while ( i_stack.COUNT > 0)
623 	loop
624 		pop(0);
625 	end loop;
626 
627 	if(l_statementEnabled) then
628 		print_stack;
629 	end if;
630 
631 if (l_procedureEnabled) then
632   ecx_debug.pop(i_method_name );
633 end if;
634 
635 exception
636 when ecx_utils.program_exit then
637         if (l_procedureEnabled) then
638           ecx_debug.pop(i_method_name );
639         end if;
640         raise ecx_utils.program_exit;
641 when others then
642 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.POPALL');
643 	if(l_unexpectedEnabled) then
644            ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_OUTBOUND.POPALL',i_method_name);
645 	end if;
646 	if (l_procedureEnabled) then
647           ecx_debug.pop(i_method_name );
648         end if;
649 	raise ecx_utils.program_exit;
650 end popall;
651 
652 /**
653 Fetches data from the ec_views recurrsively for a given document.
654 **/
655 PROCEDURE fetch_data_from_view(
656     i_level IN pls_integer )
657 IS
658   i_method_name VARCHAR2(2000) := 'ecx_outbound.fetch_data_from_view';
659   i_column_counter pls_integer :=0;
660   i_rows_processed pls_integer ;
661   i_start_element VARCHAR2(2000);
662   j pls_integer;
663   i_count pls_integer;
664   l_clob CLOB;
665   i_len pls_integer;
666   l_temp VARCHAR2(32767);
667 BEGIN
668   IF (l_procedureEnabled) THEN
669     ecx_debug.push(i_method_name );
670   END IF;
671   IF(l_statementEnabled) THEN
672     ecx_debug.log(l_statement,'i_level',i_level,i_method_name);
673     ecx_debug.log(l_statement,'Source level',ecx_utils.g_source_levels.COUNT,i_method_name);
674     ecx_debug.log(l_statement,'target_source_levels',ecx_utils.g_target_source_levels.COUNT,i_method_name);
675   END IF;
676   -- push root element on stack
677   IF (i_level = 0) THEN
678     push(i_level);
679   END IF;
680   FOR i IN 1..ecx_utils.g_source_levels.last
681   LOOP
682     IF ecx_utils.g_source_levels(i).parent_level = i_level THEN
683       IF(l_statementEnabled) THEN
684         ecx_debug.log(l_statement,'SQL Statement',ecx_utils.g_source_levels(i).sql_stmt,i_method_name);
685       END IF;
686       -- Set the Global Variable for Current Level
687       ecx_utils.g_current_level := i;
688       /* Bind the Variables for the Where Clause */
689       ecx_actions.bind_variables_for_view(10,i);
690       i_rows_processed := dbms_sql.execute (ecx_utils.g_source_levels(i).Cursor_Handle);
691       IF(l_statementEnabled) THEN
692         ecx_debug.log(l_statement,'Cursor Handle',ecx_utils.g_source_levels(i).Cursor_handle, i_method_name);
693       END IF;
694       WHILE (dbms_sql.fetch_rows( ecx_utils.g_source_levels(i).Cursor_handle) > 0)
695       LOOP
696         push(i);
697         IF(l_statementEnabled) THEN
698           ecx_debug.log(l_statement,'Executing Fetch Rows',i_method_Name);
699         END IF;
700         -- Get Values from the View
701         -- Initialize the Column Counter
702         i_column_counter :=0;
703         j                := ecx_utils.g_source_levels(i).file_start_pos;
704         LOOP
705           IF (ecx_utils.g_source(j).external_level = i) THEN
706             i_column_counter                      := i_column_counter + 1;
707             IF ecx_utils.g_source(j).data_type    <> 112 THEN
708               dbms_sql.column_value ( ecx_utils.g_source_levels(i).Cursor_handle, i_column_counter, ecx_utils.g_source(j).value );
709             ELSE
710               dbms_sql.column_value ( ecx_utils.g_source_levels(i).Cursor_handle, i_column_counter, ecx_utils.g_source(j).clob_value );
711               /** Change required for Clob Support -- 2263729 ***/
712               ecx_utils.g_source(j).clob_length := dbms_lob.getlength( ecx_utils.g_source(j).clob_value);
713               i_len                             := ecx_utils.g_source(j).clob_length;
714               ecx_utils.g_source(j).is_clob     := 'N';
715               /** Fix for bug 8845448*/
716               IF i_len <= ecx_utils.G_CLOB_VARCHAR_LEN THEN
717                 BEGIN
718                   dbms_lob.read(ecx_utils.g_source(j).clob_value,i_len,1,l_temp);
719                   ecx_utils.g_source(j).value       := l_temp;
720                   ecx_utils.g_source(j).clob_value  := NULL;
721                   ecx_utils.g_source(j).clob_length := NULL;
722                 EXCEPTION
723                 WHEN OTHERS THEN
724                   ecx_utils.g_source(j).is_clob := 'Y';
725                   ecx_debug.log(l_statement,'Unable to convert clob to varchar, using clob itself',i_method_name);
726                 END;
727               ELSE
728                 ecx_utils.g_source(j).is_clob := 'Y';
729               END IF;
730             END IF;
731             /** If the value is null set the default value **/
732             IF ecx_utils.g_source(j).value IS NULL THEN
733               ecx_utils.g_source(j).value  := ecx_utils.g_source(j).default_value;
734             END IF;
735             IF(l_statementEnabled) THEN
736               IF ecx_utils.g_source(j).base_column_name IS NOT NULL THEN
737                 /**  Change required for Clob Support -- 2263729 ***/
738                 IF ecx_utils.g_source(j).data_type     = 112 THEN
739                   IF ecx_utils.g_source(j).clob_value IS NULL THEN
740                     ecx_debug.log(l_statement, ecx_utils.g_source(j).base_column_name, ecx_utils.g_source(j).value, i_method_name );
741                   ELSE
742                     ecx_debug.log(l_statement, ecx_utils.g_source(j).base_column_name, ecx_utils.g_source(j).clob_value, i_method_name );
743                   END IF;
744                 ELSE
745                   ecx_debug.log(l_statement, ecx_utils.g_source(j).base_column_name, ecx_utils.g_source(j).value, i_method_name );
746                 END IF;
747               END IF;
748             END IF;
749           END IF;
750           EXIT
751         WHEN j = ecx_utils.g_source_levels(i).file_end_pos;
752           j   := ecx_utils.g_source.next(j);
753         END LOOP;
754         IF(l_statementEnabled) THEN
755           ecx_debug.log(l_statement,'All Rows fetched',i_method_name);
756         END IF;
757         i_count                             :=0;
758         IF (ecx_utils.g_source_levels.count <> 0) THEN
759           FOR m                             IN ecx_utils.g_source_levels.first..ecx_utils.g_source_levels.last
760           LOOP
761             IF(l_statementEnabled) THEN
762               ecx_debug.log(l_statement,'Source level '||m,'Parent level'||ecx_utils.g_source_levels(m).parent_level, i_method_name);
763             END IF;
764             IF ecx_utils.g_source_levels(m).parent_level=i THEN
765               i_count                                  := i_count+1;
766             END IF;
767           END LOOP;
768         END IF;
769         IF(l_statementEnabled) THEN
770           ecx_debug.log(l_statement,'i_count',i_count,i_method_name);
771         END IF;
772         IF i_count > 0 THEN
773           fetch_data_from_view(i);
774         END IF;
775       END LOOP;
776       IF i                                           = 1 THEN
777         ecx_utils.g_source_levels(i).rows_processed := dbms_sql.last_row_count;
778       ELSE
779         ecx_utils.g_source_levels(i).rows_processed := ecx_utils.g_source_levels(i).rows_processed + dbms_sql.last_row_count;
780       END IF;
781     END IF;
782   END LOOP;
783   IF (l_procedureEnabled) THEN
784     ecx_debug.pop(i_method_name );
785   END IF;
786 EXCEPTION
787 WHEN invalid_number THEN
788   IF(l_unexpectedEnabled) THEN
789     ecx_debug.log(l_unexpected,'ECX','ECX_PROGRAM_ERROR',i_method_name, 'PROGRESS_LEVEL','ECX_OUTBOUND.FETCH_DATA_FROM_VIEW');
790     ecx_debug.log(l_unexpected,'ECX','ECX_ERROR_MESSAGE',i_method_name,
791 	              'ERROR_MESSAGE',SQLERRM);
792   end if;
793   ecx_debug.setErrorInfo(2,30,'ECX_INVALID_NUMBER - ECX_OUTBOUND.FETCH_DATA_FROM_VIEW' );
794   if (l_procedureEnabled) then
795     ecx_debug.pop(i_method_name);
796   end if;
797   raise ecx_utils.program_exit;
798 WHEN ecx_utils.PROGRAM_EXIT then
799         raise;
800 WHEN OTHERS THEN
801         if(l_unexpectedEnabled) then
802           ecx_debug.log(l_unexpected,'ECX','ECX_PROGRAM_ERROR',i_method_name,'PROGRESS_LEVEL',
803 	             'ECX_OUTBOUND.FETCH_DATA_FROM_VIEW');
804           ecx_debug.log(l_unexpected,'ECX','ECX_ERROR_MESSAGE',i_method_name,'ERROR_MESSAGE',SQLERRM);
805         end if;
806 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.FETCH_DATA_FROM_VIEW');
807 	if(l_unexpectedEnabled) then
808           ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_OUTBOUND.FETCH_DATA_FROM_VIEW',
809 		       i_method_name);
810 	end if;
811         if (l_procedureEnabled) then
812           ecx_debug.pop(i_method_name );
813         end if;
814         raise ecx_utils.PROGRAM_EXIT;
815 END fetch_data_from_view;
816 
817 procedure log_summary(level pls_integer)
818 is
819 i_method_name varchar2(2000);
820 begin
821 	i_method_name:='ecx_outbound.log_summary';
822         if (l_procedureEnabled) then
823           ecx_debug.push(i_method_name);
824         end if;
825 
826 	ecx_debug.log(level,'Processing Summary','====',i_method_name);
827 	if (ecx_utils.g_source_levels.count <> 0)
828 	then
829 	   for i in ecx_utils.g_source_levels.first..ecx_utils.g_source_levels.last
830 	   loop
831 		ecx_debug.log(level,ecx_utils.g_source_levels(i).rows_processed||
832 			     ' row(s) processed for Level : '|| ecx_utils.g_source_levels(i).start_element
833 			     || '('|| i || ') ',i_method_name);
834 	   end loop;
835 	end if;
836         if (l_procedureEnabled) then
837           ecx_debug.pop(i_method_name);
838         end if;
839 exception
840 when others then
841 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.LOG_SUMMARY');
842 	if(l_unexpectedEnabled) then
843            ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_OUTBOUND.LOG_SUMMARY',i_method_name);
844 	end if;
845         if (l_procedureEnabled) then
846           ecx_debug.pop(i_method_name);
847         end if;
848 
849 	raise ecx_utils.program_exit;
850 end log_summary;
851 
852 /**
853 Main Call for Processing Outbound Documents
854 **/
855 procedure process_outbound_documents
856 	(
857 	i_message_standard	IN	varchar2,
858 	i_transaction_type	IN	varchar2,
859 	i_transaction_subtype	IN	varchar2,
860 	i_tp_id			IN	varchar2,
861 	i_tp_site_id		IN	varchar2,
862 	i_tp_type		In	varchar2,
863 	i_document_id		IN	varchar2,
864 	i_map_code		IN	varchar2,
865 	i_xmldoc		IN OUT	NOCOPY clob,
866         i_message_type          IN      varchar2
867 	)
868 is
869 
870 i_method_name   varchar2(2000) := 'ecx_outbound.process_outbound_documents';
871 
872 i_msgid			raw(16);
873 i_dtd_id		pls_integer;
874 i_run_id		pls_integer;
875 i_variable_found	BOOLEAN := TRUE;
876 i_stack_pos		pls_integer;
877 i_fullpath		ecx_objects.fullpath%TYPE;
878 i_root_element		ecx_objects.root_element%TYPE;
879 i_filename		varchar2(200);
880 i_temp			varchar2(32767);
881 i_logdir                varchar2(200);
882 x_same_map		BOOLEAN := FALSE;
883 i_tp_header_id		pls_integer;
884 i_map_id		pls_integer;
885 i_standard_id		pls_integer;
886 i_parameterlist		wf_parameter_list_t;
887 i_parameter		wf_parameter_t;
888 counter number;
889 i_paramCount     number;
890 i_stack_param_name 	VARCHAR2(2000);
891 i_stack_param_value 	VARCHAR2(4000);
892 i_param_name       	VARCHAR2(30);
893 i_mode                  varchar2(10) := 'FALSE';
894 l_IANAcharset           varchar2(2000);
895 l_xmldecl               varchar2(4000);
896 l_parseXML              boolean;
897 l_value                 number;
898 i_node_type             pls_integer;
899 
900 attachment_id pls_integer;
901 ctemp              varchar2(32767);
902 clength            pls_integer;
903 offset            pls_integer := 1;
904 g_varmaxlength     pls_integer := 1999;
905 g_instlmode         VARCHAR2(100);
906 
907 begin
908 
909 
910 if (l_procedureEnabled) then
911   ecx_debug.push(i_method_name );
912 end if;
913 if(l_statementEnabled) then
914   ecx_debug.log(l_statement,'ECX','ECX_START_OUTBOUND','MAP_ID',i_map_id,i_method_name);
915   ecx_debug.log(l_statement,'i_message_standard',i_message_standard,i_method_name);
916   ecx_debug.log(l_statement,'i_transaction_type',i_transaction_type,i_method_name);
917   ecx_debug.log(l_statement,'i_transaction_subtype',i_transaction_subtype,i_method_name);
918   ecx_debug.log(l_statement,'i_tp_id',i_tp_id,i_method_name);
919   ecx_debug.log(l_statement,'i_tp_site_id',i_tp_site_id,i_method_name);
920   ecx_debug.log(l_statement,'i_tp_type',i_tp_type,i_method_name);
921   ecx_debug.log(l_statement,'i_document_id',i_document_id,i_method_name);
922   ecx_debug.log(l_statement,'i_map_code',i_map_code,i_method_name);
923 end if;
924 
925 /** check for the Event Object. If null , initialize it **/
926 if ecx_utils.g_event is null
927 then
928 	wf_event_t.initialize(ecx_utils.g_event);
929 end if;
930 i_parameterlist := wf_event_t.getParameterList(ecx_utils.g_event);
931 if(l_statementEnabled) then
932 	if i_parameterList is not null
933 	then
934 		for i in i_parameterList.FIRST..i_parameterList.LAST
935 		loop
936 			i_parameter := i_parameterList(i);
937 			ecx_debug.log(l_statement,i_parameter.getName(),i_parameter.getValue(),i_method_name);
938 		end loop;
939 	end if;
940 end if;
941 
942 
943 /** Set the GLobal variables **/
944 ecx_utils.g_transaction_type := i_transaction_type;
945 ecx_utils.g_transaction_subtype := i_transaction_subtype;
946 ecx_utils.g_document_id := i_document_id;
947 
948 	/** Check for Message Standard Code **/
949 	begin
950 		select 	standard_id
951 		into  	i_standard_id
952 		from  	ecx_standards
953 		where 	standard_code = i_message_standard
954                 and     standard_type = nvl(i_message_type, 'XML');
955 
956 		ecx_utils.g_standard_id := i_standard_id;
957 	exception
958 	when others then
959 		ecx_debug.setErrorInfo(1, 30, 'ECX_CODE_CONVERSION_DISABLED',
960 				      'MESSAGE_STANDARD', i_message_standard);
961 		if(l_statementEnabled) then
962                    ecx_debug.log(l_statement,'ECX', 'ECX_CODE_CONVERSION_DISABLED',i_method_name,
963  				      'MESSAGE_STANDARD', i_message_standard);
964 	        end if;
965 	end;
966 
967 	/** Check for Map Code **/
968 	begin
969 		select 	map_id
970 		into  	i_map_id
971 		from  	ecx_mappings
972 		where 	map_code = i_map_code;
973 	exception
974 	when others then
975 		ecx_debug.setErrorInfo(1, 30, 'ECX_MAP_NOT_FOUND', 'MAP_CODE', i_map_code);
976 		if(l_unexpectedEnabled) then
977                    ecx_debug.log(l_unexpected,'ECX', 'ECX_MAP_NOT_FOUND', i_method_name,'MAP_CODE', i_map_code);
978 		end if;
979 		raise ecx_utils.program_exit;
980 	end;
981 
982 	/** Check for tp_header_id **/
983 	begin
984 		select 	tp_header_id
985 		into  	i_tp_header_id
986 		from  	ecx_tp_headers
987 		where 	party_id = i_tp_id
988 		and 	party_site_id = i_tp_site_id
989 		and 	party_type = i_tp_type;
990 
991 		/** Set the GLobal g_rcv_tp_id **/
992 		ecx_utils.g_rec_tp_id:= i_tp_header_id;
993 	exception
994 	when others then
995 		ecx_debug.setErrorInfo(1, 30, 'ECX_TP_NOT_FOUND', 'PARTY_ID', i_tp_id);
996 		if(l_statementEnabled) then
997                    ecx_debug.log(l_statement,'ECX', 'ECX_TP_NOT_FOUND', i_method_name,'PARTY_ID', i_tp_id);
998 		end if;
999 	end;
1000 
1001 	begin
1002 		select 	root_element,
1003 			fullpath
1004 		into  	i_root_element,
1005 			i_filename
1006 		from  	ecx_objects eo
1007 		where 	eo.map_id = i_map_id
1008 		and   	eo.object_type in ('DTD','XML')
1009 		and	eo.object_id = 2;
1010 	exception
1011 	when others then
1012 		ecx_debug.setErrorInfo(1, 30, 'ECX_ROOT_ELEMENT_NOT_FOUND', 'MAP_ID', i_map_id);
1013 		if(l_unexpectedEnabled) then
1014                    ecx_debug.log(l_unexpected,'ECX', 'ECX_ROOT_ELEMENT_NOT_FOUND',i_method_name, 'MAP_ID', i_map_id);
1015 		end if;
1016 		raise ecx_utils.program_exit;
1017 	end;
1018 
1019 	/**
1020 	Initialize Memory Structures Set the direction for the Transaction **/
1021 	ecx_utils.g_direction :='OUT';
1022 	ecx_utils.initialize(i_map_id,x_same_map);
1023 
1024 
1025 	/**
1026 	Find the Stack Variable.If Found set the value.
1027 	**/
1028 			i_variable_found := ecx_actions.find_stack_variable
1029 				(
1030 				'TRANSACTION_TYPE',
1031 				i_stack_pos
1032 				);
1033 
1034 			if (i_variable_found AND i_transaction_type is not null)
1035 			then
1036 				ecx_utils.g_stack(i_stack_pos).variable_value := i_transaction_type;
1037 			end if;
1038 
1039 			i_variable_found := ecx_actions.find_stack_variable
1040 				(
1041 				'TRANSACTION_SUBTYPE',
1042 				i_stack_pos
1043 				);
1044 
1045 			if (i_variable_found AND i_transaction_subtype is not null)
1046 			then
1047 				ecx_utils.g_stack(i_stack_pos).variable_value := i_transaction_subtype;
1048 			end if;
1049 
1050 
1051 			i_variable_found := ecx_actions.find_stack_variable
1052 				(
1053 				'DOCUMENT_ID',
1054 				i_stack_pos
1055 				);
1056 
1057 			if (i_variable_found AND i_document_id is not null)
1058 			then
1059 				ecx_utils.g_stack(i_stack_pos).variable_value := i_document_id;
1060 			end if;
1061 
1062 			i_variable_found := ecx_actions.find_stack_variable
1063 				(
1064 				'TP_ID',
1065 				i_stack_pos
1066 				);
1067 
1068 			if (i_variable_found AND i_tp_id is not null)
1069 			then
1070 				ecx_utils.g_stack(i_stack_pos).variable_value := i_tp_id;
1071 			end if;
1072 
1073 			i_variable_found := ecx_actions.find_stack_variable
1074 				(
1075 				'TP_SITE_ID',
1076 				i_stack_pos
1077 				);
1078 
1079 			if (i_variable_found AND i_tp_site_id is not null)
1080 			then
1081 				ecx_utils.g_stack(i_stack_pos).variable_value := i_tp_site_id;
1082 			end if;
1083 
1084 			i_variable_found := ecx_actions.find_stack_variable
1085 				(
1086 				'TP_TYPE',
1087 				i_stack_pos
1088 				);
1089 
1090 			if (i_variable_found AND i_tp_type is not null)
1091 			then
1092 				ecx_utils.g_stack(i_stack_pos).variable_value := i_tp_type;
1093 			end if;
1094 
1095 			/* If the input wf_event_t object passed is null , the following loop raises an exception.
1096 			   so initialize the i_event_obj
1097 			IF ( i_event_obj IS NULL ) THEN
1098 				WF_EVENT_T.initialize(i_event_obj);
1099 			END IF; */
1100 
1101 			-- Get the Parameter List from the Global Event Message Object. Iterate through it and populate the
1102 			-- Global variables in the Engine Stack
1103 			if i_parameterlist is not null
1104 			then
1105 				FOR counter in i_parameterList.FIRST..i_parameterList.LAST
1106 				LOOP
1107 					i_parameter := i_parameterList(counter);
1108 					if i_parameter is not null
1109 					then
1110 						i_stack_param_name := i_parameter.getname();
1111 						-- For backward Compatability , if the ECX_PARAMETER1..5 is passed changed it to
1112 						-- PARAMETER1..5
1113 						if i_stack_param_name = 'ECX_PARAMETER1'
1114 						then
1115 							i_stack_param_name := 'PARAMETER1';
1116 
1117 						elsif i_stack_param_name = 'ECX_PARAMETER2'
1118 						then
1119 							i_stack_param_name := 'PARAMETER2';
1120 
1121 						elsif i_stack_param_name = 'ECX_PARAMETER3'
1122 						then
1123 							i_stack_param_name := 'PARAMETER3';
1124 
1125 						elsif i_stack_param_name = 'ECX_PARAMETER4'
1126 						then
1127 							i_stack_param_name := 'PARAMETER4';
1128 
1129 						elsif i_stack_param_name = 'ECX_PARAMETER5'
1130 						then
1131 							i_stack_param_name := 'PARAMETER5';
1132 						end if;
1133 
1134 						if ( i_stack_param_name is not null)
1135 						then
1136 							i_variable_found := ecx_actions.find_stack_variable
1137 							(
1138 							i_stack_param_name,
1139 							i_stack_pos
1140 							);
1141 
1142 							if (i_variable_found)
1143 							then
1144 								i_stack_param_value := i_parameter.getValue();
1145 								/** Only overwrite the Global variable value if not null **/
1146 								if i_stack_param_value is not null
1147 								then
1148 									ecx_utils.g_stack(i_stack_pos).variable_value
1149 										:= i_stack_param_value;
1150 								end if;
1151 							end if;
1152 						end if;
1153 					end if;
1154 				END LOOP;
1155 			end if;
1156 			/* End of changes for bug 2120165 */
1157 
1158 	/**
1159 	Should Avoid Parsing and Loading the Next Map if it is same as the previous one.
1160 	**/
1161 	if NOT (x_same_map)
1162 	then
1163 		ecx_utils.load_objects(i_map_id);
1164 	end if;
1165 
1166 	if (ecx_utils.g_source_levels.count <> 0)
1167 	then
1168 	   for i in ecx_utils.g_source_levels.first..ecx_utils.g_source_levels.last
1169 	   loop
1170 		ecx_utils.g_source_levels(i).rows_processed := 0;
1171 	   end loop;
1172 	end if;
1173 	/**
1174 	Initialize the temporary XML Buffer
1175 	**/
1176 	ecx_print_local.i_tmpxml.DELETE;
1177 	ecx_print_local.l_node_stack.DELETE;
1178 
1179          l_IANACharset := ECX_UTIL_API.getIANACharset();
1180          l_xmlDecl := 'version = "1.0" encoding= "'||l_IANAcharset||'" standalone="no"';
1181 
1182 	/** PI Node **/
1183 	--ecx_print_local.pi_node('xml','version = "1.0" standalone="no" ');
1184         ecx_print_local.pi_node('xml',l_xmlDecl);
1185 
1186 	/** Comment Node **/
1187 	ecx_print_local.comment_node('Oracle eXtensible Markup Language Gateway Server ');
1188 
1189 
1190 	/** DOCUMENT NODE **/
1191 	if (not ecx_utils.g_delete_doctype) then
1192 		ecx_print_local.document_node(i_root_element,i_filename,null);
1193 		if(l_statementEnabled) then
1194 			ecx_debug.log(l_statement, 'Printed DOCTYPE', i_method_name);
1195 		end if;
1196 	end if;
1197 
1198 	fetch_data_from_view (0);
1199 	popall;
1200 	ecx_print_local.xmlPOPALL(i_xmldoc);
1201 
1202         ecx_util_api.parseXML(ecx_utils.g_parser, i_xmldoc, l_parseXML, ecx_utils.g_xmldoc);
1203 	if(l_statementEnabled) then
1204           ecx_debug.log(l_statement, 'Parsed XML', l_parseXML,i_method_name);
1205 	end if;
1206 
1207         -- Post-Processing for the Document on Target Side
1208 	ecx_actions.execute_stage_data
1209 		(
1210 		30,
1211 		0,
1212 		'T'
1213 		);
1214 
1215         -- Post Processing for the Document on Source Side
1216         ecx_actions.execute_stage_data
1217                 (
1218                 30,
1219                 0,
1220 		'S'
1221                 );
1222 
1223 	-- set the out variable to have the latest document.
1224        if l_parseXML then
1225            /*bug 10254870 5000-XST Tranform
1226 			 if xslt transformation is defined for a map then get output which is transformed
1227 			 else get clob output  from dom node
1228 			 */
1229 			if(ecx_utils.g_cnt_xslt_defined > 0) then
1230 			  if(l_statementEnabled) then
1231 				ecx_debug.log(l_statement, 'xslt transformation is defined and getting transformed output',i_method_name);
1232 			  end if;
1233 			  i_xmldoc := ecx_utils.g_out_transformed;
1234 			else
1235 			  dbms_lob.trim(i_xmldoc, 0);
1236 			  xmlDOM.writetoCLOB(ecx_utils.g_xmldoc,i_xmldoc);
1237 			end if;
1238 
1239         g_instlmode := wf_core.translate('WF_INSTALL');
1240 
1241            if (l_statementEnabled)
1242            then
1243 		IF g_instlmode = 'EMBEDDED' THEN
1244 			fnd_message.set_name('ecx', 'XML File for logging');
1245 			attachment_id := fnd_log.message_with_attachment(fnd_log.level_statement, substr(ecx_debug.g_aflog_module_name,1,length(ecx_debug.g_aflog_module_name)-4)||'.xml', TRUE);
1246 			if(attachment_id <> -1 AND i_xmldoc is not null) then
1247 			       clength := dbms_lob.getlength(i_xmldoc);
1248 			       while  clength >= offset LOOP
1249 				     ctemp :=  dbms_lob.substr(i_xmldoc,g_varmaxlength,offset);
1250 				     fnd_log_attachment.writeln(attachment_id, ctemp);
1251 				     offset := offset + g_varmaxlength;
1252 			       End Loop;
1253 				fnd_log_attachment.close(attachment_id);
1254 			end if;
1255 		ELSE
1256 			xmlDOM.writetofile(ecx_utils.g_xmldoc,ecx_utils.g_logdir||'/'||
1257 			substr(ecx_utils.g_logfile,1,length(ecx_utils.g_logfile)-4)
1258 			||'.xml');
1259 		END IF;
1260            end if;
1261         end if;
1262 
1263 	if(l_statementEnabled) then
1264 		ecx_outbound.log_summary(l_statement);
1265 
1266 		ecx_debug.log(l_statement,'ECX','ECX_DOCUMENTS_PROCESSED',i_method_name,'NO_OF_DOCS',
1267 		    ecx_utils.g_source_levels(0).rows_processed);
1268 		ecx_debug.log(l_statement,'ECX','ECX_FINISH_OUTBOUND',i_method_name,'MAP_ID',i_map_id);
1269 	end if;
1270 
1271 if not XMLDom.isNull(ecx_utils.g_xmldoc) then
1272         i_node_type := xmlDOM.getNodeType(ecx_utils.g_xmldoc);
1273         if (i_node_type = xmlDOM.DOCUMENT_NODE) then
1274 	  xmlDOM.freeDocument(xmlDOM.makeDocument(ecx_utils.g_xmldoc));
1275         else
1276           xmlDOM.freeDocFrag(xmlDOM.makeDocumentFragment(ecx_utils.g_xmldoc));
1277         end if;
1278 xmlparser.freeparser(ecx_utils.g_parser);
1279 end if;
1280 if (l_procedureEnabled) then
1281   ecx_debug.pop(i_method_name );
1282 end if;
1283 
1284 EXCEPTION
1285 WHEN ecx_utils.PROGRAM_EXIT then
1286         if(l_unexpectedEnabled) then
1287           ecx_debug.log(l_unexpected, 'Clean-up i_stack, l_node_stack, i_tmpxml and last_printed',
1288 	               i_method_name);
1289 	  ecx_outbound.log_summary(l_unexpected);
1290 	end if;
1291         i_stack.DELETE;
1292 	ecx_print_local.i_tmpxml.DELETE;
1293 	ecx_print_local.l_node_stack.DELETE;
1294 	ecx_print_local.last_printed := -1;
1295         if (l_procedureEnabled) then
1296            ecx_debug.pop(i_method_name );
1297         end if;
1298 	raise ecx_utils.program_exit;
1299 WHEN OTHERS THEN
1300         if(l_unexpectedEnabled) then
1301           ecx_debug.log(l_unexpected,'ECX','ECX_PROGRAM_ERROR',i_method_name,'PROGRESS_LEVEL',
1302 	             'ECX_OUTBOUND.PROCESS_OUTBOUND_DOCUMENTS');
1303           ecx_debug.log(l_unexpected,'ECX','ECX_ERROR_MESSAGE',i_method_name,'ERROR_MESSAGE',SQLERRM);
1304 	  ecx_outbound.log_summary(l_unexpected);
1305         end if;
1306 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.PROCESS_OUTBOUND_DOCUMENTS');
1307 	if(l_unexpectedEnabled) then
1308 	  ecx_debug.log(l_unexpected, 'ECX', SQLERRM || ' - ECX_OUTBOUND.PROCESS_OUTBOUND_DOCUMENTS',i_method_name);
1309 	  ecx_debug.log(l_unexpected, 'Clean-up i_stack, l_node_stack, i_tmpxml and last_printed',i_method_name);
1310 	end if;
1311         i_stack.DELETE;
1312 	ecx_print_local.i_tmpxml.DELETE;
1313 	ecx_print_local.l_node_stack.DELETE;
1314 	ecx_print_local.last_printed := -1;
1315 	if (l_procedureEnabled) then
1316            ecx_debug.pop(i_method_name );
1317         end if;
1318 	raise ecx_utils.PROGRAM_EXIT;
1319 end process_outbound_documents;
1320 
1321 
1322 procedure putmsg
1323 	(
1324 	i_transaction_type	IN	varchar2,
1325 	i_transaction_subtype	IN	varchar2,
1326 	i_party_id		IN	varchar2,
1327 	i_party_site_id		IN	varchar2,
1328 	i_party_type		IN	varchar2,
1329 	i_document_id		IN	varchar2,
1330 	i_map_code		IN	varchar2,
1331 	i_message_type		IN	varchar2,
1332 	i_message_standard	IN	varchar2,
1333 	i_ext_type		IN	varchar2,
1334 	i_ext_subtype		IN	varchar2,
1335 	i_destination_code	IN	varchar2,
1336 	i_destination_type	IN	varchar2,
1337 	i_destination_address	IN	varchar2,
1338 	i_username		IN	varchar2,
1339 	i_password		IN	varchar2,
1340 	i_attribute1		IN	varchar2,
1341 	i_attribute2		IN	varchar2,
1342 	i_attribute3		IN	varchar2,
1343 	i_attribute4		IN	varchar2,
1344 	i_attribute5		IN	varchar2,
1345 	i_debug_level		IN	pls_integer,
1346         i_trigger_id            IN      number,
1347 	i_msgid			OUT	NOCOPY raw
1348 	)
1349 is
1350 i_method_name   varchar2(2000) := 'ecx_outbound.putmsg';
1351 i_xmldoc		CLOB;
1352 ecx_logging_enabled boolean := false;
1353 e_qtimeout	exception;
1354 pragma		exception_init(e_qtimeout,-25228);
1355 i_logdir	varchar2(200);
1356 i_direct	BOOLEAN := true;
1357 
1358 /* Start changes for bug 2120165 */
1359 i_paramCount number;
1360 /* End of changes for bug 2120165 */
1361 
1362 i_from_agt      wf_agent_t := wf_agent_t(NULL, NULL);
1363 i_system        varchar2(200);
1364 
1365 cursor get_run_s
1366 is
1367 select  ecx_output_runs_s.NEXTVAL
1368 from    dual;
1369 
1370 p_aflog_module_name         VARCHAR2(2000) ;
1371 
1372 begin
1373 --- Sets the Log Directory in both Standalone and the Embedded mode
1374 ecx_utils.getLogDirectory;
1375 
1376 if ecx_utils.g_logfile is null
1377 then
1378 	i_direct := false;
1379 	--  Fetch the Run Id for the Transaction
1380 	open	get_run_s;
1381 	fetch	get_run_s
1382 	into	ecx_utils.g_run_id;
1383 	close	get_run_s;
1384 
1385 	ecx_utils.g_logfile :=i_message_standard||'OUT'||
1386 		i_transaction_type||i_transaction_subtype||i_document_id||ecx_utils.g_run_id||'.log';
1387 
1388 	p_aflog_module_name := '';
1389 	IF (i_message_standard is not null) THEN
1390 		p_aflog_module_name := p_aflog_module_name||i_message_standard||'.';
1391 	END IF;
1392 	p_aflog_module_name := p_aflog_module_name || 'out.';
1393 	IF (i_transaction_type is not null) THEN
1394 		p_aflog_module_name := p_aflog_module_name||i_transaction_type||'.';
1395 	END IF;
1396 	IF (i_transaction_subtype is not null) THEN
1397 		p_aflog_module_name := p_aflog_module_name||i_transaction_subtype||'.';
1398 	END IF;
1399 	IF (i_document_id is not null) THEN
1400 		p_aflog_module_name := p_aflog_module_name||i_document_id||'.';
1401 	END IF;
1402 	IF (ecx_utils.g_run_id is not null) THEN
1403 		p_aflog_module_name := p_aflog_module_name||ecx_utils.g_run_id;
1404 	END IF;
1405 	p_aflog_module_name := p_aflog_module_name||'.log';
1406 
1407 	ecx_debug.enable_debug_new(i_debug_level,ecx_utils.g_logdir,ecx_utils.g_logfile, p_aflog_module_name);
1408 end if;
1409 
1410 -- Assign local variables with the ecx_debug global variables
1411 l_procedure          := ecx_debug.g_procedure;
1412 l_statement          := ecx_debug.g_statement;
1413 l_unexpected         := ecx_debug.g_unexpected;
1414 l_procedureEnabled   := ecx_debug.g_procedureEnabled;
1415 l_statementEnabled   := ecx_debug.g_statementEnabled;
1416 l_unexpectedEnabled  := ecx_debug.g_unexpectedEnabled;
1417 
1418 if (l_procedureEnabled) then
1419      ecx_debug.push(i_method_name);
1420 end if;
1421 
1422 if(l_statementEnabled) then
1423   ecx_debug.log(l_statement,'i_transaction_type',i_transaction_type,i_method_name );
1424   ecx_debug.log(l_statement,'i_transaction_subtype',i_transaction_subtype,i_method_name );
1425   ecx_debug.log(l_statement,'i_party_id',i_party_id,i_method_name );
1426   ecx_debug.log(l_statement,'i_party_site_id',i_party_site_id,i_method_name );
1427   ecx_debug.log(l_statement,'i_party_type',i_party_type,i_method_name );
1428   ecx_debug.log(l_statement,'i_document_id',i_document_id,i_method_name );
1429   ecx_debug.log(l_statement,'i_map_code',i_map_code,i_method_name );
1430   ecx_debug.log(l_statement,'i_message_type',i_message_type,i_method_name );
1431   ecx_debug.log(l_statement,'i_message_standard',i_message_standard,i_method_name );
1432   ecx_debug.log(l_statement,'i_ext_type',i_ext_type,i_method_name );
1433   ecx_debug.log(l_statement,'i_ext_subtype',i_ext_subtype,i_method_name );
1434   ecx_debug.log(l_statement,'i_destination_code',i_destination_code,i_method_name );
1435   ecx_debug.log(l_statement,'i_destination_address',i_destination_address,i_method_name );
1436   ecx_debug.log(l_statement,'i_destination_type',i_destination_type,i_method_name );
1437   ecx_debug.log(l_statement,'i_username',i_username,i_method_name );
1438   ecx_debug.log(l_statement,'i_password',i_password,i_method_name );
1439   ecx_debug.log(l_statement,'i_attribute1',i_attribute1,i_method_name );
1440   ecx_debug.log(l_statement,'i_attribute2',i_attribute2,i_method_name );
1441   ecx_debug.log(l_statement,'i_attribute3',i_attribute3,i_method_name );
1442   ecx_debug.log(l_statement,'i_attribute4',i_attribute4,i_method_name );
1443   ecx_debug.log(l_statement,'i_attribute5',i_attribute5,i_method_name );
1444 end if;
1445 
1446 ecx_errorlog.outbound_engine
1447 (
1448   i_trigger_id,
1449   '10',
1450   'Processing message...',
1451   null,
1452   null,
1453   i_party_type
1454  );
1455 
1456 	process_outbound_documents
1457 			(
1458 			i_message_standard,
1459 			i_transaction_type,
1460 			i_transaction_subtype,
1461 			i_party_id,
1462 			i_party_site_id,
1463 			i_party_type,
1464 			i_document_id,
1465 			i_map_code,
1466 			i_xmldoc,
1467                         i_message_type
1468 			);
1469 
1470 	-- call ecx_out_wf_qh.enqueue with the correct parameters
1471      	ecx_utils.g_event.addParameterToList('PARTY_TYPE', i_party_type);
1472      	ecx_utils.g_event.addParameterToList('PARTYID', i_destination_code);
1473      	ecx_utils.g_event.addParameterToList('PARTY_SITE_ID', i_destination_code);
1474      	ecx_utils.g_event.addParameterToList('DOCUMENT_NUMBER', ecx_utils.g_document_id);
1475      	ecx_utils.g_event.addParameterToList('MESSAGE_TYPE', i_message_type);
1476      	ecx_utils.g_event.addParameterToList('MESSAGE_STANDARD', i_message_standard);
1477      	ecx_utils.g_event.addParameterToList('TRANSACTION_TYPE', i_ext_type);
1478      	ecx_utils.g_event.addParameterToList('TRANSACTION_SUBTYPE', i_ext_subtype);
1479      	ecx_utils.g_event.addParameterToList('PROTOCOL_TYPE', i_destination_type);
1480      	ecx_utils.g_event.addParameterToList('PROTOCOL_ADDRESS', i_destination_address);
1481      	ecx_utils.g_event.addParameterToList('USERNAME', i_username);
1482      	ecx_utils.g_event.addParameterToList('PASSWORD', i_password);
1483      	ecx_utils.g_event.addParameterToList('ATTRIBUTE1', i_attribute1);
1484      	ecx_utils.g_event.addParameterToList('ATTRIBUTE2', i_attribute2);
1485      	ecx_utils.g_event.addParameterToList('ATTRIBUTE3', i_attribute3);
1486      	ecx_utils.g_event.addParameterToList('ATTRIBUTE4', i_attribute4);
1487      	ecx_utils.g_event.addParameterToList('ATTRIBUTE5', i_attribute5);
1488         ecx_utils.g_event.addParameterToList('TRIGGER_ID', i_trigger_id);
1489      	ecx_utils.g_event.addParameterToList('LOGFILE', ecx_utils.g_logfile);
1490      	ecx_utils.g_event.addParameterToList('ITEM_TYPE', ecx_utils.g_item_type);
1491      	ecx_utils.g_event.addParameterToList('ITEM_KEY', ecx_utils.g_item_key);
1492      	ecx_utils.g_event.addParameterToList('ACTIVITY_ID', ecx_utils.g_activity_id);
1493      	ecx_utils.g_event.addParameterToList('EVENT_NAME', ecx_utils.g_event.event_name);
1494      	ecx_utils.g_event.addParameterToList('EVENT_KEY', ecx_utils.g_event.event_key);
1495      	ecx_utils.g_event.event_data := i_xmldoc;
1496 
1497 	 -- set the from agent
1498      	select  name
1499      	into    i_system
1500      	from    wf_systems
1501      	where   guid = wf_core.translate('WF_SYSTEM_GUID');
1502 
1503         -- set default outbound agents based on protocol_type
1504         if (upper(i_destination_type) = 'SOAP') then
1505           i_from_agt.setname('WF_WS_JMS_OUT');
1506 
1507           -- set default Web Services related attributes
1508           ecx_utils.g_event.addParameterToList('WS_SERVICE_NAMESPACE',
1509                             'urn:defaultSoapMessaging');
1510           ecx_utils.g_event.addParameterToList('WS_PORT_OPERATION',
1511                             'ReceiveDocument');
1512           ecx_utils.g_event.addParameterToList('WS_HEADER_IMPL_CLASS',
1513                             'oracle.apps.fnd.wf.ws.client.DefaultHeaderGenerator');
1514           ecx_utils.g_event.addParameterToList('WS_RESPONSE_IMPL_CLASS',
1515                             'oracle.apps.fnd.wf.ws.client.WfWsResponse');
1516           ecx_utils.g_event.addParameterToList('WS_CONSUMER', 'ecx');
1517 
1518         else
1519 
1520           if (upper(i_destination_type) = 'JMS') then
1521             if(i_destination_address is null) then
1522  		i_from_agt.setname('WF_JMS_OUT');
1523 	    else
1524  		i_from_agt.setname(i_destination_address);
1525 	    end if;
1526           else
1527             i_from_agt.setname('ECX_OUTBOUND');
1528           end if;
1529 
1530         end if;
1531      	i_from_agt.setsystem(i_system);
1532 	ecx_utils.g_event.setFromAgent(i_from_agt);
1533 
1534                 if(l_statementEnabled) then
1535                      ecx_debug.log(l_statement, 'Calling WF_EVENT.Send for Enqueue', i_method_name);
1536                  end if;
1537      	wf_event.send(ecx_utils.g_event);
1538         ecx_errorlog.outbound_log(ecx_utils.g_event);
1539 
1540         if (upper(i_destination_type) = 'SOAP') or
1541            (upper(i_destination_type) = 'JMS') then
1542             i_msgid := wf_event.g_msgid; -- JMS QH store enqueue msgid in wf_event.g_msgid
1543         else
1544             i_msgid := ecx_out_wf_qh.msgid;
1545         end if;
1546 
1547         -- check the retcode and retmsg. This should be populated here only
1548         -- in the case of dup val index when inserting in doclogs (since no
1549         -- exception is raised in this case)
1550         if (ecx_out_wf_qh.retmsg is not null) then
1551            ecx_debug.setErrorInfo(ecx_out_wf_qh.retcode, 30, ecx_out_wf_qh.retmsg);
1552 	   if(l_unexpectedEnabled) then
1553              ecx_debug.log(l_unexpected, ecx_utils.i_errbuf,i_method_name);
1554 	  end if;
1555         end if;
1556 
1557    if dbms_lob.istemporary(i_xmldoc) = 1 then
1558       dbms_lob.freetemporary(i_xmldoc);
1559    end if;
1560 
1561 if(l_statementEnabled) then
1562   ecx_debug.log(l_statement,'msgid',i_msgid,i_method_name);
1563 end if;
1564 if (l_procedureEnabled) then
1565   ecx_debug.pop(i_method_name);
1566  end if;
1567 
1568 if NOT ( i_direct )
1569 then
1570 	ecx_debug.print_log;
1571 	ecx_debug.disable_debug;
1572 	ecx_utils.g_logfile:=null;
1573 end if;
1574 
1575 EXCEPTION
1576 WHEN ecx_utils.PROGRAM_EXIT then
1577         if dbms_lob.istemporary(i_xmldoc) = 1 then
1578 	   dbms_lob.freetemporary(i_xmldoc);
1579         end if;
1580 	if (l_procedureEnabled) then
1581            ecx_debug.pop(i_method_name);
1582         end if;
1583 	if NOT ( i_direct )
1584 	then
1585 		ecx_debug.print_log;
1586 		ecx_debug.disable_debug;
1587 		ecx_utils.g_logfile:=null;
1588 
1589                 ecx_errorlog.outbound_engine
1590                 (
1591                  i_trigger_id,
1592                  ecx_utils.i_ret_code,
1593                  ecx_utils.i_errbuf,
1594                  i_msgid,
1595                  null,
1596                  i_party_type
1597                 );
1598 
1599 	else
1600 		raise ecx_utils.program_exit;
1601 	end if;
1602 
1603 WHEN OTHERS THEN
1604 	if (ecx_out_wf_qh.retmsg is null AND ecx_out_wf_qh.retcode = 0)
1605         then
1606 	   ecx_debug.setErrorInfo(2, 30, SQLERRM);
1607 	   if(l_unexpectedEnabled) then
1608 	     ecx_debug.log(l_unexpected, 'ECX', SQLERRM,i_method_name);
1609 	   end if;
1610 	else
1611 	   ecx_debug.setErrorInfo(ecx_out_wf_qh.retcode, 30, ecx_out_wf_qh.retmsg);
1612 	   if(l_unexpectedEnabled) then
1613 	     ecx_debug.log(l_unexpected, 'msg and code set in queue handler',i_method_name);
1614 	     ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
1615 	   end if;
1616 	end if;
1617 
1618         if dbms_lob.istemporary(i_xmldoc) = 1 then
1619    	   dbms_lob.freetemporary(i_xmldoc);
1620         end if;
1621 
1622 	if (l_procedureEnabled) then
1623            ecx_debug.pop(i_method_name);
1624         end if;
1625 	if NOT ( i_direct )
1626 	then
1627 		IF (ecx_logging_enabled ) THEN
1628 			ecx_debug.print_log;
1629 			ecx_debug.disable_debug;
1630 			ecx_utils.g_logfile:=null;
1631 		END IF;
1632                 ecx_errorlog.outbound_engine
1633                 (
1634                  i_trigger_id,
1635                  ecx_utils.i_ret_code,
1636                  ecx_utils.i_errbuf,
1637                  i_msgid,
1638                  null,
1639                  i_party_type
1640                 );
1641 	else
1642 		raise ecx_utils.program_exit;
1643 	end if;
1644 
1645 end putmsg;
1646 
1647 /* Wrapper procedure for backward comaptibilty */
1648 procedure putmsg
1649 	(
1650 	i_transaction_type	IN	varchar2,
1651 	i_transaction_subtype	IN	varchar2,
1652 	i_party_id		IN	varchar2,
1653 	i_party_site_id		IN	varchar2,
1654 	i_party_type		IN	varchar2,
1655 	i_document_id		IN	varchar2,
1656 	i_parameter1		IN	varchar2,
1657 	i_parameter2		IN	varchar2,
1658 	i_parameter3		IN	varchar2,
1659 	i_parameter4		IN	varchar2,
1660 	i_parameter5		IN	varchar2,
1661 	i_map_code		IN	varchar2,
1662 	i_message_type		IN	varchar2,
1663 	i_message_standard	IN	varchar2,
1664 	i_ext_type		IN	varchar2,
1665 	i_ext_subtype		IN	varchar2,
1666 	i_destination_code	IN	varchar2,
1667 	i_destination_type	IN	varchar2,
1668 	i_destination_address	IN	varchar2,
1669 	i_username		IN	varchar2,
1670 	i_password		IN	varchar2,
1671 	i_attribute1		IN	varchar2,
1672 	i_attribute2		IN	varchar2,
1673 	i_attribute3		IN	varchar2,
1674 	i_attribute4		IN	varchar2,
1675 	i_attribute5		IN	varchar2,
1676 	i_debug_level		IN	pls_integer,
1677         i_trigger_id            IN    number,
1678 	i_msgid			OUT	NOCOPY raw
1679 	) as
1680 
1681 
1682 i_method_name   varchar2(2000) := 'ecx_outbound.putmsg';
1683 
1684 -- logging enabled
1685 ecx_logging_enabled boolean := false;
1686 logging_enabled varchar2(20);
1687 module varchar2(2000);
1688 
1689 begin
1690 --To populate the global variable ecx_debug.g_v_module_name , need to call ecx_debug.module_enabled
1691 ecx_debug.g_v_module_name := 'ecx.plsql.';
1692 ecx_debug.module_enabled(i_message_standard,i_transaction_type,i_transaction_subtype,i_document_id);
1693 fnd_profile.get('AFLOG_ENABLED',logging_enabled);
1694 fnd_profile.get('AFLOG_MODULE',module);
1695 if(logging_enabled = 'Y' AND ((lower(module) like 'ecx%'
1696 AND instr(lower(ecx_debug.g_v_module_name),rtrim(lower(module),'%'))> 0)
1697 OR module='%')
1698 AND FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) then
1699 	ecx_logging_enabled := true;
1700 end if;
1701 -- /logging enabled
1702 
1703 /**
1704   Populate the Parameters in the global event Object .if it is null ,
1705   initialize and create a new Instance and populate the variables
1706  **/
1707 
1708   if ecx_utils.g_event is null
1709   then
1710         wf_event_t.initialize(ecx_utils.g_event);
1711 
1712   end if;
1713 
1714   /* Add the above Parameters to the Global Event Message Object
1715      For backward compatability */
1716 
1717   ecx_utils.g_event.addparametertolist('PARAMETER1',i_parameter1);
1718   ecx_utils.g_event.addparametertolist('PARAMETER2',i_parameter2);
1719   ecx_utils.g_event.addparametertolist('PARAMETER3',i_parameter3);
1720   ecx_utils.g_event.addparametertolist('PARAMETER4',i_parameter4);
1721   ecx_utils.g_event.addparametertolist('PARAMETER5',i_parameter5);
1722 
1723   putmsg(  i_transaction_type	 ,
1724 	   i_transaction_subtype ,
1725 	   i_party_id		 ,
1726 	   i_party_site_id       ,
1727 	   i_party_type	         ,
1728 	   i_document_id         ,
1729 	   i_map_code		 ,
1730 	   i_message_type	 ,
1731 	   i_message_standard	 ,
1732 	   i_ext_type		 ,
1733 	   i_ext_subtype	 ,
1734 	   i_destination_code	 ,
1735 	   i_destination_type	 ,
1736 	   i_destination_address ,
1737 	   i_username		 ,
1738 	   i_password		 ,
1739 	   i_attribute1		 ,
1740 	   i_attribute2		 ,
1741 	   i_attribute3		 ,
1742 	   i_attribute4		 ,
1743 	   i_attribute5		 ,
1744 	   i_debug_level	 ,
1745            i_trigger_id          ,
1746 	   i_msgid		);
1747 Exception
1748 WHEN OTHERS THEN
1749 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.putmsg ');
1750 	if(l_unexpectedEnabled) then
1751           ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_OUTBOUND.putmsg ',
1752 	               i_method_name);
1753 	end if;
1754         raise ecx_utils.PROGRAM_EXIT;
1755 end putmsg;
1756 
1757 procedure GETXML
1758 	(
1759 	i_message_standard	IN	varchar2,
1760 	i_transaction_type	IN	varchar2,
1761 	i_transaction_subtype	IN	varchar2,
1762 	i_tp_id			IN	varchar2,
1763 	i_tp_site_id		IN	varchar2,
1764 	i_tp_type		In	varchar2,
1765 	i_document_id		IN	varchar2,
1766 	i_map_code		IN	varchar2,
1767 	i_debug_level		IN	pls_integer,
1768 	i_xmldoc		IN OUT	NOCOPY clob,
1769 	i_ret_code		OUT	NOCOPY pls_integer,
1770 	i_errbuf		OUT	NOCOPY varchar2,
1771 	i_log_file		OUT	NOCOPY varchar2,
1772         i_message_type          IN      VARCHAR2 default 'XML'
1773 	)
1774 is
1775 i_method_name   varchar2(2000) := 'ecx_outbound.getxml';
1776 /* Start changes for Bug 2120165 */
1777 i_paramCount number;
1778 /* End of changes for bug 2120165 */
1779 cursor get_run_s
1780 is
1781 select  ecx_output_runs_s.NEXTVAL
1782 from    dual;
1783 
1784 i_logdir	varchar2(200);
1785 i_tmpxmldoc     CLOB;
1786 p_aflog_module_name         VARCHAR2(2000) ;
1787 g_instlmode         VARCHAR2(100);
1788 
1789 ecx_logging_enabled boolean := false;
1790 logging_enabled varchar2(20);
1791 module varchar2(2000);
1792 
1793 begin
1794 --To populate the global variable ecx_debug.g_v_module_name , need to call ecx_debug.module_enabled
1795 ecx_debug.g_v_module_name := 'ecx.plsql.';
1796 ecx_debug.module_enabled(i_message_standard,i_transaction_type,i_transaction_subtype,i_document_id);
1797 
1798   g_instlmode := wf_core.translate('WF_INSTALL');
1799 
1800   if(g_instlmode = 'EMBEDDED')
1801   then
1802     fnd_profile.get('AFLOG_ENABLED',logging_enabled);
1803     fnd_profile.get('AFLOG_MODULE',module);
1804 if(logging_enabled = 'Y' AND ((lower(module) like 'ecx%'
1805 AND instr(lower(ecx_debug.g_v_module_name),rtrim(lower(module),'%'))> 0)
1806 OR module='%')
1807        AND FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) then
1808       ecx_logging_enabled := true;
1809     end if;
1810   elsif(g_instlmode = 'STANDALONE')
1811   then
1812     if (i_debug_level > 0) then
1813       ecx_logging_enabled := true;
1814     end if;
1815   end if;
1816 
1817   IF (ecx_logging_enabled ) THEN
1818 	--- Sets the Log Directory in both Standalone and the Embedded mode
1819 	ecx_utils.getLogDirectory;
1820 
1821 	/** Fetch the Run Id for the Transaction **/
1822 	open	get_run_s;
1823 	fetch	get_run_s
1824 	into	ecx_utils.g_run_id;
1825 	close	get_run_s;
1826 
1827 	ecx_utils.g_logfile :=i_message_standard||'OUT'||
1828 		i_transaction_type||i_transaction_subtype||i_document_id||ecx_utils.g_run_id||'.log';
1829 
1830 	p_aflog_module_name := '';
1831 	IF (i_message_standard is not null) THEN
1832 		p_aflog_module_name := p_aflog_module_name||i_message_standard||'.';
1833 	END IF;
1834 	p_aflog_module_name := p_aflog_module_name || 'out.';
1835 	IF (i_transaction_type is not null) THEN
1836 		p_aflog_module_name := p_aflog_module_name||i_transaction_type||'.';
1837 	END IF;
1838 	IF (i_transaction_subtype is not null) THEN
1839 		p_aflog_module_name := p_aflog_module_name||i_transaction_subtype||'.';
1840 	END IF;
1841 	IF (i_document_id is not null) THEN
1842 		p_aflog_module_name := p_aflog_module_name||i_document_id||'.';
1843 	END IF;
1844 	IF (ecx_utils.g_run_id is not null) THEN
1845 		p_aflog_module_name := p_aflog_module_name||ecx_utils.g_run_id;
1846 	END IF;
1847 	p_aflog_module_name := p_aflog_module_name||'.log';
1848 	ecx_debug.enable_debug_new(i_debug_level,ecx_utils.g_logdir,ecx_utils.g_logfile, p_aflog_module_name);
1849   END IF;
1850 
1851 	IF g_instlmode = 'EMBEDDED' THEN
1852 		IF (ecx_logging_enabled ) THEN
1853 			i_log_file := ecx_debug.g_sqlprefix || p_aflog_module_name;
1854 		ELSE
1855 			i_log_file := 'Please ensure that FND-Logging is enabled for module '||ecx_debug.g_sqlprefix||'%';
1856 		END IF;
1857 	ELSE
1858 		if (ecx_logging_enabled) then
1859 			i_log_file := ecx_utils.g_logdir||ecx_utils.getFileSeparator()||ecx_utils.g_logfile;
1860 		else
1861 			i_log_file := 'Please ensure that logging is enabled';
1862 		end if;
1863 	END IF;
1864 
1865 /* Assign local variables with the ecx_debug global variables*/
1866 l_procedure          := ecx_debug.g_procedure;
1867 l_statement          := ecx_debug.g_statement;
1868 l_unexpected         := ecx_debug.g_unexpected;
1869 l_procedureEnabled   := ecx_debug.g_procedureEnabled;
1870 l_statementEnabled   := ecx_debug.g_statementEnabled;
1871 l_unexpectedEnabled  := ecx_debug.g_unexpectedEnabled;
1872 
1873 if (l_procedureEnabled) then
1874    ecx_debug.push(i_method_name);
1875 end if;
1876 
1877 if(l_statementEnabled) then
1878   ecx_debug.log(l_statement,'i_transaction_type',i_transaction_type,i_method_name );
1879   ecx_debug.log(l_statement,'i_transaction_subtype',i_transaction_subtype,i_method_name );
1880   ecx_debug.log(l_statement,'i_tp_id',i_tp_id,i_method_name );
1881   ecx_debug.log(l_statement,'i_tp_site_id',i_tp_site_id,i_method_name );
1882   ecx_debug.log(l_statement,'i_tp_type',i_tp_type,i_method_name );
1883   ecx_debug.log(l_statement,'i_document_id',i_document_id,i_method_name );
1884   ecx_debug.log(l_statement,'i_map_code',i_map_code,i_method_name );
1885 end if;
1886 -- initialize i_tmpxmldoc
1887 dbms_lob.createtemporary(i_tmpxmldoc,TRUE,DBMS_LOB.SESSION);
1888 
1889 	process_outbound_documents
1890 			(
1891 			i_message_standard,
1892 			i_transaction_type,
1893 			i_transaction_subtype,
1894 			i_tp_id,
1895 			i_tp_site_id,
1896 			i_tp_type,
1897 			i_document_id,
1898 			i_map_code,
1899 			i_tmpxmldoc
1900 			);
1901 -- assign i_tmpxmldoc to the return variable
1902 i_xmldoc := i_tmpxmldoc;
1903 
1904 -- free i_tmpxmldoc
1905 if i_tmpxmldoc is not null
1906 then
1907    dbms_lob.freetemporary (i_tmpxmldoc);
1908 end if;
1909 ecx_debug.setErrorInfo(0, 10, 'ECX_SUCCESSFUL_EXECUTION');
1910 i_ret_code := ecx_utils.i_ret_code;
1911 i_errbuf := ecx_utils.i_errbuf;
1912 
1913 if(ecx_utils.i_ret_code = 0 ) then
1914   if(l_statementEnabled) then
1915   ecx_debug.log(l_statement, 'Ret Code',ecx_utils.i_ret_code,i_method_name);
1916   ecx_debug.log(l_statement, 'Ret Msg ',ecx_utils.i_errbuf,i_method_name);
1917   end if;
1918 else
1919 if(l_unexpectedEnabled) then
1920   ecx_debug.log(l_unexpected, 'Ret Code',ecx_utils.i_ret_code,i_method_name);
1921   ecx_debug.log(l_unexpected, 'Ret Msg ',ecx_utils.i_errbuf,i_method_name);
1922 end if;
1923 end if;
1924 
1925 if(l_procedureEnabled) then
1926   ecx_debug.pop(i_method_name);
1927 end if;
1928 IF (ecx_logging_enabled ) THEN
1929 	ecx_debug.print_log;
1930 	ecx_debug.disable_debug;
1931 END IF;
1932 EXCEPTION
1933 WHEN ecx_utils.program_exit THEN
1934 	i_ret_code := ecx_utils.i_ret_code;
1935 	i_errbuf := ecx_utils.i_errbuf;
1936 	if(l_unexpectedEnabled) then
1937 	  ecx_debug.log(l_unexpected,ecx_utils.i_errbuf,i_method_name);
1938         end if;
1939 	if(l_procedureEnabled) then
1940            ecx_debug.pop(i_method_name);
1941 	end if;
1942 	-- free i_tmpxmldoc
1943 	if i_tmpxmldoc is not null
1944 	then
1945 		dbms_lob.freetemporary (i_tmpxmldoc);
1946 	end if;
1947 	IF (ecx_logging_enabled ) THEN
1948 		ecx_debug.print_log;
1949 		ecx_debug.disable_debug;
1950 	END IF;
1951 WHEN OTHERS THEN
1952 	ecx_debug.setErrorInfo(2, 30, SQLERRM || ' - ECX_OUTBOUND.PUTMSG');
1953 	if(l_unexpectedEnabled) then
1954           ecx_debug.log(l_unexpected,'ECX', SQLERRM || ' - ECX_OUTBOUND.PUTMSG',i_method_name);
1955         end if;
1956         i_ret_code := ecx_utils.i_ret_code;
1957         i_errbuf := ecx_utils.i_errbuf;
1958 	if(l_procedureEnabled) then
1959            ecx_debug.pop(i_method_name);
1960 	end if;
1961 	-- free i_tmpxmldoc
1962 	if i_tmpxmldoc is not null
1963 	then
1964 		dbms_lob.freetemporary (i_tmpxmldoc);
1965 	end if;
1966 	IF (ecx_logging_enabled ) THEN
1967 		ecx_debug.print_log;
1968 		ecx_debug.disable_debug;
1969 	END IF;
1970 end GETXML;
1971 
1972 end ecx_outbound;