49
SAP document.docGuide SAP Debugging Guide Page 1 of 49

Debugging Concepts

Embed Size (px)

DESCRIPTION

Debugging Concepts

Citation preview

Page 1: Debugging Concepts

SAP document.docGuide

SAP Debugging Guide

Page 1 of 41

Page 2: Debugging Concepts

SAP document.docGuide

Contents

Debugger………………………………………………………………………………… 04

Debugging Techniques……………………………………………………………..…… 04 Starting the debugger…………………………………………………………..….. 04 Debugger’s Views……………………………………………………….……..…… 05 Debugger Screen…………………………………………………………..……….. 06 Breakpoint…………………………………………………………..…………………... .07 Static Breakpoint…………………………………………………………..………. 07 Dynamic Breakpoint…………………………………………………………..…… 07 When a static breakpoint is used?..…………………………………………..…… 07 When a dynamic breakpoint is used? ………………………………………….….07 Watchpoint……………………………………………………………...…….……. 07 When a watchpoint is used?…………………………………….…………………. 07 When to use watch points…………………………………………….......….……. 07 Key word (statement) or event breakpoints……………………….......….……... 08 When to use breakpoints at Keywords (statements) or Events….......….…….... 08

Setting Static Breakpoints…………………………………………….......….……….. .08Setting Dynamic Breakpoints……………………………………………......………... 08Setting Watchpoints………………………………………….……….......….…….….. 10Setting Breakpoints at (statements) keywords or subroutines…….......….……........ 12

Deleting Static Breakpoints………………………………….………........….…….…. 13Deleting Dynamic Breakpoints…………………….…………….……….......….……. 13Deleting Watchpoints………………………………………….……….......….…….… 14

Ways of viewing the code…………………………………….……….......….…….….. 15

Displaying the field contents…………………………………….……….......….……..17Displaying the Internal table…………………………………….……….......….……. 18A View of internal table display…………………………………….……...….……… 19Changing contents of fields and internal tables………………….……...….…….….. 19Changing Internal Tables at Runtime……………………………………....….…….. 20 Deleting a row…………………………………….……….......….……………….. 20 Editing a row…………………………………….…..…….......….……………….. 20 Adding a row…………………………………….……….......….………………….21

Debugging a BSP application using SICF tcode….……….......….……………….…..21

Debugging Tips and Tricks….……….......….……………………………......……...... 31

Page 2 of 41

Page 3: Debugging Concepts

SAP document.docGuide

Skip breakpoints…….......….………………………………………………..……….... 31Check sorting before READ BINARY SEARCH…………………………..………... 32System Debugging………………………………………………………………………. 34Update debugging………………………………………………………………………..36Debugging a Popup Window…………………………..………......................................36External breakpoints.…………………………..………................................................. 38Saving breakpoints.…………………………..………..................................................... 40

Page 3 of 41

Page 4: Debugging Concepts

SAP document.docGuide

Debugger

The Debugger is a programming tool that you can use to execute ABAP programs, by line or by section. With this tool, you can display data objects and check the flow logic of programs.

The ABAP/4 Debugger lets you stop a program during runtime and examine the flow and results of each statement during execution. Stepping through a program with the debugger helps you to detect and correct errors in your code.

Debugging Techniques

Starting the Debugger

On running a program in the debugging mode the following steps can be followed.

In the object browser , Select a report or transaction. Choose debugging in the ABAP/4 editor initial screen. Choose Program àExecute àDebugging or choose debugging.

From any screen, Choose SystemàUtilities àDebug ABAP/4.

Page 4 of 41

Page 5: Debugging Concepts

SAP document.docGuide

Debugger’s views

We can have different views in the debugger by selecting appropriate view name by Push-Buttons, in debugger.

These Push buttons have following specific meaning.

Overview - Displays the structure of the program to be debugged. Call stack - Displays an active event chain and the call sequence up to the

current breakpoint. Fields - Displays the field content and technical characteristics. Table - Displays the content of an internal table. Break-Points - Displays the Break-Points set in the program. Watchpoints - Displays the Watch-Points set in the program.

Page 5 of 41

Page 6: Debugging Concepts

SAP document.docGuide

DEBUGGER SCREEN

We can set breakpoints in a program and then start the program within the debugger. Alternatively, we can run the program in the debugger without any breakpoints.

Page 6 of 41

Page 7: Debugging Concepts

SAP document.docGuide

Breakpoint

A breakpoint is a signal that tells the debugger to temporarily suspend execution of your program at a certain point. When execution is suspended at a breakpoint, your program is said to be in break mode. Entering break mode does not terminate or end the execution of your program. Execution can be resumed at any time.

Following are the types of breakpoints.

Static

