ABAP

Code Statement

Each code statement starts with a keyword and end with a period. Example:

WRITE 'Hello world!'.

It will display Hello world!


Variables

Type Description Default value Example
C Characters Spaces
DATA myVariableName(5) TYPE C VALUE 'Haha!'.
WRITE myVariableName.
 
N Numeric text field '0...0'
DATA myVariableName(5) TYPE N VALUE '12345'.
WRITE myVariableName.
 
D Date field '00000000'
DATA myVariableName TYPE D VALUE '20101231'. "Format: YYYYMMDD
WRITE myVariableName.
 
T Time field '000000'
DATA myVariableName TYPE T VALUE '125959'. "Format: HHMMSS
WRITE myVariableName.
 
X Hexadecimal field X'0...0'
??????
 
P Packed number 0
??????
 
I Integer 0
DATA myVariableName TYPE I VALUE 2147483647.
WRITE myVariableName.
 
F Floating point number 0
DATA myVariableName TYPE F VALUE '1.01234567891234'.
WRITE myVariableName.
 
STRING String ?
DATA myVariableName TYPE STRING VALUE 'String has variable length.'.
WRITE myVariableName.
 
XSTRING Byte sequence ?
????????
 


Comments

Type Description Example
Line comment If you want to comment the whole line, then put * in front of the line.
* Comment the whole line.
 
Partial comment If you want to partially comment a line, then put " before your comment in the line. Everything after " will be considered as a comment.
WRITE 'Hello world!'  "It will display Hello world!
 


Assignment Operator

DATA counter TYPE I VALUE 0.
 
*Statement sequence: Increment the counter variable by 1, 4 times.
*                    Spaces are very important here.
counter = counter + 1.
counter = counter + 1.
counter = counter + 1.
counter = counter + 1.
WRITE counter.
 
*Chain statement: Another way to rewrite the above but shorter. Increment the counter variable by 1, 4 times.
counter = 0.
counter = counter +:1,1,1,1.
WRITE counter.


Conditional statement

OperatorDescription
EQ equal to
= equal to
NE not equal to
<> not equal to
>< not equal to
LT less than
< less than
LE less than or equal to
<= less than or equal to
GT greater than
> greater than
GE greater than or equal to
>= greater than or equal to
DATA a TYPE I VALUE 3.
DATA b TYPE I VALUE 4.
DATA c TYPE I VALUE 3.
 
*Simple IF statement.
IF a = c.
  WRITE 'a and c are equal.'.
ENDIF.
 
*IF statement with multiple conditions.
IF ( a = c ) AND ( a < b ).
  WRITE 'a and c are equal.'.
ENDIF.
 
 
*IF ELSE statement.
IF a GT b.
  WRITE 'a is greater than b.'.
ELSE.
  WRITE 'a is less than b.'.
ENDIF.
 
*IF ELSEIF statement.
IF a GT c.
  WRITE 'a is greater than b.'.
ELSEIF a = c.
  WRITE 'a is equal to c.'.
ELSE.
  WRITE 'a is less than b.'.
ENDIF.

String comparison operator

OperatorDescription
COContains Only
CNContains Not only
CAContains Any
NAcontains Not Any
CSContains String
NScontains No String
CPContains Pattern
NPcontains No Pattern


Loops

DATA i TYPE I VALUE 0.
DO 4 TIMES.
  i = i + 1.
ENDDO.
WRITE i.