点击此处---> 群内免费提供SAP练习系统(在群公告中)
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
动态 ABAP ALV
*&---------------------------------------------------------------------* *& Report ZDYNALV *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT ZDYNALV. *-------------ALV Ïà¹Ø-------------------------- DATA: wa_layo TYPE lvc_s_layo. DATA: wa_fcat TYPE lvc_s_fcat, it_fcat TYPE lvc_t_fcat. DATA it_scol TYPE lvc_t_scol. DATA: g_grid TYPE REF TO cl_gui_alv_grid. FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE, <dyn_wa>, <dyn_field>. DATA: dy_table TYPE REF TO data, dy_line TYPE REF TO data. DATA: colname(10), index(2). * ÁÐÊý *PARAMETERS: col TYPE i. CLEAR: it_fcat. * ¸ù¾ÝÌõ¼þ¶¯Ì¬Éú³ÉÁÐ *DO col TIMES. DO 90 TIMES. index = index + 1. CONCATENATE 'COL' index INTO colname. PERFORM frm_add_fcat USING: colname 'C' 'ÃèÊö' '100'. ENDDO. * ¸ù¾Ýit_factÉú³É¶¯Ì¬±í CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING it_fieldcatalog = it_fcat IMPORTING ep_table = dy_table. ASSIGN dy_table->* TO <dyn_table>. CREATE DATA dy_line LIKE LINE OF <dyn_table>. ASSIGN dy_line->* TO <dyn_wa>. * ¸ø±í×ֶθ³Öµ CLEAR: index. DO 90 TIMES. index = index + 1. CONCATENATE 'COL' index INTO colname. ASSIGN COMPONENT colname OF STRUCTURE <dyn_wa> TO <dyn_field>. <dyn_field> = 'ÁÐÊý¾Ý1'. ENDDO. APPEND <dyn_wa> TO <dyn_table>. * Ï൱ÓÚ¸øÄÚ±í·ÅÈëÁ½ÌõÊý¾Ý CLEAR: index. DO 90 TIMES. index = index + 1. CONCATENATE 'COL' index INTO colname. ASSIGN COMPONENT colname OF STRUCTURE <dyn_wa> TO <dyn_field>. <dyn_field> = 'ÁÐÊý¾Ý2'. ENDDO. APPEND <dyn_wa> TO <dyn_table>. CLEAR: wa_layo. wa_layo-zebra = 'X'. wa_layo-cwidth_opt = 'X'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid is_layout_lvc = wa_layo it_fieldcat_lvc = it_fcat TABLES t_outtab = <dyn_table> EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. *&---------------------------------------------------------------------* *& Form frm_add_fcat *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->VALUE1 text * -->VALUE2 text * -->VALUE3 text * -->VALUE4 text *----------------------------------------------------------------------* FORM frm_add_fcat USING value1 value2 value3 value4. wa_fcat-fieldname = value1. wa_fcat-inttype = value2. wa_fcat-reptext = value3. wa_fcat-intlen = value4. APPEND wa_fcat TO it_fcat. CLEAR: wa_fcat. ENDFORM. "frm_add_fcat