Sie sind auf Seite 1von 41

ABAP Overview Training

v5.0

AGENDA 1. Introduction

2. Components of an ABAP Program / SAP Transaction


3. Introduction in to the ABAP Runtime environment and Debugging facilities

4. Examples / Exercises

v5.0

1. Introduction

Landscape: Database, Application and Presentation server Processes Data Dictionary Components of ABAP: Reports, Dialog Programming, SAP script / smartform, BDC and user exits Basic commands

v5.0

2. Components of an ABAP Program code


Purpose of that Chapter:

In order not to get lost in the coding you need to know Where

you are how a program is structured and how to navigate in it


To make the debugging more efficient, it is necessary to learn how to debug only the relevant parts of the program and to skip

unimportant parts.
This is a small repetition from ABAP basic programming, Please note that we will not discuss all details of all Program

components.

v5.0

2. Components of an ABAP Program code

All ABAP programs are modular in structure and made up of processing blocks. There are two kinds of processing blocks, those that are called from outside a program by the ABAP runtime system, and those that can be called by ABAP statements in ABAP programs.

Source Code Modules


Programs and Program includes Program Macros

Procedures
Form routines Function Modules

v5.0

2. Components of an ABAP Program code


Source Code Modules: When you modularize source code, you place a sequence of ABAP statements in a module. Then, instead of placing all of the statements in your main program, you just call the module. When the program is generated, the source code in the modularization unit is treated as though it were actually physically present in the main program. Source code modules help you to avoid repeatedly writing the same set of statements and to make your programs easier to read and understand. They are not used to modularize tasks and functions. You should use procedures for this purpose. ABAP contains two kinds of source code modules: Local modules are called macros, and cross-program modules are called include programs.

v5.0

2. Components of an ABAP Program code


MACROS
If you want to reuse the same set of statements more than once in a program, you can include them in a macro. For example, this can be useful for long calculations or complex WRITE statements. You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition.

DEFINE <macro>. <statements> END-OF-DEFINITION.

v5.0

2. Components of an ABAP Program code Include Programs


Include programs are global R/3 Repository objects. They are solely for modularizing source code, and have no parameter interface They have the following functions: - Library: Include programs allow you to use the same source code in different programs. For example, this can be useful if you have lengthy data declarations that you want to use in different programs. - Order. Include programs allow you to manage complex programs in an orderly way. Function groups and module pools use include programs to store parts of the program that belong together. The ABAP Workbench supports you extensively when you create such complex programs by creating the include programs automatically and by assigning them unique names. A special include is the TOP include of a program. If you name it according to the naming convention, it is always included in program navigation and in the syntax check.

v5.0

2. Components of an ABAP Program code


Procedures
Procedures contain a set of statements, and are called from other ABAP programs . ABAP contains the following kinds of procedures: Subroutines: Subroutines are principally for local modularization, that is, they are generally called from the program in which they are defined. You can use subroutines to write functions that are used repeatedly within a program. You can define subroutines in any ABAP program. Function Modules: Function modules are for global modularization, that is, they are always called from a different program. Function modules contain functions that are used in the same form by many different programs. They are important in the R/3 System for encapsulating processing logic and making it reusable. Function modules must be defined in a function group, and can be called from any program. Methods: Methods describe the functions and behavior of classes and their instances in ABAP Objects. Methods must be defined in classes. When you call them, you must observe certain special rules of object-oriented programming. You can call procedures either internally or externally. If you call procedures externally, it is important that you understand how memory is organized in the R/3 System, how screens are processed, and how interface work areas are used.

v5.0

2. Components of an ABAP Program code

Defining Subroutines
A subroutine is a block of code introduced by FORM and concluded by ENDFORM.
FORM <subr> [USING ... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ] [CHANGING... [VALUE(]<pi>[)] [TYPE <t>|LIKE <f>]... ]. ... ENDFORM.

<subr> is the name of the subroutine. The optional additions USING and CHANGING define the parameter interface.

Calling Subroutines
You call subroutines using the statement
PERFORM... [USING ... <pi>... ] [CHANGING... <pi>... ].

Subroutines can call other subroutines (nested calls) and may also call themselves (recursive calls). Once a subroutine has finished running, the calling program carries on processing after the PERFORM statement. You can use the USING and CHANGING additions to supply values to the parameter interface of the subroutine.

10

v5.0

2. Components of an ABAP Program code

