Professional Documents
Culture Documents
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.
Content
Presentation component
ABAP Workbench
Database
Content
ABAP/4 overview
Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object
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
SE41 - Menu Painter : Used to design the menus that appear in your
interface
ABAP/4 overview
Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object
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
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
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 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)
ABAP/4 overview
Topics: Often used transactions What is ABAP/4 program? ABAP dictionary Function Module Message Transaction code Authorization in ABAP object
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.
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
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
100
Transaction code has been requested from R/3 user
200 300
Module pool
Question??
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.
In this case program ZTEST will generate the list consist of line Hello world.
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
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
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
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
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
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)
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>
SELECT statement
For selecting individual columns from a table:
( full key )
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>
SAP Table
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
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.
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
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>
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
DO Command
DO <n> TIMES.
statements
ENDDO.
SY-INDEX
Loop index
WHILE Command
WHILE <logical expression>.
statements
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>
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.
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
Comment example * Write Sales Order number to the screen Write: Sales Order : , 20 it_vbak-vbeln. Sales Order Number
Expression & Operation Relational Operator String Comparison Logical Expression If/Case/Check Statement Exit/Continue Statement
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
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*'
'ABXDE'
CP
( 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 )
IF <logical expression>.
IF Statement
statements
ELSE. ENDIF.
statements
IF <logical expression>.
statements
ELSE.
statements
ENDIF.
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.
CHECK statement
1
statements
CHECK <condition>.
statements
Terminate loop entirely without any condition Terminate a subroutine without any condition
statements
CONTINUE.
DO 100 TIMES.
statements
ENDDO.
PROGRAM RSDEMO01. Call calculate_tax . . . Subroutine Calculate_tax PROGRAM RSDEMO02. . . . Call calculate_tax . . . PROGRAM RSDEMO03. . . . Call calculate_tax
Function module
Define FORM <name> [<parameters>]. <statement block> ENDFORM. Calling internally PERFORM <name> [<parameters>]. Calling external subroutine PERFORM <name>(program name) <parameters> [IF FOUND]
Content
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
Content
Program bug
Cause: Written code is not correct
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)
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
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
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
Question ??