Get Example source ABAP code based on a different SAP table
ID SET-BIT • SET BIT ABAP Statement • OF SET BIT • TO SET BIT
SET BIT> Short Reference >
ABAP_SYNTAX SET BIT bitpos OF byte_string $[TO val$].>
What does it do? This statement sets the bit in bit position bitpos> of the variable byte_string> to 1 or, if specified, to the value of data object val>. The other bits in byte_string> remain unchanged. The data object byte_string> must be byte-like, whereas bitpos > and val> are numeric expression positions> of operand type i>. The value of bitpos> must be greater than 0 and val> must be either 0 or 1, otherwise an uncatchable exception is 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 replacement is made and sy-subrc> is set to 4. System Fields> sy-subrc>Meaning> 0A bit of the data object byte_string> was set at position bitpos>. 4The value of bitpos> is greater than the number of bits in byte_string> and no bit was set.
Latest notes:
If byte_string> has the deep> type xstring>, a bit is set in the referenced byte string, not in the reference.
Setting single bits is intended in particular for preparing operators in bit expressions>.
The built-in function bit-set>> can also be used to set an individual bit.
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 In the data object hex> with eight bits, the bit is set to the value 1 at the position determined by the loop counter sy-index>, with all other bits set to 0. The output is 80 40 20 10 08 04 02 01 >. ABEXA 00645 ABAP_EXAMPLE_END