Documente Academic
Documente Profesional
Documente Cultură
ABAP Language
Login to SAP System
What is SAP transaction code?
First ABAP Program
ABAP Data Types and Constants
ABAP Variables
ABAP System Variables
Basic Operations
Control Statements
Loops
String Operations
ABAP Language
ABAP stands for Advanced Business Application Programming. It is a programming
language developed by SAP.
Chained statements.If consecutive statements have identical part at the beginning, then
ABAP allows you to chain these statements into a single statement. First write the
identical part once and then place a colon (:). Then write the remaining parts of the
individual statements separated by commas.Normal Statements:
WRITE 'Hello'.
WRITE 'ABAP'.
Chained Statement:
Comments.If you want to make the entire line as comment, then enter asterisk (*) at the
beginning of the line.
T coDe description
SE11 ABAP Data Dictionary
SE16 Data Browser
SE37 Function Builder
SE38 ABAP Editor
SE41 Menu Painter
SE51 Screen Painter
SE71 SAP Script Layout
SE80 ABAP Workbench
SE91 Message Maintenance
SE93 Maintain Transaction
This is the screen where you can write the ABAP code.
Successful syntax check message will be displayed in the status bar. Then activate( Ctrl + F3 )
the program.
In the following screen select your program and press continue. Then run(F8) the program.
ABAP Data Types and Constants
Data Type describes the technical characteristics of a Variable of that type. Data type is just
the blue print of a variable.
Structured data type is grouping of several simple data types under one name.
Use the keywords BEGIN OF and END OF to create a structured data type.
Constants
Constants are used to store a value under a name. We must specify the value when we declare a
constant and the value cannot be changed later in the program.
ABAP Variables
ABAP Variables are instances of data types. Variables are created during program execution
and destroyed after program execution.
While declaring a variable we can also refer to an existing variable instead of data type. For that
use LIKE instead of TYPE keyword while declaring a variable.
Structured Variable
Similar to structured data type, structured variable can be declared using BEGIN OFand END
OF keywords.
We can also declare a structured variable by referring to an existing structured data type.
Each individual field of the structured variable can be accessed using hyphen (-). For example,
name field of the house_address structure can be accessed using housing_address-name.
Character is the default data type.
The complete list of ABAP system variables is found in the SYST table in SAP. Individual fields
of the SYST structure can be accessed either using SYST- or SY-.
Output
Basic Operations
Assigning values to ABAP variables
Use = or MOVE keyword to assign a value to a variable.
DATA: a TYPE i,
b TYPE i,
c TYPE i,
d TYPE i.
a = 10.
b = a.
MOVE 20 TO c.
MOVE c TO d.
WRITE:/ a, b, c, d.
Output
DATA: a TYPE i,
b TYPE i,
c TYPE i,
d TYPE i.
*Using Keywords
add 10 to a.
subtract 5 from b.
multiply c by 2.
divide d by 2.
Output
DATA: a TYPE i,
b TYPE i.
a = 10 + 20.
b = 20 - 10.
clear: a, b.
WRITE:/ 'After Clear'.
WRITE:/ a, b.
Output
Control Statements
To control the flow of the ABAP program use the following statements.
IF Branching Conditionally
IF statement The code between IF and ENDIF is executed only if the condition is true.
DATA: a TYPE i VALUE 10. " We can assign a value in the declaration
IF a > 5.
WRITE:/ 'Condition True'.
ENDIF.
Output
IF-ELSE statement The code between IF and ELSE is executed if the condition is true, the
code between ELSE and ENDIF is executed if the condition is False.
IF a > 5.
WRITE:/ 'Condition True'.
ELSE.
WRITE:/ 'Condition False'.
ENDIF.
Output
IF a > 5.
WRITE:/ a, 'Greater Than', 5.
ELSEIF a > 4.
WRITE:/ a, 'Greater Than', 4.
ELSEIF a > 3.
WRITE:/ a, 'Greater Than', 3.
ELSE.
WRITE:/ a, 'Less Than', 3.
ENDIF.
Output
CASE a.
WHEN 3.
WRITE:/ a, 'Equals', 3.
WHEN 4.
WRITE:/ a, 'Equals', 4.
WHEN OTHERS.
WRITE:/ 'Not Found'.
ENDCASE.
Output
Loops
DO ENDDO Unconditional Loop
DO can be used to execute a certain lines of codes specific number of times.
DO 5 TIMES.
WRITE sy-index. " SY-INDEX (system variable) - Current loop pass
ENDDO.
Output
WHILE ENDWHILE Conditional Loop
WHILE can be used to execute a certain lines of codes as long as the condition is true.
Output
After continue the control directly goes to the end statement of the current loop pass ignoring the
remaining statements in the current loop pass, starts the next loop pass.
DO 5 TIMES.
IF sy-index = 2.
CONTINUE.
ENDIF.
WRITE sy-index.
ENDDO.
Output
If the condition is false, the control directly goes to the end statement of the current loop pass
ignoring the remaining statements in the current loop pass, starts the next loop pass.
DO 5 TIMES.
CHECK sy-index < 3.
WRITE sy-index.
ENDDO.
Output
After EXIT statement the control goes to the next statement after the end of loop statement.
String Operations
CONCATENATE Combines 2 or more strings into one string.
WRITE / result1.
WRITE / result2.
Output
If the the concatenated string fits in the result string, then the system variable sy-subrc is set to 0.
If the result has to be truncated then sy-subrc is set to 4.
Output
If all target fields are long enough and no target fields has to be truncated then sy-subrc is set to
0, else set to 4.
SEARCH Searches for a sub string in main string. If found then sy-subrc is set to 0, else set to
4.
DATA: string(30) VALUE 'SAP ABAP Development',
str(10) VALUE 'ABAP'.
Output
REPLACE Replaces the sub string with another sub string specified, in the main string. If
replaced successfully then sy-subrc is set to 0, else set to 4.
Output