7120983-16-Debugging-Techniques.ppt

37
Debugging

Transcript of 7120983-16-Debugging-Techniques.ppt

Page 1: 7120983-16-Debugging-Techniques.ppt

Debugging Debugging

Page 2: 7120983-16-Debugging-Techniques.ppt

Debugging Debugging

Program ... . Breakpoint ... .

ABAP/4 Editor

ABAP/4 DebuggerABAP/4

Debugger

Debugging

Program B170D051

Breakpoints

Object List

Development object ... ... ...

. . .Test/execute. . .

Any screen

... ... ... System Help

. . .Utilities. . .

. . .Debug ABAP/4. . ./h

Branching to Debugging Mode

Page 3: 7120983-16-Debugging-Techniques.ppt

Debugging Mode

PROGRAM B170D051.DATA: DIFF TYPE P,

.

.

.COMPUTE DATE_1 = SY-DATUM.

.

.

.

Execute Single step Execute Continue Table

DATE_1 00000000

SY-DATUM 19940223

Variables

X R

R

R

R

R

O S V F T P

View pushbuttons

Debugging Debugging

Page 4: 7120983-16-Debugging-Techniques.ppt

The Most Important Debugging Functions

Single Step Processes the next program line.

Execute In contrast to the single step, executesall processing steps belonging to one line.

Continue

Table

Processing continues until the next breakpoint oruntil the end of the program.

Displays the contents of internal tables.

Breakpoint With the functions of this menu youdefine breakpoints.

Editor You go to the ABAP/4 editor.

Hexadecimal-display

Data contents can be displayed in hexedecimal format.

Debugging Debugging

Page 5: 7120983-16-Debugging-Techniques.ppt

Setting Breakpoints

Menu

Keyword

Utilities -> Breakpoints

BREAK-POINT

Line selection (double-click)

Menu: Breakpoint -> Set/deleteGoto -> Breakpoints

ABAP/4 Editor

Debugging mode

11

22

Debugging Debugging

Page 6: 7120983-16-Debugging-Techniques.ppt

Other Debugger Features

Replace Field ContentsReplace Field Contents

Display/Change Internal Table EntriesDisplay/Change Internal Table Entries

Display Output List Display Output List

Switch to ABAP/4 EditorSwitch to ABAP/4 Editor

Database ReleaseDatabase Release

Activate/Deactivate BreakpointsActivate/Deactivate Breakpoints

Debugging Debugging

Page 7: 7120983-16-Debugging-Techniques.ppt

A detailed explanation of ABAP/4 Debugging.

The slides for the ABAP/4 Development Workbench’s on line Debuggers Contain the following topics, •Online debugging tools.•Starting the debugger•The debugger’s six views•Using break points•Setting static break points•Setting dynamic break points•Setting watch points•Setting breakpoints at keywords or events•Deleting and deactivating breakpoints•Stepping through program codes•Displaying field contents

Debugging Debugging

Page 8: 7120983-16-Debugging-Techniques.ppt

•Displaying Internal tables•Displaying ABAP/4 lists•Replacing field values at runtime•Changing internal tables at runtime•Switching to the ABAP/4 Editor•Releasing the database during debugging

Online debugging tools : A review

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.This documentation is designed for developers new to the Workbench’s debugging facilities or for those who want to learn the tool to use the tool more effectively.

Debugging Debugging

Page 9: 7120983-16-Debugging-Techniques.ppt

After working through this slides , you should be able to debugg both familiar and unfamiliar programs effectively. With this slides, you will learn how to

Switch on the debuggerSet and delete static and dynamic break points.Set watch pointsStop a program at specific key words or events or when a field contents change.Continue processing after an interrupt.Display field contents during runtime.Display the contents of an internal table.Change field contents for testing purposes.Change the contents of an internal table.Display and use debugger’s six different views.

Debugging Debugging

Page 10: 7120983-16-Debugging-Techniques.ppt

Debugging Strategies form within ABAP/4 Development Work bench. 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.

A Breakpoint is a signal within a line of code that tells the ABAP/4 runtime processor to interrupt the program at the line.Setting break points is a good strategy if we want to examine a program: After the system has already processed certain events Just before a specific event is carried out By skipping quickly to a specific routines or calls

Debugging Debugging

