Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 

Deep Dive into ABAP Debugging - Basic

 

 

What is ABAP Debugger?

The ABAP Debugger is the important tool used to analyze ABAP programs. In the development phase of any program, the Debugger can be used to analyze error situations like runtime errors and unexpected program behaviors. Also, it can also be used to analyze existing programs to understand their logic flow.

Versions of ABAP Debugger

  1. Classic Debugger.
  2. New Debugger.

How to start ABAP Debugger?

  1. For Executable Programs & Transactions
    1. In Object Navigator-SE80, Right click on the Program, Choose to Execute & click Debugging.
    2. In ABAP Editor-SE38, under option Program, Choose to Execute & click Debugging.
    3. In ABAP Editor-SE38, Click Debugging in application toolbar.
  2. For Background Jobs
    1. In Job Overview-SM37, select a finished Background job & in the command field enter JDBG. This will trigger the Debugger & simulate the exact scenario with the variant of the Background job.
  3. For Methods in Class & Function modules
    1. Both Function module Builder-SE37 & Class Builder-SE24 have Test Environment (in Execution mode), using this we can start Debugging all the methods or Function modules.

How to start/switch on Debugging when running applications/transactions?

  1. For Executable Programs & Transactions
    1. To debug screen i.e., ABAP statements & Screen logic, enter /h in command field.
    2. To debug system i.e., Screen, custom programs & System programs, enter /hs in command field.
    3. To debug ABAP only, enter /ha in command field. This includes PAI & PBO modules debugging also.

Just like activating debugger with /h in command field, to activate classic debugger enter /hset debugger=classic and use /hset debugger=standard to activate standard debugger. However, this will have effect only on the current logon session. Standard debugger will be the default for any new SAP logon session.

Note: Post SAP release 7.4, Standard debugging has been the only way for Debugging external requests irrespective of the OK Codes used.

Now, how to end Debugging session?

  1. Under Debugging in the toolbar, when the debugger is active.
    1. Option Restart – Debugger is closed & Application is restarted.
    2. Option Exit (close application), both Debugger & Application is closed.
    3. Option Exit (Application continues running), Debugger is closed while Application continues running.
  2. Enter /hx in command field, to switch off debugging that was switched on by /h.

Types of ABAP Debugger

  1. External Breakpoint prabhakaran_rajenthiran_6-1709049949902.png
  2. Session Breakpoint prabhakaran_rajenthiran_8-1709050022076.png

  3. Persistent Breakpoint prabhakaran_rajenthiran_9-1709050506826.png

Default tools available in Debugging session: -prabhakaran_rajenthiran_12-1709051049848.png

Other tools available that can be added in the debugger screen: -

prabhakaran_rajenthiran_13-1709051597141.png

We will see about the tools in detail as we go on.

Debugging in ABAP code

  • Options available to step through the code

prabhakaran_rajenthiran_14-1709055018305.png

Debugger options explained with the purpose: -

  • Options available other than the above 4, to step through the code.
    • Continue to cursor – Execute the ABAP code till the cursor position – Press SHIFT + F8.
    • Goto Statement – Helps in skipping/reprocessing section of source code, without having to go in a new debugger session. Right click on the ABAP statement from which we want to execute, choose Goto statement in the dialog menu that pops up.
  • Step Sizeprabhakaran_rajenthiran_15-1709055095182.png 
    • If we want to debug the sub conditions in the ABAP code. This can help in the following places,
      • When we have multiple sub conditions in the conditional statements.
      • When we want to debug every step in VALUE, REDUCE, FOR iterations & similar ABAP 7.4 & above statements.

Call stack Debugger tool: - 

This tool helps to see the programs (call stack) that are called before reaching the debugger stop.

prabhakaran_rajenthiran_20-1709056132036.png

Breakpoints & Watchpoints

All types of breakpoints do the job of the allowing the developers to mark places/statements in the ABAP code where the debugger should start/stop.

Every type of breakpoints has different scopes & lifetimes.

Session Breakpoint

If the breakpoint should be active only in the current user session, then Session break point would be right choice. This breakpoint will get deleted once the user logs off. This breakpoint can be set in the following ways.

  • Place the cursor on the statement where we want to have breakpoint, then press CTRL + SHIFT + F12 key.
  • Place the cursor on the statement where we want to have breakpoint, click on prabhakaran_rajenthiran_22-1709056219450.pngin the toolbar.
  • Left click on the status column i.e., left side of the source code line on which we want the breakpoint in the ABAP editor.
  • Session breakpoint can be created in Debugger session also, right click on the source code line on which we want the Session Breakpoint & select the Create Session Breakpoint option.

External Breakpoint

External Breakpoints will be active/valid for future user sessions. These breakpoints are valid for 2 hours and whenever a new breakpoint is set, the lifetime of all breakpoints is reset. These breakpoints are useful when we want to debug applications/ web services that are connected to SAP via RFC & HTTP request. Also, these breakpoints can be set specific for certain User or a Terminal ID. Following are the ways to set external breakpoint,

  • Place the cursor on the statement where we want to have breakpoint, then press CTRL + SHIFT + F9 key.
  • Place the cursor on the statement where we want to have breakpoint, click on      prabhakaran_rajenthiran_23-1709056263346.png in the toolbar.
  • Right click on the Status column, left side of the source code line, Select Create External breakpoint.
  • External breakpoint can be created in Debugger session also, right click on the relevant statement and choose Create User Breakpoint.

