ABAP Debugging Techniques

March 17, 2018 | Author: Guru | Category: Subroutine, Areas Of Computer Science, Computer Programming, Computing, Technology
Share Embed Donate


Short Description

Guide to ABAP Debugging Techniques...

Description

SAP ABAP Debugging Techniques Author : Lalit Kabra Employee ID: 239602

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 1 of 12 Created by: Lalit Kabra TCS Confidential

ABAP Debugger The ABAP Debugger is an integrated test tool within the ABAP Workbench. We use it to check the program logic and to find errors in the source code of an ABAP program. In the Debugger, you can step through the source code of a program. The running program is interrupted after each step, allowing you to check its processing logic and the results of individual statements.

Features The Debugger provides an efficient means of identifying errors in ABAP programs. It contains the following functions: •

Displaying source code in the Debugger



Setting and deleting breakpoints



Setting and deleting watchpoints



Stopping a program at a particular statement or event



Displaying and changing field contents at runtime



Setting and deleting database locks



Opening the ABAP Editor, or Object Navigator



System settings and runtime warnings

Starting the Debugger There are two possible ways for starting the Debugger in the ABAP Workbench: •

Debugging without Breakpoint



Debugging with Breakpoint

Debugging without Breakpoint You can start the Debugger as follows: •

In SE80: Select a program or transaction and from the top menu choose Program → Test → Debugging.



In SE38: From the top menu choose Program → Execute → Debugging.



From any other screen: From the top menu choose System → Utilities → Debug ABAP Or Enter /h in the command field and press enter

Debugging with Breakpoints A breakpoint is a signal in a specific line of the program source code. This signal indicates to the ABAP runtime processor to stop the program at the relevant line and start the ABAP Debugger.

There are different ways to put break points: •

Hard coded / Static break points: You can put a breakpoint in our program by writing statement “BREAK-POINT” or “BREAK ”. Use “BREAK ” to stop the program execution when a specific user is executing the program.

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 2 of 12 Created by: Lalit Kabra TCS Confidential

Static breakpoints are not normally user-specific. Once a user has inserted the statement BREAK-POINT or BREAK name in an ABAP program, the system always interrupts the program at that point for that user or only for the user name. This procedure is only useful in the development phase of an application, when the program execution is always to be interrupted at the same place. Î Remove all hard coded breakpoints from your program before you transport it. •

Dynamic break points: We can put dynamic breakpoints from SE80 or SE38 or debugger. Dynamic breakpoints are always user-specific, and are deleted when you log off from the R/3 System.

Dynamic breakpoints are more flexible than static breakpoints, because you can deactivate or delete them at runtime. They have the following advantages: •

You do not have to change the program code



You can set them even when the program is locked by another programmer



You can define a counter that only activates the breakpoint after it has been reached

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 3 of 12 Created by: Lalit Kabra TCS Confidential



Setting Breakpoints from Debugger: We can set breakpoint at a specific statement, Subroutine, Function Module or Method Refer to the screen shot below for menu path. We can also set breakpoints at system exceptions; the debugger stops the program directly after a system exception, that is, after a runtime error has been intercepted

The statement “BREAK-POINT” without the addition ID causes an error in the extended program check. A breakpoint in SELECT - ENDSELECT loops can cause an exception through loss of the database cursor. The reason for this is that - during debugging - a database Commit is triggered. During background processing and during the database update, program execution is not interrupted. If you have a breakpoint that is always active, the system writes a "Breakpoint reached" entry into the system log during background processing and during updating. After this entry, the program name and the position of the breakpoint in the program are listed.

Watchpoints Like a breakpoint, a watchpoint is an indicator in a program that tells the ABAP runtime processor to interrupt the program at a particular point. Unlike breakpoints, however, watchpoints are not activated until the contents of a specified field change. Watchpoints, like dynamic breakpoints, are user-specific, and so do not affect other users running the same program. You can only define watchpoints in the Debugger.

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 4 of 12 Created by: Lalit Kabra TCS Confidential

You set watchpoints in the Debugger to monitor the contents of specific fields. They inform you when the value of a field changes. When the value changes; the Debugger interrupts the program. • • • •

You can set up to ten watchpoints in a program. You can also specify the conditions on which a watchpoint is to become active. You can specify logical conditions between up to five conditional watchpoints. You can define watchpoints as either local or global. If you define a global watchpoint, it is active in all called programs. Local watchpoints are only active in the specified program.



You can use watchpoints to display changes to the references of strings, data and object references, and internal tables. Setting Watchpoints

To set a watchpoint, start the Debugger and proceed as follows: 1. Choose Create watchpoint 2. Select local or global watchpoint. 3. Enter the program and the name of the field for which you want to set the watchpoint. In the Program field, the name of the program currently running is always defaulted. 4. If you want your watchpoint to be activated each time the contents of the field change, the definition is now complete, and you can return to the Debugger by pressing ENTER. 5. To create a conditional watchpoint, that is only activated when a particular situation arises. 6. You can use the Comparison field option to specify whether the comparison is to be carried out with a value that you specify or with the contents of another field. Depending on your choice from step 6, enter a value or a field for the comparison.

