Chapter 06 - Control Statements
Chapter 06 - Control Statements
Control Statements
Objectives
The participants will be able to:
Use the basic Control Flow Constructs that are available in the ABAP Editor
Use the following statements in an ABAP Program
IF, CASE, DO, WHILE, CHECK, EXIT, and CONTINUE
Use the Logical Expressions that are available in the ABAP Editor
The IF Statement
IF X =5.
WRITE :/ ‘The value of X is 5’.
ELSEIF X =6.
WRITE :/ ‘The value of X is 6’.
ELSE .
WRITE :/ ‘X is neither 5 nor 6’.
ENDIF.
Logical Expressions
Logical Expressions use :
RELATIONAL OPERATORS
LOGICAL OPERATORS
STRING COMPARISON OPERATORS
Relational Operators
Comparison Syntax
Is Equal to =, EQ
Is not equal to < >, ><, NE
Greater than >, GT
Greater than or equal to > =, = >, GE
Less than <, LT
Less than or equal to <=, =<, LE
Logical Operators
AND
OR
NOT
If not ( X = 0 )
or not ( Y = 1 and
Z = X or X = 3
and ( Z = 5 )
Comparison Syntax
Contains only CO
Contains any CA
Contains string CS
Contains pattern CP
Contains not only CN
Contains not any NA
Contains no string NS
Contains no pattern NP
Demonstration
Writing an ABAP program with the ‘IF’ statement with logical operators.
Practice
Writing an ABAP program with the ‘IF’ statement with logical operators.
hen
W
V E ’.
‘SA n
CASE Whe .
RTA’
SY-UCOMM. ‘S
When
‘SRTD’.
When
Wh ‘GET
en D’.
‘ P IC
Don’t forget K’.
those periods!
Demonstration
Practice
The DO Loop
J =4.
DO. DO J TIMES.
WRITE :/ ‘Hello world!’. WRITE :/ ‘Hello world!’.
ENDDO. ENDDO.
DO 2 TIMES.
WRITE :/ SY-INDEX.
DO 3 TIMES.
WRITE : / ‘ ‘, SY-INDEX.
ENDDO.
ENDDO.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
DO 10 TIMES.
IF SY-INDEX >4.
CONTINUE .
ENDIF.
WRITE :/ SY-INDEX.
ENDDO.
Demonstration
Practice
Summary
Logical expressions are constructed using relational, logical, and string
comparison operators.
The CASE statement is used to distinguish between mutually exclusive options.
A DO loop is used to unconditionally execute a block of code multiple times.
WHILE loop conditionally executes a block of code, possibly multiple times.
The CHECK statement is used to test a logical expression
The EXIT statement unconditionally terminates a loop, subroutine, or program.
The CONTINUE statement is used inside a loop.
Questions
What are the different kind of control statements in ABAP?
What are different logical expressions available in ABAP?