Function Modules:
Function modules are procedures that are defined in function groups (special ABAP programs with type F) and can be called from any ABAP program. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder. Function modules allow you to encapsulate and reuse global functions in the R/3 System. They are stored in a central library. The R/3 System contains a wide range of predefined function modules that you can call from any ABAP program. Function modules also play an important role in data base updates and in remote communications between R/3 Systems or between a R/3 System and a non-SAP system. Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer.

11

v5.0

2. Components of an ABAP Program code

To call a function module, use the CALL FUNCTION statement:


CALL FUNCTION <module> [EXPORTING f1 = a 1.... f [IMPORTING f1 = a 1.... f [CHANGING f1 = a 1.... f [TABLES f1 = a 1.... f [EXCEPTIONS e1 = r 1.... e [ERROR_MESSAGE = r E] [OTHERS = ro]]. n n n n n = = = = = a a a a r n] n] n] n] n

12

v5.0

3. Introduction in to the ABAP Runtime environment and Debugging facilities


Purpose of that Chapter:

After that Chapter you should know / know how to perform:

How to start the Debugger To name the components and the functionality of the ABAP debugger How to step trough / navigate the coding (during a debugging session) How to display the content of variables / internal tables How to change the content of variable / internal tables How to set Break points

How to set Watch points

13

v5.0

3. Introduction in to the ABAP Runtime environment and Debugging facilities


How to start the Debugger Start from any point you are by typing /h in the command field (Except: SAP displays currently a popup window )

From Transaction SE38:


- Enter the Program name

- Press the debugging button


- Disadvantage: The debugger will show the handling of the selection screen.

14

v5.0

3. Introduction in to the ABAP Runtime environment and Debugging facilities


How to start the Debugger From Transaction SE80
1. Enter the program name and check Program and click Display
3. Click on Debugging in Execution Type Popup.

Advantage:
2. Put the cursor on the program name an press the execute button Debugging starts directly in the program event processing

15

v5.0

3. Introduction in to the ABAP Runtime environment and Debugging facilities


Components of the ABAP Debugger
Navigation trough the coding Creation of watch points

Creation of watch points

Navigation trough the coding Switch to the internal table display Next Program step to be executed Currently active ABAP Program Include in which the current coding is located

Program Coding line number

Delete all variables from


List of variables for which the content should be analysed

Scroll trough the list of variables

Important System Variables


16
v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities


Display Modes of the ABAP Debugger: Fields:
The scrollable field display can display the contents of up to eight fields. It also always contains the values of the three most important system fields. This is the default display mode in the Debugger.

Table:
The Displays the contents of an internal table. You can also edit the contents of the table in this mode

Break points:
Scrollable display containing up to 30 breakpoints. You can also delete breakpoints from the display, and set a counter for each one.

17

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities


Display Modes of the ABAP Debugger: Watch Points:
The scrollable field display can display the contents of up to eight fields. It also always contains the values of the three most important system fields. This is the default display mode in the Debugger.

Calls (Call stack):


Displays the active sequences of events and calls up to the current breakpoint. The last call is displayed at the top of the list, with previous calls below. As soon as an event (such as STARTOF-SELECTION) is finished, it disappears from the list..

Overview:
Displays the structure of the program. This display contains the events, subroutines, and modules in the program, and shows which section of code belongs to which event. The section currently being processed is displayed

18

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities


Display Modes of the ABAP Debugger: Setting:
Displays the current Debugger settings. You can change these using the checkboxes

19

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities


Navigation trough the coding There are four different ways of stepping through program code in the Debugger: Single step:
Use this option to step through the program a statement at a time. This is particularly suitable when you want to look into subroutines and function modules, since this method steps through them as well as the main program. After processing a subroutine or function module, the Debugger returns to the statement in the main program that follows the call.

Execute:
This option processes a program a line at a time. All steps in the same line are processed together. If you are positioned on a line that calls a subroutine and choose Execute, the system executes the subroutine and proceeds directly to the next line in the main program, bypassing the statements in the subroutine.

Return:
Returns to the position at which a calling program regains control. Use this option when you are debugging a subroutine or function module and want to return to the program that called it.

Continue
Use this option to process the program up to the next breakpoint (dynamic or static) or up to the cursor position. If there are no more breakpoints in the program and you have not set a cursor, the system processes the remainder of the program and ends the debugging session.

20

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Displaying Field content:
In the Fields display mode in the Debugger, you can display, and also change, the contents of up to eight program fields. This is the default display mode in the Debugger.

