How to use if Statement in SAP
Wednesday, July 2nd, 2008The if statement in ABAP/4 has relational operators for equality and inequality and special relational operators for string comparisons and for bit masks.
Syntax for the if Statement
The following is the syntax for the if statement.
if [not] exp [ and [not] exp ] [ or [not] exp ].
—
[elseif exp.
---]
[else.
---]
endif.
where:
* exp is a logical expression that evaluates to a true or false condition.
* — represents any number of lines of code. Even zero lines are allowed.
The following points apply:
* Every if must have a matching endif.
* else and elseif are optional.
* Parentheses can be used. Each parentheses must be separated by a space. For example, if ( f1 = f2 ) or ( f1 = f3 ) is correct, and if (f1 = f2) or (f1 = f3) is incorrect.
* Variables can be compared with blanks or zeros using the addition is initial. For example, if f1 is initial will be true if f1 is type c and is blank. If f1 is any other data type, the statement is true if f1 contains zeros.
* To accomplish negation, not must precede the logical expression. For example, if not f1 is initial is correct. if f1 is not initial is incorrect.
* Variables can be compared with nulls using the addition is null. For example, if f1 is null.
Comparing two values that do not have the same data type will result in an internal automatic type adjustment of one or both of the values. One type will take precedence and will dictate what type of conversion is performed. The order of precedence is: (more…)
Popularity: 6% [?]