IBM Global Business Services
Control Statements
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
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
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Basic Flow Control in ABAP
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
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.
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Logical Expressions
Logical Expressions use :
RELATIONAL OPERATORS
LOGICAL OPERATORS
STRING COMPARISON OPERATORS
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
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
Control Statements |
<=, =<, LE
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Logical Operators
AND
OR
NOT
The hierarchy of the logical
operators is: NOT, AND and
then OR. (i.e. different from
creating views)
7
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Bad Programming Practice with Logical Operators
If not ( X = 0 )
or not ( Y = 1 and
Z = X or X = 3
and ( Z = 5 )
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
String Comparison Operators
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
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Demonstration
Writing an ABAP program with the IF statement with logical operators.
10
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Practice
Writing an ABAP program with the IF statement with logical operators.
11
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
The CASE Statement
CASE
SY-UCOMM.
en
h
W
E.
V
SA
n
Whe .
TA
SR
When
SRTD.
Dont forget
those periods!
12
Control Statements |
Wh
en
PIC
K.
Dec-2008
When
GET
D.
IBM Corporation 2013
IBM Global Business Services
Demonstration
Writing an ABAP program with the CASE statement.
13
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Practice
Writing an ABAP program with the CASE statement.
14
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
The DO Loop
15
DO.
WRITE :/ Hello world!.
J =4.
DO J TIMES.
WRITE :/ Hello world!.
ENDDO.
ENDDO.
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
The WHILE Loop
If expression evaluates
to TRUE, code in loop is
executed.
16
Control Statements |
If expression evaluates to
FALSE, code in loop is NOT
executed, and control moves
to after ENDWHILE.
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Nested Loops and Control Structures
DO 2 TIMES.
WRITE :/ SY-INDEX.
DO 3 TIMES.
WRITE : / , SY-INDEX.
ENDDO.
ENDDO.
17
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
The CHECK Statement
DO 10 TIMES.
CHECK SY-INDEX <= 4.
WRITE :/ SY-INDEX.
ENDDO.
18
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
The EXIT Statement
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
19
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
The CONTINUE Statement
DO 10 TIMES.
IF SY-INDEX >4.
CONTINUE .
ENDIF.
WRITE :/ SY-INDEX.
ENDDO.
20
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Demonstration
Writing an ABAP program and work with the LOOP statement.
21
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Practice
Writing an ABAP program and work with the LOOP statement.
22
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
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.
23
Control Statements |
Dec-2008
IBM Corporation 2013
IBM Global Business Services
Questions
What are the different kind of control statements in ABAP?
What are different logical expressions available in ABAP?
24
Control Statements |
Dec-2008
IBM Corporation 2013