Entering content frame

Checking Requirements Locate the document in its SAP Library structure

In addition to the logical expressions for comparisons, there is in ABAP a set of logical expressions that you can use to check certain requirements of data objects.

Checking Whether a Field Belongs to a Range

Use the following logical expression to check whether the value of a field lies within a particular range:

... f1 BETWEEN f2 AND f3 ...

ExampleExample for Checking Whether Field Belongs to a Range:

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 flag is set to X if the value of number is between 3 and 7.

Checking for the Initial Value

Use the following logical expression to check whether the value of a field is initial:

... f IS INITIAL ...

ExampleExample for checking the initial value of a data object:

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 declaration through the DATA statement because it was set to start value 'X' using the VALUE parameter. When the CLEAR statement is executed, it is reset to its initial value.

Checking Selection Criteria

Use the following logical expression to check whether the contents of a field satisfy the criteria in a selection table:

... f IN seltab ...

For further information about selection criteria and how to use them, refer to Selection Screens.

Example

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’.

Checking Whether a Field Symbol is Assigned

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>.

Directly after the definition of a field symbol, the expression behaves as follows:

         With non-typed field symbols, it is true since these point to space.

         With typed field symbols, it is false since these do not point to any field.

         In the case of fields 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:

        Directly after the declaration of a typed field symbol

        After the statement UNASSIGN <fs>

        If a local field to which <fs> pointed no longer exists.

        If <fs> points to a global parameter of the interface of a function module that is currently inactive

Example

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.

 

Leaving content frame