1: package body fa_rx_util_pkg as
2: /* $Header: FARXUTLB.pls 120.10.12010000.1 2008/07/28 13:14:06 appldev ship $ */
3:
4:
5: ------------------------------------------------------------
53: buffer varchar2(10000);
54: idx number;
55: begin
56: IF (g_print_debug) THEN
57: fa_rx_util_pkg.debug('fa_rx_util_pkg.build_select('||to_char(Num_Columns)||')+');
58: END IF;
59:
60: idx := 1;
61: while idx <= Num_Columns and Rep_Columns(idx).select_column_name is null loop
88: ORDER BY '||Order_By_Clause;
89: end if;
90:
91: IF (g_print_debug) THEN
92: fa_rx_util_pkg.debug('SELECT Statement = ');
93: fa_rx_util_pkg.debug(buffer);
94: fa_rx_util_pkg.debug('fa_rx_util_pkg.build_select()-');
95: END IF;
96:
89: end if;
90:
91: IF (g_print_debug) THEN
92: fa_rx_util_pkg.debug('SELECT Statement = ');
93: fa_rx_util_pkg.debug(buffer);
94: fa_rx_util_pkg.debug('fa_rx_util_pkg.build_select()-');
95: END IF;
96:
97: return buffer;
90:
91: IF (g_print_debug) THEN
92: fa_rx_util_pkg.debug('SELECT Statement = ');
93: fa_rx_util_pkg.debug(buffer);
94: fa_rx_util_pkg.debug('fa_rx_util_pkg.build_select()-');
95: END IF;
96:
97: return buffer;
98:
98:
99: exception
100: when no_data_found then
101: IF (g_print_debug) THEN
102: fa_rx_util_pkg.debug('Missing item at '||to_char(idx));
103: fa_rx_util_pkg.debug('Check your calls to assign_column() and make sure that you have that index');
104: END IF;
105:
106: raise;
99: exception
100: when no_data_found then
101: IF (g_print_debug) THEN
102: fa_rx_util_pkg.debug('Missing item at '||to_char(idx));
103: fa_rx_util_pkg.debug('Check your calls to assign_column() and make sure that you have that index');
104: END IF;
105:
106: raise;
107: end build_select;
130: buf2 varchar2(10000);
131: begin
132:
133: IF (g_print_debug) THEN
134: fa_rx_util_pkg.debug('fa_rx_util_pkg.build_insert()+');
135: END IF;
136:
137: idx := 1;
138: while idx <= Num_Columns and Rep_Columns(idx).insert_column_name is null loop
156: buf1 := buf1||', request_id, created_by, creation_date, last_updated_by, last_update_date, last_update_login';
157: buf2 := buf2 ||', :b_request_id, :b_user_id, :b_today, :b_user_id, :b_today, :b_login_id)';
158:
159: IF (g_print_debug) THEN
160: fa_rx_util_pkg.debug('INSERT Statement = ');
161: fa_rx_util_pkg.debug(buf1||buf2);
162: fa_rx_util_pkg.debug('fa_rx_util_pkg.build_insert()-');
163: END IF;
164:
157: buf2 := buf2 ||', :b_request_id, :b_user_id, :b_today, :b_user_id, :b_today, :b_login_id)';
158:
159: IF (g_print_debug) THEN
160: fa_rx_util_pkg.debug('INSERT Statement = ');
161: fa_rx_util_pkg.debug(buf1||buf2);
162: fa_rx_util_pkg.debug('fa_rx_util_pkg.build_insert()-');
163: END IF;
164:
165: return(buf1||buf2);
158:
159: IF (g_print_debug) THEN
160: fa_rx_util_pkg.debug('INSERT Statement = ');
161: fa_rx_util_pkg.debug(buf1||buf2);
162: fa_rx_util_pkg.debug('fa_rx_util_pkg.build_insert()-');
163: END IF;
164:
165: return(buf1||buf2);
166: end build_insert;
191: c integer;
192: rows number;
193: begin
194: IF (g_print_debug) THEN
195: fa_rx_util_pkg.debug('fa_rx_util_pkg.bind_insert()+');
196: END IF;
197:
198: buffer := 'BEGIN ';
199: for idx in 1..Num_Columns loop
206: end loop;
207: buffer := buffer ||' END;';
208:
209: IF (g_print_debug) THEN
210: fa_rx_util_pkg.debug('bind_insert: ' || buffer);
211: END IF;
212:
213: c := dbms_sql.open_cursor;
214: dbms_sql.parse(c, buffer, dbms_sql.native);
220: dbms_sql.bind_variable(p_cursor, 'b_login_id', Login_Id);
221: dbms_sql.bind_variable(p_cursor, 'b_today', Today);
222:
223: IF (g_print_debug) THEN
224: fa_rx_util_pkg.debug('fa_rx_util_pkg.bind_insert()-');
225: END IF;
226: end bind_insert;
227:
228: -----------------------------------------------------------
257:
258: begin
259:
260: IF (g_print_debug) THEN
261: fa_rx_util_pkg.debug('fa_rx_util_pkg.define_columns()+');
262: END IF;
263:
264: sel_idx := 1;
265:
320: end loop;
321: buffer := buffer || 'END;';
322:
323: IF (g_print_debug) THEN
324: fa_rx_util_pkg.debug('define_columns: ' || buffer);
325: END IF;
326:
327: c := dbms_sql.open_cursor;
328: dbms_sql.parse(c, buffer, dbms_sql.native);
330: dbms_sql.close_cursor(c);
331: */
332:
333: IF (g_print_debug) THEN
334: fa_rx_util_pkg.debug('fa_rx_util_pkg.define_columns()-');
335: END IF;
336: end define_columns;
337:
338:
362:
363: buffer varchar2(10000);
364: begin
365: IF (g_print_debug) THEN
366: fa_rx_util_pkg.debug('fa_rx_util_pkg.column_values()+');
367: END IF;
368:
369: sel_idx := 1;
370: buffer := 'BEGIN ';
380: end loop;
381: buffer := buffer || 'END;';
382:
383: IF (g_print_debug) THEN
384: fa_rx_util_pkg.debug('column_values: ' || buffer);
385: END IF;
386:
387: --* bug#3266462, rravunny
388: If c is null then
385: END IF;
386:
387: --* bug#3266462, rravunny
388: If c is null then
389: fa_rx_util_pkg.debug('cursor cursor_column_values/ c is defined for first time');
390: c := dbms_sql.open_cursor;
391: dbms_sql.parse(c, buffer, dbms_sql.native);
392: else
393: fa_rx_util_pkg.debug('cursor cursor_column_values/ c is already defined');
389: fa_rx_util_pkg.debug('cursor cursor_column_values/ c is defined for first time');
390: c := dbms_sql.open_cursor;
391: dbms_sql.parse(c, buffer, dbms_sql.native);
392: else
393: fa_rx_util_pkg.debug('cursor cursor_column_values/ c is already defined');
394: End If;
395: rows := dbms_sql.execute(c);
396: --* bug#3266462, rravunny dbms_sql.close_cursor(c);
397:
395: rows := dbms_sql.execute(c);
396: --* bug#3266462, rravunny dbms_sql.close_cursor(c);
397:
398: IF (g_print_debug) THEN
399: fa_rx_util_pkg.debug('fa_rx_util_pkg.column_values()-');
400: END IF;
401: cursor_column_values := c; --* bug#3266462, rravunny
402: end column_values;
403:
433: p_interface_table in varchar2 default null)
434: is
435: begin
436: IF (g_print_debug) THEN
437: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_request('||to_char(p_request_id)||')+');
438: END IF;
439:
440: --
441: -- If Initialization has already occurred, then exit
460: if p_request_id = 0 then
461: --
462: -- This is a debugging request
463: IF (g_print_debug) THEN
464: fa_rx_util_pkg.debug('init_request: ' || 'Running from SQL*Plus');
465: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_request(DEBUG)-');
466: END IF;
467: elsif p_interface_table is not null then
468: Interface_Table := p_interface_table;
461: --
462: -- This is a debugging request
463: IF (g_print_debug) THEN
464: fa_rx_util_pkg.debug('init_request: ' || 'Running from SQL*Plus');
465: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_request(DEBUG)-');
466: END IF;
467: elsif p_interface_table is not null then
468: Interface_Table := p_interface_table;
469: else
498: DBMS_SQL.BIND_VARIABLE(c,':request_id',p_request_id); --* bug#3207863, rravunny
499: rows := dbms_sql.execute(c);
500:
501: IF (g_print_debug) THEN
502: fa_rx_util_pkg.debug('init_request: ' || to_char(dbms_sql.last_row_count)||' row(s) deleted from table '||Interface_Table);
503: END IF;
504: dbms_sql.close_cursor(c);
505: end;
506:
504: dbms_sql.close_cursor(c);
505: end;
506:
507: IF (g_print_debug) THEN
508: fa_rx_util_pkg.debug('init_request: ' || 'Using RX Interface Table = '||Interface_Table);
509: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_request()-');
510: END IF;
511: exception
512: when no_data_found then
505: end;
506:
507: IF (g_print_debug) THEN
508: fa_rx_util_pkg.debug('init_request: ' || 'Using RX Interface Table = '||Interface_Table);
509: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_request()-');
510: END IF;
511: exception
512: when no_data_found then
513: IF (g_print_debug) THEN
510: END IF;
511: exception
512: when no_data_found then
513: IF (g_print_debug) THEN
514: fa_rx_util_pkg.debug('init_request: ' || 'No RX request with request id = '||to_char(p_request_id)||' found!');
515: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_request(NO_DATA_FOUND)-');
516: END IF;
517: end init_request;
518:
511: exception
512: when no_data_found then
513: IF (g_print_debug) THEN
514: fa_rx_util_pkg.debug('init_request: ' || 'No RX request with request id = '||to_char(p_request_id)||' found!');
515: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_request(NO_DATA_FOUND)-');
516: END IF;
517: end init_request;
518:
519:
532: -- find out the interface table name.
533: -- You should prepare a test script whenever testing RX reports which
534: -- 1) Calls fnd_global.initialize
535: -- This initializes Oracle Applications.
536: -- 2) Calls fa_rx_util_pkg.enable_debug
537: -- Enable debugging for these routines
538: -- 3) Calls fa_rx_util_pkg.init_debug
539: -- Initialize these routines
540: -- 4) Calls your RX report
534: -- 1) Calls fnd_global.initialize
535: -- This initializes Oracle Applications.
536: -- 2) Calls fa_rx_util_pkg.enable_debug
537: -- Enable debugging for these routines
538: -- 3) Calls fa_rx_util_pkg.init_debug
539: -- Initialize these routines
540: -- 4) Calls your RX report
541: --
542: -- Modification History
546: procedure init_debug(p_interface_table in varchar2)
547: is
548: begin
549: IF (g_print_debug) THEN
550: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_debug()+');
551: fa_rx_util_pkg.debug('init_debug: ' || 'This initialization routine should only be called during debugging sessions from SQL*Plus!');
552: END IF;
553:
554: Interface_Table := p_interface_table;
547: is
548: begin
549: IF (g_print_debug) THEN
550: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_debug()+');
551: fa_rx_util_pkg.debug('init_debug: ' || 'This initialization routine should only be called during debugging sessions from SQL*Plus!');
552: END IF;
553:
554: Interface_Table := p_interface_table;
555: Request_Id := 0;
554: Interface_Table := p_interface_table;
555: Request_Id := 0;
556:
557: IF (g_print_debug) THEN
558: fa_rx_util_pkg.debug('init_debug: ' || 'Using RX Interface Table = '||Interface_Table);
559: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_debug()-');
560: END IF;
561: end init_debug;
562:
555: Request_Id := 0;
556:
557: IF (g_print_debug) THEN
558: fa_rx_util_pkg.debug('init_debug: ' || 'Using RX Interface Table = '||Interface_Table);
559: fa_rx_util_pkg.debug('fa_rx_util_pkg.init_debug()-');
560: END IF;
561: end init_debug;
562:
563:
638: end Find_Column_Index;
639:
640: begin
641: IF (g_print_debug) THEN
642: fa_rx_util_pkg.debug('fa_rx_util_pkg.assign_column('||
643: p_key||','||
644: p_select_column_name||','||
645: p_insert_column_name||','||
646: p_placeholder_name||','||
668: Rep_Columns(l_index).column_type := p_column_type;
669: Rep_Columns(l_index).column_length := p_column_length;
670:
671: IF (g_print_debug) THEN
672: fa_rx_util_pkg.debug('fa_rx_util_pkg.assign_column()-');
673: END IF;
674: end assign_column;
675:
676:
839: end Find_Report_Index;
840:
841: begin
842: IF (g_print_debug) THEN
843: fa_rx_util_pkg.debug('fa_rx_util_pkg.assign_report()+');
844: END IF;
845:
846: l_section_number := Find_Report_Index(p_section_name);
847:
857: Report(l_section_number).after_report || p_after_report;
858:
859:
860: IF (g_print_debug) THEN
861: fa_rx_util_pkg.debug('fa_rx_util_pkg.assign_report('||to_char(l_section_number)||')-');
862: END IF;
863: end assign_report;
864:
865:
899: cursor_after_report integer;
900:
901: begin
902: IF (g_print_debug) THEN
903: fa_rx_util_pkg.debug('fa_rx_util_pkg.run_report()+');
904: END IF;
905:
906: retcode := 0;
907: errbuf := null;
913:
914: for idx in 1..Num_Sections loop
915: Current_Section := Report(idx).section_name;
916: IF (g_print_debug) THEN
917: fa_rx_util_pkg.debug('run_report: ' || 'Current section = '||current_Section);
918: END IF;
919:
920: if not Report(idx).enabled then
921: goto next_section;
932: Order_By_Clause := null;
933:
934: -- Before Report Trigger
935: IF (g_print_debug) THEN
936: fa_rx_util_pkg.debug('run_report: ' || 'Before Report = '''||Report(idx).before_report||'''');
937: END IF;
938: if Report(idx).before_report is not null then
939: cursor_before_report := dbms_sql.open_cursor;
940: dbms_sql.parse(cursor_before_report,
952: dbms_sql.native);
953: if Report(idx).bind is not null then
954: -- Bind variables in the select statement
955: IF (g_print_debug) THEN
956: fa_rx_util_pkg.debug('run_report: ' || ' Bind...');
957: fa_rx_util_pkg.debug('run_report: ' || Report(idx).bind);
958: END IF;
959: cursor_bind := dbms_sql.open_cursor;
960: dbms_sql.parse(cursor_bind,
953: if Report(idx).bind is not null then
954: -- Bind variables in the select statement
955: IF (g_print_debug) THEN
956: fa_rx_util_pkg.debug('run_report: ' || ' Bind...');
957: fa_rx_util_pkg.debug('run_report: ' || Report(idx).bind);
958: END IF;
959: cursor_bind := dbms_sql.open_cursor;
960: dbms_sql.parse(cursor_bind,
961: 'BEGIN '||Report(idx).bind||' END;',
968: end if; -- of Bind
969: define_columns(cursor_select);
970:
971: IF (g_print_debug) THEN
972: fa_rx_util_pkg.debug('run_report: ' || 'Executing SELECT statement');
973: END IF;
974: rows := dbms_sql.execute(cursor_select);
975:
976: IF (g_print_debug) THEN
973: END IF;
974: rows := dbms_sql.execute(cursor_select);
975:
976: IF (g_print_debug) THEN
977: fa_rx_util_pkg.debug('run_report: ' || 'Building INSERT');
978: END IF;
979: cursor_insert := dbms_sql.open_cursor;
980: dbms_sql.parse(cursor_insert, build_insert, dbms_sql.native);
981:
979: cursor_insert := dbms_sql.open_cursor;
980: dbms_sql.parse(cursor_insert, build_insert, dbms_sql.native);
981:
982: IF (g_print_debug) THEN
983: fa_rx_util_pkg.debug('run_report: ' || 'After Fetch Initialization');
984: END IF;
985: if Report(idx).after_fetch is not null then
986: cursor_after_fetch := dbms_sql.open_cursor;
987: dbms_sql.parse(cursor_after_fetch,
995: rows := dbms_sql.fetch_rows(cursor_select);
996: exit when rows < 1;
997:
998: IF (g_print_debug) THEN
999: fa_rx_util_pkg.debug('run_report: ' || 'Get values ');
1000: END IF;
1001: column_values(cursor_select);
1002:
1003: IF (g_print_debug) THEN
1000: END IF;
1001: column_values(cursor_select);
1002:
1003: IF (g_print_debug) THEN
1004: fa_rx_util_pkg.debug('run_report: ' || 'After Fetch');
1005: END IF;
1006: if cursor_after_fetch is not null then
1007: rows := dbms_sql.execute(cursor_after_fetch);
1008: end if;
1007: rows := dbms_sql.execute(cursor_after_fetch);
1008: end if;
1009:
1010: IF (g_print_debug) THEN
1011: fa_rx_util_pkg.debug('run_report: ' || 'Insert Row');
1012: END IF;
1013: bind_insert(cursor_insert);
1014: rows := dbms_sql.execute(cursor_insert);
1015: end loop; -- Fetch
1023: end if;
1024:
1025: -- After Report Trigger
1026: IF (g_print_debug) THEN
1027: fa_rx_util_pkg.debug('run_report: ' || ' After Report Trigger, Pass #'||to_char(idx));
1028: END IF;
1029: if Report(idx).after_report is not null then
1030: cursor_after_report := dbms_sql.open_cursor;
1031: dbms_sql.parse(cursor_after_report,
1039: null;
1040: end loop;
1041:
1042: IF (g_print_debug) THEN
1043: fa_rx_util_pkg.debug('fa_rx_util_pkg.run_report()-');
1044: END IF;
1045: exception
1046: when others then
1047: IF (g_print_debug) THEN
1044: END IF;
1045: exception
1046: when others then
1047: IF (g_print_debug) THEN
1048: fa_rx_util_pkg.debug('run_report: ' || sqlerrm);
1049: fa_rx_util_pkg.debug('fa_rx_util_pkg.run_report(EXCEPTION)-');
1050: END IF;
1051:
1052: retcode := 2; -- Error
1045: exception
1046: when others then
1047: IF (g_print_debug) THEN
1048: fa_rx_util_pkg.debug('run_report: ' || sqlerrm);
1049: fa_rx_util_pkg.debug('fa_rx_util_pkg.run_report(EXCEPTION)-');
1050: END IF;
1051:
1052: retcode := 2; -- Error
1053: errbuf := sqlerrm;
1083: procedure enable_debug
1084: is
1085: begin
1086: m_debug_flag := true;
1087: fa_rx_util_pkg.debug('Enabling debug...');
1088: end enable_debug;
1089:
1090: procedure enable_debug(debug_dir in varchar2, debug_file in varchar2)
1091: is
1132: -------------------------------------------------------------------------
1133: procedure disable_debug
1134: is
1135: begin
1136: fa_rx_util_pkg.debug('Disabling debug...');
1137: if Request_Id = 0 then
1138: fnd_file.close;
1139: end if;
1140: m_debug_flag := false;
1156: -- Description
1157: -- Checks to see if debugging is enabled. Call this function
1158: -- if you want to have a block of code run only if debugging
1159: -- is enabled.
1160: -- If you have a whole bunch offa_rx_util_pkg.debug() calls in succession,
1161: -- then it is preferable if you first check to see if debuggin
1162: -- is enabled.
1163: --
1164: -- Modification History
1302: --* bug#3344455, rravunny dbms_session.set_sql_trace(false);
1303: Null;
1304: end disable_trace;
1305:
1306: end fa_rx_util_pkg;