Show TOC

Comparison OperationsLocate this document in the navigation structure

Definition

Comparison operations are used to define how the system shall perform a comparison between an incoming value that has been passed to an expression as context parameter and a predefined value or value range. The test parameter may also be supplied as the result of a nested expression, rather than by a context parameter.

Use

You can use comparison operations mainly to discriminate between different processing paths in a business rule. For example, in a decision table, the predefined values in the condition columns serve as the comparison parameters against which an incoming value is compared.

Structure

All types of comparison operations supported by BRFplus are used to compare one incoming elementary data object (the test parameter) to a predefined value or value range (the comparison parameter). The formal description of a comparison operation is therefore:

<test parameter> <comparison operator> <comparison parameter>

Example

You want to determine whether an incoming value lies within a predefined value range.

Test parameter: tp = 24

Comparison operator: is between

Comparison parameter: cp = [18..25]

Comparison: tp is between cp (that is, "24 is between [18..25]")

Result: true

The formal description given above is also valid for operators that, from a user's perspective, have no comparison parameter ( is initial , is supplied , and the negation of both). The operators belonging to this group (group 3 in the following table) compare the test parameter against an implicit comparison parameter that the system derives internally. Therefore, it is not needed (and not possible) to manually provide a comparison parameter for these types of operations.

Groups of Operators

Whether a particular operator can be used or not depends on the type of the parameters involved. In order to reduce the complexity of possible combinations of operators and parameter types, the comparison operators provided by BRFplus can be grouped by their allowed usages. For each of the groups explained below it is possible to say which parameter types can be combined with the operators of that group.

Note

In this section, all comparison operators supported by BRFplus are described. However, it depends on the definition of an elementary data object whether all of the comparison operators can be used or not. This behavior is controlled by the Allowed Comparisons setting on the Element Properties tab of the data object. For more information, see Creating an Element Data Object .

Group

Description

Operators

Constant

ID

1

Ordinal comparisons

is equal to

is not equal to

is less than

is less than or equal to

is greater than

is greater than or equal to

is between

is not between

GC_OPTION_EQUAL

GC_OPTION_NOT_EQUAL

GC_OPTION_LESS

GC_OPTION_LESS_EQUAL

GC_OPTION_GREATER

GC_OPTION_GREATER_EQUAL

GC_OPTION_BETWEEN

GC_OPTION_NOT_BETWEEN

EQ

NE

LT

LE

GT

GE

BT

NB

2

String comparisons

contains any

does not contain any

contains only

does not contain only

contains string

does not contain string

matches pattern

does not match pattern

GC_OPTION_CONTAINS_ANY

GC_OPTION_CONTAINS_NOT_ANY

GC_OPTION_CONTAINS_ONLY

GC_OPTION_CONTAINS_NOT_ONLY

GC_OPTION_CONTAINS_STRING

GC_OPTION_CONTAINS_NO_STRING

GC_OPTION_CONTAINS_PATTERN

GC_OPTION_NOT_CONTAINS_PATTERN

CA

NA

CO

CN

CS

NS

CP

NP

3

Implicit comparisons

is initial

is not initial

is supplied

is not supplied

GC_OPTION_INITIAL

GC_OPTION_NOT_INITIAL

GC_OPTION_SUPPLIED

GC_OPTION_NOT_SUPPLIED

I1

I2

S1

S2

The operators are all represented internally by constants that are defined for the affected interfaces (for example, IF_FDT_RANGE ).

The operator IDs given in the last column of the above table are the technical names used internally. Mostly, they are referring to the corresponding comparison operators as defined in ABAP. Actually, BRFplus passes the execution of comparison operations to the equivalent ABAP expressions. Therefore, the detailed processing behavior of the BRFplus comparison parameters is identical to the respective ABAP expressions.

Data Type Combinations For Comparisons

The way how the system actually performs a comparison depends on the operator and the test parameter type. The following table presents an overview of the different comparison approaches, grouped by the involved data types:

Data Type

Comments

Text

Alphanumeric comparison of values. In order to reduce complexity, text parameters are internally converted into a sortable byte sequence according to the ABAP command CONVERT TEXT . This normalization helps to avoid problems that can occur if characters belonging to different codepages are compared. At the same time, this approach may lead to results that differ from what you would expect.

Number

Numeric comparison of values

Amount, Quantity

If the parameters have different currencies or units, the parameters are first internally converted into one of the involved currencies or units. Then, the system performs a numeric comparison of the values.

Timepoint

Date and time values are compared numerically. If the values to be compared have different subtypes, then only the matching parts of both values are taken into account for the comparison. For example, if you want to compare a timestamp with date and time given against a mere date (without time), the system ignores the time part of the timestamp and concentrates on the date only.

Boolean

Equality check

As a general rule, it is correct to say that a comparison can only be performed by the system if both involved parameters are of the same type. However, as an exception to this general rule, the system supports some additional comparison operations under the following conditions:

  • Ordinal comparisons (group 1) can be performed if both involved parameters can be converted into a valid number. In this case, the system performs a numeric comparison. Otherwise, both parameters are treated as text and a string comparison is performed.

  • String comparisons (group 2) can be performed with parameters of different types. To accomplish this, the system carries out an implicit type conversion so that both parameters are treated as text.

The following tables present the various combinations grouped by the question whether the comparison is possible at all (with or without a previous internal type conversion) or not. The tables are of course only dealing with operator groups 1 and 2, because in group 3, a type conflict is by definition impossible.