Page 11: 7120983-16-Debugging-Techniques.ppt

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 screenChoose Program Execute Debugging or choose debugging.From any screen , Choose SystemUtilities Debug ABAP/4.

Debugger’s six views

A debugger selects between six different views , by selecting appropriate view name in debugger’s menu. Or by pressing small push-buttons at right corner of each debugging screen.

Debugging Debugging

Page 12: 7120983-16-Debugging-Techniques.ppt

These buttons has following specific meaning.

O Overview - Displays the structure of the program to be debugged.S Call stack – Displays an active event chain and the call sequence up to the current breakpoint.V Variables – Displays the contents up to four fields or field strings.F Field display – Displays the fields content and technical characteristics.T Table Display – Displays the content of an internal table.P Programs –Displays all programs needed to run the report or transaction to be debugged, including system program

Debugging Debugging

Page 13: 7120983-16-Debugging-Techniques.ppt

Structure of the Debugging view.

Each debugging view has the same structure. The top half of the screen displays a portion of the programs source code. The lower half shows information specific to that particular view .Next to the Line Display appears two push buttons + sign and – sign , to scroll through the program code.

The line currently ready for processing is indicated by “>”.A small stop sign appears to the left of each dynamic break point .A red light appears at the bottom of screen after reaching a break point.If no breakpoints are present, the light is green.

Using Breakpoints

A breakpoint is a signal within a program’s code , which tells the ABAP/4 processor to interrupt the program at a particular point. The type of breakpoint depends on the purpose of debugging.

Debugging Debugging

Page 14: 7120983-16-Debugging-Techniques.ppt

Following are the types of breakpoints.

Static These are user independent , set directly into a program’s code with the editor. User dependent breakpoints also is possible.

Dynamic Set within the ABAP/4 debugger or editor. This type is invisible when the program is displayed in the editor.

Watch points Set within the ABAP/4 debugger .Watch points are field-specific. This is used to observe changes to a particular field .The debugger interrupts the program when fields content change. Only one watch point is possible at a time.

Debugging Debugging

Page 15: 7120983-16-Debugging-Techniques.ppt

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

When a static breakpoint is used? Static break point 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.

Debugging Debugging

Page 16: 7120983-16-Debugging-Techniques.ppt

When to use watch points.

We can set watchpoints only from within the debugger.They are useful if we want to interrupt a program only when there is a change in a particular field or a field string. We can set and remove watch points asNeeded .This , as dynamic breakpoint , does not disturb the other users of the same program.

When to use breakpoints at Keywords or Events.

From within debugger , we can allocate breakpoint for specific ABAP/4 keywords or program events.This is useful if we do not know exactly where a key word or event occurs , but still want the program to be interrupted just before the command or event is carried out.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:

Debugging Debugging

Page 17: 7120983-16-Debugging-Techniques.ppt

REPORT RSDEBUG1……………CHECK ACCOUNT

IF SY-SUBRC NE 0. BREAK-POINT.ENDIF.…….When we start the report , ABAP/4 interrupts the processing at the break point.We can number breakpoints like BREAK-POINT1 ,BREAK-POINT2..for easier identification.

Removing Breakpoints.It is necessary to remove the breakpoints after debugging .Use function Utilities Global search to help in locating break-points in larger programs. It is necessary to remove breakpoints since it may cause serious disruptions in productive process.

Debugging Debugging

Page 18: 7120983-16-Debugging-Techniques.ppt

Setting Dynamic Breakpoints We can set dynamic breakpoint , without changing the program’s code.Following are the steps to set a breakpoint in ABAP/4 Editor.

Place the cursor on the line where to position the breakpoint.

Choose Utilities Breakpoint Set.

A display of all breakpoints in a program can be obtained by selecting

UtilitiesBreakpointsDisplay function.

Debugging Debugging

Page 19: 7120983-16-Debugging-Techniques.ppt

Setting Watchpoints.

A watch point is set to interrupt a program when the contents of a specific field or a string change.Following are the steps to set a watch point.

Locate the field in the code.Place the cursor directly on the field.Choose ‘F’ for Field display. The debugger displays the field display view.The field view displays the field’s content and offers detailed information about its technical nature.Set the watch point checkbox to the right of fields name.Continue executing the program by choosing Continue.

Debugging Debugging

Page 20: 7120983-16-Debugging-Techniques.ppt

Displaying the current watchpoint.

Choose Goto Breakpoints .The system displays the breakpoint overview screen.

