SAP BYTEORDER



Get Example source ABAP code based on a different SAP table
  



Byte Order
The byte order determines the order in which bytes of specific data objects are stored in the memory.

Binary Representation of Numbers
The binary representation of numbers with the ABAP type i, int8, decfloat16, decfloat34, f, and s is hardware-dependent. An important part of this is the byte order, which is predefined by the processor of the host computer on the current ABAP_ASINSTANCE , is important: It determines whether the highest-value byte or lowest-value byte is stored first in the memory. In the case of the highest-value byte, the binary representation is referred to as big endian and in the latter case, the representation is known as little endian.



Latest notes:

The byte order of the host computer of the current ABAP_ASINSTANCE can be taken from the static attribute ENDIAN in the system class CL_ABAP_CHAR_UTILITIES.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The number 16909060 in hexadecimal notation can be represented by the following byte strings: EndianByte 1Byte 2Byte 3Byte 4 Big0x010x020x030x04 Little0x040x030x020x01
The most common processors that use little endian representations are Intel and DEC Alpha. Most other processors use big endian.
ABAP_EXAMPLE_END

Binary Representation of Characters
Characters are represented by unsigned 2-byte integer values in the Unicode format UCS-2, which is supported by the ABAP programming language. This means that this format depends on the number representation used by the hardware. A distinction is therefore made between UCS-2BE (big endian) and UCS-2LE (little endian).

Container Problems
Character-like or byte-like data objects of the type c or string, or x or xstring, are often used as anonymous containers for data objects, in particular structures, and stored persistently.
If such a container is stored and imported from an ABAP_ASINSTANCE whose host computer has a different byte order, problems can occur if the container is used for content for which the byte order is critical. This is always the case when numeric content of the type i, int8, decfloat16, decfloat34, f, or s is stored in character-like or byte-like containers. Problems can also arise when byte-like content is stored in character-like containers.
Usually, in order to be able to work with the content of an imported container, a casting is performed on the data type whose data is stored in the container. However, because no type information is stored in the container, any necessary conversion of the byte order cannot take place.
The only way to prevent these problems is to avoid having numeric components in anonymous containers and never store byte-like content in character-like fields.



Latest notes:

The statement EXPORT ... TO DATA BUFFER can be used to store ABAP data in byte strings. When the statement IMPORT is used, the byte order is handled automatically.
NON_V5_HINTS
ABAP_HINT_END