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

ASSIGN - static_dobj

Quick Reference

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 dereferenced using the dereferencing 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 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

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( ).

Example

A field symbol <fs1> points to the component col1 of the structure struct. In the first assignment of <fs1> to a field symbol <fs2>, an offset without length is specified, which means that the length 10 of the component col1 is used implicitly. This assignment is not possible, since the assigned memory area is outside of the permitted range. In the second assignment, the permitted memory area is expanded to the full structure using the assignment RANGE and the assignment is successful.

DATA:
  BEGIN OF struct,
    col1 TYPE c LENGTH 10 VALUE 'aaaaaaaaaa',
    col2 TYPE c LENGTH 10 VALUE 'bbbbbbbbbb',
  END OF struct.

FIELD-SYMBOLS: <fs1> TYPE c,
               <fs2> TYPE c.

ASSIGN struct-col1 TO <fs1>.
ASSIGN <fs1>+5 TO <fs2>.
IF <fs2> IS NOT ASSIGNED.
  cl_demo_output=>write( `No assignment without sufficient RANGE` ).
ENDIF.
ASSIGN <fs1>+5 TO <fs2> RANGE struct.
IF <fs2> IS ASSIGNED.
  cl_demo_output=>display( `Assignment with sufficient RANGE` ).
ENDIF.