IBM Global Business Services: Control Statements
IBM Global Business Services: Control Statements
Control Statements
Control Statements |
Dec-2008
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
Control Statements |
Dec-2008
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
Logical Expressions
Logical Expressions use :
RELATIONAL OPERATORS
LOGICAL OPERATORS
STRING COMPARISON OPERATORS
Control Statements |
Dec-2008
Relational Operators
Comparison
Syntax
Is Equal to
=, EQ
Is not equal to
Greater than
>, GT
> =, = >, GE
Less than
<, LT
Control Statements |
<=, =<, LE
Dec-2008
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
If not ( X = 0 )
or not ( Y = 1 and
Z = X or X = 3
and ( Z = 5 )
Control Statements |
Dec-2008
Syntax
Contains only
CO
Contains any
CA
Contains string
CS
Contains pattern
CP
CN
NA
Contains no string
NS
Contains no pattern
NP
Control Statements |
Dec-2008
Demonstration
Writing an ABAP program with the IF statement with logical operators.
10
Control Statements |
Dec-2008
Practice
Writing an ABAP program with the IF statement with logical operators.
11
Control Statements |
Dec-2008
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.
Demonstration
Writing an ABAP program with the CASE statement.
13
Control Statements |
Dec-2008
Practice
Writing an ABAP program with the CASE statement.
14
Control Statements |
Dec-2008
The DO Loop
15
DO.
WRITE :/ Hello world!.
J =4.
DO J TIMES.
WRITE :/ Hello world!.
ENDDO.
ENDDO.
Control Statements |
Dec-2008
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
DO 2 TIMES.
WRITE :/ SY-INDEX.
DO 3 TIMES.
WRITE : / , SY-INDEX.
ENDDO.
ENDDO.
17
Control Statements |
Dec-2008
18
Control Statements |
Dec-2008
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
19
Control Statements |
Dec-2008
DO 10 TIMES.
IF SY-INDEX >4.
CONTINUE .
ENDIF.
WRITE :/ SY-INDEX.
ENDDO.
20
Control Statements |
Dec-2008
Demonstration
Writing an ABAP program and work with the LOOP statement.
21
Control Statements |
Dec-2008
Practice
Writing an ABAP program and work with the LOOP statement.
22
Control Statements |
Dec-2008
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
Questions
What are the different kind of control statements in ABAP?
What are different logical expressions available in ABAP?
24
Control Statements |
Dec-2008