Monday, February 13, 2012

Debugging EBS API calls in APEX

This picture comes from Dmitry Vostokov site.
While I was looking into E-Business Suite and especially the API calls, I wondered how I could debug what was going.

I find it important to understand what I'm doing. EBS is big, but the more I get into it, the more I want to know what is going on (because the more I get into having issues ;-)).

Although I don't have the time right now to really dive into a detailed EBS-APEX debugging post, I quickly want to share my ideas.

In EBS people tend to use the hr_utility package to trace what is going on. You can do something like :

apps.hr_utility.set_trace_options ('TRACE_DEST:DBMS_OUTPUT');

Unfortunately if you don't have SQL Plus or SQL Developer access to the EBS database and you only have APEX, what do you do? It would be nice if the TRACE_DEST parameter would allow HTP as a value, but it doesn't.

So here is some pseudo-code I thought would help me to debug from within my APEX app (or SQL Workshop):


BEGIN
  if APEX_APPLICATION.G_DEBUG
  then
    -- trace_dest possible values: DBMS_PIPE, DBMS_OUTPUT, PAY_LOG
    apps.hr_utility.set_trace_options ('TRACE_DEST:DBMS_PIPE');
    -- set trace on
    apps.hr_utility.trace_on;
    -- do EBS API call 
    /* EBS api call */
    -- custom message in EBS trace output
    apps.hr_utility.trace('Custom message in trace');
    -- custom message in APEX debug
    apex_debug_message.log_message (
      p_message    => 'My message',
      p_enabled    => TRUE,
      p_level      => 5
    );
    -- like to work with Tyler Muth's logger package
    -- logger.log('if the logger package is installed, another way to log a message');
    -- run some other code
    /* my custom code */
    -- set trace off
    apps.hr_utility.trace_off;
    -- log the EBS trace data to APEX or custom table
    /* insert the data of the EBS HR Utility PIPE into APEX debug messages */
    /* query debug output in a report or in APEX debug view */
  end if;
EXCEPTION
WHEN OTHERS 
THEN
  -- store your error in some logging/debugging of the above
  -- dbms_output.put_line(sqlerrm);
  apps.hr_utility.trace_off;
END;


I hope by reading the code you understand what I think would be a good way to debug your EBS code in APEX. I didn't find the time yet to write an entire EBS-APEX debug package, but maybe some of you already did or if you want to complete the above code, feel free to share it in the comments.

Happy debugging :-)

Previous related posts:

1 comments:

Chris said...

Hi Dimitri,

in the past, I've often found it useful to display dbms_output of server-side code into my Forms and Apex apps. Since it seems to be possible to configure EBS to write trace to DBMS_OUTPUT, you could use code like this:

(1) set up dbms_output

dbms_output.enable;
apps.hr_utility.set_trace_options ('TRACE_DEST:DBMS_OUTPUT');

(2) run ebs code

(3)
declare
l_lines sys.dbms_output.chararr;
l_count number;
begin
if apex_application.g_debug then
loop
l_count := 10000;
sys.dbms_output.get_lines (
lines => l_lines,
numlines => l_count );
exit when l_count = 0;
for i in 1 .. l_count loop
apex_application.debug(l_lines(i));
end loop;
end loop;
end if;
end;

In fact, we should probably add an API call for (3) to Apex itself.

Regards,
Christian

PS: recaptcha drives me crazy