ABAPCOMPUTE_BIT - COMPUTE BIT

CPI1466 during Backup   ABAP Short Reference  
This documentation is copyright by SAP AG.

bit_exp - Bit Expressions

Short Reference



Syntax

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


Effect

A bit expression formulates a binary calculation. The result of a bit expression is a byte chain in thecalculation lengthassigned to the bit expression. In a bit expression bit_exp, an operand operand1 can be associated with one or more operands operand2, operand3, and so on usingbit operators BIT-AND, BIT-OR, or BIT-XOR;Brackets are possible.Bit expressions can be used in the COMPUTE statement or atread positions of certain expressions (as of Release 7.1).

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

You can specify the bitoperator BIT-NOT 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.

Example

Bit sequences are an efficient way of mapping set operations. If a set contains n elements, the existenceof an element i in n can be represented by a 1 at the position of i in a byte-like field. You can usethe SET BITstatement, amongst others, 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.

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

res = p1 BIT-AND p2 BIT-AND p3.      "00000001

Exceptions

Non-Catchable Exceptions

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







Addresses (Business Address Services)   CPI1466 during Backup  
This documentation is copyright by SAP AG.


Length: 4872 Date: 20120522 Time: 035847     triton ( 200 ms )