Setting Breakpoints at keywords or Events.

If we want to interrupt the program directly before a certain keyword, event or a subroutine , we use this facility.We can achieve this with the following steps.

Choose either Breakpoint Breakpoint at At event/FORM or Breakpoint Breakpoint atAt key word.

The system will display a small screen prompting to enter name event or keyword.

Debugging Debugging

Page 21: 7120983-16-Debugging-Techniques.ppt

The system will set a breakpoint each time the key word , event for subroutine appears in the program.For break point in form routines , it is possible to access the current program , not external subroutine calls.Choose OK.

To interrupt a program whenever the system return is not equal to zero, select Breakpoint Breakpoint atAt SY-SUBRC<>0.

Debugging Debugging

Page 22: 7120983-16-Debugging-Techniques.ppt

Deleting and Deactivating Breakpoints.

During the debugging process, the breakpoints in the earlier run need to be ignored.In case of static dynamic breakpoints it is flexible during runtime. In case of dynamic breakpoints, there are more possibilities of controlling it ,than static breakpoints.

Deactivating Static Breakpoints.Sataic breakpoints are hard coded directly into program using BREAK-POINT or BREAK. This is deactivated by deleting the BREAK-POINT or BREAK keywords.

Breakpoints and breakpoints at keywords and events.

Dynamic breakpoint are not written directly in the program’s code. It can be deleted or temporarily deactivated and reactivate breakpoints at keywords or events as the same way as dynamic breakpoints.

Debugging Debugging

Page 23: 7120983-16-Debugging-Techniques.ppt

Stepping through program code.

From within the debugger several options for stepping through the program.

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 click carries to the called routine.After stepping the way through the subroutine, returns to the line of code directly following the subroutine call.

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.

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

Debugging Debugging

Page 24: 7120983-16-Debugging-Techniques.ppt

To delete a dynamic breakpoint , place the cursor in a line and choose BreakpointSet/Delete all.Deleting this breakpoint is also possible by double clicking the appropriate line.

From within the editor, deleting the dynamic breakpoint is done by the following steps.

Choose UtilitiesBreakpointsDisplay.The System will list all the breakpoints.Select one or more breakpoint.Choose Delete individual .

Temporary deleting of Dynamic breakpoint is possible by selecting the appropriate line and select Breakpoint Deactivate/Activate.

Debugging Debugging

Page 25: 7120983-16-Debugging-Techniques.ppt

Deleting Watchpoints.Watch points are special break points set for specific fields. Only one watch can be set at a time.To remove a watch point , the following steps will do.

Choose F to enter the field display view.Choose Breakpoint Delete/Set watchpoint or turn the Watchpoint checkbox off.

Displaying the Location of breakpoints.

Select Goto Breakpoints to get an overview of all existing breakpoints in a program’s code.From the breakpoint display , it is possible to set or delete individual breakpoints.

Debugging Debugging

Page 26: 7120983-16-Debugging-Techniques.ppt

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

Displaying the field contents.

During the course of debugging , display of the contents of the critical fields used in the program.To display the field view contents, enter the variable view.This is the default Debugger view. It is possible to reach the variable view from any of the Debugger’s other five views by choosing V.

Display of the contents up to four fields or field strings possible can be done. We can 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.

Debugging Debugging

Page 27: 7120983-16-Debugging-Techniques.ppt

We can use the variable screen to display the contents of any system field or all field that a program references. Also the debugger to display fields defined in the ABAP/4 Dictionary can be used.To display the contents of dictionary fields, we must define relevant table in the TABLES statement of the current program.

Additionally the contents of the fields from external programs can be displayed.For this we need to place the name of the external program in brackets in front of the field name.

We can display the contents of the fields in either edited or hexadecimal format. To switch to the hexadecimal display, choose the small push-button directly following the value field. When the field is in hexadecimal, an X appears on this push-button. Other wise , the button is blank.We can always display a whole field string. To show only certain sections, specify the appropriate offset and length. In this case we can switch to the hexadecimal display in order to interpret packed values.

Debugging Debugging

Page 28: 7120983-16-Debugging-Techniques.ppt

Field contents and the most important attributes of a selected field or field string can also be displayed in the special field view screen.

Debugging Debugging

Page 29: 7120983-16-Debugging-Techniques.ppt

Displaying Internal tables.

