Ansicht
Dokumentation

ABAPASSIGN_MEM_AREA_WRITABLE_EXP - ASSIGN MEM AREA WRITABLE EXP

ABAPASSIGN_MEM_AREA_WRITABLE_EXP - ASSIGN MEM AREA WRITABLE EXP

RFUMSV00 - Advance Return for Tax on Sales/Purchases   General Material Data  
This documentation is copyright by SAP AG.
SAP E-Book

ASSIGN, writable_exp

Short Reference



... NEW class( ... )->attr $| CAST type( ... )->dobj
  $| table_exp  ...


Alternatives:

1. ... NEW class( ... )->attr $| CAST type( ... )->dobj

2. ... table_exp

Effect

The operand position after ASSIGN is a result position in which writable expressions can be specified.

Notes

  • Writable expressions can be specified for the memory area but no other expressions, because only writable expressions can have a non-temporary result. Assigning a temporary data object to a field symbol would not make sense.
  • Writable expressions cannot be specified dynamically in a data object name.

Alternative 1

... NEW class( ... )->attr  $| CAST type( ... )->dobj


Effect

This alternative to specifying the memory area mem_area of the statement ASSIGN assigns the result of the following constructor expression to a field symbol:

The same rules apply as to statically specifying the memory area, but no offsets/lengths can be specified.

Notes

  • Assigning an attribute attr of an object created using NEW to a field symbol persists this object as long as the field symbol points to the attribute.
  • In this variant, the used constructor expression sets the return code sy-subrc instead of the statement ASSIGN.
  • If the object is created successfully, the instance operator NEW sets the return code sy-subrc to 0.

  • The casting operator CAST does not set the return code sy-subrc.

Example

Constructor expression with NEW in the specified memory area of the statement ASSIGN. The assignment of the attribute attr to a field symbol persists the object.

Constructor expression with CAST in the specified memory area of ASSIGN statements.

Alternative 2

... table_exp


Effect

This alternative to specifying the memory area mem_area of the statement ASSIGN assigns the result of the table expression table_exp or table expression chaining to the field symbol. The result of a table expression in these positions is always a temporary field symbol.

  • If a single table expression is specified, or a chaining whose last position is a table expression, the entire line found is assigned to the field symbol.
  • If a chaining is specified whose last position is a structure component after a structure component selector, this component is assigned to the field symbol. No offsets/lengths, however, can be specified for the structure component here.

In this variant, the statement ASSIGN sets the return code sy-subrc.

  • If the specified line is found, sy-subrc is set to 0.
  • If the line is not found, sy-subrc is set to 4, except when the end of the table is reached in binary searches in sorted tables. In this case, sy-subrc is set to 8.

Unlike in other use cases of table expressions, the system field sy-tabix is set here in the same way as in a corresponding READ TABLE statement.

If the assignment is not successful, the field symbol keeps its previous state. In this variant, it is therefore not sufficient to evaluate the predicate expression <fs> IS ASSIGNED, but sy-subrc needs to be checked as well.

In this variant of the statement ASSIGN, the addition CASTING can only be specified in assignments to an existing field symbol and not in inline declarations, and only as a standalone addition. The addition RANGE cannot be specified.

Notes

  • More specifically, the value of sy-subrc and sy-tabix is set as in the statement READ TABLE and

Unlike READ TABLE, chainings can also be used to assign components of read lines or lines of nested internal tables.
  • The constructor operators VALUE and REF used to control the result of the table expression cannot be used here.
  • If the specified line is not found, an exception is not raised, unlike in other uses of table expressions.

Example

This example works in the same way as the example for READ TABLE ... ASSIGNING .... Here, the READ statement is replaced by an ASSIGN statements and the required component is assigned directly.






ABAP Short Reference   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.

Length: 8323 Date: 20240616 Time: 105702     sap01-206 ( 129 ms )