1. 程式人生 > >ABAP動態內表運用

ABAP動態內表運用

unique collect cat led vol gin cor ssi ade

     REPORT  ztest.  
      
    DATA: BEGIN OF wa_ets,  
          vbeln     LIKE lips-vbeln,  
          posnr     LIKE lips-posnr,  
    END OF wa_ets.  
      
    DATA:  
         l_fname    LIKE dd03l-fieldname,  
         typedesr   TYPE REF TO cl_abap_typedescr,  
         gt_comp    TYPE cl_abap_structdescr=>component_table,  
         gs_comp    
LIKE LINE OF gt_comp, is_comp TYPE abap_componentdescr, it_comp TYPE abap_component_tab, cl_stru TYPE REF TO cl_abap_structdescr, c2_stru TYPE REF TO cl_abap_structdescr, cl_tabl TYPE REF TO cl_abap_tabledescr, c2_tabl
TYPE REF TO cl_abap_tabledescr, cl_handle TYPE REF TO data, c2_handle TYPE REF TO data, cl_st TYPE REF TO data, c2_st TYPE REF TO data, c3_st TYPE REF TO data, key TYPE abap_keydescr_tab. FIELD-SYMBOLS
: <gt_itab> TYPE ANY TABLE , <it_itab> TYPE ANY TABLE , <fs1> TYPE ANY, <fs2>, <fs3>, <fs4>, <fs5>, <gs_struc> TYPE ANY. DATA: BEGIN OF gt_field OCCURS 0, kopos(2) TYPE n, fieldname LIKE dd03l-fieldname, rollname LIKE dd03l-rollname, ref_table LIKE dd03l-tabname, ref_field LIKE dd03l-fieldname, key TYPE c, END OF gt_field. ** DATA: it_field LIKE STANDARD TABLE OF gt_field WITH HEADER LINE. gt_field-fieldname = VBELN. gt_field-rollname = VBELN_VL. gt_field-ref_table = LIPS. gt_field-ref_field = VBELN. APPEND gt_field. MOVE gt_field TO it_field. APPEND it_field. gt_field-fieldname = POSNR. gt_field-rollname = POSNR_VL. gt_field-ref_table = LIPS. gt_field-ref_field = POSNR. APPEND gt_field. CLEAR gt_field. gt_field-fieldname = BRGEW. gt_field-rollname = GSGEW. gt_field-ref_table = LIPS. gt_field-ref_field = BRGEW. APPEND gt_field. MOVE gt_field TO it_field. APPEND it_field. gt_field-fieldname = VOLUM. gt_field-rollname = VOLUM. gt_field-ref_table = LIPS. gt_field-ref_field = VOLUM. APPEND gt_field. MOVE gt_field TO it_field. APPEND it_field. . LOOP AT gt_field. CLEAR: gs_comp, l_fname. CLEAR l_fname. CONCATENATE gt_field-ref_table - gt_field-ref_field INTO l_fname. is_comp-name = gt_field-fieldname. "is_comp-type ?= cl_abap_elemdescr=>describe_by_name( gt_field-rollname ). is_comp-type ?= cl_abap_datadescr=>describe_by_name( l_fname ). APPEND is_comp TO it_comp. ENDLOOP. cl_stru = cl_abap_structdescr=>create( it_comp ). ** APPEND VBELN TO key. cl_tabl = cl_abap_tabledescr=>create( p_line_type = cl_stru p_table_kind = cl_abap_tabledescr=>tablekind_sorted " p_unique = abap_true p_key = key ). APPEND POSNR TO key. c2_tabl = cl_abap_tabledescr=>create( p_line_type = cl_stru p_table_kind = cl_abap_tabledescr=>tablekind_hashed p_unique = abap_true p_key = key ). CREATE DATA cl_handle TYPE HANDLE cl_tabl. CREATE DATA c2_handle TYPE HANDLE c2_tabl. CREATE DATA cl_st TYPE HANDLE cl_stru. CREATE DATA c2_st TYPE HANDLE cl_stru. CREATE DATA c3_st TYPE HANDLE cl_stru. ASSIGN cl_handle->* TO <gt_itab>. ASSIGN c2_handle->* TO <it_itab>. ASSIGN cl_st->* TO <fs1>. ASSIGN c2_st->* TO <fs3>. ASSIGN c3_st->* TO <fs5>. ASSIGN COMPONENT VBELN OF STRUCTURE <fs1> TO <fs2>. <fs2> = 0080021838. ASSIGN COMPONENT POSNR OF STRUCTURE <fs1> TO <fs2>. <fs2> = 000030. ** SELECT * FROM lips INTO CORRESPONDING FIELDS OF TABLE <gt_itab> UP TO 10 ROWS ORDER BY vbeln posnr. LOOP AT <gt_itab> INTO <fs3>. ASSIGN COMPONENT POSNR OF STRUCTURE <fs3> TO <fs4>. CLEAR <fs4>. COLLECT <fs3> INTO <it_itab>. ENDLOOP. DELETE ADJACENT DUPLICATES FROM <gt_itab>. READ TABLE <gt_itab> FROM <fs1> TRANSPORTING NO FIELDS. IF sy-subrc = 0. WRITE:/ SSSS. ENDIF. c2_stru ?= cl_abap_structdescr=>describe_by_data( wa_ets ). gt_comp = c2_stru->get_components( ).

ABAP動態內表運用