In addition to the logical expressions for comparisons, ABAP contains a set of logical expressions that you can use to check certain requirements of data objects.
Use the following logical expression to check whether the value of a field lies within a particular range:
... f1 BETWEEN f2 AND f3 ...
DATA: number TYPE i, flag(1) TYPE c.
...
number = ...
...
IF number BETWEEN 3 AND 7. flag = 'X'.ELSE. flag = ' '.ENDIF.
In this example, the content of the field flagis set to X if the value of numberis between 3 and 7.
Use the following logical expression to check whether the value of a field is initial:
... f IS INITIAL ...
REPORT demo_log_expr_is_initial .
DATA flag(1) TYPE c VALUE 'X'.
IF flag IS INITIAL. WRITE / 'Flag is initial'.ELSE. WRITE / 'Flag is not initial'.ENDIF.
CLEAR flag.
IF flag IS INITIAL. WRITE / 'Flag is initial'.ELSE. WRITE / 'Flag is not initial'.ENDIF.
The list output is as follows:
Flag is not initial
Flag is initial.
Here, the character field flag does not contain its initial value after being declared by the DATA statement because it was set to the start value 'X' using the VALUE parameter. When the CLEAR statement is executed, it is reset to its initial value.
Use the following logical expression to check whether the contents of a field satisfy the criteria in a selection table:
... f IN seltab ...
For more information about selection criteria and how to use them, see Selection Screens .
REPORT demo_log_expr_in_seltab .
DATA wa TYPE spfli.
SELECT-OPTIONS s_carrid FOR wa-carrid.
IF 'LH' IN s_carrid. WRITE 'LH was selected'.ENDIF.
The logical expression in the If statement is true if the user has entered a selection on the selection screen containing the value 'LH'.
To check whether a field is assigned to a field symbol, use the following logical expression:
... <fs> IS ASSIGNED ...
The expression is true if a field has been assigned explicitly or implicitly to the field symbol <fs>. The expression is false if a field has not been assigned explicitly or implicitly to the field symbol <fs>.
Directly after the definition of a field symbol, the expression behaves as follows:
In the case of non-typed field symbols, it is true since these point to space.
In the case of typed field symbols, it is false since these do not point to any field.
In the case of field symbols with a defined structure, it is true since the field assignment takes place already during the declaration.
The expression can be false in the following cases:
REPORT demo_log_expr_is_assigned .
FIELD-SYMBOLS <fs> TYPE ANY.
DATA text(10) TYPE c VALUE 'Assigned!'.
ASSIGN text TO <fs>.
IF <fs> IS ASSIGNED. WRITE <fs>.ENDIF.
The output is
Assigned!
since the logical expression in the IF statement is true.