These are user specific, set directly into a program’s code with the editor. These breakpoints are user-independent.

Dynamic

Set within the ABAP/4 debugger or editor. This type is visible when the program is displayed in the editor. We can set up to 30 dynamic breakpoints.

When a static breakpoint is used?

Static break points are generally user-independent. On setting this breakpoint, every use who executes the program encounters the breakpoint. This is used when several developers are working in the same program, and all wants to the program to interrupt at the same place during execution. These breakpoints are visible in the programs code.

When a dynamic breakpoint is used?

Dynamic break point is user-specific. If we want to interrupt a program when we execute and while others are running, we use dynamic break-point. Dynamic breakpoints are more flexible than static breakpoint , they can be removed or deactivated during runtime.

Watch points

Set within the ABAP/4 debugger .Watch points are field-specific. This is used to observe changes to a particular field.

When to use watch points

We can set watchpoints only from within the debugger.The debugger interrupts the program when fields content change.

Key word (statement) or event breakpoints

Page 7 of 41

Page 8: Debugging Concepts

SAP document.docGuide

Set within the ABAP/4 debugger. The debugger interrupts the program when the ABAP/4 processor comes in contact with a specific key word (statement) or event in program’s code.

When to use breakpoints at Keywords (statements) or Events

From within debugger, we can allocate breakpoint for specific ABAP/4 keywords or events.

Setting Static Breakpoints

To set a static break point use ‘BREAK-POINT’ keyword.Place the break point on the line where to interrupt the program:

REPORT ZDEBUG.……………

IF SY-SUBRC NE 0. BREAK-POINT.ENDIF.

We can number breakpoints like BREAK-POINT1, BREAK-POINT2…,for identification.

Setting Dynamic Breakpoints

Place the cursor on the line where to position the breakpoint. Choose Utilities àBreakpoint àSet OR press the ‘stop’ pushbutton on the application tool bar.

Utilities àBreakpoint àSet/Delete.

Page 8 of 41

Page 9: Debugging Concepts

SAP document.docGuide

(OR)

STOP pushbutton on the Application tool bar.

Page 9 of 41

Page 10: Debugging Concepts

SAP document.docGuide

A display of all breakpoints in a program can be obtained by selecting UtilitiesàBreakpointàDisplay, in the ABAP editor.

Setting Watchpoints

On the Debugging editor, enter the table-field. Press the pushbutton ‘Watchpoint’ on the top left. A dialog box appears, asking for the ‘local watch point’, relational operator. Fill

in as per requirement. Fill the appropriate value in the Comparison field or value, as per preference in

the given check box or text field press the tick.

Page 10 of 41

Page 11: Debugging Concepts

SAP document.docGuide

A display of watch points can be viewed by Goto-->Control Debugging--> Watchpoint or by pressing ‘Watchpoint’ pushbutton in the ABAP editor.

Page 11 of 41

Page 12: Debugging Concepts

SAP document.docGuide

Setting Breakpoints at (statements) keywords or subroutines.

Choose either Breakpoint àBreakpoint at àStatement or subroutine or function module in the menu.

The system will display a small screen prompting to enter statement keyword or subroutine etc., as per selection in the menu.

Page 12 of 41

Page 13: Debugging Concepts

SAP document.docGuide

The system will set a breakpoint each time the statement or subroutine appears in the program.

For break point in form routines, it is possible to access the current program, not external subroutine calls.

Deleting Static Breakpoints

It is necessary to remove the breakpoints after debugging .Use function Utilities à Global search to help in locating break-points in larger programs.

Deleting a dynamic Break-point

To delete a dynamic breakpoint, place the cursor in a line and choose BreakpointàSet/Delete or Delete in the ABAP editor screen.

Page 13 of 41

Page 14: Debugging Concepts

SAP document.docGuide

Temporary deleting of Dynamic breakpoint is possible by selecting the appropriate line and select Breakpointà Deactivate/Activate in the ABAP Debugger’s menu bar.

Deleting Watchpoints

From the debugger’s menu bar ,

Page 14 of 41

Page 15: Debugging Concepts

SAP document.docGuide

Choose Goto à Control debuggingàWatchpoint or click ‘Watchpoint’ pushbutton in the editor.

A display of the watch points occurs, and can be deleted by pressing ‘delete’ checkbox at the end (last column) of each Watchpoint display.

Ways of viewing the code

F5 Single step: Execute a program statement by statement. If single step is chosen while on a line that calls a FORM routine, for example the next mouse

Page 15 of 41

Page 16: Debugging Concepts

SAP document.docGuide

click carries to the called routine. After stepping the way through the subroutine, returns to the line of code directly following the subroutine call.

F6 Execute: Process a program line by line. On choosing Execute while on a line, that calls a FORM routine, the debugger executes the subroutine subroutine and halts at the line of code directly following the call.

