Logical Expression syntax in ABAP

In ABAP (Advanced Business Application Programming), logical expressions are used for conditions and control structures. Here is the Logical Expression syntax in ABAP.

CO Contains Only: True, if operand1 only contains characters from operand2. Upper/lower case and trailing blanks are taken into account for both operands. If operand2 is of type string and is initial, then the logical expression is false, unless operand1 is also of type string and is initial, in which case the logical expression is always true. If the result of the comparison is negative, sy-fdpos contains the offset of the first character in operand1, that is not contained in operand2. If the result of the comparison is positive, sy-fdpos contains the length of operand1.

CN Contains Not Only; True if a logical expression with CO is false, that is, if operand1 contains not only characters from operand2. sy-fdpos is set in the same way as for CO. If the comparison is true, sy-fdpos contains the offset of the first character in operand1 that is not contained in operand2. If the comparison is false, sy-fdpos contains the length of operand1.

CA Contains Any: True, if operand1 contains at least one character from operand2. Upper/lower case and trailing blanks are taken into account for both operands. If operand1 or operand2 is of type string and initial, the logical expression is always false. If result of the comparison is positive, sy-fdpos contains the offset of the first character in operand1 that is also contained in operand2. If the result of the comparison is negative, sy-fdpos contains the length of operand1.

NA Contains Not Any: True if a logical expression with CA is false, that is if operand1 does not contain any characters from operand2. If the result of the comparison is negative, sy-fdpos contains the offset of the first character in operand1 that is also contained in operand2. If the result of the comparison is true, sy-fdpos contains the le of operand1.

CS Contains String: True if the content of operand2 is contained in operand1. Upper/lower case is not taken into account, trailing blanks of the left operand are taken into account. If operand1 is of type string and initial, or of type c and contains only blank characters, the logical expression is false, unless operand2 is also of type string and initial, or of type c and only contains blank characters. In this case the logical expression is always true. If the result of the comparison is true, sy-fdpos contains the offset of operand2 in operand1. If the result of the comparison is negative, sy-fdpos contains the length of operand1.

NS Contains No String: True, if a logical expression with CS is false, that is if operand1 does not contain the content of operand2. If the result of the comparison is negative, sy-fdpos contains the offset of operand2. If the comparison is true, sy-fdpos contains the length of operand1.

CP Covers Pattern: True, if the content of operand1 fits the pattern in operand2. Wildcard characters can be used for forming the operand2 pattern, where “*” represents any character string, and “+” represents any character. Upper/lower case is not taken into account. If the comparison is true, sy-fdpos contains the offset of operand2 in operand1, whereby leading wildcard characters “*” in operand2 are ignored if operand2 also contains other characters. If the comparison is false, sy-fdpos contains the length of operand1. You can select characters in operand2 for a direct comparison by adding the escape symbol “#” before the required characters. For these characters, upper/lower case is taken into account, wildcard characters and the escape symbol itself do not receive special treatment, and trailing blanks in operands of type c are not cut off.

NP No Pattern: True, if a logical expression with CP is false, that is, if operand1 does not fit the pattern operand2. If the comparison is false, sy-fdpos contains the offset of operand2 in operand1, whereby leading wildcard characters “*” in operand2 are ignored if operand2 also contains other characters. If the comparison is true, sy-fdpos contains the length of operand1.

More about Logical Expression syntax in ABAP

In ABAP (Advanced Business Application Programming), logical expressions are used for conditions and control structures. Here is the syntax for logical expressions in ABAP:

  1. Basic Logical Operators:

    • AND: AND
    • OR: OR
    • NOT: NOT
  2. Comparison Operators:

    • Equal to: =
    • Not equal to: <>
    • Less than: <
    • Less than or equal to: <=
    • Greater than: >
    • Greater than or equal to: >=
  3. Parentheses for Grouping:

    • Use parentheses to group logical expressions and specify the order of evaluation.
  4. Built-in Functions:

    • ABAP provides various built-in functions that can be used within logical expressions. For example:
      • CONCATENATE: Concatenates strings.
      • CO: Checks if a value is contained in a list.
      • CONTAINS: Checks if a string contains a substring.
      • IS INITIAL: Checks if a value is initial.
      • IS NOT INITIAL: Checks if a value is not initial.

Example 

IF (condition1 AND condition2) OR (condition3 AND NOT condition4).
” Statements to be executed if the condition is true.
ELSEIF condition5 OR condition6.
” Statements to be executed if the condition is true.
ELSE.
” Statements to be executed if none of the conditions are true.
ENDIF.

In this example, the logical expression combines conditions using the logical operators AND, OR, and NOT. The conditions can be simple comparisons or more complex expressions. The IF, ELSEIF, and ELSE statements allow branching based on the logical conditions.

Please note that this is a general syntax guide for logical expressions in ABAP. The specific usage and available functions may vary depending on the context and version of ABAP you are using.

Leave a comment