Quick and Dirty Anonymous Block for outputting FND_MSG_PUB error logs

While working on some PL/SQL code developed to call EBS Accounts Receivables APIs, I’ve found a code snippet on Oracle CRM Blog useful for outputting errors logged by Accounts Receivables APIs. Below is an anonymous block that includes this snippet of code, ready to be copied and pasted into SQL Developer to quickly output errors generated by Oracle Applications. I usually add this to the bottom of my Unit Testing scripts for easy debugging.

Hope it helps someone!

set serveroutput on
declare
  out_message varchar2(2048);
  i number;
  l_msg_index_OUT number;
begin
  IF ( FND_MSG_PUB.Count_Msg > 0) THEN
    FOR i IN 1..FND_MSG_PUB.Count_Msg LOOP
      FND_MSG_PUB.Get(p_msg_index => i,
        p_encoded => 'F',
        p_data => out_message,
        p_msg_index_OUT => l_msg_index_OUT );
      dbms_output.put_line('l_msg_data :' ||out_message);
    END LOOP;
  ELSE
  dbms_output.put_line('No errors to output.');
  END IF;
end;

Credit to Oracle CRM Blog for the body of the Anonymous Block.