7. Checking all the breakpoints/watch points in the program. From here any watch point or break point can be activated/deactivated.

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 5 of 12 Created by: Lalit Kabra TCS Confidential

Stepping Through the Source Code in Debugging •

F5 (Single Step): Use this option to step through the program statement by statement.



F6 (Execute): Use this option to process a program line by line. All of the statements on the current line are processed in a single step. This allows you to process the whole program. This is mainly used to execute a Function Module or a Subroutine in a single step; without entering into the Function Module / Subroutine.



F7 (Return): The Debugger returns to the point at which control returns to the main program. We use this option to return from other programs or to return from a module or subroutine or a function module.



F8 (Run / continue): Use this option to process the program up to the next breakpoint. If there are no more breakpoints in the program, the system exits debugging mode and executes the rest of the program normally.

Processing Fields You can display / change the contents of various fields like variables, structures, internal tables etc at runtime in debugging mode

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 6 of 12 Created by: Lalit Kabra TCS Confidential

To view all fields of a structure double click on that structure.

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 7 of 12 Created by: Lalit Kabra TCS Confidential

Releasing Database Locks During Debugging, the COMMIT statement, which indicates the end of a Logical Unit of Work, may occur after a significant number of debugging steps. Any database locks that are set are maintained for the whole of this time There may be occasions when you want to interrupt your testing without actually ending the debugging session. In this case, you should release the database locks, otherwise other users will not be able to make changes until your debugging session is finished. To do this, choose Debugging → Database → Commit (unlock) to unlock the database and permanently write the changes to the database. Remember that this could, in certain circumstances, lead to database inconsistencies. If you want to undo all of the database changes that have been made since the last commit, choose Debugging → Database → Rollback.

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 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 Background Job You can do this only after the job has finished execution. This will simulate the exact background scenario with the same selection screen values as used in the job and sy-batch set to 'X'. Use SM37 to get list of jobs, type 'JDBG' in the command line (no '/’), put the cursor on the job and press ENTER.

You are in debug mode now. Step through SAP program (press F7 couple of times) until you get to code you need.

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 8 of 12 Created by: Lalit Kabra TCS Confidential

Debugging Modal Dialogs Programs Some time we have situations where we get a pop up window and we want to debug it, to do that follow the steps as given below. Create a txt file on the desktop with the following lines: [FUNCTION] Command=/H Title=Debugger Type=SystemCommand Drag and drop this file to the modal window to set debugging on.

Debugging SAPScripts Activate the ABAP debugger from in the form layout of SAP Script From the top Menu in SE71 go to System -- > Utilities --> Debug ABAP Then execute the print program and the script opens in the debug mode.

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 9 of 12 Created by: Lalit Kabra TCS Confidential

Debugging SMARTFORMS To debug a smart-form, one should place a hard-coded breakpoint (BREAK-) at the place where you want to debug. This will take you directly to the smartform. Please make sure to delete this hard coded break point before transporting to the next system.

Difference between Classical Debugger and New Debugger: Classical Debugger: 1.) In classical Debugger Debuggee and Debugger run in the same session. Debugger Dynpro is placed in between. 2.) Not all ABAP code can be debugged and some functions are restricted. 3.) The classical Debugger sessions are live in an internal session. These break points are no longer available if new internal session is created (e.g. SUBMIT, CALL TRANSACTION)

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 10 of 12 Created by: Lalit Kabra TCS Confidential

New ABAP Debugger: 1.) New ABAP debugger runs in the two separate sessions i.e. Debuggee and Debugger are in two different sessions. With this once can refer to the Input Screen any time during the debugging. Debuggee session is inactive and is only for display. 2.) More Robust Debugger Architecture. 3.) It has possibility to implement new features faster and with less risk. 4.) New debugger is more flexible and extensible state of the art debugger UI. 5.) Upto 4 parallel visible instances of a tool can be opened. (e.g. Compare 4 internal tables). 6.) In the New ABAP Debugger breakpoints are live in external sessions. 7.) The new ABAP Debugger Provides 9 Desktops: Three user specific desktops, which can be customized and can be saved as favorite debugger environment. Six Standard desktops, which should cover most of the common working conditions in the debugger.

• • • • • •

Standard: Stepping Through the code (Editor, Stack, Quick Watch). Structures : Compare Structures Tables : Compare Tables Objects : Compare Objects Detail Dispels : Compare Strings, Simple Fields. Breakpoints: Maintain the Breakpoints.

There are some features which are better in Classical Debugger. So one can switch to classical debugger: To switch to classical Debugger from the debugger screen follow the path: Debugger >> Switch to Classical Debugger

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 11 of 12 Created by: Lalit Kabra TCS Confidential

References http://help.sap.com/ https://www.sdn.sap.com/

_______________________________________________________________________________________ SAP ABAP Debugging Techniques Page 12 of 12 Created by: Lalit Kabra TCS Confidential

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF