You are on page 1of 83

Simple ABAP/4 for trouble shooting

May 25th, 2004

Objectives:

Understand and get an idea on what ABAP/4 programming does, and what is the component in ABAP workbench

Get to know common statement, understand the ABAP program logic roughly.

Able to do the basic investigation when facing the problem.

Content

Introduction R/3 Basis system overview ABAP/4 overview


Component, Program, ABAP dictionary, Function Module , Message/Transaction code, etc.

Common Statement / Command


- Main event in ABAP program - General ABAP command

Transportation for ABAP objects Type of problem and how to investigate


Program bug, ABAP runtime error, Update terminate, Unexpected error message.

Introduction R/3 Basis system overview


R/3 user R/3 user R/3 user

Presentation component

ABAP Workbench

R/3 Basis system

R/3 R/3 Application 1 ... Application N

Kernel & Basis services

Database Management System

Database

Content

Introduction R/3 Basis system overview ABAP/4 overview


Component, Program, ABAP dictionary, Function Module , Message/Transaction code, etc.

Common Statement / Command


- Main event in ABAP program - General ABAP command

Transportation for ABAP objects Type of problem and how to investigate


Program bug, ABAP runtime error, Update terminate, Unexpected error message.

ABAP/4 overview

Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object

Often used transactions

SE80 - Repository Browser: Used to display and edit hierarchical lists of


development objects.

SE11 - Dictionary : Used to define and save data definitions You can also store
documentation, help information, data relationships, and other information. You also use the Dictionary to generate database objects like tables and indexes. The Dictionary is a central storage area for system-wide data definitions. Because definitions are stored centrally, they are available for use anywhere in any program throughout the system

SE38 - ABAP editor : Create/edit/Display program code SE37 - Function Builder : define and store function modules, use the library to
write new modules and look up information on existing modules

Often used transactions (cont)

SE51 - Screen Painter : Used to design the screens in an application's


graphical user interface.

SE41 - Menu Painter : Used to design the menus that appear in your
interface

SE16 - Data browser : Display data in Transparent table or Database view


SM30 -

Table maintenance : Maintain data

ABAP/4 overview

Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object

What is ABAP/4 program?

ABAP/4 : Advance Business Application Programming Type of ABAP/4 program


1 I M F S Executable program(Report/Interface)
Can be started with transaction code/directly/background (via SE38 or SA38 - For example: RMCB0100 )

INCLUDE program
Can not run on its own, has been included in other program

Module pool
Processing step of screens, can be executed via transaction code or Menu function (For example: SAPMV45A - Sale order processing)

Function group
Contain function modules (SE37)

Subroutine pool
Externally-called subroutines

ABAP/4 overview

Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object

ABAP Dictionary
SE11 - Data dictionary

View Table Structure

Data element ABAP Dictionary

Domain

F4
Search help

Lock object

ABAP/4 overview

Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object

Function module

Function Module - ABAP/4 program: Include program - Special external subroutines (include) stored in a central library - Different from normal ABAP routine is the clearly defined interface for passing data to and from the function module. The calling program and the called function module have separate work areas

- Located in Function group (main program start with SAPLxxxx)


- Can be tested separately in SE37 - Statement in ABAP to call function module are: - CALL FUNCTION xxxxx

ABAP/4 overview

Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object

Message

There are several different types of message: W - Warning (Correction possible) E - Error (Correction required) S - Success (message on next screen) I - Information (press Enter to continue) A - Abend (Transaction terminated) X - Exit (Terminated with short dump)

Note :

Transaction code for message maintenance is SE91, Table store the message text is T100, language dependent. ABAP key word - MESSAGE

ABAP/4 overview

Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object

Transaction code

Transaction code is:


Sequence of alphanumeric characters forming a code for business task.

Transaction type: Dialog transaction - Flow by sequence of screens (for example FB03) Report transaction - Start program with type 1 (for example MCBA) Variant transaction - (client specific) start another transaction with variant
(for example UPAR)

Area menu - Menu which contain the group of frequently-used transactions


(for example S001)

Parameter transaction - pre-assign values in the initial screen and


suppress the screen when transaction is executed (for example OB22)
Note : All transactions are stored in table TSTC, Maintain via SE93

ABAP/4 overview

Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object

Authorization in ABAP object

Program authorization Transaction code Table maintenance/Data browser

Program authorization group

Authorization group is field of the authorization objects S_DEVELOP (program development and program execution) and S_PROGRAM (program maintenance). This field contains the name of a program group that allows users to
y execute programs y schedule jobs for background processing y maintain programs y maintain variants

When creating a program, you can specify an authorization group as one of the program attributes. This allows you to group together programs for the purposes of authorization checking.

Transaction authorization group

Authorization object in transaction code will be checked whenever the transaction is started. The following object will be checked S_TCODE(Authorization check for transaction start ) The authorization checks defined by the developer with transaction SE93 (transaction maintenance) or in the ABAP/4 source code continue to be performed. Field to be checked is TCD: Transaction code

Table maintenance/Data browser

Authorizations for displaying or maintaining tables. The object only controls access using the standard table maintenance tool (SM31), enhanced table maintenance (SM30) or the Data Browser (SE16), including access in Customizing. Object S_TABU_DIS -Table Maintenance (via standard tools such as SM31) will be checked for the following fields: Authorization group for DD objects: Authorization for tables by authorization class according to table TDDAT. (Using SM31 to display the authorization group table) Activity: Allowed operations. Possible values are: - 02: Create, change or delete (Maintain) table entries - 03: Display table entries only

Content

Introduction R/3 Basis system overview ABAP/4 overview


Component, Program, ABAP dictionary, Function Module , Message/Transaction code, etc.

Common Statement / Command


- Main event in ABAP program - General ABAP command

Transportation for ABAP objects Type of problem and how to investigate


Program bug, ABAP runtime error, Update terminate, Unexpected error message.

Common Statement / Command

Topics: Event in ABAP/4 program


- Dialog module - Executable program (Selection screen, lists)

ABAP statement and Keyword

Event in ABAP/4 program


Event in Dialog Module
PBO Module. Module xxxx Module yyyy PAI Module Module aaaa PBO Module. Module bbbb Module xxxx Module yyyy PAI Module PBO Module. Module aaaa Module Module xxxx bbbb Module yyyy PAI Module Module aaaa Module bbbb

100
Transaction code has been requested from R/3 user

200 300

Dialog screen chain


PBO = Process Before Output PAI = Process After Input

Module pool

Question??

Common Statement / Command

Topics: Event in ABAP/4 program


- Dialog module - Executable program (Selection screen, lists)

ABAP statement and Keyword

ABAP statement and Keyword

Statement
The ABAP programming language consists of the following element types: STATEMENT, KEYWORD, COMMENT. An ABAP program consists of individual ABAP statements. Each statement begins with a keyword and ends with a period. There might be comment in the same line as a statement For example:
PROGRAM ZTEST.

WRITE Hello world.

In this case program ZTEST will generate the list consist of line Hello world.

ABAP statement and Keyword(cont)

Keywords
Declarative keywords :
define data types or declare the data objects

Modularization keywords : define processing blocks in an ABAP program Event keyword :The respective processing blocks are processed as Define keyword: define processing blocks that are processed as
soon as a particular event occurs soon as they are called by an explicit statement in an ABAP program or in a screen flow logic

Control keywords: control the flow of an ABAP program according to certain


conditions

Calling keywords: call processing blocks (defined by modularization


keywords) in the same or other ABAP programs or branch completely to other ABAP programs

Expression and Operation keywords: Process the data

ABAP statement and Keyword(cont)

Declarative keywords
TYPES create user-defined elementary data types and structured data types Example TYPES: surname(20) TYPE C. DATA define local/global variable for structure/internal table/memory block address Example DATA: BEGIN OF address, OCCURS 0 address_number(10) TYPE C, street(30), country LIKE T001-LAND1, END OF address. TABLES create a data object called a table work area refer to ABAP dictionary(tables, structure,view) Example TABLES: KNA1, KNB1. CONSTANTS declare it as a fixed value variable Example CONSTANTS: name(10) VALUE Exxon Mobil Internal table structure

