SET BIT

Short Reference

Syntax

SET BIT bitpos OF byte_string [TO val].

Effect

This statement sets the bit in bit position bitpos of variable byte_string to 1 or, if specified, to the value of data object val. The other bits in byte_string remain unchanged.

Data object byte_string must be byte-like, and bitpos and val must have data type i. The value of bitpos must be greater than 0 and val must be either 0 or 1. Otherwise an exception that cannot be handled is 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 replaced and sy-subrc is set to 4.

Systemfields

sy-subrc Meaning
0 A bit in data object byte_string was set at position bitpos.
4 The value of bitpos is greater than the number of bits in byte_string, therefore no bit was set

Notes

Example

A bit in an 8-bit data object hex is set to 1 at the bit positions determined by the loop counter sy-index while the other bits are 0. The output is #80 40 20 10 08 04 02 01#.

DATA hex TYPE x LENGTH 1.
DO 8 TIMES.
  CLEAR hex.
  SET BIT sy-index OF hex.
  WRITE  hex.
ENDDO.

Exceptions

Non-Catchable Exceptions