Ansicht
Dokumentation

ABAPASSIGN_MEM_AREA_DYNAMIC_DOBJ - ASSIGN MEM AREA DYNAMIC DOBJ

ABAPASSIGN_MEM_AREA_DYNAMIC_DOBJ - ASSIGN MEM AREA DYNAMIC DOBJ

Vendor Master (General Section)   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.
SAP E-Book

ASSIGN, dynamic_dobj

Short Reference



... ${ (name) $}
  $| ${ dref->* $}
  $| ${ dobj INCREMENT inc $} ...

Alternatives:

1. ... (name)

2. ... dref->*

3. ... dobj INCREMENT inc

Effect

These alternatives to specifying the memory area mem_area of the statement ASSIGN dynamically are used to dynamically access data objects.

In an inline declaration of the field symbol using FIELD-SYMBOL(<fs>), its typing is performed with the generic type data.

In these variants, the statement ASSIGN sets the return code sy-subrc. If the assignment is successful, sy-subrc is set to 0, otherwise to 4. If the assignment is not successful, the field symbol keeps its previous state. It is therefore not sufficient to evaluate the predicate expression <fs> IS ASSIGNED in a dynamic ASSIGN; sy-subrc must be checked as well.

Alternative 1

... (name)


Effect

In this dynamic variant of mem_area, the memory area is not specified directly, but as content of a character-like data object (name) in parentheses. The following can be specified for name:

  • Literal or constants
If the data object name is specified as a character literal or as a constant, it can be evaluated statically, and the specified data object is recognized as the used object.
  • Variable
If the data object name is specified as a variable, it is specified only dynamically, and the content is not evaluated statically.

When the statement is executed, name is not evaluated until runtime in both cases. The name in name is structured in exactly the same way as if specified directly: When executing the statement, the content of name must be the name of a data object which may contain offsets and lengths, structure component selectors, and other component selectors for assigning structure components, attributes in classes or attributes in objects. The content of name does not have to be in uppercase letters.

name can contain a chain of names consisting of component selectors. For an individual name or if the first name is followed by an object component selector (->), the specified data object is searched for according to the following hierarchy:

  1. If the statement is located in a procedure, the system searches for the local data objects of the procedure.
  2. If the statement is located in a method, the system searches in the visible attributes of a class in the method. In instance methods, this means a search of the static type of me (special case of cref->(attr_name) in dynamic_access).
  3. The system searches in the global data of the current program.
  4. The system searches in the interface work areas of the main program of the current program group declared using TABLES.
  5. If the statement is in an instance method, the system searches in the dynamic type of me (special case of cref->(attr_name) in dynamic_access).

If the data object is found and the name is followed by an object component selector (->), the search for the following names is continued from left to right, as described under dynamic_access.

If the first name is followed by a class component selector (=>), the specified class is searched for, as described under dynamic_access, and the search is then continued accordingly from left to right.

Notes

  • Dynamically specifying a structure component using a structure component selector is less effective than using the addition COMPONENT OF STRUCTURE, see the executable example.
  • Writable expressions writable_exp cannot be specified dynamically in name.
  • For internal use only, the name in name can also have the form "(PROG)DOBJ", where "PROG" is the name of an ABAP program and "DOBJ" the name of a global data object of this program, whereby the name is not case-sensitive. If the program "PROG" is loaded into the same internal session as the current program when the statement ASSIGN is executed, the data object "DOBJ" is searched for in this program and the field symbol points to this data object if the assignment was successful.
  • In an obsolete variant, the addition TABLE FIELD can be specified before name to restrict the search to table work areas.

Example

Dynamic output of the content of any system field. The validity of the input is checked before it is dynamically assigned with (name) to field symbol syfield via an application of classes of RTTI on structure SYST

Alternative 2

... dref->*


Effect

When specifying a dereferenced data reference dref for mem_area using the dereferencing operator ->*, the memory area of the data object is assigned to the field symbol to which dref points. If the reference variable dref does not reference a data object, the assignment is not performed and sy-subrc is set to 4.

Unlike all other operand positions, where a data reference that does not point to a data object raises an uncatchable exception, in the statement ASSIGN no exception occurs but sy-subrc is set to 4.

Assigning a dereferenced data reference that is initial. Here, no exception occurs.

Alternative 3

... dobj INCREMENT inc


Effect

This expression for mem_area assigns a memory area to the field symbol that has exactly the same length as the memory area of dobj and is incremented inc times this length in reference to the memory area of dobj. inc expects a numeric data object. A data object or a field symbol must be specified directly for dobj. Offset or length specifications or the dereferencing of a data reference are not possible. The field symbol cannot be declared via an inline declaration FIELD-SYMBOL(<fs>).

Notes

  • The dynamic ASSIGN variant with INCREMENT is designed for sequential access to similar memory areas that are located at regular intervals after each other, such as consecutive structure components of the same data type. In all other cases, ASSIGN ... INCREMENT should be used carefully. Note in particular:
  • Usually the addition RANGE must be used to defined the area, within which it is possible to work with INCREMENT.
  • The assigned memory area is handled using the data type dobj if the addition CASTING is not specified in casting_spec. This means that an implicit casting of the assigned memory areas to the data type of dobj is performed.
  • The typing check also refers to dobj, but is performed only when the statement is executed.
  • Runtime errors always occur if the following general rule is violated: If deep data objects that are in the assigned memory area do not match the typing in their type and position.

Example

After the ASSIGN statement, the field symbol points to the fourth component col4. See the example for the addition RANGE.

Field Symbols, ASSIGN INCREMENT






RFUMSV00 - Advance Return for Tax on Sales/Purchases   ABAP Short Reference  
This documentation is copyright by SAP AG.

Length: 12387 Date: 20240614 Time: 052935     sap01-206 ( 287 ms )