Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Statements for Character String and Byte String Processing 

GET BIT

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


GET BIT bitpos OF byte_string INTO val. 

Effect

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), where a variable of type i is declared.

The data object byte_string must be byte-like. bitpos is a numeric expression position of operand type i. The value of bitpos must be greater than 0, otherwise exceptions that cannot be handled are raised. The bit positions in byte_string are counted from the beginning 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

System Fields

sy-subrc Meaning
0 The value of the bit at position bitpos of byte_string was placed in the result field val.
4 The value of bitpos is greater than the number of bits in byte_string, therefore no bit was read.


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.
  • In einem obsoleten Nicht-Unicode-Programm sind für byte_string auch zeichenartige Datenobjekte zugelassen.

Example

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 display of decimal 27 or hexadecimal "1B".

DATA hex TYPE xstring VALUE `1B`. 
DATA(len) = xstrlen( hex ) * 8. 
DATA output TYPE string. 

WHILE sy-index <= len. 
  GET BIT sy-index OF hex INTO DATA(res). 
  output = output && res. 
ENDWHILE. 
cl_demo_output=>display_text( output ). 

Exceptions


Non-Catchable Exceptions

  • Cause: n is smaller than or equal to 0.
    Runtime Error: BIT_OFFSET_NOT_POSITIVE