Procedure:
From any display mode in the Debugger, choose Fields. Enter the field names, either directly in the input fields, or by double-clicking the field name in the source code display. The system automatically enters the field name in the display. Step through the program to analyze the coding.

21

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Displaying Field content:
Displaying Other Fields
The field display only has space for four fields. However, you can use the scroll buttons to display other fields.

Displaying System Fields


This mode allows you to display the contents of system fields or fields defined in the program. The three most important system fields (SY-SUBRC, SYTABIX, and SY-DBCNT) are always displayed.

Displaying Fields From External Programs


You can also display the contents of fields from external programs as long as you know the program name. Enter the program name in parentheses before the field name.

Changing the Display Format


You can display the field contents with their normal formatting or in hexadecimal form.

Use this button to display the field contents in hexadecimal form


Use this button to display the field contents in their normal output format.

Deleting All Field Names


Use this button to delete all of the field names from the field display.

22

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Displaying Internal Tables :
The Debugger allows you to display and change the contents of simple or nested internal tables. The table display mode also allows you to find out information about the table type, table key, or memory use of an internal table. Procedure: 1. 2. 3. 4. From any display mode in the Debugger, choose Goto => Table or press The table display mode appears. In the Internal table field, enter a table name (or double-click the name of an internal table in the source code display). Choose ENTER . Step through the program to analyze the source code.

23

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities


Displaying Internal Tables :
Header Line If the internal table has a header line, this is indicated by the hat icon. Double-click the icon to go to the Structured field display. This displays the component names, their current contents, and the technical attributes of the table structure. Scrolling Vertically The table lines are numbered. The fist column of the display heading is an input field in which you can enter the line of the table that you want to display. You can also use the normal scrolling keys to scroll page by page. Scrolling Horizontally Use the scrolling buttons to scroll through the internal table horizontally if the table is too wide to display on the screen. You can also shift the column headings Shifting Column Headings You can rearrange the order in which the fields are displayed by shifting the column headings. Simply overwrite the existing headings with the sequence that you want. You can remove a field from the display by deleting its heading from the display header. If you enter an incorrect name, the system displays a row of question marks. If there is insufficient room to display the whole field, the system truncates the display and indicates this with the "<" character. Shifting Columns to the Left When you double-click a column heading, the table display shifts to the left. Any columns that appear to the left of the chosen column disappear from the display. To redisplay them, use the buttons for horizontal scrolling. Displaying the Table Type The Type field next to the table name contains the type of the internal table - standard, hashed, or sorted. Changing the Display Format As in the field display, you can also change the display format for internal tables. The Format field usually contains the value E (for display in output format). You can replace this with the value X (for hexadecimal display) or C (for character display). Resizing the Table Extract Use this button next to the format field to expand the amount of the internal table that is displayed. The display switches to 3 lines of ABAP code, with the rest of the display taken up with the internal table. Use this button to reduce the amount of the internal table that is displayed. The display switches to 5 lines of the internal table, with the rest of the display taken up with ABAP code. Displaying Memory Use To display the amount of memory occupied by the internal table, choose Goto => More screens => Memory usage.
24
v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Changing the Values of Fields at Runtime:
While you are debugging a program, you might want to change the content of specific fields to influence your program's flow. For example, suppose your debugging session reveals that a field contains a wrong value. The Debugger allows you to replace the wrong value with a correct one. You can now see whether the program works properly when the field values are correct. You can change the values of all fields, database tables (with offset), and internal tables referenced in a program. The system displays a message to notify you of any format errors.

Procedure
1. 2. 3. 4. Switch to field display mode. Double-click a field to place it in the field display. The field is displayed with its current value. Enter a new value for the field contents. Choose the pencil icon at the end of the line. Result

The Debugger writes the new value into the program field(s), and records the change in the system log. If you forget to click on the pencil icon, the system ignores the values you entered. The Debugger records the values exactly as you enter them. You must therefore make sure that you use the correct format (upper/lowercase, left-justified input for hexadecimal numbers).

25

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Changing Internal Tables at Runtime:
The Debugger allows you to manipulate the contents of an internal table during runtime. You 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 screen. 2. Enter the table name in the Internal Table field. 3. Choose ENTER . The system displays the contents of the table. 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.

26

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Changing Internal Tables at Runtime: Editing a Row
The functions Modify, Insert, and Append are field-specific in the Debugger. You can only apply them to one field at a time. For example, if you want to edit the following line: bukrs gjahr rjahr belnr buzei |1500 |2002 |2002 |5110000727|001 rblnr rbuze |5105603189|000001|

