Entering content frame

Conversion Rules for Structures Locate the document in its SAP Library structure

ABAP has one rule for converting structures that do not contain internal tables and do not contain strings as components. There are no conversion rules for structures that contain internal tables or strings. You can only make assignments between structures that are compatible.

You can combine convertible structures in the following combinations:

        Converting a structure into a non-compatible structure

        Converting elementary fields into structures

        Converting structures into elementary fields

In each case, the system first converts all the structures concerned to type c fields and then performs the conversion between the two resulting elementary fields. The length of type c fields is the sum of the lengths of the components. This rule applies to all operations using structures that do not contain internal tables.

If a structure is aligned, the filler fields are also added to the length of the type C field.

Example

A non-aligned structure without filler fields:

This graphic is explained in the accompanying text

If you convert a structure into a shorter structure, the original structure is truncated. If you convert a structure into a longer one, the parts at the end are not initialized according to their type, but filled with blanks.

It can make sense to assign a structure to another, incompatible, structure if, for example, the target structure is shorter than the source, and both structures have the same construction over the length of the shorter structure. However, numeric components of structures that are filled in incompatible assignments may contain nonsensical or invalid values that may cause runtime errors.

Example

REPORT demo_data_conversion_structure.

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',
         date     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.

Output:

        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. In each one, the first two components have the same data type. After assignment of fs1 to fs2, only the result for the first two components is as if they had been transferred component by component. fs2-text is filled with the first five figures of fs1-text. All the remaining positions of fs1 are omitted.

 

 

Leaving content frame