Tuesday, December 21, 2010
Create Object to receive events and link them to handler methods.When the ALV Control raises the event for the specified instance the corresponding method is automatically called.
Flow logic of screen 1001.
Flow logic of screen 1002
REPORT ztest_notepad. CLASS lcl_event_receiver DEFINITION DEFERRED. DATA: g_grid_1 TYPE REF TO cl_gui_alv_grid, g_grid_2 TYPE REF TO cl_gui_alv_grid, g_container_1 TYPE REF TO cl_gui_custom_container, g_container_2 TYPE REF TO cl_gui_custom_container, event_receiver TYPE REF TO lcl_event_receiver. *ALV GRID Declaration DATA: it_fieldcat_1 TYPE lvc_t_fcat, it_fieldcat_2 TYPE lvc_t_fcat, it_fieldcat TYPE lvc_t_fcat, wa_fieldcat TYPE lvc_s_fcat, wa_layout TYPE lvc_s_layo. *Variable declararion TYPES: BEGIN OF ty_t001, bukrs TYPE t001-bukrs, butxt TYPE t001-butxt, adrnr TYPE t001-adrnr, END OF ty_t001, BEGIN OF ty_adrc, addrnumber TYPE adrc-addrnumber, name1 TYPE adrc-name1, city1 TYPE adrc-city1, city2 TYPE adrc-city2, home_city TYPE adrc-home_city, post_code1 TYPE adrc-post_code1, END OF ty_adrc. DATA: wa_t001 TYPE ty_t001, wa_adrc TYPE ty_adrc, it_t001 TYPE STANDARD TABLE OF ty_t001, it_adrc TYPE STANDARD TABLE OF ty_adrc. CONSTANTS: c_ccontrol_1 TYPE scrfname VALUE 'G_CCONTROL_1', c_ccontrol_2 TYPE scrfname VALUE 'G_CCONTROL_2'. DEFINE fieldcat. wa_fieldcat-fieldname = &1. wa_fieldcat-tabname = &2. wa_fieldcat-coltext = &3. append wa_fieldcat to it_fieldcat. clear wa_fieldcat. END-OF-DEFINITION. START-OF-SELECTION. CALL SCREEN 1001. *=================================================================== * class lcl_event_receiver: local class to handle 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 lcl_event_receiver IMPLEMENTATION. METHOD handle_double_click. * read selected row from internal table gt_sflight READ TABLE it_t001 INDEX e_row-index INTO wa_t001. CALL SCREEN 1002." STARTING AT 10 5. ENDMETHOD. "handle_double_click ENDCLASS. "lcl_event_receiver IMPLEMENTATION *&---------------------------------------------------------------------* *& Module PBO_1001 OUTPUT *&---------------------------------------------------------------------* MODULE pbo_1001 OUTPUT. "Set pf-status SET PF-STATUS 'STATUS1'. SET TITLEBAR 'STATUS1'. IF g_container_1 IS INITIAL. "create a custom container control for our ALV Control CREATE OBJECT g_container_1 EXPORTING container_name = c_ccontrol_1. "create an instance of alv control CREATE OBJECT g_grid_1 EXPORTING i_parent = g_container_1. IF it_t001[] IS INITIAL. "select data from table t001 SELECT * FROM t001 INTO CORRESPONDING FIELDS OF TABLE it_t001 UP TO 10 ROWS. ENDIF. fieldcat: 'BUKRS' 'IT_T001' 'BUKRS', 'BUTXT' 'IT_T001' 'BUTXT', 'ADRNR' 'IT_T001' 'ADRNR'. it_fieldcat_1[] = it_fieldcat[]. CLEAR it_fieldcat[]. wa_layout-cwidth_opt = 'X'. CALL METHOD g_grid_1->set_table_for_first_display EXPORTING is_layout = wa_layout CHANGING it_outtab = it_t001 it_fieldcatalog = it_fieldcat_1.
" Create Object to receive events and link them to handler methods. " When the ALV Control raises the event for the specified instance " the corresponding method is automatically called.CREATE OBJECT event_receiver. SET HANDLER event_receiver->handle_double_click FOR g_grid_1. ENDIF. CALL METHOD cl_gui_control=>set_focus EXPORTING control = g_grid_1. ENDMODULE. " PBO_1001 OUTPUT *&---------------------------------------------------------------------* *& Module PAI_1001 INPUT *&---------------------------------------------------------------------* MODULE pai_1001 INPUT. CASE sy-ucomm. WHEN 'EXIT'. LEAVE PROGRAM. ENDCASE. ENDMODULE. " PAI_1001 INPUT *&---------------------------------------------------------------------* *& Module PBO_1002 OUTPUT *&---------------------------------------------------------------------* MODULE pbo_1002 OUTPUT. "Set pf-status SET PF-STATUS 'STATUS1'. SET TITLEBAR 'STATUS2'. IF g_container_2 IS INITIAL. "create a custom container control for our ALV Control CREATE OBJECT g_container_2 EXPORTING container_name = c_ccontrol_2. "create an instance of alv control CREATE OBJECT g_grid_2 EXPORTING i_parent = g_container_2. IF it_adrc[] IS INITIAL. "select data from table t001 SELECT * FROM adrc INTO CORRESPONDING FIELDS OF TABLE it_adrc WHERE addrnumber = wa_t001-adrnr. ENDIF. fieldcat: 'ADDRNUMBER' 'IT_ADRC' 'ADDRNUMBER', 'NAME1' 'IT_ADRC' 'NAME1', 'CITY1' 'IT_ADRC' 'CITY1', 'CITY2' 'IT_ADRC' 'CITY2', 'HOME_CITY' 'IT_ADRC' 'HOME_CITY', 'POST_CODE1' 'IT_ADRC' 'POST_CODE1'. it_fieldcat_2[] = it_fieldcat[]. CLEAR it_fieldcat[]. wa_layout-cwidth_opt = 'X'. wa_layout-grid_title = 'ALV Grid Control Report after double click'. CALL METHOD g_grid_2->set_table_for_first_display EXPORTING is_layout = wa_layout CHANGING it_outtab = it_adrc it_fieldcatalog = it_fieldcat_2. ELSE. "The next time dynpro 1002 is called you use method "refresh_table_display' to display newly selected data "in the instance of ALV Control that 'belongs' to dynpro 1002. CALL METHOD g_grid_2->refresh_table_display. ENDIF. CALL METHOD cl_gui_control=>set_focus EXPORTING control = g_grid_2. ENDMODULE. " PBO_1002 OUTPUT *&---------------------------------------------------------------------* *& Module PAI_1002 INPUT *&---------------------------------------------------------------------* MODULE pai_1002 INPUT. CASE sy-ucomm. WHEN 'EXIT'. LEAVE TO SCREEN 0. ENDCASE. ENDMODULE. " PAI_1002 INPUT
Flow logic of screen 1001.
PROCESS BEFORE OUTPUT. MODULE pbo_1001. PROCESS AFTER INPUT. MODULE pai_1001.
PROCESS BEFORE OUTPUT. MODULE pbo_1002. PROCESS AFTER INPUT. MODULE pai_1002.
Followers
Popular Posts
- ABAP - ALV Report example with steps
- ABAP - Step by step tutorial on Smart Forms - Template Node
- ABAP - Sending email with pdf attachment
- SAP Adobe Form - Steps to create simple ADOBE Form and calling it from ABAP Program
- SAP ABAP - CL_ABAP_CHAR_UTILITIES class usage
- ABAP - Multiple value selection from F4 help for SELECT-OPTIONS
- Execute ABAP Report using SUBMIT statement
- ABAP - Select all or Deselect all in ALV or Check box handling in ALV
- Web Dynpro ABAP ALV - ON_CLICK event
- ABAP - Dynamic WHERE clause
0 comments:
Post a Comment
Your useful comments, suggestions are appreciated.Your comments are moderated.