Tutorial Decisions in SAP ABAP
Tutorial Decisions in SAP ABAP
The Decision making structure has one or more conditions to be evaluated or tested by the program, accompanied by statements or statements to be executed, if conditions are determined to be correct, and optionally, other statements to be executed,
Following are the general forms of decision structure used in most programming languages:
The ABAP programming language provides the following types of decision-making statements:
Baca Juga: Tutorial Dasar SAP ABAP
Outpunya adalah
Outpunya adalah
Outpunya adalah
The output is
The Decision making structure has one or more conditions to be evaluated or tested by the program, accompanied by statements or statements to be executed, if conditions are determined to be correct, and optionally, other statements to be executed,
Following are the general forms of decision structure used in most programming languages:
The ABAP programming language provides the following types of decision-making statements:
No | Statement & Description |
---|---|
1 | IF Statement IF statements consist of logical expressions followed by one or several statements. |
2 | IF.. Else Statement IF statements can be followed by optional ELSE statements that execute when the expression is false. |
3 | Nested IF Statement You can use one IF or ELSEIF statement in another IF or ELSEIF statement.. |
4 | CASE Control Statement CASE is used when we need to compare two or more fields or variables. |
IF Statement
Syntax
IF<condition_1>.
<Statements...>.
ENDIF
Contoh:
1
2
3
4
5
6
| Report YH_SEP_15. Data Title_1( 20 ) TYPE C. Title_1 = 'Tutorials' . IF Title_1 = 'Tutorials' . write 'This is IF statement' . ENDIF. |
This is IF statement
IF.. Else Statement
SyntaxIF<condition_1>.
<statement block 1>.
ELSE.
<statement block 2>.
ENDIF.
Contoh:
1
2
3
4
5
6
7
8
9
10
11
| Report YH_SEP_15. Data Title_1( 20 ) TYPE C. Title_1 = 'Tutorials' . IF Title_1 = 'Tutorial' . write 'This is IF Statement' . ELSE. write 'This is ELSE Statement' . ENDIF. |
This is ELSE Statement.
Nested IF Statement
SyntaxIF<condition_1>.
<statement block>.
IF<condition_2>.
<statement block>.
ELSE.
<statement block>.
ENDIF.
ELSE <statement block>.
ENDIF.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| Report YH_SEP_15. Data: Title_1( 10 ) TYPE C, Title_2( 15 ) TYPE C, Title_3( 10 ) TYPE C. Title_1 = 'ABAP' . Title_2 = 'Programming' . Title_3 = 'Tutorial' . IF Title_1 = 'ABAP' . IF Title_2 = 'Programming' . IF Title_3 = 'Tutorial' . Write 'Yes, It’s Correct' . ELSE. Write 'Sorry, It’s Wrong' . ENDIF. ENDIF. ENDIF. |
Yes, It’s Correct.
CASE Control Statement
SyntaxCASE <field>.
WHEN <abc>.
<statement block>.
WHEN <def>.
<tatement block>.
WHEN <pqr>.
<statement block>.
......
......
......
WHEN <xyz>.
<statement block>.
WHEN OTHERS.
<statement block>.
ENDCASE.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| eport YH_SEP_15. Data: Title_1( 10 ) TYPE C, Title_2( 15 ) TYPE C. Title_1 = 'ABAP' . Title_2 = 'Programming' . CASE Title_2. WHEN 'ABAP' . Write 'This is not the title' . WHEN 'Tutorials' . Write 'This is not the title' . WHEN 'Limited' . Write 'This is not the title' . WHEN 'Programming' . Write 'Yes, this is the title' . WHEN OTHERS. Write 'Sorry, Mismatch' . ENDCASE. |
Yes, this is the title.