ABAPASSIGN_MEM_AREA_DYNAMIC_DOBJ - ASSIGN MEM AREA DYNAMIC DOBJ

General Data in Customer Master   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.

ASSIGN - dynamic_dobj

Short Reference



Syntax

... { (name) }
  | { dref->* }
  | { dobj INCREMENT inc }
  | { COMPONENT comp OF STRUCTURE struc } ...

Alternatives:

1. ... (name)

2. ... dref->*

3. ... dobj INCREMENT inc

4. ... COMPONENT comp OF STRUCTURE struc

Effect

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

In these variants, the ASSIGN statement sets the return code sy-subrc. If the assignmentis successful, sy-subrc is set to 0; if not, it is set to 4. If the assignment is not successful,the field symbol keeps its previous state. The evaluation of the logical expression <fs>IS ASSIGNED is not sufficient for a dynamic ASSIGN and sy-subrc must be checked.

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 name in name is structured in 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 component selectors for assigning attributes in classes or objects. The content of name must be in uppercase letters.

If the name in name is a field symbol or a formal parameter with unstructuredtyping,you can use structure component selectors to address components. The components must exist when the statement is executed.

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 local data objects of the procedure are scanned.

  2. If the statement is located in a method, the attributes visible in the method within the class are scanned. In instance methods, thestatic type of me (special case of cref->(attr_name) in dynamic_access) is scanned.

  3. The global data of the current program is scanned.

  4. The interface work areas of the main program of the current program group declared using TABLES are scanned.

  5. If the statement is located in an instance method, thedynamic type of me (special case of cref->(attr_name) in dynamic_access) is scanned.

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 underdynamic_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

  • If an attribute of a class in a different program is specified in name using anabsolute type name, then, depending on the program type, it is loaded into a newadditional program group or to the currentprogram group, if not already loaded. Any existingprogramconstructors are not executed, however, unlike in a genuine dynamic_access.

  • 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. If the program "PROG" is loaded into the sameinternalsession as the current program when the ASSIGN statement is executed, then 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 TABLEFIELD can be specified before name. This restricts the search to table work areas.


Alternative 2

... dref->*


Effect

When specifying a dereferenced data reference dref for mem_area using the dereferencingoperator ->*, the memory area of the data object is assigned to the field symbol to which drefpoints. 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 for which the data reference dref must be fully typed fordereferencing, dref can be typed generically in the statement ASSIGN using TYPE REFTO data. Dereferencing of a data refrence that does not point to a data object also results in an unhandleable exception in all cases except in the ASSIGN statement.

Example

Creating a local copy of a global data object g_dat in a procedure using a data reference dref and using a local field symbol <l_dat> for access after dereferencing.

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 3

... dobj INCREMENT inc


Effect

This expression for mem_area assigns a memory area to the field symbol that has the same lengthas the memory area of dobj and is incremented inc times this length in reference to thememory area of dobj. inc expects a numeric data object. A data object or a field symbolmust be specified directly for dobj. Offset or length specifications or the dereferencing of a data reference are not possible.

Notes

The dynamic ASSIGN variant with INCREMENT is designed for sequential access to similarmemory areas that are located at regular intervals after each other, such as consecutive structure componentsof the same data type. In all other cases, ASSIGN ... INCREMENT must be used with caution. You should note the following in particular:

  • The assigned memory area is handled using the data type dobj if the addition CASTING isnot 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.

  • The behavior of the statement can be different inUnicode systems and non-Unicode systems if dobj consumes a different number of bytes.

  • Runtime errors always occur if the following general rule is violated: Ifdeepdata objects that are in the assigned memory area do not match the typing as far as type and position are concerned.


Example

For information about the behavior of the ASSIGN statement with the addition INCREMENT, see the respectiveABAP example.For an example of usage, see the second example for range_spec.

Alternative 4

... COMPONENT comp OF STRUCTURE struc


Effect

This expression for mem_area assigns a memory area of a component comp of a structurestruc to the field symbol. While the structure struc is specified directly, you must specify a data object for comp. The evaluation depends on the data type of comp:

  • If the field comp has a text-like type (c or string) or the type of aflatstructure, its content is interpreted as the name of the component. The name must be in uppercase letters.

  • If the field comp has a non-text-like elementary type, the content is converted to the type iand interpreted as the position of the component in the structure. If the value of comp is 0, the memory area of the entire structure is assigned to the field symbol.


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

Notes

  • Identifying a component by its name is far more performance-intensive than using its position, since far more internal processes are involved.

  • To access statically known components of unstructured typed formal parameters or field symbols, youcan use the structure component selector after the parenthesized dynamic formal parameter or field symbol directly, instead of the assignment of dynamic structure components shown here.


Examples

The following source code excerpts show the dynamic assignment of the components of a structure (passed to the parameter para of a method meth) to a field symbol <comp>.

The first implementation does not use RTTI. The statement DESCRIBEFIELD is used to check whether the passed data object is a structure. The components are then assigned to the field symbol in a DO loop.

METHOD meth.
  "IMPORTING para TYPE data.
  DATA dtype TYPE c LENGTH 1.
  FIELD-SYMBOLS <comp> TYPE any.
  DESCRIBE FIELD para TYPE dtype.
  IF dtype <> 'u' AND dtype <> 'v'.
    RETURN.
  ENDIF.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE para TO <comp>.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    ...
  ENDDO.
ENDMETHOD.

The second implementation uses RTTI. Adown cast of the type description object to the classCL_ABAP_STRUCTDESCR for the passed data objectensures that the object is a structure. A loop across the component table COMPONENTS assigns the components to the field symbol.

METHOD meth.
  "IMPORTING para TYPE data.
  DATA struct_descr TYPE REF TO cl_abap_structdescr.
  FIELD-SYMBOLS:
    <comp_descr> LIKE LINE OF cl_abap_structdescr=>components,
    <comp> TYPE any.
  TRY.
      struct_descr ?= cl_abap_typedescr=>describe_by_data( para ).
    CATCH cx_sy_move_cast_error.
      RETURN.
  ENDTRY.
  LOOP AT struct_descr->components ASSIGNING <comp_descr>.
    ASSIGN COMPONENT <comp_descr>-name
           OF STRUCTURE para TO <comp>.
  ENDLOOP.
ENDMETHOD.







TXBHW - Original Tax Base Amount in Local Currency   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.


Length: 15752 Date: 20120518 Time: 192739     triton ( 410 ms )