ABAP - Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Assignments →  Assigning References →  Setting Field Symbols → 

ASSIGN

Quick 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>. A data object or a memory area calculated from the address of a data object can be assigned. 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 following can be specified for <fs>:

The data type with which the assigned memory area is handled depends on what is specified in casting_spec. Either an explicit casting can be performed or the field symbol uses the data type of the data object specified in the assignment. In both cases, the data type used must match the typing of the field symbol. 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 at least 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.

The information in range_spec is used to define the memory area that can be assigned to the field symbol.

System Fields

The return value is set only for the dynamic variants and the table expression variant of mem_area. If the constructor operator NEW is used as a writable expression, this operator sets the return value.

sy-subrc Meaning
0 Assignment completed.
4 Assignment not completed.
8 A table expression was not assigned.

If a dynamic assignment or assignment of a table expression could not be performed, the field symbol keeps its previous state. If the static assignment could not be performed, a memory is not assigned to the field symbol after the statement ASSIGN and the assignment can be checked with the predicate expression <fs> IS ASSIGNED. If an assignment were to produce illegal memory accesses, an exception is raised in the case of both static and dynamic ASSIGN statements.

Notes

Exceptions

Handleable Exceptions

CX_SY_ASSIGN_CAST_ILLEGAL_CAST

CX_SY_ASSIGN_CAST_UNKNOWN_TYPE

CX_SY_ASSIGN_OUT_OF_RANGE

Non-Handleable Exceptions



Continue
ASSIGN - mem_area
ASSIGN - casting_spec
ASSIGN - range_spec