Thus this skips over the lines of the subroutine itself.

F7 Return: Returns the debugger to where a calling program resumes control. Can be used from within a subroutine call.

F8 Continue: Processes the program up to the next active dynamic or static break point. If no further breakpoints exist, the system executes the report in its entirety without stopping.

Page 16 of 41

Page 17: Debugging Concepts

SAP document.docGuide

Displaying the field contents:

While debugging, display of contents of the fields (up to eight fields) are possible.

This can be performed by selecting the ‘Fields’ Push button in the view options buttons.

Enter the field names directly in the spaces provided or double click the field in the code display and the system lists it as a variable automatically.

Deleting the fields are possible by an appropriate push button placed just above the field names table.

To display fields defined in the ABAP/4 Dictionary can be performed by defining the relevant table in the TABLES statement.

Additionally the contents of the fields from external programs can be displayed by placing the name of the external program in brackets in front of the field name.

Page 17 of 41

Page 18: Debugging Concepts

SAP document.docGuide

Displaying internal tables.

Within the debugger, we can display the contents of an internal table by choosing the ‘Table’ pushbutton.

The system displays the Table view with the table rows numbered.

Page 18 of 41

Page 19: Debugging Concepts

SAP document.docGuide

Specify a table name in the internal table field or double click on the table. If the internal table contains a header line, this line appears before the actual table contents.

A View of internal table contents display

Changing contents of fields and internal tables

1. Go to the variable display screen. This is the Debugger’s default view.2. Double click on a variable to place it in the variables display.3. Enter a new value in the field contents row.4. Choose the ‘Change field content’ button.

If we forget to click on the ‘Change field content’ push-button, the system ignores the values we entered.

Old Debugger:

Page 19 of 41

Page 20: Debugging Concepts

SAP document.docGuide

New Debugger:

Changing Internal Tables at Runtime

The debugger allows to manipulate the contents of an internal table during runtime. We can delete, edit or add a row to an internal table.

Deleting a row

To delete an entry from an internal table:1. Go to the table display screen2. Enter the table name in the internal table field.3. Choose Enter.

The system displays the table’s contents.4. Place the cursor on the line you wish to remove from the table.5. Press ‘Delete’ pushbutton.

The line disappears from the table and the system adjusts the line numbering accordingly.

Editing a row

1. Place the cursor on the row and field we want to edit.

Page 20 of 41

Page 21: Debugging Concepts

SAP document.docGuide

2. Choose Change.3. Enter a new value for the field.4. Choose Enter.The system updates the line and displays the new contents in the table.

Adding a Row

We can add a new row to an internal table by using either Append or the Insert function. Append places the new line at the end of the table. Insert lets us to position the line anywhere.

To add a new row to the end of the table, the following steps will do.1. Choose append.2. Enter a value for the first field in the line.3. Choose Enter.The system adds a line to the table and fills in the first field.

To insert a new line anywhere in the internal table, position the cursor on the line directly following the line where we want the new row to appear. Then, Choose Insert button and proceed as we want to append the line.

Debugging BSP using SICF transaction code:

Step1:

Go to Se80 ABAP Workbench.Choose BSP Application in the drop down and enter the name of the BSP application.

Page 21 of 41

Page 22: Debugging Concepts

SAP document.docGuide

Double click on .htm page which is under Pages with flow logic.At the bottom of the properties tab there is a field named URL. This is the link of the portal page.For this BSP application the link is: http://blade23.wipro.com:8000/sap/bc/bsp/sap/zbsp_download/first.htm

Page 22 of 41

Page 23: Debugging Concepts

SAP document.docGuide

Step2:

Go to SICF tcode and execute.

Page 23 of 41

Page 24: Debugging Concepts

SAP document.docGuide

Expand each node according to the link.That is default_host -> sap -> bc -> bsp.

Page 24 of 41

Page 25: Debugging Concepts

SAP document.docGuide

Now select bsp. Go to menu item Edit -> debugging -> activate debugging.

Page 25 of 41

Page 26: Debugging Concepts

SAP document.docGuide

Now we get a pop up. In this pop up screen check the field System debugging.Click on Activate.

Page 26 of 41

Page 27: Debugging Concepts

SAP document.docGuide

Step3:

Place an external breakpoint in the BSP application where ever necessary according to functionality.

Step4:

Now execute the URL. This can be done either by directly using internet explorer by entering the URL or by right clicking on .htm page and clicking on Test.

Page 27 of 41

Page 28: Debugging Concepts

SAP document.docGuide

Now the control goes to debugger. Now we can step into the code and check how the code is working. Accordingly changes can be made.

Page 28 of 41

Page 29: Debugging Concepts

