Using ABAP Debug Loops in OpenText Vendor Invoice Management for SAP Solutions (SAP VIM)

When analysing problems in OpenText Vendor Invoice Management for SAP Solutions (SAP VIM), depending on the system architecture and authorisations, there are parts of the source code that are very difficult to access with the ABAP debugger. This is the case, for example, with data enrichments (e.g. logical modules) executed by a background user at the start of the process.

A debug loop is an endless loop in the code which you can activate when required. The infinite loop allows you to find and debug the running code in the process monitor.

Adding a debug loop to your ABAP code

In order to be able to use a debug loop, it is first necessary for it to exist. This is the case in many parts of the product standard, but should not be forgotten in custom developments either. A debug loop can look like this, for example:

ABAP
DO.  

  SELECT SINGLE value 
  FROM /opt/cp_debug 
  INTO @DATA(lv_debug) 
  WHERE debugarea = 'Z_LOGIC_MODULE'.  " keep text below 20 chars
    
  IF lv_debug IS INITIAL.  
    EXIT.  
  ENDIF. 
     
ENDDO.  

Activating a debug loop using the ABAP Editor SE38

The table /opt/cp_debug has some advantages over self-built tables. It is used in the product standard and the loop can be activated and deactivated with the ABAP Editor (SE38) using the program /OPT/VIM_DEBUG.

If a debugging area is activated, the system remains in an infinite loop until it is deactivated again or until the infinite loop is exited manually in the debugger.

But be careful, the debug loop runs for all users on the system, so this tool should only be used with caution. In the production system only in absolutely exceptional cases and only for a short time in consultation with the system supervisor.

Some consultants even comment out the coding for debug loops before productive operation, but I find that the possibility of debugging in the P system can be a great advantage for tracking down tricky errors.

Tip: As you often spend a long time in the code when debugging, I suggest that the debugging loop is always exited via /OPT/VIM_DEBUG. This way you cannot forget to deactivate the loop.

Starting the debugger in Work process overview (SM50)

If your debug loop is active, you are ready to go: Provoke the system to run the loop, for example by processing a new document.

As soon as the corresponding line in the source code is run through, the process stops and we have the opportunity to jump to the debugger, for which we use the transaction code SM50.

To make it easy to find our process, we switch to the Active Work Processes view.

If you cannot find your process, have a look at the System-Wide List. The process you are looking for may be running on a different application server.

Now we can select our process and start it via Administration > Program > Debugging in the ABAP Debugger and eliminate the error.

Do you have any tips or best practices for dealing with debug loops in ABAP? Let us know in the comments!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *