Start of Content Area

Function documentation Conditional Statements  Locate the document in its SAP Library structure

Use

You achieve conditional statements using an IF statement. Further conditional statements can follow an IF statement in an ELSEIF statement. The ELSE statement can be used for dealing with all other cases in a chain of conditional statements. The schema looks roughly as in the following example.

Example

IF <Expression1>.

<Statement1>.

ELSEIF <Expression2>.

<Statement2>.

ELSE.

<Statement3>.

ENDIF.

Expressions in the IF statement consist of operands, plus variables and constants, relational operators and logical operators.

Note

Note that constants may only come to the right of a comparison operator.

Example

To check the special case of whether an operand <oper1> has the initial value, you can write:

IF <oper1> IS INITIAL. or IF <oper1> = '#'.

Example

Example construction with logical operators: IF NOT <oper1> < <oper2> AND <oper3> = <oper4> OR <oper5> > <oper2>.

Working with Character-Type Operands

The following operators are available to you when working with character-type operands.

Working with Character-Type Operands for an Expression c1 <op> c2 Example

Operator

Meaning in Expression

CP (Contains Pattern)

The whole of string c1 matches the pattern c2.

Wildcards can also be contained in pattern c2 where '*' stands for a string and '+' for a symbol.

CO (Contains Only)

c1 only contains characters from those in c2.

If c1 or c2 is of internal type C, then the complete length of the field is included in the comparison, that means blanks at the end are also taken into account.

If c1 is of type STRING and is empty then the output of the comparison is always positive.

If c2 is of type STRING and is empty, then the output of the comparison is always negative except when c1 is also an empty string.

CA (Contains Any)

c1 only contains characters from those in c2.

If c1 or c2 is of internal type C then the complete length of the field is included in the comparison, that means blanks at the end are also taken into account.

If c1 or c2 is of type STRING and is empty then the output of the comparison is always negative.

CS (Contains String)

c1 contains the string c2. If the respective field is of type C, then the final blanks in c1 and c2 are ignored.

An empty c2 string (therefore only blanks for type C or an empty string for type STRING) is contained in any c1 string and in the string itself. On the other hand there is no 'not-empty' c2 string contained in an empty c1 string.

 

 

End of Content Area