SAP GET BIT ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID GET-BIT
• GET BIT ABAP Statement
• OF GET BIT
• INTO GET BIT

GET BIT
Short Reference

ABAP_SYNTAX
GET BIT bitpos OF byte_string INTO val.

What does it do?
This statement reads the bit at the bit position bitpos of the data object byte_string and assigns its value to the target field val. val can be specified as follows:
An existing variable that expects the data type i.
An inline declaration DATA(var) or FINAL(var), where a variable of type i is declared.
Expressions with the CAST and NEW operators and table expressions.
The data object byte_string must be byte-like. Bit, constructor and table expressions can be used. bitpos is a numeric expression position of operand type i. The value of bitpos must be greater than 0, otherwise uncatchable exceptions are raised. The bit positions in byte_string are counted from left to right, starting with the most significant bit (MSB) of the data object. If the value of bitpos is greater than the number of bits in byte_string, no bit is read and sy-subrc is set to 4.
System Fields sy-subrcMeaning 0The value of the bit at position bitpos of byte_string was placed in the result field val. 4The value of bitpos is greater than the number of bits in byte_string and no bit was read.



Latest notes:

If byte_string has the deep type xstring, a bit is read from the referenced byte string, not from the reference.
The reading of single bits is especially intended for evaluating the results of bit expressions.
Counting the bits from the most significant bit (MSB) can have unexpected results when working with components that count from the least significant bit (LSB).
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The hexadecimal value 1B is assigned to the data object hex and its bits are read from front to back. The output is 00011011, which corresponds to the binary representation of decimal 27 or hexadecimal 1B.
ABEXA 00298
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
Hexadecimal values are assigned to data objects and included in an internal table which is looped across. During the loop, the bits are read from front to back. Finally, the result is added to the internal table which shows the hexadecimal and binary values. The GET BIT statement demonstrates a table expression following OF.
ABEXA 01657
ABAP_EXAMPLE_END



Runtime Exceptions


Non-catchable Exceptions
Reason for error:
n is smaller than or equal to 0.
Runtime error:
BIT_OFFSET_NOT_POSITIVE
ABAP_NONCAT_END

Return to menu