ABAP statement and Keyword(cont)

Modularization keywords
Event define keywords INITIALIZATION AT SELECTION-SCREEN START-OF-SELECTION GET <table> END-OF-SELECTION TOP-OF-PAGE END-OF-PAGE AT LINE-SELECTION AT USER-COMMAND Before selection screen is displayed After input selection screen + selection screen is active After process selection screen when logical DB offer a line of database table After all selection has been done Process when new page is started Process when page is ended When user select line in the list When user press function key/enter command in command field

ABAP statement and Keyword(cont)

Modularization keywords (cont)


Process define key word for statement block FORM...ENDFORM Define subroutine

FUNCTION...ENDFUNCTION Define Function module MODULE...ENDMODULE After process selection screen

ABAP statement and Keyword(cont)

Built in function
Arithmetic & string function ABS SIGN Amount (absolute value) x von x Sign of x; SIGN( x ) = 1 if x>0 SIGN( x ) = 0 if x=0 SIGN( x ) = -1 if x<0 Smallest integer value that is not less than x Largest integer value that is not greater than x Interger part of x Decimal part of x String length

CEIL FLOOR TRUNC FRAC STRLEN

ABAP statement and Keyword(cont)

1. SELECT statements 2. SAP tables vs. Internal Tables 3. LOOP-ENDLOOP 4. WRITE statements 5. Comment in ABAP 6. Expressions and Operations in ABAP 7. Subroutines: FORMS, FUNCTION MODULE

ABAP statement and Keyword(cont)

SELECT statement to read table entries (records) from a table (database) the return code is stored in system field SY-SUBRC - 0: if one or more table entries were retrieved - 4: if no table entries were retrieved (table is empty/ no data match the criteria)

ABAP statement and Keyword(cont)

SELECT statement
 For selecting 1 or more records from a table:

SELECT * FROM <dbtab> Additions . . . WHERE <condition> . . . ORDER BY PRIMARY KEY . . . ORDER BY <f1> <f2> . . . <fn>

ABAP statement and Keyword(cont)

SELECT statement
 For selecting individual columns from a table:

SELECT <f1> . . . <fn> INTO (<h1> . . . <hn>) FROM <dbtab> . . .

 For selecting a single record from a table:

SELECT SINGLE * FROM <dtab> WHERE <condition>.

( full key )

ABAP statement and Keyword(cont) SELECT statement


 For excluding duplicates:

SELECT DISTINCT <f1> <f2> . . . <fn> INTO (<g1> <g2> . . . <gn>) FROM <dbtab> . . .
 Aggregate expressions:

SELECT

