Posted: Fri Sep 21, 2007 4:56 pm Post subject: Example: Table of dynamic objects
Code:
REPORT s_dynamic_data_objects.
* Data declarations
TYPES: BEGIN OF t_item,
content TYPE i,
next TYPE REF TO data,
END OF t_item.
DATA: dref_start TYPE REF TO data,
dref_new TYPE REF TO data.
FIELD-SYMBOLS <fs_new> TYPE t_item.
* Create dynamic list
DO 10 TIMES.
CREATE DATA dref_new TYPE t_item.
ASSIGN dref_new->* TO <fs_new>.
<fs_new>-content = sy-index ** 2.
IF sy-index = 1.
dref_start = dref_new.
ENDIF.
PERFORM append_item USING dref_start
dref_new.
ENDDO.
PERFORM show_list_content USING dref_start.
* Subroutines
FORM append_item USING dref_start TYPE REF TO data
dref_new TYPE REF TO data.
FIELD-SYMBOLS <fs_curitem> TYPE t_item.
DATA dref_cur TYPE REF TO data.
IF dref_start = dref_new.
EXIT.
ENDIF.
dref_cur = dref_start.
ASSIGN dref_cur->* TO <fs_curitem>.
WHILE NOT <fs_curitem>-next IS INITIAL.
dref_cur = <fs_curitem>-next.
ASSIGN dref_cur->* TO <fs_curitem>.
ENDWHILE.
<fs_curitem>-next = dref_new.
ENDFORM.
*
FORM show_list_content USING dref_start TYPE REF TO data.
FIELD-SYMBOLS <fs_curitem> TYPE t_item.
DATA dref_cur TYPE REF TO data.
dref_cur = dref_start.
WHILE NOT dref_cur IS INITIAL.
ASSIGN dref_cur->* TO <fs_curitem>.
WRITE:/ <fs_curitem>-content.
dref_cur = <fs_curitem>-next.
ENDWHILE.
ENDFORM.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.