The following table shows all sorts of comparison operations that the system can perform without having to make any implicit type conversions:

Test Parameter Type

Comparison Parameter Type

Comparison Operator

Comparison Type

Number

Number

Group 1

Numeric

Text

Text

Group 1

Text

Text

Text

Group 2

Text

Amount

Amount

Group 1

Amount

Quantity

Quantity

Group 1

Quantity

Timepoint

Timepoint

Group 1

Timepoint

Boolean

Boolean

Equal to, Not equal to

Boolean

The following table shows all sorts of comparison operations that the system can perform, but only after an implicit type conversion of at least one of the involved parameters:

Test Parameter Type

Comparison Parameter Type

Comparison Operator

Comparison Type

Comments

Number

Number

Group 2

Text

Numbers are converted to text internally

Number

Text

Group 1

Numeric or Text

1. The comparison parameter of type text is converted to number and a numeric comparison is performed.

2. If this is not possible, then the test parameter is converted to text and a text comparison is performed.

Number

Text

Group 2

Text

Test parameter is converted to text.

Text

Number

Group 1

Numeric or Text

1. The test parameter of type text is converted to number and a numeric comparison is performed.

2. If this is not possible, then the comparison parameter is converted to text and a text comparison is performed.

Text

Number

Group 2

Text

Comparison parameter is converted to text

Amount

Number

Group 2

Text

Both parameters are converted to text

Amount

Text

Group 2

Text

Test parameter is converted to text

Quantity

Number

Group 2

Text

Both parameters are converted to text

Quantity

Text

Group 2

Text

Test parameter is converted to text

Timepoint

Number

Group 2

Text

Both parameters are converted to text

Timepoint

Text

Group 2

Text

Test parameter is converted to text

The following table shows all sorts of comparison operations that the system cannot perform:

Test Parameter Type

Comparison Parameter Type

Comparison Operator

Number

Amount

Group 1, Group 2

Number

Quantity

Group 1, Group 2

Number

Timepoint

Group 1, Group 2

Number

Boolean

Group 1, Group 2

Text

Amount

Group 1, Group 2

Text

Quantity

Group 1, Group 2

Text

Timepoint

Group 1, Group 2

Text

Boolean

Group 1, Group 2

Amount

Amount

Group 2

Amount

Number

Group 1

Amount

Text

Group 1

Amount

Quantity

Group 1, Group 2

Amount

Timepoint

Group 1, Group 2

Amount

Boolean

Group 1, Group 2

Quantity

Quantity

Group 2

Quantity

Number

Group 1

Quantity

Text

Group 1

Quantity

Amount

Group 1, Group 2

Quantity

Timepoint

Group 1, Group 2

Quantity

Boolean

Group 1, Group 2

Timepoint

Timepoint

Group 2

Timepoint

Number

Group 1

Timepoint

Text

Group 1

Timepoint

Amount

Group 1, Group 2

Timepoint

Quantity

Group 1, Group 2

Timepoint

Boolean

Group 1, Group 2

Boolean

Number

Group 1, Group 2

Boolean

Text

Group 1, Group 2

Boolean

Amount

Group 1, Group 2

Boolean

Quantity

Group 1, Group 2

Boolean

Timepoint

Group 1, Group 2

Boolean

Boolean

Group 1 (however, is equal to and is not equal to are allowed), Group 2

Additional Information on Selected Comparison Operators

The following table provides some more detailed information on how exactly the comparison operators work. The table mentions only those operators whose behavior is not self-evident.

In addition to the detailed information given in the table below, the following general rules apply:

  • For string comparisons, case-sensitivity is controlled via the respective setting of the value range expression that is used as comparison parameter.

  • As opposed to the previous rule, pattern matching comparisons are performed case-insensitive.

  • For string comparisons, leading and trailing whitespace is removed from the test parameter before the comparison is executed. Whitespace inside of a string, however, is retained.

  • For ordinal comparisons of strings (for example, is less than ), case-sensitivity is not taken into account. For example, 'a' is less than 'B' is evaluated as true although 'a' has a higher ASCII code value than 'B'.

  • As opposed to the previous rule, equality checks ( is equal to ) of text parameters are performed like string comparisons, that is, the system respects the case-sensitivity setting during evaluation.

Comparison Operator

Comment

is between

Returns true if the test parameter value lies between the low and high value of a range, including these values (that is, value >= low AND value <= high ).

contains any

Returns true if the test parameter contains at least one character that is also contained in the comparison parameter. The character sequence, however, can be different, as well as the number of occurrences of matching characters.

contains only

Returns true if the test parameter contains only characters that are also contained in the comparison parameter. The character sequence, however, can be different, as well as the number of occurrences of matching characters.

contains string

Returns true if the string contained in the comparison parameter is also contained in the test parameter. The character sequence must be identical in both parameters.

is equal to

Returns true if the test parameter value is identical to the comparison parameter value.

matches pattern

Returns true if the supplied test parameter matches the pattern used in the comparison parameter. The following wildcard characters are supported:

  • + - matches exactly one character

  • * - matches any number of characters

Example

Wildcard = '*':

Test parameter: tp = 'Hello'

Comparison parameter: cp = 'He*o'

Comparison: tp matches pattern cp

Result: true

Wildcard = '+':

Test parameter: tp = 'Hero'

Comparison parameter: cp = 'He+o'

Comparison: tp matches pattern cp

Result: true

More Information