AVG( <f1> ) COUNT( DISTINCT <f1> ) COUNT( * ) MAX( <f1> ) MIN( <f1> ) SUM( <f1>

FROM <dbtab> . . . INTO (<g1> . . . <gn>)

ABAP statement and Keyword(cont)

SAP Table

Two dimensional matrix describing relationship in database system Components:


Table fields Foreign keys Technical Settings Indexes

ABAP statement and Keyword(cont)

Internal Table One way to process large quantities of data in ABAP Internal table is a dynamic sequential dataset in which all records have the same structure and a key The data is taken from a fixed structure, stored line by line in the memory

ABAP statement and Keyword(cont)

Internal Table Declaration <No header line> TYPES: BEGIN OF T_T001K, BWKEY LIKE T001K-BWKEY, BUKRS LIKE T001K-BUKRS, END OF T_T001K. DATA: IT_T001K TYPE T_T001K OCCURS 0.

ABAP statement and Keyword(cont)

Internal Table Declaration <With header line> DATA: BEGIN OF IT_T001K OCCURS 0, BWKEY LIKE T001K-BWKEY, BUKRS LIKE T001K-BUKRS, END OF IT_T001K. WITH HEADER LINE

ABAP statement and Keyword(cont)

SAP --> Internal table Allows us to get contents of table and put it into internal table SELECT <field1> <field2>.. <fieldn> FROM <table> INTO TABLE <internal table> WHERE <condition>

ABAP statement and Keyword(cont)

LOOP Command To perform looping operation in the flow logic Four kinds of loops in ABAP: Unconditional loops using the DO statement Conditional loops using the WHILE statement Loops through internal tables and extract datasets using the LOOP statement Loops through datasets from database tables using SELECT statement

ABAP statement and Keyword(cont)

DO Command
DO <n> TIMES.

statements

ENDDO.

SY-INDEX

Loop index

ABAP statement and Keyword(cont)

WHILE Command
WHILE <logical expression>.
statements

ENDWHILE. SY-INDEX Loop index

WHILE COUNTER > 0. . . . SUBTRACT 1 FROM COUNTER. ENDWHILE.

ABAP statement and Keyword(cont)

LOOP Command Example

LOOP AT IT_T001K. WRITE: / IT_T001K-BWKEY. ENDLOOP.

ABAP statement and Keyword(cont)

WRITE Command The basic ABAP statement for displaying data on the screen WRITE <f> <AT position(length)> <option> <AS CHECKBOX> <AS SYMBOL> <AS ICON> <AS LINE>

ABAP statement and Keyword(cont)

WRITE Command
<OPTION> behind the WRITE statement is for formatting options E.g. : ..NO-ZERO, NO-SIGN, No GROUPING, DD/MM/YY, LEFT-JUSTIFIED, CENTERED, RIGHT-JUSTIFIED The most commonly used options: CURRENCY w to treat the content of field <f> as a currency amount with w as a currency key DECIMALS d to determine number of decimals to be displayed UNIT u to format the value according to the unit specified in the field u. The content of field <f> is treated as a quantity.

ABAP statement and Keyword(cont)

WRITE Command Example

WRITE: / Write. WRITE: it_bseg-dmbtr CURRENCY it_bkpf-hwaer. WRITE: text-t01 LEFT-JUSTIFIED.

ABAP statement and Keyword(cont)

Comment Written between statements of the ABAP program to explain its purpose to a reader / for internal documentation Helps to understand and change the program Flagged by special character: Asterisk (*) entire line to be a comment Double quotation mark () part of a line to be a comment Ignored by the system

ABAP statement and Keyword(cont)

Comment example * Write Sales Order number to the screen Write: Sales Order : , 20 it_vbak-vbeln. Sales Order Number

ABAP statement and Keyword(cont)

Expression & Operation Relational Operator String Comparison Logical Expression If/Case/Check Statement Exit/Continue Statement

ABAP statement and Keyword(cont)

Relational Operator

Display
EQ = NE <> >< GT > GE >= => LT < LE <= =<

Meaning
Equal to Not equal to Greater than Greater than or equal to Smaller than Smaller than or equal to

DATA: START TYPE D, SUM1 TYPE F, BETWEEN f1 and f2 SUM2 TYPE P. IS INITIAL . . . IF START IS INITIAL ... . IF SUM1 GT SUM2 ... . IF SUM1 ... . BETWEEN 0 AND 100

Interval Initial value

ABAP statement and Keyword(cont)

String Comparison
<f1> CO <f2> contains only: f1 contains only characters from f2 ACCOUNT CO '0123456789' <f1> CA <f2> contains any: f1 contains at least one character from f2 contains string: f1 contains the string f2 'DE' contains pattern: f1 corresponds to the model f2 Model: * any string + any character # escape symbol '*B+D*'

<f1> CS <f2> 'ABCDE' CS <f1> CP <f2>

'ABXDE'

CP

ABAP statement and Keyword(cont)

Logical Expression 1. AND 2. OR 3. NOT


COUNTER GE 0

COUNTER GT 0 AND FLAG IS INITIAL

( FLAG1 NE SPACE OR FLAG2 NE SPACE ) AND COUNTER BETWEEN 0 AND 100 COUNTER EQ 0 AND NOT ( FLAG1 EQ SPACE AND FLAG2 EQ SPACE )

ABAP statement and Keyword(cont)

IF <logical expression>.

IF Statement

statements

ENDIF. IF <logical expression>.


statements

ELSE. ENDIF.

statements

IF <logical expression>.
statements

ELSEIF <logical expression>.


statements

ELSEIF <logical expression>.


statements

ELSE.
statements

ENDIF.

ABAP statement and Keyword(cont)

CASE statement
Execute different statement blocks depending on the contents of particular data fields WHEN OTHERS: contents of <field> does not equal to any of the <value?> contents
CASE <field>. WHEN <value1>.
statements

WHEN <value2>.
statements

WHEN <value3>.
statements

WHEN OTHERS.
statements

ENDCASE.

ABAP statement and Keyword(cont)

CHECK statement
1

CHECK <logical expression>. CHECK within a loop structure. WHILE COUNTER GT 0.

Within Loop: to terminate loop pass conditionally

statements

CHECK FLAG NE SPACE.


statements

ENDWHILE. 2 CHECK outside loop structures.


statements

CHECK <condition>.
statements

ABAP statement and Keyword(cont)

Terminate loop entirely without any condition Terminate a subroutine without any condition

EXIT. 1 EXIT within a loop structure. DO ...


statements

IF COUNTER GE 100. EXIT. ENDIF.


statements

ENDDO. EXIT outside loop structure.


statements

IF ... . EXIT. ENDIF.

statements

ABAP statement and Keyword(cont)

CONTINUE.

DO 100 TIMES.

Terminate loop pass immediately without any condition

statements

IF SY-INDEX GE 10 AND SY-INDEX LE 20. CONTINUE. ENDIF.


statements

ENDDO.

ABAP statement and Keyword(cont)

PROGRAM RSDEMO01. Call calculate_tax . . . Subroutine Calculate_tax PROGRAM RSDEMO02. . . . Call calculate_tax . . . PROGRAM RSDEMO03. . . . Call calculate_tax
Function module

Avoid redundancy Modularization: easy to read easy to call


PROGRAM RSDEMO04. Subroutine SUB1 Subroutine Calculate_tax ABAP/4 function library

Function module Calculate_tax

ABAP statement and Keyword(cont)

Define FORM <name> [<parameters>]. <statement block> ENDFORM. Calling internally PERFORM <name> [<parameters>]. Calling external subroutine PERFORM <name>(program name) <parameters> [IF FOUND]

ABAP statement and Keyword(cont)

form f_check_file_exists using filename. ............. endform.

Parameters: p_path like rlgrap-filename. .............................. perform f_check_file_exists using p_path.

Content

Introduction R/3 Basis system overview ABAP/4 overview


Component, Program, ABAP dictionary, Function Module , Message/Transaction code, etc.

Common Statement / Command


- Main event in ABAP program - General ABAP command

Transportation for ABAP objects Type of problem and how to investigate


Program bug, ABAP runtime error, Update terminate, Unexpected error message.

Transportation of ABAP objects

Type of ABAP object


In Workbench organizer, there are several ABAP objects which are transportable Object In Transport request contain the following key

PgmID: Program Id in request and task, normally there are 2 types for ABAP objects R3TR - name for R/3 Repository objects and Customizing objects LIMU - enables transport of R/3 Repository object components Obj: Object type (for example, DOMA, DTEL, FORM, PROG..) Object name: Name of the each object Funct.: Function D,K,M ObjStatus: LOCKED,ERR_IMP,OK_IMP and OK_GEN

Transportation of ABAP objects (cont)

Version management serves different purposes and user groups:


- The developer can keep track of his or her work ("What have I changed?") - The developer can restore a previous version by reactivating it. - The system administrator can monitor work ("Which objects were changed and how were they changed in a specific time interval?") - It provides the basis for the auditor, who requires a complete history of changes. - It enables customers to adjust data with the help of the system after upgrading to a new Release.

Transportation of ABAP objects (cont)

ABAP object Version compare


ABAP program Transaction code SE38, Under menu Utilities-->Version management Function module Transaction code SE37, Under menu Utilities-->Version management Data Dictionary Transaction code SE11, Under menu Utilities-->Version management Object Browser Transaction code SE80, Go to specific object and under menu utilities, Version management Workbench Organization Transaction code SE09, under menu Environment

Transportation of ABAP objects (cont)

ABAP object Version compare


From Version management, you can 1. Display the object in other version 2. Compare the object in 2 versions 3. Retrieve the content of older version 4. Remote compare with another system 5. Display Transport Request

Content

Introduction R/3 Basis system overview ABAP/4 overview


Component, Program, ABAP dictionary, Function Module , Message/Transaction code, etc.

Common Statement / Command


- Main event in ABAP program - General ABAP command

Transportation for ABAP objects Type of problem and how to investigate


Program bug, ABAP runtime error, Update terminate, Unexpected error message.

Type of problem & How to investigate

Type of problems ABAP Runtime Error


Cause: Program error, system exception, database process error, etc. Using transaction code ST22 to analyze error.

Unexpected message Update Terminate


Cause: Update module can not be completed

Program bug
Cause: Written code is not correct

ABAP Runtime error - Analysis


Error ID

Date and time

Double click to display detail

Unexpected message

How to deal with unexpected message? 1. Go to Message long text if available. 2. Read through the section in the message help text, process where appropriate. Message help text component Diagnosis System response Procedure 3. Find the message location, the logic that drive the message appearance. Debugging Use Where used list function to find out the code where message is located (Not applicable for dynamic call)

Unexpected message (cont)


How to debug and locate the message in the program? 1. Debugging Set Debugger ON In Debugging screen, Set dynamic breakpoint on command Message Select debugging -> Continue (F8) When program reach MESSAGE command, cursor will be stopped Check the above logic before get into the current command, see the related data/value from debugging screen.

2. Using Where used list Function in message workbench SE91/SE80 When message is displayed, Double click on the status bar(if the message appear only in status bar , not popup) OR press F1 for popup message. Go to transaction code SE91/SE80 to find the location of the message call.

Update terminate

Update terminate: Message/SAP internal mail will be sent to the transaction owner, either Error message Or ABAP runtime error (short dump) might be created.

Analyzing the error Go to transaction code SM13 to analyze the update error. (Or Select Tools --> Administration --> Monitoring --> Update) Go to detail in update modules, You will get the following information: Where the error occurred: Program name, function module, line number and error text. (go to ABAP short dump Or Editor to locate the position) Why the error occurred:

Program bug

Analyzing the error 1. Find out what went wrong. 2. Locate the position in the ABAP program How to find the right place? 1. Debugging 2. Use Call Hierarchy (SE48) 3. Use find function in ABAP editor

Simple Debugging

How to:
Switch on the debugger. Set and delete static and dynamic breakpoints. Set Watch points. Stop a program at specific key words or events or when a fields 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 the debuggers six different views.

Simple Debugging

Start debugging:
/h Start the debugger in Normal mode. Press enter to start. /hs Start the Debugger in System mode, for example, in order to debug the system program (program with type S) Appropriate menu options under system -> Utilities -> Debug ABAP Break-points Command. SE38 Start of programs in the debugging of transaction code SE38 SM50/SM51 via debugging menu SE80 - Object browser

Simple Debugging

Set and delete static and dynamic breakpoints Static break-point


Command BREAK-POINT. Or BREAK <User name>

Dynamic break-point
In ABAP Editor SE38 --> Utilities --> Breakpoints --> Display/Set
In Debugging mode Place the cursor on the statement Choosing break-point -> Set/Delete

At ABAP command At Event/Subroutine At Function module System exception

Simple Debugging

Stepping
Single step (F5) Execute (F6) Return (F7) Continue (F8)

Display mode
Field : Display content of fields up to 8 fields Table: Display content of internal table Watchpoints: Manage watchpoint during debug mode Calls : Display Call stack up to current statement (in sequence) Overview: structure of program, display event, sub routine, module and current statement

Simple Debugging

Caution when debugging in Production system


Since only a restricted number of dialog work processes can be switched to debugging mode, you should leave the debugger as soon as possible when you have finished working with it. Otherwise, the work process is not released for other users

Question ??

You might also like