External breakpoints can be set for another user, can be helpful when we are trying to debug RFC call or HTTP request made by another user. To do this, follow the below steps,

  • Click on Utilities in the ABAP editor top menu, then Settings -> ABAP editor tab -> Debugging. Enter the user for whom the External breakpoint needs to be set.

prabhakaran_rajenthiran_24-1709056683711.png

In cases where the external breakpoint (for another user) needs to be only in the current application server, Flag the checkbox Current application server only.

Debugger Breakpoint

As the name indicates, these breakpoints can be set only in Debugger session, so they are visible in debugger session and deleted right after the debugger session ends. Both Session & External breakpoints can be set on the ABAP statements (Known positions) that is seen on the screen while Debugger breakpoints can be set on unknown positions as well. We will see how to do this.

Set Debugger breakpoints at a known position,

  • Right click on the relevant ABAP statement & Choose Create Debugger Breakpoint.
  • Left click on the status column i.e., the left side of the line number in ABAP editor, to the left of the relevant ABAP statement.

Set the cursor the on the ABAP statement that is of interest, choose Breakpoints -> Line Breakpoint. We get options to Set/Delete & Activate/Deactivate debugger breakpoint.

prabhakaran_rajenthiran_25-1709056904483.png

Let’s see how to set Debugger breakpoints at an unknown position.

  • Simply by pressing F9 key.
  • Click on the Stop prabhakaran_rajenthiran_27-1709057002785.png in the Toolbar.
  • Choose Breakpoints in the Menu, Select Breakpoint at.

This dialog box opens when we press F9 or Create breakpoint. With this, Debugger breakpoints can be created for the following items.

prabhakaran_rajenthiran_28-1709057329842.png

  • ABAP statements – Breakpoint can be set for all possible ABAP command statements.

prabhakaran_rajenthiran_29-1709057480565.png

  • Methods of Class (Global & Local).

prabhakaran_rajenthiran_30-1709057530966.png

We should enter the class & method to set a breakpoint for the method. Similarly, if we want to set a breakpoint for a method of a local class within any specific program.

  • Function modules – If we want to set breakpoint for any Function module.

prabhakaran_rajenthiran_31-1709057740681.png

  • Forms (Both in current program and in a called program).

prabhakaran_rajenthiran_33-1709057977728.png

  • Exceptions & Messages of all types – Set breakpoints at all instances of specific exception class. Also, we set breakpoint for a specific Message of a certain Type (I, E, A, S).

prabhakaran_rajenthiran_34-1709058175783.png

  • Include programs & PAI/PBO flow logic of any screen at any specific line numbers – We can set breakpoint at a specific line in an Include of a Program. Also, Set breakpoint on a line no. within any PAI/PBO flow logic.

prabhakaran_rajenthiran_40-1709058685611.png

  • Simple Transformation templates.
  • Methods of Web Dynpro controller – We can set breakpoint for methods in controller of any Web Dynpro component.

prabhakaran_rajenthiran_41-1709058754793.png

Breakpoint Overview

All the Breakpoints that are defined can be seen in within Breakpoint Tab in Break/Watchpoints tab in Debugger session. From this tab, Breakpoints can be created, activated, deactivated & deleted. Also, we can change the type of breakpoint from here.

prabhakaran_rajenthiran_42-1709058800318.png

We can also set conditions for the breakpoints., if we want the breakpoint (that is already set) to be triggered only on for a specific condition. Like the below example, if we want the breakpoint to be triggered only when the username is ‘PRABHAKARAN’

prabhakaran_rajenthiran_43-1709059368931.png

We can also see the overview of Breakpoint from ABAP Editor.

prabhakaran_rajenthiran_44-1709059439392.png

Watchpoints

Watchpoints are a way to make the debugger stop when the value of the variable/data object (for which watchpoint is created) changes.

How to create Watchpoints – Watchpoints can be created only in debugger sessions.

  • Choose Watchpoint in the application toolbar.

prabhakaran_rajenthiran_52-1709059747067.png

  • Choose Breakpoint -> Create Watchpoint

prabhakaran_rajenthiran_53-1709059988610.png

  • Press SHIFT + F4 key.

On creating the Watchpoint, we get the below dialog box where we should enter the variable/data object for which Watchpoint needs to be created.

Below example, Watchpoint is created for variable SY-UNAME with condition SY_UNAME = ‘PRABHAKARAN’. So whenever the value of SY_UNAME changes to PRABHAKARAN debugger will stop. If we want the debugger to stop whenever the value of the variable changes, then leave the Free condition blank.

prabhakaran_rajenthiran_54-1709060052116.png

Watchpoints created can be seen in Watchpoints tab under Break./Watchpoint tab in debugger session. We can also activate, deactivate, create, change, delete any watchpoint from here also.

prabhakaran_rajenthiran_55-1709060143041.png

How to save & load Debugger session?

Following the below steps, Debugger sessions can be saved, loaded for a later debugging session, can also be deleted if no longer needed along with components that can be chosen.

prabhakaran_rajenthiran_56-1709060201676.png

Dialog box while saving & loading the Debugger session.

prabhakaran_rajenthiran_57-1709060265020.png

prabhakaran_rajenthiran_58-1709060547930.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Labels in this area