Sie sind auf Seite 1von 12

Basics of Debugging in SAP

Debugging on SAP:
Debuggingisoneofthebestandwonderfultoolusedbythedeveloper(Inanydevelopment
Environment)totrackdownaissueandalsotounderstandcodeorlogicwrittenbyanyother
developer.
Asweknow,sinceitsbeingatechnicalstuff,notallFunctionalConsultantswillhaveanidea
aboutit,sotheyhavesometoughtimeinitiallytounderstandaswhatitisandhowitworks,but
oncetheyunderstandit,itslikepieceofcaketoanyperson.
Ihaveputsomebasicinformationregardingdebuggerandsomebasicconceptsaboutdebugger,
goingoverthesemighthelpyouinnotgettingpanicwhenyouseeadebuggerscreen:).
Note:InSAP,thereare2typesofdebuggers.OneisClassicdebuggerandtheotheroneisNew
Debugger.ClassicdebuggerisloteasytouseandalsotounderstandbutNewdebugger(available
fromreleaselevels6.40)ishasmorefeaturesandalsowillbeusedvastlyinfuture,soIam
goingoverNewdebuggerinmyblog.
Somebriefdifferencesbetweenthese2typesare,(CourtesyofSAP)

The Classic Debugger runs in the same roll area as the application to
be analyzed (debuggee). It is therefore displayed in the same window
as the application. However, this technology also has some
restrictions. For example, some ABAP programs (such as conversion
exist) cannot be analyzed in debug mode for technical reasons.
However, the most significant restriction is that no ABAP technology
can be used for designing the Debugger interface and it is therefore
not possible to create a modern user interface.

The New Debugger on the other hand, is executed in a separate


external session (Debugger), while
the application to be analyzed
(debuggee) uses a second external session. With this technology, the
user interface of the Debugger can be designed freely by ABAP means.

About New Debugger:


SAP's old debugger which is Classic debugger was user-friendly but has some cons as described
above. This New Debugger is a lot different to old debugger, just not in look but also in features.

List of few features available on New Debugger are:


1. Ability to Configure the look of the debugger screen.
2. Multiple Desktops options to go over multiple types of data while debugging.
3. Access to all the Global Variables of the report or function module which we are debugging.
4. Tab Layouts to easily access multiple information which is necessary while debugging. In
Classic debugging, to get to some of the information, we have to navigate through Menu
Options.
5. Advance features like Saving a test variants to functions modules while debugging, searching
for a particular entry inside a table while in debugging, option to get to the updated source code
being in debugging mode and few others.
6. More options while debugging Object Oriented code compared to Classic debugger.
Setting up a break-point or starting a debug session:
Option 1:
Program goes to debug mode when you enter /h in command prompt and then execute the report.
Option 2:
In the program place the cursor on a particular point where you want to debug and click on the
stop button on the top. When you execute, program will stop here in Debug mode.
Option 3:
Using BREAK-POINT command inside the code. This is mostly used by the developer, if you
are not the developer of that report, you cannot use this option.

Difference between the 2 Stop Buttons is, generally for debugging a report we use the one with
no human icon on it. STOP icon with human icon on it will be used only for External Debugging,
that is if your application is being called from out of SAP's current session. Example cases are:
1. If we are debugging a Webdynpro application which actually runs on an Internet Explorer
browser, we use the External Debugging button to put a break-point.
2. If we want to debug any Portal or PI Application Call, we use External Debugger.
This doesn't mean that you cannot use that for normal report debugging, we can set a break-point
using this button too for a normal debugging.
Also, for the below screen shots, I have configured my debug screen to show Code on the left
part of screen and the variables data on the right part of the screen, Actually this is the standard
layout, but you can change this layout to have 4 screens on a layout..
Once you are in Debug Mode,

On the left screen you will see the code and on the right screen you can see the values of the
variables at that point of the program. Like, if you see on the right side p_copy variable has value
001 at this point of the program execution.
Here, to debug step by step, we can use the buttons on the top of debugger screen which are,

If you want to go Step-by-Step either click on F5 or click on first button of above.


If you want to execute a complete step(Like a Function Module called in program without going
into the function module, click on second button or F6.
F7 is to come out of step. Like you have gone into a function module, now to come out of it
without going through the whole logic, use F7.
F8 can be used to come out of debugger and continue execution normally.
Using the above commands you can navigate through each point of the code and keep checking
the main variable which you think has an issue or the main variables which are shown in the
output of the report.
Important concepts to know while debugging:
1. One of the most helpful and used property of a debugger is, ability to change values of the
variable while in debugging. I can explain that in brief in below screen shots:

In the above screen shot, I am inside a Loop of an internal table, one of the field of that table has
a value of '01', as shown below

I have some code to check when that value becomes '02'(LI_CNODID_LINE-NODE_ID),

suppose I dont have test case for that, what I can do is click on that Pencil Icon next to that field
and you will see that field as input enabled and you can change the value of that field to 02 as
shown below,

If you see the above screen, that pencil icon changed to DISPLAY icon and the field is input
enabled. Once you change the value of that field you can just hit enter and the value gets
changed.
Most important point is, you would need authorizations to do that :), most of the functional
people will not be provided authorization to do that.
2. Setting up a break-point at a particular ABAP Command or a Statement. - If we know that
the program is failing at a particular command, we can use the below option to set the breakpoint at that particular statement instead of debugging through the whole code.
When you are in debugger mode and if you want to set a break-point at any of abap command
you can do it based on the navigation screen shot below.

On the right part of screen, if you see Tabs which say Variables1, Variables3, Locals and
Globals, in that Globals shows the list of values of all the variables used in that program at that
point of time.
We have some notes under help.sap.com too about the Classic and the New Debugger. Below is
the link for the same.

Creating watchpoints while debugging the ABAP


Code
Introduction:
Many times we have large number of rows into an internal table and we need to debug a
particular row say for a particular value of a field which is at 110th row of an internal table, in this
case it is very cumbersome to debug an internal table row by row to reach that particular row.
To avoid this we can set a watchpoint for the particular value of a field or variable.
As soon as a change is found in the content of the variable after a Debug step and any conditions
set have been met, the Debugger will stop and we see the message "Watchpoint is reached
(<Watchpointvariable>).
For example, there are 30 entries into the internal table as shown below. Let us see how can we
analyze the 21st record i.e. material number 000000000000000599?

Steps:
1.

Set a debugging point at the loop statement of the internal table, once the debugging screen
appears then press F5, an entry would appear in the workarea LS_MARA.

2.

Now keep the cursor on the field to which we want to set the watchpoint. In this example we
want to set watchpoint for the LS_MARA-MATNR.

3.

Press Create watchpoint button on the toolbar of the debugger screen as below.

4.

We will automatically have the variable field populated with the desired field as shown
below.

5.

Now enter the condition for which we want to set the watchpoint in the Free Condition Entry
Field.

6.

We want to set watchpoint against material number 000000000000000599, so we entered


value LS_MARA-MATNR = 000000000000000599 in above highlighted field Free
Condition Entry.

7.

The watchpoint will be created and we will have below message appeared in the status bar.

8.

Now press F7 to reach your desired record. We will get below message at the status bar of
the debugger screen:

9.

Now we will have the LS_MARA-MATNR = 000000000000000599 value in the workarea.


We can analyze the contents of the workarea for this material number directly, without
looking at all records in the internal table.

So in this way, we can set maximum 5 watchpoints.

Das könnte Ihnen auch gefallen