Scenario:
There will be two ALV side by side. The left ALV will have the header data and the right ALV will contain the item data. On selecting a particular header data from the left side, the corresponding item data should be displayed in the right side.
Consideration:
1. For demo purpose we have used EKKO (Header Table) and EKPO (Item Table) & we have used only 20 records from EKKO table.2. We have used Custom Container for the purpose and that's why the container has been created in the Screen Painter
Solution:
First, create a program in SE38 and then create a screen in SE80 and then open Screen Painter.Step 1: From the screen painter, add two containers by selecting the custom control button. Name them as CUST_CONT_1 and CUST_CONT_2 respectively. Refer the below screenshots:
Screen Painter - The Two Containers |
Step 2: Now copy the status from standard ALV. (How to?)
Step 3: Now refer to the following code:
*&---------------------------------------------------------------------* *& Two ALVs in a single screen EKKO & EKPO *& The custom container has been created from the layout *& On selecting the header record from left will give the corresponding item record *&---------------------------------------------------------------------* CLASS lcl_event_receiver DEFINITION DEFERRED. TYPES: BEGIN OF gty_ekko, ebeln TYPE ebeln, bukrs TYPE bukrs, bstyp TYPE ebstyp, bsart TYPE esart, bsakz TYPE bsakz, END OF gty_ekko. TYPES: BEGIN OF gty_ekpo, ebeln TYPE ebeln, ebelp TYPE ebelp, loekz TYPE eloek, statu TYPE astat, aedat TYPE paedt, END OF gty_ekpo. DATA: go_grid_1 TYPE REF TO cl_gui_alv_grid, go_grid_2 TYPE REF TO cl_gui_alv_grid, go_cont_1 TYPE REF TO cl_gui_custom_container, go_cont_2 TYPE REF TO cl_gui_custom_container, gt_ekko TYPE TABLE OF gty_ekko, gs_ekko TYPE gty_ekko, gt_ekpo TYPE TABLE OF gty_ekpo, gs_ekpo TYPE gty_ekpo, go_event_receiver TYPE REF TO lcl_event_receiver. . START-OF-SELECTION. CALL SCREEN 0100. *&---------------------------------------------------------------------* *& Form CREATE_GRID *&---------------------------------------------------------------------* * CREATE TWO CONTAINERS & THEIR CORRESPONDING GRIDS *----------------------------------------------------------------------* FORM create_grid. CREATE OBJECT go_cont_1 "CONTAINER 1 EXPORTING container_name = 'CUST_CONT_1'. CREATE OBJECT go_grid_1 "GRID 1 EXPORTING i_parent = go_cont_1. CREATE OBJECT go_cont_2 "CONTAINER 2 EXPORTING container_name = 'CUST_CONT_2'. CREATE OBJECT go_grid_2 "GRID 2 EXPORTING i_parent = go_cont_2. ENDFORM. " CREATE_GRID *&---------------------------------------------------------------------* *& Form DISPLAY_GRID *&---------------------------------------------------------------------* * DISPLAY GRID 1 - LEFT GRID *----------------------------------------------------------------------* FORM display_grid1 . CALL METHOD go_grid_1->set_table_for_first_display EXPORTING i_structure_name = 'EKKO' CHANGING it_outtab = gt_ekko EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ENDFORM. " DISPLAY_GRID *&---------------------------------------------------------------------* *& Form DISPLAY_GRID *&---------------------------------------------------------------------* * DISPLAY GRID 2 - RIGHT GRID *----------------------------------------------------------------------* FORM display_grid2 . CALL METHOD go_grid_2->set_table_for_first_display EXPORTING i_structure_name = 'EKPO' CHANGING it_outtab = gt_ekpo EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ENDFORM. " DISPLAY_GRID
*&---------------------------------------------------------------------* *& Form GET_DATA *&---------------------------------------------------------------------* * FETCH DATA FROM THE HEADER TABLE 'EKKO' *----------------------------------------------------------------------* FORM get_data_ekko . SELECT ebeln bukrs bstyp bsart bsakz FROM ekko INTO TABLE gt_ekko UP TO 20 ROWS . ENDFORM. " GET_DATA *----------------------------------------------------------------------* * CLASS lcl_event_receiver DEFINITION *----------------------------------------------------------------------* * CLASS DEFINITION FOR HANDLING THE ALV EVENT - DOUBLE CLICK *----------------------------------------------------------------------* CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column. ENDCLASS. "lcl_event_receiver DEFINITION *----------------------------------------------------------------------* * CLASS lcl_event_receiver IMPLEMENTATION *----------------------------------------------------------------------* * CLASS IMPLEMENTATION FOR HANDLING THE ALV EVENT - DOUBLE CLICK *----------------------------------------------------------------------* CLASS lcl_event_receiver IMPLEMENTATION. METHOD handle_double_click. * FETCHING THE PARTICULAR RECORD THAT HAS BEEN SELECTED IN THE ALV READ TABLE gt_ekko INTO gs_ekko INDEX e_row-index. IF sy-subrc EQ 0. SELECT ebeln ebelp loekz statu aedat FROM ekpo INTO TABLE gt_ekpo WHERE ebeln = gs_ekko-ebeln. IF sy-subrc EQ 0. PERFORM display_grid2. ENDIF. ENDIF. ENDMETHOD. "handle_double_click ENDCLASS. "lcl_event_receiver IMPLEMENTATION *&---------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&---------------------------------------------------------------------* * PBO EVENT OF THE SCREEN *----------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'PF_STATUS'. IF go_cont_1 IS INITIAL AND go_cont_2 IS INITIAL. PERFORM get_data_ekko. PERFORM create_grid. CREATE OBJECT go_event_receiver. SET HANDLER go_event_receiver->handle_double_click FOR go_grid_1. PERFORM display_grid1. ENDIF. ENDMODULE. " STATUS_0100 OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* * PAI EVENT OF THE SCREEN *----------------------------------------------------------------------* MODULE user_command_0100 INPUT. CASE sy-ucomm. WHEN '&F03' OR 'BACK' OR 'BCK' OR '&F15' OR '&F12' . LEAVE TO SCREEN 0. ENDCASE. ENDMODULE. " USER_COMMAND_0100 INPUT
HOW TO ADD ONE MORE DOUBLE CLICK TO CALL NEXT SCREEN AFTER THE FIRST DOUBLE CLICK
ReplyDelete