前言:
当前朋友们对“grid function”大约比较注意,小伙伴们都需要剖析一些“grid function”的相关文章。那么小编也在网络上收集了一些对于“grid function””的相关知识,希望咱们能喜欢,各位老铁们快快来了解一下吧!项目上有时候遇到特殊需求要在同一个屏幕上显示多个ALV,比如一个ALV显示抬头数据,另一个ALV显示明细数据。对于这样的要求可以通过以下的方法来实现,主要用到的相关类:CL_GUI_SPLITTER_CONTAINER
其中实现的关键代码:设置分割容器。
最终实现效果如下:
刚开始运行程序后,第一个ALV显示数据,第二个ALV没有显示数据;双击第一个ALV中的某一行,则第二个ALV显示相应的数据。
具体实现的全部代码如下:
主程序
************************************************************************* TITLE : Demo Multiple ALV* AUTHOR : Danny* DATE : 2021.08.03* CHANGE REQUEST :* DESCRIPTION : Demo Multiple ALV************************************************************************* CHANGE HISTORY LOG*-----------------------------------------------------------------------* MOD. NO. | DATE | NAME | TR NUMBER*-----------------------------------------------------------------------* MOD-0000 | YYYY.MM.DD | XXXXXX | XXXXXXXXX* <Change Description>*-----------------------------------------------------------------------REPORT zdemo_multiple_alv.*&---------------------------------------------------------------------** INCLUDE*&---------------------------------------------------------------------** Data DefinitionINCLUDE zdemo_multiple_alv_top.* Selection ScreenINCLUDE zdemo_multiple_alv_sel.* PBOINCLUDE zdemo_multiple_alv_pbo.* PAIINCLUDE zdemo_multiple_alv_pai.* Form DefinitionINCLUDE zdemo_multiple_alv_f01.*&---------------------------------------------------------------------** INITIALIZATION*&---------------------------------------------------------------------*INITIALIZATION. PERFORM frm_init_data.*&---------------------------------------------------------------------** AT SELECTION-SCREEN*&---------------------------------------------------------------------*AT SELECTION-SCREEN.*&---------------------------------------------------------------------** START-OF-SELECTION*&---------------------------------------------------------------------*START-OF-SELECTION. PERFORM frm_get_data.*&---------------------------------------------------------------------** END-OF-SELECTION*&---------------------------------------------------------------------*END-OF-SELECTION. IF gt_sflight IS INITIAL. MESSAGE s015(a5) DISPLAY LIKE /isdfps/cl_const_abc_123=>gc_e. ELSE. CALL SCREEN 9000. ENDIF.
Include TOP
*&---------------------------------------------------------------------**& Include ZDEMO_MULTIPLE_ALV_TOP*&---------------------------------------------------------------------**--------------------------------------------------------------------** Structure Definition*--------------------------------------------------------------------*TYPES BEGIN OF ts_sflight.INCLUDE TYPE sflight.TYPES END OF ts_sflight.TYPES BEGIN OF ts_sbook. INCLUDE TYPE sbook.TYPES END OF ts_sbook.*--------------------------------------------------------------------** Table/Work area Definition*--------------------------------------------------------------------*DATA: gs_sflight TYPE ts_sflight, gt_sflight TYPE STANDARD TABLE OF ts_sflight ##NEEDED, gt_sbook TYPE STANDARD TABLE OF ts_sbook ##NEEDED, gt_sbook_alv TYPE STANDARD TABLE OF ts_sbook ##NEEDED, gv_ok_code TYPE syucomm ##NEEDED, gr_split_container TYPE REF TO cl_gui_splitter_container ##NEEDED, gr_container1 TYPE REF TO cl_gui_container ##NEEDED, gr_container2 TYPE REF TO cl_gui_container ##NEEDED, gr_alv_grid1 TYPE REF TO cl_gui_alv_grid ##NEEDED, gr_alv_grid2 TYPE REF TO cl_gui_alv_grid ##NEEDED.*--------------------------------------------------------------------** Global Constants Definition*--------------------------------------------------------------------*CONSTANTS: gc_eq TYPE char2 VALUE 'EQ', gc_st_name TYPE string VALUE 'ZSTANDARD', gc_tb_name TYPE string VALUE 'ZTITLE', gc_back_code TYPE gui_code VALUE 'ZBACK', gc_exit_code TYPE gui_code VALUE 'ZEXIT', gc_canc_code TYPE gui_code VALUE 'ZCANC'.*--------------------------------------------------------------------** Class Definition*--------------------------------------------------------------------*CLASS cl_event_receiver DEFINITION FINAL. PUBLIC SECTION.* Set handle for double click METHODS handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_column es_row_no.ENDCLASS.DATA: gr_event_receiver TYPE REF TO cl_event_receiver ##NEEDED.
Include Selection Screen
*&---------------------------------------------------------------------**& Include ZDEMO_MULTIPLE_ALV_SEL*&---------------------------------------------------------------------*SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE TEXT-001. SELECT-OPTIONS: s_carrid FOR gs_sflight-carrid OBLIGATORY, s_fldate FOR gs_sflight-fldate.SELECTION-SCREEN END OF BLOCK blk.
Include PBO
*&---------------------------------------------------------------------**& Include ZDEMO_MULTIPLE_ALV_PBO*&---------------------------------------------------------------------**&---------------------------------------------------------------------**& Module STATUS_9000 OUTPUT*&---------------------------------------------------------------------** Set Status*----------------------------------------------------------------------*MODULE status_9000 OUTPUT. SET PF-STATUS gc_st_name. SET TITLEBAR gc_tb_name WITH TEXT-002.ENDMODULE.*&---------------------------------------------------------------------**& Module DISPLAY_DATA OUTPUT*&---------------------------------------------------------------------** Display data*----------------------------------------------------------------------*MODULE display_data OUTPUT. IF gr_split_container IS INITIAL.* Set container PERFORM frm_set_container.* Set ALV grid PERFORM frm_set_grid.* Set event PERFORM frm_set_event.* Display ALV data PERFORM frm_display_alv. ENDIF.ENDMODULE.
Include PAI
*&---------------------------------------------------------------------**& Include ZDEMO_MULTIPLE_ALV_PAI*&---------------------------------------------------------------------**&---------------------------------------------------------------------**& Module USER_COMMAND_9000 INPUT*&---------------------------------------------------------------------** User command*----------------------------------------------------------------------*MODULE user_command_9000 INPUT. gv_ok_code = sy-ucomm. CASE gv_ok_code. WHEN gc_back_code OR gc_exit_code OR gc_canc_code. LEAVE TO SCREEN 0. WHEN OTHERS. RETURN. ENDCASE.ENDMODULE.
Include Subroutine
*&---------------------------------------------------------------------**& Include ZDEMO_MULTIPLE_ALV_F01*&---------------------------------------------------------------------**&---------------------------------------------------------------------**& CLASS cl_event_receiver IMPLEMENTATION*&---------------------------------------------------------------------***----------------------------------------------------------------------*CLASS cl_event_receiver IMPLEMENTATION. METHOD handle_double_click. DATA ls_sflight TYPE ts_sflight. CLEAR ls_sflight. READ TABLE gt_sflight INTO ls_sflight INDEX es_row_no-row_id. IF sy-subrc = 0. CLEAR gt_sbook_alv. gt_sbook_alv = gt_sbook. DELETE gt_sbook_alv WHERE carrid <> ls_sflight-carrid OR connid <> ls_sflight-connid OR fldate <> ls_sflight-fldate.* Refresh second ALV PERFORM frm_refresh_alv. ENDIF. ENDMETHOD.ENDCLASS.*&---------------------------------------------------------------------**& Form FRM_INIT_DATA*&---------------------------------------------------------------------** Init data*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM frm_init_data. CONSTANTS: lc_aa TYPE char2 VALUE 'AA'. CLEAR: s_carrid,s_carrid[]. s_carrid-sign = /isdfps/cl_const_abc_123=>gc_i. s_carrid-option = gc_eq. s_carrid-low = lc_aa. APPEND s_carrid TO s_carrid[].ENDFORM.*&---------------------------------------------------------------------**& Form FRM_GET_DATA*&---------------------------------------------------------------------** Get data from DB table*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM frm_get_data. CLEAR gt_sflight.* Get data from table SFLIGHT/SBOOK SELECT * INTO TABLE gt_sflight FROM sflight WHERE carrid IN s_carrid AND fldate IN s_fldate. IF sy-subrc = 0. CLEAR gt_sbook. SELECT * INTO TABLE gt_sbook FROM sbook FOR ALL ENTRIES IN gt_sflight WHERE carrid = gt_sflight-carrid AND connid = gt_sflight-connid AND fldate = gt_sflight-fldate. IF sy-subrc <> 0. CLEAR gt_sbook. ENDIF. ENDIF.ENDFORM.*&---------------------------------------------------------------------**& Form FRM_SET_CONTAINER*&---------------------------------------------------------------------** Set containter*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM frm_set_container.* Set split container CREATE OBJECT gr_split_container EXPORTING link_dynnr = sy-dynnr link_repid = sy-repid parent = cl_gui_container=>default_screen rows = 2 columns = 1.* Set ALV container in split container CALL METHOD gr_split_container->get_container EXPORTING row = 1 column = 1 RECEIVING container = gr_container1. CALL METHOD gr_split_container->get_container EXPORTING row = 2 column = 1 RECEIVING container = gr_container2.ENDFORM.*&---------------------------------------------------------------------**& Form FRM_SET_GRID*&---------------------------------------------------------------------** Set ALV grid*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM frm_set_grid. CREATE OBJECT gr_alv_grid1 EXPORTING i_parent = gr_container1. CREATE OBJECT gr_alv_grid2 EXPORTING i_parent = gr_container2.ENDFORM.*&---------------------------------------------------------------------**& Form FRM_SET_EVENT*&---------------------------------------------------------------------** Set event handler*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM frm_set_event. CREATE OBJECT gr_event_receiver. SET HANDLER gr_event_receiver->handle_double_click FOR gr_alv_grid1.ENDFORM.*&---------------------------------------------------------------------**& Form FRM_DISPLAY_ALV*&---------------------------------------------------------------------** Display ALV*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM frm_display_alv. DATA: ls_sflight TYPE ts_sflight, ls_sbook TYPE ts_sbook, ls_layout1 TYPE lvc_s_layo, ls_layout2 TYPE lvc_s_layo, lt_fieldcat1 TYPE lvc_t_fcat, lt_fieldcat2 TYPE lvc_t_fcat, lt_exclude TYPE ui_functions.* Set ALV layout PERFORM frm_set_layout USING TEXT-003 CHANGING ls_layout1. PERFORM frm_set_layout USING TEXT-004 CHANGING ls_layout2.* Set fieldcat PERFORM frm_set_fieldcat USING ls_sflight CHANGING lt_fieldcat1. PERFORM frm_set_fieldcat USING ls_sbook CHANGING lt_fieldcat2.* Set exclude toolbar PERFORM frm_set_exclude CHANGING lt_exclude.* Display First ALV data CALL METHOD gr_alv_grid1->set_table_for_first_display EXPORTING i_save = /isdfps/cl_const_abc_123=>gc_a is_layout = ls_layout1 it_toolbar_excluding = lt_exclude CHANGING it_outtab = gt_sflight it_fieldcatalog = lt_fieldcat1.* Display Second ALV data CALL METHOD gr_alv_grid2->set_table_for_first_display EXPORTING i_save = /isdfps/cl_const_abc_123=>gc_a is_layout = ls_layout2 it_toolbar_excluding = lt_exclude CHANGING it_outtab = gt_sbook_alv it_fieldcatalog = lt_fieldcat2. FREE: lt_fieldcat1,lt_fieldcat2,lt_exclude.ENDFORM.*&---------------------------------------------------------------------**& Form FRM_SET_LAYOUT*&---------------------------------------------------------------------** Set ALV layout*----------------------------------------------------------------------** -->iv_title small title* <--cs_layout ALV layout*----------------------------------------------------------------------*FORM frm_set_layout USING iv_title TYPE lvc_title CHANGING cs_layout TYPE lvc_s_layo. CLEAR cs_layout. cs_layout-zebra = abap_true. cs_layout-cwidth_opt = abap_true. cs_layout-smalltitle = abap_true. cs_layout-grid_title = iv_title. cs_layout-sel_mode = /isdfps/cl_const_abc_123=>gc_a.ENDFORM.*&---------------------------------------------------------------------**& Form FRM_SET_FIELDCAT*&---------------------------------------------------------------------** Set fieldcat*----------------------------------------------------------------------** -->is_structure structure* <--ct_fieldcat fieldcat table*----------------------------------------------------------------------*FORM frm_set_fieldcat USING is_structure TYPE any CHANGING ct_fieldcat TYPE lvc_t_fcat. DATA: ls_fieldcat TYPE lvc_s_fcat, ls_desc TYPE x030l, lr_stdesc TYPE REF TO cl_abap_structdescr, lt_fields TYPE cl_abap_structdescr=>included_view, ls_fields TYPE LINE OF cl_abap_structdescr=>included_view. CONSTANTS: lc_mandt TYPE lvc_fname VALUE 'MANDT'.* Determine structure descriptor lr_stdesc ?= cl_abap_structdescr=>describe_by_data( is_structure ).* Get structure fields lt_fields = lr_stdesc->get_included_view( ).* Build field catalog LOOP AT lt_fields INTO ls_fields. CLEAR: ls_fieldcat,ls_desc. ls_fieldcat-col_pos = sy-tabix. ls_fieldcat-fieldname = ls_fields-name. IF ls_fields-type->is_ddic_type( ) IS NOT INITIAL. ls_desc = ls_fields-type->get_ddic_header( ). ls_fieldcat-rollname = ls_desc-tabname. ELSE. ls_fieldcat-inttype = ls_fields-type->type_kind. ls_fieldcat-intlen = ls_fields-type->length. ls_fieldcat-decimals = ls_fields-type->decimals. ENDIF.* Do not display client field IF ls_fieldcat-fieldname = lc_mandt. ls_fieldcat-no_out = abap_true. ENDIF. APPEND ls_fieldcat TO ct_fieldcat. ENDLOOP. FREE: lt_fields.ENDFORM.*&---------------------------------------------------------------------**& Form FRM_SET_EXCLUDE*&---------------------------------------------------------------------** Set exclude toolbar*----------------------------------------------------------------------** <--ct_exclude exclude function table*----------------------------------------------------------------------*FORM frm_set_exclude CHANGING ct_exclude TYPE ui_functions. DATA: ls_exclude TYPE ui_func.* Exclude paste new row button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row. APPEND ls_exclude TO ct_exclude.* Exclude copy button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy. APPEND ls_exclude TO ct_exclude.* Exclude append row button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row. APPEND ls_exclude TO ct_exclude.* Exclude copy row button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row. APPEND ls_exclude TO ct_exclude.* Exclude insert row button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row. APPEND ls_exclude TO ct_exclude.* Exclude delete row button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row. APPEND ls_exclude TO ct_exclude.* Exclude move row button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row. APPEND ls_exclude TO ct_exclude.* Exclude cut button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut. APPEND ls_exclude TO ct_exclude.* Exclude paste button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste. APPEND ls_exclude TO ct_exclude.* Exclude undo button ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo. APPEND ls_exclude TO ct_exclude.ENDFORM.*&---------------------------------------------------------------------**& Form FRM_REFRESH_ALV*&---------------------------------------------------------------------** Refresh ALV*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM frm_refresh_alv. DATA: ls_layout TYPE lvc_s_layo, ls_stable TYPE lvc_s_stbl.* Reset layout before refresh ALV PERFORM frm_set_layout USING TEXT-004 CHANGING ls_layout. CALL METHOD gr_alv_grid2->set_frontend_layout EXPORTING is_layout = ls_layout.* Row-based/Column-based stable refresh ls_stable-row = abap_true. ls_stable-col = abap_true. CALL METHOD gr_alv_grid2->refresh_table_display EXPORTING is_stable = ls_stable.ENDFORM.
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #grid function