ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Assignments → Assigning References → Setting Field Symbols → ASSIGN → ASSIGN - mem_area
ASSIGN - static_dobj
Other versions:
7.31 | 7.40 | 7.54
Syntax
... dobj[+off][(len)] ...
Effect
In the static variant for the memory area, a data object dobj
with an optional offset/length +off(len)
can be specified in accordance with the rules in the section
Data Objects in Operand Positions, with the following exception: A data reference deferenced using the deferencing operator ->* is
specified dynamically. dobj
specified using a field symbol, on the other hand, is a static variant.
The memory area is determined by the specified offset/length +off(len)
as follows:
-
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
dobj
is 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. The general rules for
substring accesses apply. If these rules are met, memory
outside the
dobj
field limits can also be addressed. The addressable memory is based on the specificationrange_spec
. If an offsetoff
is specified without a lengthlen
, the length of the data objectdobj
is used implicitly forlen
. If a field symbol is specified fordobj
, to which a memory area is already assigned, the content of the offset length can be negative, as long as the area specified inrange_spec
is not exited. The following restrictions apply when offsets/lengths are specified:
- No inline declaration of the field symbol with
FIELD-SYMBOL(<fs>)
can be made.
- The data type of
dobj
cannot bestring
orxstring
. This means thatlen
can never be less than or equal to zero.
- If the name of a data object is specified for
dobj
and if no explicitRANGE
addition is used, no offsetoff
can 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 offsetoff
is specified without lengthlen
.
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
predicate expression
<fs> IS ASSIGNED
can be evaluated.
In an inline declaration of the field symbol with
FIELD-SYMBOL(<fs>), the field symbol is typed with the data type that can be determined
statically for mem_area
. If mem_area
is a generically typed field symbol or a generically typed formal parameter, the generic type is used.
Notes
-
Ensure that the system field
sy-subrc
is not evaluated inadvertently after the static variant. The value of the system field in this case is always the same as it was before theASSIGN
statement 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-subrc
being set. -
If a generically typed field symbol or a generically typed formal parameter is specified for
dobj
, its current type at runtime determines the behavior, for example whether offsets/lengths can be specified.
Example
Assigns 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>.
cl_demo_output=>write_text( |{ <char> }| ).
ENDDO.
cl_demo_output=>display( ).