Example: Interactive ALV Reporting (Double - Click Event, Button - Click Event, Hotspot - Click Event) - End To End
Example: Interactive ALV Reporting (Double - Click Event, Button - Click Event, Hotspot - Click Event) - End To End
INCLUDE Z730ALV15_INC.
START-OF-SELECTION.
call screen 100.
Include Program:
data gv_kunnr type kna1-kunnr.
SELECT-OPTIONS so_kunnr for gv_kunnr DEFAULT '1000' to '1010'.
data : o_kna1_cont type ref to cl_gui_custom_container,
o_kna1_grid type ref to cl_gui_alv_grid,
o_vbak_cont type ref to cl_gui_custom_container,
o_vbak_grid type ref to cl_gui_alv_grid,
o_vbap_cont type ref to cl_gui_custom_container,
o_vbap_grid type ref to cl_gui_alv_grid.
types : begin of ty_kna1,
kunnr type kna1-kunnr,
land1 type kna1-land1,
name1 type kna1-name1,
end of ty_kna1.
data : t_kna1 type table of ty_kna1,
wa_kna1 type ty_kna1.
types : begin of ty_vbak.
include type zcvbak.
types end of ty_vbak.
data : t_vbak type table of ty_vbak,
wa_vbak type ty_vbak.
types : begin of ty_vbap.
include type zcvbap.
types end of ty_vbap.
data : t_vbap type table of ty_vbap,
wa_vbap type ty_vbap.
data : t_fcat type lvc_t_fcat,
wa_fcat type lvc_s_fcat.
data wa_layo type lvc_s_layo.
class lcl_eventreceiver DEFINITION.
public SECTION.
methods handle_double_click
for event double_click of cl_gui_alv_grid
IMPORTING e_row e_column.
methods handle_button_click
for event button_click of cl_gui_alv_grid
IMPORTING es_row_no.
methods handle_hotspot_click
for event hotspot_click of cl_gui_alv_grid
importing e_row_id.
endclass.
class lcl_eventreceiver IMPLEMENTATION.
method handle_double_click.
case e_column-fieldname.
when 'KUNNR'.
* get the content of the selected row
clear wa_kna1.
read table t_kna1 into wa_kna1
index e_row-index
TRANSPORTING kunnr.
if sy-subrc eq 0.
* get sales orders for selected customer
perform getsalesorders.
if t_vbak is not initial. "sales orders found
call screen 200.
else. "no sales orders
message 'No sales orders' type 'I'.
endif.
endif.
when others.
message 'Please double click on customer no only' type 'I'.
endcase.
endmethod.
method handle_button_click.
* message 'button click' type 'I'.
clear wa_vbak.
read table t_vbak into wa_vbak
index es_row_no-row_id TRANSPORTING vbeln.
if sy-subrc eq 0.
* get sales items for selected sales order
perform getsalesitems.
if t_vbap is not INITIAL.
call screen 300.
else.
message 'No sales items for selected sales order' type 'I'.
endif.
endif.
endmethod.
method handle_hotspot_click.
* message 'hotspot' type 'I'.
clear wa_vbap.
read table t_vbap into wa_vbap
index e_row_id-index TRANSPORTING matnr.
if sy-subrc eq 0.
set PARAMETER ID 'MAT' field wa_vbap-matnr.
call transaction 'MM03'.
endif.
endmethod.
endclass.
data ob type ref to lcl_eventreceiver.
MODULE STATUS_0100 OUTPUT.
if o_kna1_cont is INITIAL.
SET PF-STATUS 'ABC'.
* link custom container with alv grid
CREATE OBJECT O_KNA1_CONT
EXPORTING
CONTAINER_NAME = 'CUSTCTRL1'.
* link alv grid with custom container
CREATE OBJECT O_KNA1_GRID
EXPORTING
I_PARENT = o_kna1_cont.
* get customer data
perform getcustomers.
if t_kna1 is not INITIAL.
* generate fieldcatalog for customer fields
perform fldcatkna1.
* generate layout for customer grid
perform layoutkna1.
* register handlers
perform reghandlers.
* display customer data
perform displaykna1.
endif.
else.
CALL METHOD O_KNA1_GRID->REFRESH_TABLE_DISPLAY.
endif.
ENDMODULE. " STATUS_0100 OUTPUT
FORM GETCUSTOMERS .
select kunnr land1 name1
from kna1
into table t_kna1
where kunnr in so_kunnr.
ENDFORM. " GETCUSTOMERS
FORM FLDCATVBAK .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
wa_fcat-style = cl_gui_alv_grid=>mc_style_button.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERDAT'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Creation Date'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERZET'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Creation Time'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'ERNAM'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Created By'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATVBAK
FORM LAYOUTKNA1 .
clear wa_layo.
wa_layo-grid_title = 'CUSTOMER MASTER DATA'.
ENDFORM. " LAYOUTKNA1
FORM DISPLAYKNA1 .
CALL METHOD O_KNA1_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_kna1
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYKNA1
MODULE USER_COMMAND_0100 INPUT.
case sy-ucomm.
when 'F1'.
leave program.
endcase.
ENDMODULE. " USER_COMMAND_0100 INPUT
FORM REGHANDLERS .
create object ob.
set handler ob->handle_double_click for o_kna1_grid.
ENDFORM. " REGHANDLERS
FORM GETSALESORDERS .
select vbeln erdat erzet ernam
from vbak
into table t_vbak
where kunnr = wa_kna1-kunnr.
ENDFORM. " GETSALESORDERS
MODULE STATUS_0200 OUTPUT.
if o_vbak_cont is INITIAL.
SET PF-STATUS 'PQR'.
* link custom container with alv grid
CREATE OBJECT O_VBAK_CONT
EXPORTING
CONTAINER_NAME = 'CUSTCTRL2'.
* link alv grid with custom container
CREATE OBJECT O_VBAK_GRID
EXPORTING
I_PARENT = o_VBAK_cont.
FORM LAYOUTVBAK .
clear wa_layo.
wa_layo-grid_title = 'SALES ORDERS'.
ENDFORM. " LAYOUTVBAK
FORM DISPLAYVBAK .
CALL METHOD O_VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_vbak
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAYVBAK
FORM FLDCATKNA1 .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'KUNNR'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Customer Number'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'LAND1'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Country Key'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NAME1'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Customer Name'.
wa_fcat-outputlen = 30.
append wa_fcat to t_fcat.
ENDFORM. " FLDCATKNA1
MODULE USER_COMMAND_0200 INPUT.
case sy-ucomm.
when 'F2'.
leave to screen 100.
endcase.
ENDMODULE. " USER_COMMAND_0200 INPUT
FORM REG_HANDLERS .
create object ob.
set handler ob->handle_button_click for o_vbak_grid.
ENDFORM. " REG_HANDLERS
FORM GETSALESITEMS .
select vbeln posnr matnr netwr
from vbap
into table t_vbap
where vbeln = wa_vbak-vbeln.
ENDFORM. " GETSALESITEMS
MODULE STATUS_0300 OUTPUT.
if o_vbap_cont is INITIAL.
SET PF-STATUS 'MNR'.
* link custom container with alv grid
CREATE OBJECT O_VBAP_CONT
EXPORTING
CONTAINER_NAME = 'CUSTCTRL3'.
* link alv grid with custom container
CREATE OBJECT O_VBAP_GRID
EXPORTING
I_PARENT = o_VBAP_cont.
* generate layout
perform layout_vbap.
FORM FLDCAT_VBAP .
refresh t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-col_pos = 1.
wa_fcat-coltext = 'Sales Document'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'POSNR'.
wa_fcat-col_pos = 2.
wa_fcat-coltext = 'Item Number'.
wa_fcat-outputlen = 12.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-col_pos = 3.
wa_fcat-coltext = 'Material No'.
wa_fcat-outputlen = 12.
wa_fcat-hotspot = 'X'.
append wa_fcat to t_fcat.
clear wa_fcat.
wa_fcat-fieldname = 'NETWR'.
wa_fcat-col_pos = 4.
wa_fcat-coltext = 'Net Value'.
wa_fcat-outputlen = 15.
append wa_fcat to t_fcat.
ENDFORM. " FLDCAT_VBAP
FORM LAYOUT_VBAP .
clear wa_layo.
wa_layo-grid_title = 'SALES ITEMS'.
ENDFORM. " LAYOUT_VBAP
FORM DISPLAY_VBAP .
CALL METHOD O_VBAP_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_OUTTAB = t_vbap
IT_FIELDCATALOG = t_fcat.
ENDFORM. " DISPLAY_VBAP
MODULE USER_COMMAND_0300 INPUT.
case sy-ucomm.
when 'F5'.
leave to screen 200.
endcase.
ENDMODULE. " USER_COMMAND_0300 INPUT
FORM HANDLERS_REG .
create object ob.
set handler ob->handle_hotspot_click for o_vbap_grid.
ENDFORM. " HANDLERS_REG
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
PROCESS BEFORE OUTPUT.
MODULE STATUS_0200.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0200.
PROCESS BEFORE OUTPUT.
MODULE STATUS_0300.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0300.
include z730alv16_inc.
START-OF-SELECTION.
call screen 100.
Include Program:
data : o_cust_cont type ref to cl_gui_custom_container,
o_split1 type ref to cl_gui_splitter_container,
o_split2 type ref to cl_gui_splitter_container,
o_vbak_grid type ref to cl_gui_alv_grid,
o_vbap_grid type ref to cl_gui_alv_grid,
o_top_cont type ref to cl_gui_container,
o_sub_cont type ref to cl_gui_container,
o_vbak_cont type ref to cl_gui_container,
o_vbap_cont type ref to cl_gui_container.
MODULE STATUS_0100 OUTPUT.
if o_cust_cont is INITIAL.
SET PF-STATUS 'ABC'.
* link custom container with custom control
CREATE OBJECT O_CUST_CONT
EXPORTING
CONTAINER_NAME = 'CUSTCTRL'.
* link splitter container with custom container
CREATE OBJECT O_SPLIT1
EXPORTING
PARENT = o_cust_cont
ROWS = 2
COLUMNS = 1.
CALL METHOD O_SPLIT1->SET_ROW_HEIGHT
EXPORTING
ID = 2
HEIGHT = 8.
* associate containers for each pane
CALL METHOD O_SPLIT1->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = o_top_cont.
CALL METHOD O_SPLIT1->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 1
RECEIVING
CONTAINER = o_sub_cont.
* split o_sub_cont into further panes
CREATE OBJECT O_SPLIT2
EXPORTING
PARENT = o_sub_cont
ROWS = 1
COLUMNS = 2.
CALL METHOD O_SPLIT2->SET_COLUMN_WIDTH
EXPORTING
ID = 2
WIDTH = 5.
* associate containers for sub panes
CALL METHOD O_SPLIT2->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = o_vbak_cont.
CALL METHOD O_SPLIT2->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 2
RECEIVING
CONTAINER = o_vbap_cont.
endif.
ENDMODULE. " STATUS_0100 OUTPUT
MODULE USER_COMMAND_0100 INPUT.
case sy-ucomm.
when 'F1'.
leave PROGRAM.
endcase.
ENDMODULE. " USER_COMMAND_0100 INPUT
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.