ABAP Keyword Documentation → ABAP - Reference → Assignments → Setting References → ASSIGN
ASSIGN - mem_area
Other versions: 7.31 | 7.40 | 7.54
Syntax
... { dobj[+off][(len)] } 
  | { dynamic_dobj } 
  | { dynamic_access } ... . 
Alternatives
Static SpecificationDynamic Specifications
Effect
You use mem_area to specify the memory area that is assigned to the field symbol.
The first variant is a static variant, whereas the other variants are dynamic. The variants 
dynamic_dobj are used for general dynamic access to data objects; the
variants dynamic_access are used for dynamic access to the attributes of classes.
Static and dynamic variants differ in the way the system behaves after a successful assignment: In dynamic
variants, the ASSIGN statement sets the return code sy-subrc, which is not the case with static variants.  
Notes
- 
In an internal table with a header line, either the header line or the
table body can be assigned
to a field symbol. In the 
ASSIGNstatement, the name of an internal table with a header line addresses the header line. To address the table body,[]must be appended to the name in the usual way. A field symbol to which a table body is assigned behaves in the same way in operand positions as a table without a header line. - 
Field symbols to which data objects or parts of data objects are assigned in the
heap are memory-preserving, like
heap references. 
 
Alternative 1
... dobj[+off][(len)]
 
Effect
The memory area is specified by a data object dobjj specified in accordance with the rules described in the section
Data Objects in the Operand Positions. In particular, dobj itself can be specified by a field symbol. In an
offset/length specification, the data type of dobj must not be string orxstring, ensuring that
 len cannot be less than or equal to zero.
- 
If no offset/length specification is made, the assigned memory area is the same as the memory area of
the data object. The entire data object 
dobjis assigned to the field symbol, and statements that contain the field symbol in operand positions work with the data object. - 
If an offset/length is specified, the memory area is determined from the memory address of the data
object and the offset/length specifications. Memory outside of the field limits for 
dobjcan be addressed. The addressable memory is based on the specificationrange_spec. If an offsetoffis specified without a lengthlen, the length of the data objectdobjis used implicitly forlen.
If the name of a data object is specified fordobjand if no explicitRANGEaddition is used, no offsetoffcan be specified without the lengthlen. If the name of a field symbol is specified fordobj, its data type must be flat and elementary whenever an offsetoffis specified without lengthlen. - 
If a field symbol is specified for 
dobj, to which a memory area is already assigned, the content of the offset length can be negative, as long as the area specified inrange_specis not exited. 
If the assignment is not successful, no memory area is assigned to the field symbol after the 
ASSIGN statement. The return code sy-subrc is not set for static variants.
Instead, the logical expression <fs> IS ASSIGNED can be evaluated.  
Notes
- 
Ensure that you do not inadvertently evaluate the system field 
sy-subrcafter the static variant. The value of the system field in this case is always the same as it was before theASSIGNstatement was executed and therefore does not indicate whether the statement was successful. - 
Even the static variant is dynamic in the sense that the offset and length specifications may be dynamic.
Dynamic offset/length specifications do not, however, result in the system field 
sy-subrcbeing set.
 
Example
Assignment of the memory area of the individual characters of a data object text to a field symbol <char>.
DATA text TYPE c LENGTH 10 VALUE '0123456789'. 
FIELD-SYMBOLS <char> TYPE c. 
DATA off TYPE i. 
DO 10 TIMES. 
  off = sy-index - 1. 
  ASSIGN text+off(1) TO <char>. 
  WRITE / <char>. 
ENDDO.