Самый яркий пример использования FIELD-SYMBOLS.
REPORT z_lx_test. TYPES: BEGIN OF t_table1 , field1 TYPE c , field2 TYPE i , END OF t_table1. TYPES: BEGIN OF t_table2 , field1 TYPE c , field2 TYPE i , field3 TYPE d , END OF t_table2. DATA: t1 TYPE t_table1. DATA: it1 TYPE TABLE OF t_table1. DATA: t2 TYPE t_table2. DATA: it2 TYPE TABLE OF t_table2. FIELD-SYMBOLS: <it> TYPE t_table1.
REFRESH: it1, it2. DO 5 TIMES. CLEAR t1. t1-field1 = 'X'. t1-field2 = sy-index. APPEND t1 TO it1. ENDDO. DO 8 TIMES. CLEAR t2. t2-field1 = 'X'. t2-field2 = sy-index. t2-field3 = sy-datum. APPEND t2 TO it2. ENDDO. PERFORM print TABLES it1. ULINE. PERFORM print TABLES it2. ULINE. WRITE: / 'OK'. *&---------------------------------------------------------------------* *& Form PRINT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_IT1 text *----------------------------------------------------------------------* FORM print TABLES p_it . DATA work_tab_ref TYPE REF TO data. FIELD-SYMBOLS: <work_tab> TYPE STANDARD TABLE. * скопируем структуру в символьную переменную CREATE DATA work_tab_ref LIKE p_it[]. ASSIGN work_tab_ref->* TO <work_tab>. MOVE p_it[] TO <work_tab>. FIELD-SYMBOLS: <wa> TYPE ANY. LOOP AT <work_tab> ASSIGNING <wa>. FIELD-SYMBOLS: <fld> TYPE ANY. FIELD-SYMBOLS: <comp> TYPE ANY. DO. ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO <comp>. IF <comp> IS ASSIGNED. WRITE <comp>. UNASSIGN <comp>. ELSE. EXIT. ENDIF. ENDDO. write /. ENDLOOP. ENDFORM. " PRINT
Комментарии
Отправить комментарий