Typing Field Symbols
You can type a field symbol using the <type> option of the FIELD-SYMBOLS statement as follows:
Syntax
FIELD-SYMBOLS <FS> <type>.
For the <type>, you can write either TYPE <t> or LIKE <f> (see
The Basic Form of the DATA Statement).When you assign a data object to the typed field symbol <FS> without making a type specification, the system checks whether the type of the assigned data object is compatible with the typing of the field symbol. The compatibility rules are set out in the table below. If types are incompatible, the system outputs an error message during the syntax check if possible, or reacts with a runtime error.
On the other hand, no error occurs if you want the field symbol to retain its specified type, regardless of the assigned data object. Here, you must assign a data object with a type specification to the typed field symbol. The type specified during the assignment must then be compatible with the typing of the field symbol (see
Determining the Data Type of a Field Symbol).The following compatibility rules apply for the typing of field symbols:
Typing |
Syntax check for field assignment |
no type specified TYPE ANY |
The system accepts any field type. All attributes of the field are assigned to the field symbol. |
TYPE TABLE |
The system checks whether the field is an internal table. All attributes and the structure of the table are assigned to the field symbol. |
TYPE C, N, P, or X |
The system checks whether the field is of type C, N, P, or X. The field symbol inherits the length of the field and (for type P) its DECIMALS specification. |
TYPE D, F, I, or T LIKE <f>, TYPE <ud> |
These types are fully specified. The system checks whether the data type of the field agrees completely with the type of the field symbol. |
(<ud> is user-defined)
You use the option <type> to perform the same checks as for the formal parameters of subroutines.(see
Typing Formal Parameters). 
DATA DAT(8) VALUE ‘09161995’.
FIELD-SYMBOLS <FS> TYPE D.
ASSIGN DAT TO <FS>.
WRITE <FS>.
This program results in an error during the syntax check of the ASSIGN statement because DAT is incompatible with the typing of the field symbol <FS>.
DATA DAT(8) VALUE ‘19951609’.
FIELD-SYMBOLS <FS> TYPE D.
ASSIGN DAT TO <FS> TYPE ‘D’.
WRITE <FS>.
In this program, the ASSIGN statement specifies the same type as in the typing of <FS>. Therefore, the program is executable and produces the following output:
09161995
For further information about the ASSIGN statement, see
Assiging Data Objects to Field Symbols.