you first need to decide which field to change. Then, do the following: 1. Place the cursor on the row and field you want to edit.

2. Choose Change. The system displays one field of the chosen row in the input mode.
3. Enter a new value for the field. 4. Choose ENTER . The system updates the line and displays the new contents in the table.

27

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Changing Internal Tables at Runtime: Adding appending a Row:
The Insert and Append functions allow you to add new lines to an internal table. Append places the new line at the end of the table. Insert lets you position the line anywhere. To add a new row to the end of the table: 1. 2. 3. 4. Choose Append. Enter a value for the first field in the line. Choose ENTER . The system adds a line to the table and fills in the first field. 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 you want the new row to appear. Then, choose the Insert button and proceed as you would if you wanted to append the line.

28

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Breakpoints


As well as running a program from the beginning in the Debugger, you can also set a precise point in the program at which the Debugger is called by setting one or more breakpoint. A breakpoint is a signal from the ABAP program to the runtime processor to interrupt processing and start the Debugger. As an alternative to breakpoints, you can set watch points. Watch points activate the Debugger when the contents of a selected field change. For further information, refer to Watch points Static
To set a static breakpoint, enter the ABAP statement BREAK-POINT directly in the program code. Normally user-independent, they can also be made user-specific. These are set in the ABAP Editor or the Debugger, and are displayed as stop signs. Unlike static breakpoints, they are always user-specific, and are deleted when you end your terminal session. This special form of dynamic breakpoint is set in the Debugger. The Debugger interrupts the program immediately before the specified statement is executed. This form of dynamic breakpoint is set in the Debugger. The Debugger interrupts the program immediately before the event, subroutine, or module pool is called. The Debugger interrupts the program immediately before a function module is called. The Debugger interrupts the program as soon as a system exception occurs, that is, when a runtime error is caught by a CATCH statement.

Dynamic breakpoints set directly Statement breakpoint

Event breakpoint

Breakpoints at function modules Breakpoints at system exceptions

29

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Dynamic Breakpoints
Dynamic breakpoints are user-specific. You should therefore use them whenever you want to interrupt a program without affecting other users. When you log off from the R/3 System, all of your dynamic breakpoints are automatically deleted. Dynamic breakpoints are more flexible than static breakpoints, since you can delete or deactivate them at runtime. This has the following advantages: You do not have to change the source code You can set them even if other developers are blocking the program that you are testing You can set a counter (for example, only activate the breakpoint when it is reached for the fifth time)

30

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Dynamic Breakpoints
You can set up to 30 dynamic breakpoints without having to change the source code of your program. You can set them either in the ABAP Editor or directly in the Debugger:

Setting Dynamic Breakpoints in the ABAP Editor


In the ABAP Editor, you can set dynamic breakpoints in either change or display mode. You can also set breakpoints at runtime directly within the Debugger. To set a dynamic breakpoint in the ABAP Editor: Place the cursor on the line of code at which you want to set the breakpoint. Choose Utilities => Breakpoint => Set. The system confirms that the breakpoint was set. It is displayed as a stop sign to the right of the program code. You can display a list of all dynamic breakpoints in a program by choosing Utilities => Breakpoints => Display. The dynamic breakpoint display lets you navigate to a certain breakpoint or delete one or all breakpoints from your program code.

1. 2.

Setting Dynamic Breakpoints in the Debugger


1. 2. Place the cursor on the line where you want to set the breakpoint. Select the line either by choosing Breakpoint => Set/delete or by double-clicking. The system sets a breakpoint at the line and places a small stop to the left side of the line indicating a breakpoint. If the line already contains a breakpoint, the system deletes it. When you finish your debugging session, your breakpoint will be deleted unless you have explicitly saved it.
v5.0

31

Introduction in to the ABAP Runtime environment and Debugging facilities Special Dynamic Breakpoints
Special dynamic breakpoints are useful whenever you want to interrupt a program directly before a particular ABAP statement, subroutine, or event, but you are not sure exactly where that statement, subroutine or event occurs. Special dynamic breakpoints are user-specific, and can only be set in the Debugger.

Breakpoint at ABAP Statement


1. Choose Breakpoint => Breakpoint at => Statement. 2. The following screen appears

