DBA Data[Home] [Help]

PACKAGE BODY: APPS.ASN_DEBUG

Source


1 PACKAGE BODY ASN_DEBUG AS
2 /* $Header: RCVDBUGB.pls 120.0.12010000.5 2010/01/27 18:28:19 vthevark ship $ */
3 
4 g_product_code constant varchar2(5) := 'p'||'o'||'.';  -- gscc hack
5 g_debugging_enabled VARCHAR2(1)     := asn_debug.is_debug_on; -- Bug 9152790
6 
7 
8 /*===========================================================================
9 
10   PROCEDURE NAME:	PUT_LINE()
11 
12 ===========================================================================*/
13 
14 PROCEDURE PUT_LINE (v_line in varchar2,v_level in varchar2, v_inv_debug_level in NUMBER DEFAULT 9) IS /* lcm changes */
15 
16     --x_TRACE_ENABLE_FLAG	VARCHAR2(1) := 'N';
17     /* FPJ WMS.
18      * Insert into fnd_log_messages for online mode.
19     */
20     l_processing_mode   rcv_transactions_interface.processing_mode_code%type ;
21     l_api_name         CONSTANT VARCHAR2(40) := 'PUT_LINE';
22     p_module VARCHAR2(255);
23     p_procedure VARCHAR2(20);
24     p_label VARCHAR2(20);
25 
26 BEGIN
27 -- uncomment out the line below if you want to run the preprocessor in
28 -- sqlplus
29 
30     -- dbms_output.put_line(v_line);
31 
32   if ( g_debugging_enabled = 'Y') then
33     get_calling_module(p_module,p_procedure,p_label);
34     -- lcm changes
35     debug_msg_ex(v_line,p_module,p_procedure,p_label,v_level, v_inv_debug_level); -- Bug 9152790
36   end if;
37 END PUT_LINE;
38 
39 PROCEDURE get_calling_module(p_module OUT NOCOPY VARCHAR2,
40                              p_procedure OUT NOCOPY VARCHAR2,
41                              p_label OUT NOCOPY VARCHAR2,
42                              p_stack_depth IN NUMBER) IS
43 /* p_stack_depth is the rewind depth.  for example
44    p_stack_depth = 2 -->  calling procedure name
45    p_stack_depth = 1 -->  asn_debug.put_line
46    p_stack_depth = 0 -->  get_calling_procedure
47    you can override the rewind depth as needed
48 */
49   stk VARCHAR2(2000);
50   len NUMBER;
51   p1 NUMBER;
52   p2 NUMBER;
53   t VARCHAR2(2000);
54   r VARCHAR2(2000);
55   s VARCHAR2(2000);
56   rtn VARCHAR2(1);
57 BEGIN
58   stk:=DBMS_UTILITY.format_call_stack;
59   len:=LENGTH(stk);
60   rtn:=SUBSTRB(stk,-1); --get the return character
61   p1:=INSTRB(stk,rtn,1,p_stack_depth+3)+1;
62   p2:=INSTRB(stk,rtn,1,p_stack_depth+4);
63   t:=SUBSTRB(stk,p1,p2-p1); --isolated stack line
64   t:=trim(substrb(t,instrb(t,' '))); --get rid of object address
65   r:=substrb(t,0,instrb(t,' ')-1); --isolate line number
66   s:=trim(substrb(t,instrb(t,' '))); --isolate caller
67   p1:=INSTRB(s,'.',1,1)+1;
68   s:=SUBSTRB(s,p1); --isolate calling procedure
69   p_label:=substrb(r,0,20);
70   p_procedure:=substrb(s,0,20);
71   p_module:=substrb(s,0,255);
72 END get_calling_module;
73 
74 FUNCTION get_debugging_enabled return boolean is
75 
76   v_value     VARCHAR2(128);
77 
78 BEGIN
79 
80   IF (g_debugging_enabled = 'Y') THEN
81    RETURN TRUE;
82   ELSE
83    RETURN FALSE;
84   END IF;
85 
86 end get_debugging_enabled;
87 
88 /* set the current module name that you see in the log table */
89 PROCEDURE set_module_name( module in varchar2) is
90   v_module varchar2(255);
91 BEGIN
92   v_module := trim(module);
93   if (substr(v_module,0,3)=g_product_code) then --if explicit set then override default
94     g_current_module := substr(v_module,0,255);
95   elsif (module is not null) then
96     if (lower(substr(v_module,-2,2))='.c') then --call from lpc file
97       v_module := substr(g_product_code||'src.rvtp.'||substr(v_module,0,length(v_module)-2),0,255);
98     else --call from plsql
99       v_module := substr(g_product_code||'plsql.'||v_module,0,255);
100     end if;
101     g_current_module := v_module;
102   end if;
103 END set_module_name;
104 
105 /* print stack will print out the current procedure calling stack */
106 PROCEDURE print_stack is
107 BEGIN
108   debug_msg('Current Calling Stack = '||g_procedure_stack);
109   debug_msg(DBMS_UTILITY.FORMAT_CALL_STACK);
110 END;
111 
112 /* start procedure adds procedure name to the simulated procedure stack */
113 /* g_procedure_stack is a string that keeps a list of all the stacks    */
114 /* this works because each procedure name is sure to have exactly 20    */
115 /* characters so that the substr(g_procedure_stack,60,20) gives you the */
116 /* name of the third procedure on the stack.  Note that                 */
117 /* substr(g_procedure_stack,0,20) is level zero which equals '?' or     */
118 /* the unknown procedure.                                               */
119 PROCEDURE start_procedure( procedure_name in varchar2) is
120 BEGIN
121   g_current_procedure := rpad(upper(nvl(substrb(procedure_name,0,20),'?')),20,' ');
122   debug_msg(RPAD('v--------Procedure Started',37,'-')||'v',FND_LOG.LEVEL_PROCEDURE,'begin');
123   g_level := g_level+1;
124   g_procedure_stack := g_procedure_stack||g_current_procedure;
125 EXCEPTION
126   WHEN OTHERS THEN
127     null;
128 END start_procedure;
129 
130 /* stop procedure acts like a pop on the stack.  If the procedure name */
131 /* equals the name that is currently being used then we can pop the    */
132 /* topmost element off and we're done.  However, if the name does not  */
133 /* equal the topmost element then we need to undo the stack all the way*/
134 /* back to that element - this results in Implicit Procedure Exits     */
135 /* which are generally caused by unexpected errors when the procedure  */
136 /* is exited abnormally.  In the very weird situation where we get a   */
137 /* stop procedure for a procedure name we do not recognize, we do not  */
138 /* do anything other than mention it was an unknown procedure name     */
139 /* note the use of instr to search the string in reverse - this is     */
140 /* necessary in the case of recursion and stuff                        */
141 /* the pop_this_procedure is a flag to indicate not to pop off the     */
142 /* current procedure.  Useful for the pro*C commands that do not have  */
143 /* an explicit procedure termination                                   */
144 PROCEDURE stop_procedure( procedure_name in varchar2, pop_this_procedure in boolean) is
145   l_temp_name VARCHAR2(20);
146   l_temp_level NUMBER;
147 BEGIN
148   l_temp_name := rpad(upper(nvl(substrb(procedure_name,0,20),'?')),20,' ');
149   IF (g_current_procedure <> l_temp_name) THEN -- we need to jump back on the stack
150     l_temp_level := (INSTRB(g_procedure_stack,l_temp_name)-1)/20;
151     WHILE (g_level > l_temp_level) LOOP -- to pop off the procedure that didn't get exited
152       g_level := g_level - 1;
153       debug_msg(RPAD('^--------Implicit Procedure Exit',37,'-')||'^',FND_LOG.LEVEL_PROCEDURE,'end_implicit');
154       g_current_procedure := SUBSTRB(g_procedure_stack,g_level*20+1,20);
155     END LOOP;
156   END IF;
157   if (pop_this_procedure = TRUE) then
158     IF (g_current_procedure = l_temp_name) then -- now pop off the called procedure
159       g_level := g_level-1;
160       debug_msg(RPAD('^--------Procedure Ended',37,'-')||'^',FND_LOG.LEVEL_PROCEDURE,'end');
161       IF (g_level<0) THEN -- shouldn't happen unless you call stop_procedure('?'), but just to be safe
162         g_level := 0;
163         g_current_procedure := RPAD('?',20,' ');
164       ELSE -- the normal situation, reset the current procedure to the previous procedure on the stack
165         g_current_procedure := SUBSTRB(g_procedure_stack,g_level*20+1,20);
166       END IF;
167     ELSE -- the name given wasn't anywhere on the stack
168       debug_msg(RPAD('^--------Unknown Procedure ['||procedure_name||'] Ended',37,'-')||'^',FND_LOG.LEVEL_PROCEDURE,'end_unknown');
169     END IF;
170   end if;
171   g_procedure_stack := substrb(g_procedure_stack,1,(g_level+1)*20);
172 EXCEPTION
173   WHEN OTHERS THEN
174     null;
175 END stop_procedure;
176 
177 PROCEDURE debug_msg(line in varchar2, level in varchar2, label in varchar2, inv_debug_level in number default 9) is -- Bug 9152790
178 -- If you do not specify a level then it will default to log level: Statement
179 -- If you do not specify a module then it will use the last module specified
180 --   if there is no last module specified then it Will default to module name: RCV
181 v_level	NUMBER;
182 BEGIN
183   if ( g_debugging_enabled = 'Y' ) then
184   -- Bug 9152790: rcv debug enhancement : We will not use fnd logging; instead will write to inv log file.
185     /*
186     v_level := nvl(level,FND_LOG.LEVEL_STATEMENT);
187 
188     -- GSCC HACK: need redundant v_level >= FND_CUR_LEVEL check do not remove
189     if( v_level >= FND_LOG.G_CURRENT_RUNTIME_LEVEL AND FND_LOG.TEST(v_level, G_CURRENT_MODULE )) then
190       FND_LOG.STRING(v_level,
191          substrb(G_CURRENT_MODULE||'.'
192                ||trim(nvl(G_CURRENT_PROCEDURE,'?'))||'.'
193                ||trim(nvl(label,'-1'))
194                  ,0,255)
195          ,RPAD(' ',2*g_level)||line);
196       FND_FILE.PUT_LINE(FND_FILE.LOG , '[' || to_char(sysdate,'DD-MON-YY HH24:MI:SS') || '] '||rpad(SUBSTR(g_current_module,INSTRB(g_current_module,'.',-1)+1,20),20,' ')||' '||LPAD(nvl(label,'-1'),5,' ')||':'||RPAD(' ',2*g_level+1)||line);
197     end if;
198     */
199 
200     inv_trx_util_pub.trace(RPAD(' ',2*g_level)||line,
201                            substrb(G_CURRENT_MODULE||'.'||trim(nvl(G_CURRENT_PROCEDURE,'?'))||'.'||trim(nvl(label,'-1')),0,255) ,
202                            inv_debug_level);
203 
204   end if;
205 EXCEPTION
206   WHEN OTHERS THEN
207     null;
208 
209 END debug_msg;
210 
211 /* debug_msg_ex is an extended version of the debug_msg procedure which is */
215 begin
212 /* specifically designed to facilitate the pro*C calls*/
213 PROCEDURE debug_msg_ex(message in varchar2, module in varchar2, procedure_name in varchar2, line_num in number,level in varchar2, inv_debug_level in number default 9) is -- Bug 9152790
214   v_procedure_name VARCHAR2(20);
216   if ( g_debugging_enabled = 'Y') then
217 
218     if (procedure_name is not null) then
219       v_procedure_name := rpad(upper(nvl(substrb(procedure_name,instrb(procedure_name,'/',-1)+1,20),'?')),20,' ');
220       if (v_procedure_name<>g_current_procedure) then
221         if (instr(g_procedure_stack,v_procedure_name)>0) then
222           stop_procedure(v_procedure_name,false);
223           if (module is not null) then
224             set_module_name(substrb(module,instrb(module,'/',-1)+1));
225           end if;
226         else
227           if (module is not null) then
228             set_module_name(substrb(module,instrb(module,'/',-1)+1));
229           end if;
230           start_procedure(v_procedure_name);
231         end if;
232       end if;
233     end if;
234 
235     debug_msg(message,level,line_num,inv_debug_level);  -- Bug 9152790: rcv debug enhancement
236   end if;
237 EXCEPTION
238   WHEN OTHERS THEN
239     null;
240 end debug_msg_ex;
241 
242 -- Bug 9152790: rcv debug enhancement
243 FUNCTION is_debug_on RETURN VARCHAR2 IS
244 BEGIN
245    IF (fnd_profile.VALUE('INV_DEBUG_TRACE') = '1') THEN
246        return 'Y';
247    ELSE
248        return 'N';
249    END IF;
250 END;
251 
252 END ASN_DEBUG;