Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Assignments →  Setting References →  ASSIGN →  ASSIGN - casting_spec →  Casting Examples 

Field Symbols - Casting Predefined Data Types

This example demonstrates how a casting is carried out on predefined data types.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA txt(8) TYPE c VALUE '20050606'.

    DATA mytype(1) VALUE 'X'.

    FIELD-SYMBOLS <fs> TYPE ANY.

    ASSIGN txt TO <fs>.
    WRITE / <fs>.

    SKIP.

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

    ASSIGN txt TO <fs> CASTING TYPE d.
    WRITE / <fs>.

    ASSIGN txt TO <fs> CASTING TYPE (mytype).
    WRITE / <fs>.

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

    "ASSIGN txt TO <fs> TYPE 'D'.
    "WRITE / <fs>.

    "ASSIGN txt TO <fs> TYPE mytype.
    "WRITE / <fs>.

Description

This example demonstrates casting on predefined data types. First the character string txt is assigned to the field symbol <fs> without casting. Then txt is assigned to <fs> using casting on types d and x. The format of the second output row depends on the data in the user master record. The paired numbers in the last output row represent the hexadecimal code for the character in txt and depend on the character display of the current application server.

The syntax for the corresponding obsolete casting is still included in the commented out section of the method.