Defining the Data Type of a Field Symbol 

To set the data type of a field symbol independently of that of the objects that you assign to it, use the TYPE addition in the ASSIGN statement:

ASSIGN ..... TO <FS> TYPE <t>.

You can use the TYPE addition in all variants of the ASSIGN statement. At present, you can only use the elementary ABAP types (C, D, F, I, N, P, T, and X), ‘s’ for two-byte integers (with sign) and ‘b’ for one byte integers (without sign) as literals of variables for <t>.

There are two possible cases:

If you use the TYPE addition, an untyped field symbol <FS> adopts the data type specified in <t> instead of the data type and output length of the data object assigned to it. If the field symbol is used after the assignment in the program, the assigned data object is not converted to the specified type <t>. However, the contents of the data object are interpreted as though they belonged to a field of type <t>. When you specify the type of a field symbol, you force a particular view on the data objects assigned to it.

Using the TYPE option with a typed field symbol makes sense if the data type of the data object to be assigned is incompatible with the typing of the field symbol, but you want to avoid the resulting error message. In this case, the specified type <t> and the typing of the field symbol must be compatible. The field symbol then retains its data type, regardless of the assigned data object.

A runtime error occurs if

DATA TXT(8) VALUE '19980606'.

DATA MYTYPE(1) VALUE 'X'.

FIELD-SYMBOLS <FS>.

ASSIGN TXT TO <FS>.
WRITE / <FS>.

ASSIGN TXT TO <FS> TYPE 'D'.
WRITE / <FS>.

ASSIGN TXT TO <FS> TYPE MYTYPE.
WRITE / <FS>.

The output is:

19980606

06061998

3139393830363036

In this example, the character string TXT is assigned to <FS> three times. In the first assignment, the type is not specified. The second time, the type is specified as D, and finally as X. The format of the second output line depends on the settings of the current user in their user master record. The numbers in the last line are the hexadecimal codes of the characters in TXT. They are platform-specific (in this case, ASCII).