Skip to content

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

Field Symbols, Cast Structures

This example demonstrates how field symbols are cast.

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>

  "FIELD-SYMBOLS: <f1> STRUCTURE line1 DEFAULT wa,
  "               <f2> STRUCTURE line2 DEFAULT wa.

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

    cl_demo_output=>display(
             |{ <f1>-col1 } { <f1>-col2 } { <f1>-col3 }\n| &&
             |{ <f2>-col1 } { <f2>-col2 }| ).

Description

The structures line1 and line2 are cast to the number string "0123456789". The structure is then accessed using the appropriate field symbol and the components are produced one by one. Note that the date component contains an invalid date after the assignment, which is only used here for demonstration purposes.

The structures are cast using the ASSIGN CASTING statement. The obsolete addition STRUCTURE of the statement FIELD-SYMBOLS, replaced by ASSIGN CASTING, is shown here as a comment.