SAP document.docGuide

On executing,

Page 29 of 41

Page 30: Debugging Concepts

SAP document.docGuide

This is how we can debug a BSP application.

After debugging is done, delete the external breakpoint and deactivate the debugger as shown below.

Page 30 of 41

Page 31: Debugging Concepts

SAP document.docGuide

Debugging Tips and Tricks

SAP provides a very powerful debugger, knowing all its features would make debugging fast.Below are a few.

Skip breakpoints

The new ABAP debugger gives an option to skip the first n occurrences of a breakpoint; this would be useful while debugging loops as we might want to skip the first n executions of the loop. Or the first n times a function module / subroutine is called. The below screen shot shows where we can enter the number of times the breakpoint should be skipped.

Page 31 of 41

Page 32: Debugging Concepts

SAP document.docGuide

Check sorting before READ BINARY SEARCH

Before delivering the code, we can use this option to make sure all internal tables are properly sorted before READ BINARY SEARCH is performed on them. If the table is not sorted a runtime error is generated. This ensures that the READ statement does not return incorrect results.

Path (old debugger): Settings tab

Page 32 of 41

Page 33: Debugging Concepts

SAP document.docGuide

Page 33 of 41

Page 34: Debugging Concepts

SAP document.docGuide

System Debugging

The System Debugging function enables the user to analyze system programs, in addition to application programs, using the Debugger. This function is called or terminated through the menu path Settings ® System Debugging On /Off. By selecting the menu Settings ® Save, this predefined setting is stored to the database and thus activated again each time the new Debugger is activated.

Page 34 of 41

Page 35: Debugging Concepts

SAP document.docGuide

In the program attributes we can designate a program as a System program. The debugger skips the program if the system debugging is turned off.

Page 35 of 41

Page 36: Debugging Concepts

SAP document.docGuide

We can also turn on system debugging by entering /hs in the command field in the debugger.

Update Debugging

Update function modules do not run in the same user session as the program that is currently running in the ABAP Debugger. These update functions are not called directly. They are part of an LUW that is executed after the next COMMIT WORK statement. These function modules are therefore not included in debugging. Only if you select the Update Debugging option can you display and debug them after the COMMIT WORK.

Debugging a Popup Window

Sometimes we might want to start debugging from a popup window / information message, in this case we cannot type „/h‟ as the “OK Code” box is not available.

Method 1: For this create a text file (say debugger.txt) on your desktop, and type the below lines into the file:

Page 36 of 41

Page 37: Debugging Concepts

SAP document.docGuide

[FUNCTION] Command=/H Title=Debugger Type=SystemCommand

Now drag the file onto the popup window / information message and debugging is enabled.

Method 2: From any SAP windows press the “Customize Local Layout” button (Alt + F12) and select “Create Shortcut…” in the window that appears make the below changes and click “Finish”. A file is generated on your desktop or SAP workspace. Now drag the file onto the popup window / information message and debugging is enabled.

Page 37 of 41

Page 38: Debugging Concepts

SAP document.docGuide

An icon with debugger name appears on your desktop.

External breakpoints

In order to debug ABAP code which is called via Portal or any external system you can need to follow a two step approach. Firstly enter the user ID using which you would login to the portal / HTTP application, this can be done in on of the workbench development utilities (SE38, SE37, SE80, etc) choose Utilities -> Settings -> Debugging -> External Debugging. Secondly set external breakpoint at the required position in the ABAP code using the Set/Delete External Breakpoints button. Now when the external application is run the ABAP debugger opens in a separate window.

Page 38 of 41

Page 39: Debugging Concepts

SAP document.docGuide

We can use debugging in order to carry out detailed troubleshooting. With the debugger, we check a given section of code in the Request Handler or an ABAP function module for errors.

Basically, there are two different types of debugging: With conventional debugging, we can analyze programs that we call up within

our own user session on the server, with breakpoints being set at corresponding points in the coding.

With external debugging, we can analyze programs that are called up by an external user with HTTP. For the purpose of external debugging, special breakpoints (external breakpoints) are set on the target server.

Page 39 of 41

Page 40: Debugging Concepts

SAP document.docGuide

Two variants are available for conventional debugging: the classical variant and the new (2-processor) variant, which creates a separate session for the debugger. At present, external debugging can only be performed with the classical variant.

Saving breakpoints

If you need to debug the same code again and have a set of breakpoints in place, you can create a Session to save the breakpoints and settings. Later this session can be loaded by any user, and the same set of breakpoints is restored. Path: New Debugger: Debugger -> Debugger Session -> Save Classic Debugger: Debugging -> Sessions

Page 40 of 41

Page 41: Debugging Concepts

SAP document.docGuide

Thank You

Page 41 of 41