Entering content frame

Combining Several Logical Expressions Locate the document in its SAP Library structure

You can combine several logical expressions together in one single expression by using the logical link operators ANDand OR: To negate the result of a logical expression, you can precede it with the NOT operator.

NOT takes priority over AND, and ANDtakes priority over OR. However, you can use any combination of parentheses to specify the processing sequence. As in mathematical expressions, ABAP interprets each parenthesis as a separate word. You must therefore leave at least one space before and after each one.

ABAP processes logical expressions from left to right. If it recognizes one of the component expressions as true or false, it does not perform the remaining comparisons or checks in this component. This means that you can improve performance by organizing logical expressions in such a way that you place comparisons which are often false at the beginning of an ANDchain and expensive comparisons, such as searches for character strings, at the end.

Example

REPORT demo_log_expr_connected.

DATA: f    TYPE f VALUE '100.00',
      n(3) TYPE n VALUE '123',
      c(3) TYPE c VALUE '456'.

WRITE 'The following logical expression is true:'.

IF ( c LT n ) AND ( n GT f ).
  WRITE: / '(',c,'lt',n,') AND (',n,'gt',f,')'.
ELSE.
  WRITE: / '(',c,'ge',n,') OR (',n,'le',f,')'.
ENDIF.

The list output is:

The following logical expression is true:

( 456 ge 123 ) OR ( 123 le  1.000000000000000E+02 )

The logical expression in the IF statement is true, and the inverted expression is displayed.

 

Leaving content frame