SAP Tutorials Blog


 


"Table expressions

"Note: sy-subrc is set. If the line is found, sy-subrc is set to 0.


DATA(strtab_f) = VALUE string_table( ( `ABAP` ) ).


ASSIGN strtab_f[ 1 ] TO FIELD-SYMBOL(<fs_wa_g>).

ASSERT sy-subrc = 0.


ASSIGN strtab_f[ 2 ] TO <fs_wa_g>.

ASSERT sy-subrc <> 0.


"Constructor expressions


"NEW

"Assigning instance attributes of a class

ASSIGN NEW zcl_demo_abap_objects( )->another_string TO FIELD-SYMBOL(<fs_attribute1_g>).


"CAST

TYPES: BEGIN OF struc_g,

         comp1 TYPE i,

         comp2 TYPE i,

       END OF struc_g.


DATA dref_g TYPE REF TO data.

dref_g = NEW struc_g( comp1 = 1 comp2 = 2 ).


ASSIGN CAST struc_g( dref_g )->comp1 TO FIELD-SYMBOL(<fs_comp1_g>).

ASSIGN CAST struc_g( dref_g )->comp2 TO FIELD-SYMBOL(<fs_comp2_g>).

ASSIGN CAST struc_g( dref_g )->* TO FIELD-SYMBOL(<fs_struc_g>).


DATA iref TYPE REF TO zdemo_abap_objects_interface.

DATA(oref) = NEW zcl_demo_abap_objects( ).

oref->another_string = `hello`.

iref = oref.

iref->in_str = `world`.


ASSIGN CAST zcl_demo_abap_objects( iref )->another_string TO FIELD-SYMBOL(<fs_attribute2_g>).

ASSIGN CAST zdemo_abap_objects_interface( oref )->in_str TO FIELD-SYMBOL(<fs_attribute3_g>).


Serkan AKKAVAK

Computer Engineer BSc

Head of SAP & Software Department

Contact : serkurumsal@yandex.com