Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Declarations →  Declaration Statements →  Data Types and Data Objects →  Types and Objects - Overview →  Data Objects 

Byte Order

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

Other versions: 7.31 | 7.40 | 7.54

Binary Representation of Numbers

byte order


Note

The byte order of the host computer of the current AS Instance can be derived from the static attribute ENDIAN in the system class CL_ABAP_CHAR_UTILITIES.


Example

You can represent the number 16909060 (in hexadecimal notation) as follows:

Endian Byte 1 Byte 2 Byte 3 Byte 4
Big "0x01" "0x02" "0x03" "0x04"
Little "0x04" "0x03" "0x02" "0x01"

The most common processors are Intel and DEC alpha, both of which use little endian. Most other processors use big endian.

Binary Representation of Characters

In the Unicode format UCS-2, supported by the ABAP programming language, characters are represented using 2-byte unsigned integer values. This means that this format depends on the number representation used by the hardware. Thus you must differentiate 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, especially structures, and stored persistently.

If a container is saved and imported from an AS Instance 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 saved in character-like containers.

Usually, to be able to work with the contents 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 arising is to avoid having numeric components in anonymous containers and never store byte-like contents in character-like fields.


Note

The statement EXPORT ... TO DATA BUFFER can be used to save ABAP data in byte strings. If imported using the statement IMPORT, the byte order is handled automatically.