Within the debugger , we can display the contents of an internal table by choosing the Table function.The system displays the Table view. 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 and is marked in the display by >>>>>>>.The table rows are numbered. We can scroll through the table display using the Index field or the scroll icons. If we want to see those parts of the tables that are not visible on the left or right of the screen , use the push buttons for horizontal scrolling or simply shift the title bar of the table.

Using the column header line, we can also change the sequence of the fields we want to see. If we remove a field name from the column header line, then the system deletes the field from the display. If we specify an incorrect field name, the system displays a string of question marks.

Debugging Debugging

Page 30: 7120983-16-Debugging-Techniques.ppt

If the space you leave to display a field is too small , the system truncates the display and indiates this by a “<” character.

As with the field display , we can customize the display format for internal tables. The standard entry in the Format field is an E (for edited) . You can change this to an X for hexadecimal or a C for character display.

Once we have finished examining the internal table , return to the screen with the field display and program code by selecting the program button.

Displaying ABAP/4 Lists.

If we are debugging an online report that generetes a list, we can display this list in the debugger. As soon as this list is started, the display list pushbutton appears. Choose Display list to switch to the list display. The system displays all the lines generated so far in their respective formats.

Note : The current list line is formatted only after completion (NEW-LINE).

Debugging Debugging

Page 31: 7120983-16-Debugging-Techniques.ppt

Replacing fields at Runtime.

While we are debugging a program , we might want to change the content of specific fields to influence our program’s flow. If error analysis reveals that a field contains a wrong value , for example , we can replace the faulty value at run time to determine if the program then runs correctly.

We can change the values of all fields , database tables (with offset) and internal tables referenced in a report . If we alter the values of database fields , we do not change them in the database itself , but only in the work area ABAP/4 provides for one run of the report .The system displays an appropriate message if any format errors occur.

Debugging Debugging

Page 32: 7120983-16-Debugging-Techniques.ppt

To replace the value , we can do the following steps.

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 second column of the variable display next to the appropriate field.4.Choose the R (Replace)button. ABAP/4 writes the new value back to the program field or fields and the system notes the change in the system log. If we forget to click on the ‘R’ push-button , the system ignores the values we entered.

Note: ABAP/4 accepts our entries in the contents column exactly as we specified them. You need to pay special attention to the correct format.( Upper or lower case , right justified output with packed numbers).

Debugging Debugging

Page 33: 7120983-16-Debugging-Techniques.ppt

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.Choose Delete.

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

Debugging Debugging

Page 34: 7120983-16-Debugging-Techniques.ppt

Editing a row

The functions Modify , Insert and append are field-specific in the Debugger and can be carried out only one field at a time.

For example ,If we want to edit the following line:

LH001 FRANKFURT NEWYORK 145400 400 X,

we first need to decide which field to change.

Then the following steps must be done.

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

2.Choose Modify.

3.Enter a new value for the field.

4.Choose Enter.

The system updates the line and displays the new contents in the table.

Debugging Debugging

Page 35: 7120983-16-Debugging-Techniques.ppt

.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.

4.Enter the remaining fields of the line by following the procedure for editing a row as described above.

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 Debugging

Page 36: 7120983-16-Debugging-Techniques.ppt

.Switching to the ABAP/4 Editor

We can switch from the Debugger to ABAP/4 Editor at any time. If we discover a program error during the debugging process , for example,we can enter the ABAP/4 Editor to immediately correct the error in the program’s code. We can also switch back to the editor in order to set new static break-points.

After we set static breakpoints in the editor,they are not active in the debugger when we switch back.We must re-generate the program.Then the breakpoints appear in the debugger.

To return to the Editor for the program currently being debugged ,

Select Development-->ABAP/4 Editor.

Debugging Debugging

Page 37: 7120983-16-Debugging-Techniques.ppt

.Releasing the Database during debugging

During debugging, the system normally suppresses the COMMIT statement. The COMMIT statement marks the end of a logical unit of work(LUW).

As a result , the system locks up the database for the course of that debugging session.

If we want to temporarily stop the program but do not want to end session,we should release the database that in use.If we forget to release this lock,no other user is able to modify data until we complete the test.To release the database explicitly during break in testing , choose

Debugging -->Database -->Commit.

To undo all changes made in the database since the last COMMIT select Debugging-->Database-->Rollback.

Debugging Debugging