What does it do? These variants for specifying the memory area mem_area>> of the statement ASSIGN>> access components of structures dynamically. In these variants, the statement ASSIGN> sets the return code sy-subrc>. If the assignment is successful, sy-subrc> is set to 0. In these variants, also exceptions can occur in case of some invalid dynamic specifications. If the assignment is not successful and no exception occurs, sy-subrc> is set to 4. If sy-subrc> is set to 4, the state of the field symbol depends on the addition ELSE UNASSIGN>>:
If ELSE UNASSIGN> is not specified, the field symbol keeps its previous state.
If ELSE UNASSIGN> is specified, no memory area is assigned to the field symbol. The field symbol has the state unassigned after the ASSIGN> statement.
Latest notes: If ELSE UNASSIGN> is not specified, it is not sufficient to evaluate the predicate expression > <(><)> IS ASSIGNED>> but sy-subrc> must be checked. If ELSE UNASSIGN> is specified, the predicate expression as well as sy-subrc> can be evaluated. NON_V5_HINTS ABAP_HINT_END
ABAP Alternative 1 ... struc-(comp)> BEGIN_SECTION ID ASSIGN-DYNAMIC-STRUC
What does it do? This variant of mem_area> assigns the memory area of a component specified in comp> of a structure struc> to the field symbol. struc> is a result position>. The structure can be specified as a data object or as a writable expression>. If it is detected at compile time that struc> is not a structure, a syntax error occurs. If that is detected at runtime, the runtime error STRUCTURE_ILLEGAL> occurs. For comp>, either a character-like data object or a numeric data object of type i> can be specified:
If comp> is character-like, its content is interpreted as the name of the component. The name is not case-sensitive. It may contain offsets and lengths, structure component selectors, and component selectors.
If comp> is of type i>, its value is 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 comp> has a different type, a syntax error or runtime error occurs.
ABAP_EXAMPLE_VX5 Two dynamic assignments with dynamic specification of components:
in the first, the structure is specified directly and the component is specified by its position.
in the second, the structure is specified by a writable expression with constructor operator NEW> and the component is specified by its name, which can have an offset/length specification. ABEXA 01674 ABAP_EXAMPLE_END END_SECTION ID ASSIGN-DYNAMIC-STRUC
ABAP_EXAMPLE_ABEXA Field Symbols, Dynamic Structure Components> ABAP_EXAMPLE_END
ABAP Alternative 2 ... dref->(comp_name)> BEGIN_SECTION ID ASSIGN-DYNAMIC-OREF
What does it do? This variant accesses components of structures that are referenced by a data reference variable> dref>. dref> can be any data reference variable that points to structure that contains the component specified in a character-like field comp_name>. The component name does not have to be in uppercase letters. It can contain offsets/lengths, structure component selectors, object component selectors, and class component selectors, in order to assign parts of the component or referenced objects of the component. Unlike all other operand positions, where a data reference that does not point to a data object raises an exception, no exception occurs in the statement ASSIGN> and sy-subrc> is set to 4. BEGIN_SECTION SAP_INTERNAL_HINT The exception is either the uncatchable DATREF_NOT_ASSIGNED> or the catchable CX_SY_ASSIGN_ILLEGAL_COMPONENT>. The latter is raised for a dynamic target>. END_SECTION SAP_INTERNAL_HINT