Upload
bakkalibilal
View
9
Download
0
Embed Size (px)
DESCRIPTION
Chapter 06_Control Statements
Citation preview
IBM Global Business Services
© IBM Corporation 2013Control Statements | Dec-2008
Control Statements
IBM Global Business Services
© IBM Corporation 20132 Dec-2008Control 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
IBM Global Business Services
© IBM Corporation 20133 Dec-2008Control Statements |
Basic Flow Control in ABAP
IBM Global Business Services
© IBM Corporation 20134 Dec-2008Control Statements |
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.
IBM Global Business Services
© IBM Corporation 20135 Dec-2008Control Statements |
Logical Expressions
Logical Expressions use : RELATIONAL OPERATORS LOGICAL OPERATORS STRING COMPARISON OPERATORS
IBM Global Business Services
© IBM Corporation 20136 Dec-2008Control Statements |
Comparison SyntaxIs 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
Relational Operators
IBM Global Business Services
© IBM Corporation 20137 Dec-2008Control Statements |
Logical Operators
ANDORNOT
The hierarchy of the logical operators is: NOT, AND and then OR. (i.e. different from creating views)
IBM Global Business Services
© IBM Corporation 20138 Dec-2008Control Statements |
Bad Programming Practice with Logical Operators
If not ( X = 0 )
or not ( Y = 1 and
Z = X or X = 3
and ( Z = 5 )
IBM Global Business Services
© IBM Corporation 20139 Dec-2008Control Statements |
String Comparison Operators
Comparison SyntaxContains only
Contains any
Contains string
Contains pattern
Contains not only
Contains not any
Contains no string
Contains no pattern
CO
CA
CS
CP
CN
NA
NS
NP
IBM Global Business Services
© IBM Corporation 201310 Dec-2008Control Statements |
Demonstration
Writing an ABAP program with the ‘IF’ statement with logical operators.
IBM Global Business Services
© IBM Corporation 201311 Dec-2008Control Statements |
Practice
Writing an ABAP program with the ‘IF’ statement with logical operators.
IBM Global Business Services
© IBM Corporation 201312 Dec-2008Control Statements |
The CASE Statement
CASESY-UCOMM.
Don’t forgetthose periods!
When
‘SAVE’.
When
‘SRTD’.
When‘PICK’.
When‘GETD’.
When
‘SRTA’.
IBM Global Business Services
© IBM Corporation 201313 Dec-2008Control Statements |
Demonstration
Writing an ABAP program with the ‘CASE’ statement.
IBM Global Business Services
© IBM Corporation 201314 Dec-2008Control Statements |
Practice
Writing an ABAP program with the ‘CASE’ statement.
IBM Global Business Services
© IBM Corporation 201315 Dec-2008Control Statements |
The DO Loop
DO.WRITE :/ ‘Hello world!’.
ENDDO.
J =4.DO J TIMES.
WRITE :/ ‘Hello world!’.
ENDDO.
IBM Global Business Services
© IBM Corporation 201316 Dec-2008Control Statements |
The WHILE Loop
If expression evaluates to TRUE, code in loop is executed.
If expression evaluates to FALSE, code in loop is NOT executed, and control moves to after ENDWHILE.
IBM Global Business Services
© IBM Corporation 201317 Dec-2008Control Statements |
DO 2 TIMES. WRITE :/ SY-INDEX. DO 3 TIMES. WRITE : / ‘ ‘, SY-INDEX. ENDDO.ENDDO.
Nested Loops and Control Structures
IBM Global Business Services
© IBM Corporation 201318 Dec-2008Control Statements |
The CHECK Statement
DO 10 TIMES. CHECK SY-INDEX <= 4. WRITE :/ SY-INDEX.ENDDO.
IBM Global Business Services
© IBM Corporation 201319 Dec-2008Control Statements |
The EXIT Statement
IF SY-SUBRC <> 0. EXIT.ENDIF.
IBM Global Business Services
© IBM Corporation 201320 Dec-2008Control Statements |
The CONTINUE Statement
DO 10 TIMES. IF SY-INDEX >4. CONTINUE . ENDIF. WRITE :/ SY-INDEX.ENDDO.
IBM Global Business Services
© IBM Corporation 201321 Dec-2008Control Statements |
Demonstration
Writing an ABAP program and work with the ‘LOOP’ statement.
IBM Global Business Services
© IBM Corporation 201322 Dec-2008Control Statements |
Practice
Writing an ABAP program and work with the ‘LOOP’ statement.
IBM Global Business Services
© IBM Corporation 201323 Dec-2008Control Statements |
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.
IBM Global Business Services
© IBM Corporation 201324 Dec-2008Control Statements |
Questions
What are the different kind of control statements in ABAP?
What are different logical expressions available in ABAP?