ALV 动态显示列Demo
生活随笔
收集整理的這篇文章主要介紹了
ALV 动态显示列Demo
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
開發財務報表或者一些預測數據的報表時,經常會有動態顯示列的情況。
這里轉摘貼吧上的ALV動態顯示列的Demo,可做學習用。
*-------------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.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_tableEXPORTINGit_fieldcatalog = it_fcatIMPORTINGep_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 col TIMES.index = index + 1.CONCATENATE 'COL' index INTO colname.ASSIGN COMPONENT colname OF STRUCTURE < dyn_wa> TO < dyn_field >.< dyn_field > = '列數據'. ENDDO. APPEND < dyn_wa > TO < dyn_table >.* 相當于給內表放入兩條數據 CLEAR: index. DO col TIMES.index = index + 1.CONCATENATE 'COL' index INTO colname.ASSIGN COMPONENT colname OF STRUCTURE < dyn_wa > TO < dyn_field >.< dyn_field > = '列數據'. 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'EXPORTINGi_callback_program = sy-repidis_layout_lvc = wa_layoit_fieldcat_lvc = it_fcatTABLESt_outtab = < dyn_table >EXCEPTIONSprogram_error = 1OTHERS = 2. IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH 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
總結
以上是生活随笔為你收集整理的ALV 动态显示列Demo的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【美文】没有人会根据你平庸的现在就能推断
- 下一篇: FIELD SYMBOL和TYPE RE