Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for Byte String Processing 

bit_exp - Bit Expressions

Quick Reference

Other versions: 7.31 | 7.40 | 7.54


... [BIT-NOT] operand1 
    [{BIT-AND|BIT-OR|BIT-XOR} [ BIT-NOT] operand2
    [{BIT-AND|BIT-OR|BIT-XOR} [ BIT-NOT] operand3
    ...  ]] ...


A bit expression formulates a binary calculation. The operands must be byte-like (type x or xstring). The result of a bit expression is a byte chain in the calculation length assigned to the bit expression. During assignment to an inline declaration DATA(var), the byte chain is handled as a byte string of data type xstring, and when passing a generic typed formal parameter it is handled as a byte field of data type x.

In a bit expression bit_exp, an operand operand1 can be joined with one or more operands operand2, operand3, and so on using bit operators BIT-AND, BIT-OR, or BIT-XOR; Brackets are possible. Bit expressions can occur in the reading positions of certain statements, in particular on the right side of an assignment with the assignment operator =.

The operand positions operand are general expression positions, which means byte-like data objects, functional methods with byte-like return codes, or bracketed bit expressions can be specified. The bit operators BIT-AND, BIT-OR, and BIT-XOR join two adjacent operands. When the expression is evaluated, a byte-like value is calculated and associated with the next adjacent operand. The priority of the join depends on the operators that are used; if use functional methods are used, the same applies as described for arithmetic expressions.

The bit operator BIT-NOT can be specified one or more times before an operand to negate the value of the operand. If BIT-NOT is specified an even number of times, the operand remains unchanged. An odd number of uses negates the operand.

If functional methods are specified as operands, they are specified from left to right and from inside to outside before the remainder of the expression is evaluated. The return values are buffered to be used in the corresponding operand positions.

If constructor expressions are specified as operands of bit expressions, their data type is not determined by the bit expression. The # character can be specified for the data type of the constructor expression only if the type can be determined from the constructor expression itself.


Bit sequences are an efficient way of mapping set operations. If a set contains n elements, the existence of an element i in n can be represented by a 1 at the position of i in a byte-like field. The statement SET BIT, among others, can be used to add an element to the set. The operators BIT-AND, BIT-OR, and BIT-XOR can then be used to calculate the intersection, the union, and the symmetric difference of different sets.

In the following example, the attributes of person groups are mapped in the fields p1, p2, p3 of the type x. The bit operator BIT-AND is then used to determine which attributes are shared by all people. The result shows that only the eighth attribute is shared.

  p1  TYPE x LENGTH 1 VALUE '5B',     "01011011 
  p2  TYPE x LENGTH 1 VALUE '13',     "00010011 
  p3  TYPE x LENGTH 1 VALUE 'A5'.     "10100101 

DATA(res) = p1 BIT-AND p2 BIT-AND p3. "00000001 


Non-Handleable Exceptions

  • Cause: An operand or the result field is not of type x.
    Runtime error: BITS_WRONG_TYPE


bit_exp - Bit operators

bit_exp - ( )

bit_exp - Calculation Length

Set Operations with Bit Sequences