ASSIGN

Short Reference

Syntax

ASSIGN mem_area TO <fs> casting_spec range_spec.

Effect

This statement assigns the memory area specified using mem_area to the field symbol <fs>. You can assign a data object or a memory area calculated from the address of a data object. After the assignment, the field symbol refers to the assigned memory area and can be used in operand positions. When used in a statement, it behaves like a dereferenced data reference, meaning that the statement works with the content of the memory area.

The data type with which the assgigned memory area is treated, depends on the specifications in casting_spec. You can either execute an explicit casting or the field symbol takes on the data type of the data object specified in the assignment. A field symbol to which a memory area is assigned, has this data type after the assignment and behaves like a data object of this type.

The assigned memory area mem_area must be at least as long as the data type specified in casting_spec and must have the same alignment. If the data type determined in casting_spec is deep, the deep components with their type and position must appear in the assigned memory area exactly like this.

Use the specifications in range_spec to restrict the memory area that can be assigned to the field symbol.

System Fields

The return value is set only for the dynamic variants of mem_area.

sy-subrc Meaning
0 Assignment successful.
4 Assignment not successful.

After an unsuccessful dynamic assignment, the field symbol keeps its previous state.

Note

Obsolete Form: ASSIGN LOCAL COPY

Exceptions

Catchable Exceptions

CX_SY_ASSIGN_CAST_ILLEGAL_CAST

CX_SY_ASSIGN_CAST_UNKNOWN_TYPE

CX_SY_ASSIGN_OUT_OF_RANGE

Non-Catchable Exceptions