ASSIGN - mem_area

Syntax

... { dobj[+off][(len)] }
  | { [TABLE FIELD] (name) }
  | { oref->(attr_name) }
  | { {class|(class_name)}=>{attr|(attr_name)} }
  | { dref->* }
  | { dobj INCREMENT inc }
  | { COMPONENT comp OF STRUCTURE struc } ... .

Alternatives:


Static specification

1. ... dobj[+off][(len)]


Dynamic specifications

2. ... [TABLE FIELD] (name)

3. ... oref->(attr_name)

4. ... {class|(class_name)}=>{attr|(attr_name)}

5. ... dref->*

6. ... dobj INCREMENT inc

7. ... COMPONENT comp OF STRUCTURE struc

Effect

Using mem_area, you specify the storage area that is assigned to the field symbol.

The first variant is a static variant, while the other variants are dynamic. Static and dynamic variants basically differ in the way the system behaves after successful assignment:

Note

Even the static variant is dynamic in that the offset/ length specifications can be dynamic.

Alternative 1

... dobj[+off][(len)]


Effect

The storage area is specified by a data object specified in accordance with the rules described in the section Data Objects in the Operand Positions. In particular, dobj can itself be specified by a field symbol. If you have an offset/length specification, the data type dobj heremust neither be string nor xstring.

If the name of a data object is specified for dobj and if no explicit RANGE addition is used, no offset off can be specified without the length len in Unicode programs. If the name of a field symbol is specified for dobj, its data type must be flat and elementary in Unicode programs - whenever an offset off is specified without length len.

Example

Assignment of the storage 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.

Alternative 2

... [TABLE FIELD] (name)


Alternative 3

... oref->(attr_name)


Alternative 4

... {class|(class_name)}=>{attr|(attr_name)}


Effect

There are three dynamic variants for mem_area, where the storage area is not specified directly, but as the content of character/type data objects enclosed within parentheses.

In the first variant (name), the label in name is built exactly like the direct specification. When the statement is executed, the content of name must be the label of a data object that can contain offset/length specifications, structure component selectors, and component selectors for the assignment of attributes in classes or objects (since Release 6.10). The content of name must be specified in uppercase letters.

The optional addition TABLE FIELD before (name) is only possible outside of classes. This addition limits the search area - where the data object specified in (name) is searched for (see below) - to the interface work areas for the current program group declared using TABLES. If TABLE FIELD is specified, casting_spec and range_spec cannot be specified explicitly.

If the label in name is a field symbol or a form parameter with an unstructured type, components can be addressed, as of Release 6.10, through structure component selectors. The components must exist when the statement is executed.

The second variant oref->(attr_name) is a special case of the first variant for the assignment of an instance attribute to a field symbol - where the object reference variable oref is specified statically. The label of the attribute is specified dynamically in the character-type field attr_name and must not be specified in uppercase letters.

The third variant {class|(class_name)}=>{name|(attr_name)} is a special case of the first variant for the assignment of a static attribute to a field symbol where the class name class and the name of the attribute name can be specified both directly and dynamically in character-type fields class_name or attr_name. The contents of attr_name and class_name do not have to be in uppercase letters. If the class name is specified dynamically and the attribute is specified directly, no offset/length specifications can be made for the attribute.

If a data object is specified dynamically, this is searched for in accordance with the following hierarchy.

  1. Within the local data objects of the current procedure

  2. Within the attributes, visible in a method, of the actual class, where , in instance methods, the self reference me-> is set explicitly before the label

  3. Within the global data of the current program

  4. Within the interface work areas of the main program of the current program group declared with TABLES

  5. Within the attributes of the object to which oref refers, if the label has the expression oref-> (as of Release 6.10)


Note

The label in name can also have the form (PROG)DOBJ for internal use only, where PROG is the name of an ABAP program and DOBJ is the name of a global data object of this program. If the program PROG is loaded during execution of the statement ASSIGN in the same internalmode as the current program, the data object (PROG)DOBJ is searched for in this program, and the field symbol points to this data object after the object has been successfully assigned.

Example

Dynamic access to an attribute of an object (Dynamic Access) through a field symbol.

CLASS c1 DEFINITION.
  PUBLIC SECTION.
    METHODS m1 IMPORTING oref TYPE REF TO object
                         attr TYPE string.
ENDCLASS.

CLASS c1 IMPLEMENTATION.
  METHOD m1.
    FIELD-SYMBOLS <attr> TYPE ANY.
    ASSIGN oref->(attr) TO <attr>.
    WRITE <attr> ...
  ENDMETHOD.
ENDCLASS.

Alternative 5

... dref->*


Effect

If you specify a data reference dref for a mem_area that was dereferenced using the dereferencing operator ->*, the storage area of the data object is assigned to the field symbol. The data object concerned is the one to which dref points. If the reference variable dref does not reference any data object, the assignment is not carried out and sy-subrc is set to 4.

In contrast to all the other operand positions where the specification of dref->* is only possible as of Release 6.10 and the data reference dref must be fully typed, the specification of dref->* was already possible with Release 4.6 in the statement ASSIGN.

In the statement ASSIGN, dref can be typed generically using TYPE REF TO data. Furthermore, the data referencing of a data reference that does not point to any data object does not cause an exception that cannot be handled, but only in the statement ASSIGN.

Since Release 6.10, dref->* can also be specified in the dynamic variants mentioned as a field content, and after dref->* it is possible to enter offset or length specifications - if dref is completely typed.

Example

Creating a local copy of a global data object g_dat in a procedure with the help of a data reference dref and access through a local field symbol <l_dat> after data referencing

DATA g_dat TYPE string.

...

FORM subroutine.
  DATA dref TYPE REF TO data.
  FIELD-SYMBOLS <l_dat> TYPE ANY.
  CREATE DATA dref LIKE g_dat.
  ASSIGN dref->* TO <l_dat>.
  WRITE <l_dat> ...
ENDFORM.

Alternative 6

... dobj INCREMENT inc


Effect

With this expression for mem_area, a memory area is assigned to a field symbol that is the same length as the memory area for dobj and is separated from the dobj memory area by a factor of inc times this length. A numeric data object is expected for inc. For dobj, a data object or a field symbol must be entered directly. Offset or length specifications, or dereferencing of a data reference are not possible.

Example

See the second example for range_spec.

Alternative 7

... COMPONENT comp OF STRUCTURE struc


Effect

With this expression for mem_area, the memory area of a component comp of a structure struc is assigned to the field symbol. While the structure struc is specified directly, a data object must be specified for comp. The evaluation depends on the data type of comp:

If struc is not a structure, the assignment is not executed and sy-subrc is set to 4.

Notes

Example

Assignment of the components of a structure - to which a non-typed field symbol points - to another field symbol.

DATA spfli_wa TYPE spfli.

FIELD-SYMBOLS: <wa>   TYPE ANY,
               <comp> TYPE ANY.

ASSIGN spfli_wa TO <wa>.

SELECT SINGLE *
       FROM spfli
       INTO spfli_wa
       WHERE carrid = 'LH' AND
             connid = '400'.

WHILE sy-subrc = 0.
  ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <comp>.
  WRITE / <comp>.
ENDWHILE.