1. Enter the ABAP statement. 2. Choose ENTER . The system sets a breakpoint in all liens containing the given statement. The system confirms the breakpoint and adds it to the breakpoint list. When you end your debugging session, the breakpoint is deleted automatically unless you save it explicitly.

32

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Breakpoints at Subroutines, Events, Modules
These special dynamic breakpoints allow you to interrupt a program directly before a subroutine, event, or module is called.

Procedure
1. 2. Choose Breakpoint => Breakpoint at => Event/Subroutine. The following dialog box appears:

1. 2.

Enter the subroutine, module, or event before which you want to interrupt the program. Choose ENTER.

The system sets a breakpoint immediately before all calls to the subroutine, module or event.

Result
The system confirms the breakpoint and adds it to the breakpoint list. If the subroutine, module, or event does not exist in the program, the system displays a message and does not set the breakpoint

33

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Breakpoints at Function Module Calls
These dynamic breakpoints allow you to interrupt a program directly before a particular function module is called.

Procedure
1. Choose Breakpoint => Breakpoint at => Function module The following dialog box appears:

2. Enter the function module before which you want to interrupt program processing. The system sets a breakpoint each time the function module appears in the program. 3. Choose ENTER . If you entered a function module that exists in the system, the system confirms the breakpoint and adds it to the breakpoint list.

34

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Breakpoints at System Exceptions
This special form of dynamic breakpoint allows you to interrupt a program immediately after a system exception has occurred (Short dump).

Procedure
Choose Breakpoint => Break point at => System exception.

Result
The system confirms the breakpoint and adds it to the breakpoint list. When a system exception is triggered, a warning triangle icon appears in the line that caused it. Double-click the icon to display the ID of the runtime error.

35

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Watch points
Watch points, like breakpoints, provide a signal from the program to the ABAP runtime processor to interrupt processing at a particular point in the program. Unlike breakpoints, watch points only activate the Debugger when the contents of a field change. Like dynamic breakpoints, watch points are user specific, that is, they do not affect other users who are running the program at the same time You can only set watch points in the Debugger.

Use
You can set watch points in the Debugger for specific fields. They allow you to determine when the contents of a certain field change. The Debugger interrupts the program as soon as the field contents change.

Features

36

You can set up to five watch points in a program. You can also specify conditions that have to be met before a watch point becomes active. You can define a logical relationship between up to 5 conditional watch points. See also Specifying Logical Relationships Between Watch points. You can define watch points as either local or global. Local watch points are only active in the current program. Global watch points are valid in the current program and in any other programs that it calls. You can change watch points. You can delete watch points.
v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Setting Watch points
Use watch points when you want to interrupt a program when the contents of a field or structure change. You can set up to five watch points. Watch points can be either local or global. Local watch points are only active in the current program. Global watch points are active in the current program and any programs that it calls. You set watch points in the Debugger.

Procedure
1. Choose Breakpoint => Create watchpoint. The following dialog box appears:

2. 3. 4.

5. 6.
37

Decide whether you want to create a local or a global watch point. Enter the name of the field for which you want to set the watch point. If you want your watch point to be activated each time the field contents change, you have now entered all of the necessary information, and can return to the Debugger by choosing ENTER . The watch point now appears in the watch point list. If you want to specify conditions for the watch point, continue with step 5. To create a conditional watch point, choose one of the following relational operators:
v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Setting Watch points
To create a conditional watch point, choose one of the following relational operators:

Operator Meaning
= or eq Equal <> or ne Not equal

< or lt
<= or le > or gt

Less than
Less than or equal Greater than

>= or ge Greater than or equal

38

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Specifying logical Conditions between Watchpoints
If you create more than one conditional watchpoint, you can link them using a logical operator: OR: only one of the conditions must be met. AND: All conditions must be met.

Procedure:
To establish a logical relationship between watch points: Open the watch points list by choosing Goto => Watch points. Set the Logical operator option. The default is always OR.

39

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Changing a Watchpoint
1. Choose Goto => Watch points to display the watch points.

2.

Click the pencil icon in the line containing the watch point that you want to change. The following dialog box appears:

1. 2.

Change the attributes of the watch point Choose ENTER .

40

v5.0

Introduction in to the ABAP Runtime environment and Debugging facilities Deleting Watch points
You cannot use Breakpoint => Delete or Breakpoint => Deactivate/ activate to deactivate or delete a watch point. Instead, you must: 1. 2. Choose Goto => Watch points to display the watch points. Click the trashcan icon in the line containing the watch point that you want to delete

41

v5.0