Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Obsolete Language Elements →  Obsolete Declarations →  Field Symbols 

Field Symbols - Casting Structures

This example demonstrates how field symbols are casted.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: wa(10) TYPE c VALUE '0123456789'.

    DATA: BEGIN OF line1,
            col1(3) TYPE c,
            col2(2) TYPE c,
            col3(5) TYPE c,
          END OF line1.

    DATA: BEGIN OF line2,
            col1(2) TYPE c,
            col2 TYPE sy-datum,
          END OF line2.

<span class="blue">* correct --------------------------------------------------------------</span>

    FIELD-SYMBOLS: <f1> LIKE line1,
                   <f2> LIKE line2.

    ASSIGN wa TO: <f1> CASTING,
                  <f2> CASTING.

<span class="blue">* obsolete, not supported in methods -----------------------------------</span>

  "               <f2> STRUCTURE line2 DEFAULT wa.

<span class="blue">* ----------------------------------------------------------------------</span>

    WRITE: / <f1>-col1, <f1>-col2, <f1>-col3,
           / <f2>-col1, <f2>-col2.


The numerical sequence "0123456789" is casted on the structures line1 and line2. Then the structure is accessed using the corresponding field symbol, and the components are individually output. Note that the date component contains an invalid date after the assignment, which is only used here for demonstration purposes.

The structures are casted using the ASSIGN CASTING statement. The obsolete STRUCTURE addition of the FIELD-SYMBOLS statement, which is replaced by ASSIGN CASTING, is shown here as an annotation.