Incompatible Structures and Elementary Fields

ABAP contains a rule for converting

In each of these cases, the system first converts all the structures concerned to type C fields and then performs the conversion between the two remaining elementary fields. The length of the type C fields is the sum of the lengths of the structure components.

If a structure is aligned (see Aligning Data Objects), the filler fields are also added to the length of the type C field.

 

The following structure is not aligned:

You should keep this rule in mind for all operations with structures. However, it applies only to structures which contain no internal tables as components.

If you convert a longer structure into a shorter one, the superfluous parts are omitted. If you convert a shorter structure into a longer one, the parts at the end are not initialized according to their type, but padded with blanks.

Conversions between non-compatible structures can make sense if, for example, the structure of a shorter structure corresponds to the structure of the beginning of a longer one.

DATA: BEGIN OF FS1,
INT TYPE I VALUE 5,
PACK TYPE P DECIMALS 2 VALUE ‘2.26’,
TEXT(10) TYPE C VALUE ‘Fine text’,
FLOAT TYPE F VALUE ‘1.234e+05’,
DATA TYPE D VALUE ‘19950916’,
END OF FS1.

DATA: BEGIN OF FS2,
INT TYPE I VALUE 3,
PACK TYPE P DECIMALS 2 VALUE ‘72.34’,
TEXT(5) TYPE C VALUE ‘Hello’,
END OF FS2.

WRITE: / FS1-INT, FS1-PACK; FS1-TEXT, FS1-FLOAT, FS1-DATE.
WRITE: / FS2-INT, FS2-PACK, FS2-TEXT.

MOVE FS1 TO FS2.
WRITE: / FS2-INT, FS2-PACK, FS2-TEXT.

The output appears as follows:

        5 2.26 Fine text 1.234000000000000E+05 09161995

        3 72.34 Hello

        5 2.26 Fine

This example defines two different structures, FS1 and FS2. The structure of the structures is the same for the first two components. After assigning FS1 to FS2, only the result for the first two components is as if they had been moved component-by-component. FS2-TEXT is filled with the first five characters of FS1-TEXT. All other positions of FS1 are omitted.

 

Numeric components of structures filled by assigning values of non-compatible structures can contain meaningless or even illegal values which result in a runtime error.