We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!
Writable expressions can be specified for the memory are but not any 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.
... NEW class( ... )->attr $| CAST type( ... )->dobj
to the field symbol. The same rules apply as when statically specifying the memory area, but no offsets/lengths can be specified.
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.
CLASS class DEFINITION.
DATA attr TYPE string VALUE 'foo'.
ASSIGN NEW class( )->attr TO FIELD-SYMBOL(<fs>).
cl_demo_output=>display( <fs> ).
Constructor expression with CAST in the specified memory area of ASSIGN statements.
TYPES: BEGIN OF t_struc,
col1 TYPE i,
col2 TYPE i,
END OF t_struc.
DATA dref TYPE REF TO data.
DATA struc TYPE t_struc.
dref = NEW t_struc( ).
ASSIGN CAST t_struc( dref )->col1 TO FIELD-SYMBOL(<col1>).
ASSIGN CAST t_struc( dref )->col2 TO FIELD-SYMBOL(<col2>).
This alternative way of 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.
In this variant, the statement ASSIGN sets the return code sy-subrc.
Unlike when table expressions are used in other ways, 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 enough just to evaluate the predicate expression <fs> IS ASSIGNED; sy-subrc needs to be checked as well.
In the case of 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.
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.
PARAMETERS: p_carrid TYPE sflight-carrid,
p_connid TYPE sflight-connid,
p_fldate TYPE sflight-fldate.
DATA sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate.
WHERE carrid = @p_carrid AND
connid = @p_connid
INTO TABLE @sflight_tab.
IF sy-subrc = 0.
ASSIGN sflight_tab[ KEY primary_key COMPONENTS
carrid = p_carrid
connid = p_connid
fldate = p_fldate ]-price
IF sy-subrc = 0.
<price> = <price> * '0.9'.