ALV OO: 最簡單的ALV OO例項-Docking容器
阿新 • • 發佈:2019-01-03
執行效果:
步驟:
1.新建100螢幕
螢幕邏輯流:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE INIT_CON.
PROCESS AFTER INPUT.
MODULE USER_EXIT_0100 AT EXIT-COMMAND.
2.建立工具條:
程式程式碼:
*&---------------------------------------------------------------------* *& Report ZTEST_SY10 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ztest_sy10. DATA: gs_data LIKE spfli. DATA: gt_data LIKE TABLE OF gs_data. DATA: g_dock01 TYPE REF TO cl_gui_docking_container. DATA: g_grid01 TYPE REF TO cl_gui_alv_grid. START-OF-SELECTION. PERFORM get_data. CALL SCREEN 100. *&---------------------------------------------------------------------* *& Form GET_DATA *&---------------------------------------------------------------------* * text 獲取資料 *----------------------------------------------------------------------* FORM get_data. SELECT * INTO TABLE gt_data UP TO 30 ROWS FROM spfli. ENDFORM. "GET_DATA *&---------------------------------------------------------------------* *& Module INIT_CON OUTPUT *&---------------------------------------------------------------------* * text 建立ALV *----------------------------------------------------------------------* MODULE init_con OUTPUT. IF g_dock01 IS INITIAL. " 建立DOCKING容器例項 CREATE OBJECT g_dock01 EXPORTING repid = sy-repid " 程式名 dynnr = sy-dynnr " 螢幕號 extension = 800 " ALV寬度 EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS = 6. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. " 建立GRID例項 CREATE OBJECT g_grid01 EXPORTING i_parent = g_dock01 EXCEPTIONS error_cntl_create = 1 error_cntl_init = 2 error_cntl_link = 3 error_dp_create = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. " 呼叫ALV 顯示方法 CALL METHOD g_grid01->set_table_for_first_display EXPORTING i_structure_name = 'SPFLI' " 參照表結構欄位顯示 CHANGING it_outtab = gt_data EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDIF. ENDMODULE. " INIT_CON OUTPUT *&---------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&---------------------------------------------------------------------* * text 工具條 *----------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'STATUS_BAR'. ENDMODULE. " STATUS_0100 OUTPUT *&---------------------------------------------------------------------* *& Module USER_EXIT_0100 INPUT *&---------------------------------------------------------------------* * text 取消事件 *----------------------------------------------------------------------* MODULE user_exit_0100 INPUT. LEAVE TO SCREEN 0. ENDMODULE. " USER_EXIT_0100 INPUT
注: (1). CSDN部落格的插入程式碼功能不支援ABAP語言,故選了JAVA語言替代,關鍵字無法高亮顯示;
(2). 如有疏漏之處,還請不吝賜教!