You are on page 1of 65

730 AM ALV OBJECTS: PROGRAM1(ALV REPORTING USING CLASSES):

REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program.

endcase. ENDMODULE.

" USER_COMMAND_0100 INPUT

FORM getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY CHANGING IT_OUTTAB = lt_vbak[]. ENDFORM. " display

PROGRAM2(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont.

perform getdata. if lt_vbak[] is not initial. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING I_STRUCTURE_NAME = 'VBAK' CHANGING IT_OUTTAB = lt_vbak[]. ENDFORM. report z730amalv1. " display

PROGRAM3(ALV REPORTING USING CLASSES):


data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. initialization.

so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. module status_0100 output. if o_cont is initial. set pf-status 'ABC'. create object o_cont exporting container_name = 'CST'. create object o_grid exporting i_parent = o_cont. perform getdata. if lt_vbak[] is not initial. perform display. endif. endif. endmodule. " STATUS_0100 OUTPUT

module user_command_0100 input. case sy-ucomm. when 'BACK'. leave program. endcase. endmodule. " USER_COMMAND_0100 INPUT form getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. endform. " getdata form display . call method o_grid->set_table_for_first_display exporting i_structure_name = 'ZMYVBAK' changing it_outtab = lt_vbak[]. endform. " display

PROGRAM4(ALV REPORTING USING CLASSES):


report z730amalv1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. * data : lt_fcat type lvc_t_fcat, ls_fcat like line of lt_fcat, ls_fcat type lvc_s_fcat. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. module status_0100 output. if o_cont is initial. set pf-status 'ABC'. create object o_cont exporting container_name = 'CST'. create object o_grid exporting i_parent = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform display. endif. endif. endmodule. " STATUS_0100 OUTPUT

module user_command_0100 input. case sy-ucomm.

when 'BACK'. leave program. endcase. endmodule.

" USER_COMMAND_0100 INPUT

form getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. endform. " getdata form display . call method o_grid->set_table_for_first_display changing it_outtab = lt_vbak[] it_fieldcatalog = lt_fcat[]. endform. " display

form fldcat . call function 'LVC_FIELDCATALOG_MERGE' exporting i_structure_name = 'ZMYVBAK' changing ct_fieldcat = lt_fcat[]. endform. " fldcat

PROGRAM5(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. * DATA : lt_fcat type lvc_t_fcat, ls_fcat like line of lt_fcat, ls_fcat type lvc_s_fcat. initialization.

so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. FORM fldcat . " display

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'ZMYVBAK' CHANGING CT_FIELDCAT = lt_fcat[]. if lt_fcat[] is not initial. loop at lt_fcat into ls_fcat. if ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 3. modify lt_fcat from ls_fcat transporting col_pos. elseif ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Creation time'. modify lt_fcat from ls_fcat transporting col_pos coltext. endif. endloop. endif. ENDFORM. " fldcat

PROGRAM6(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. DATA : lt_fcat type lvc_t_fcat. field-symbols <fs> like line of lt_fcat. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial.

set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform display. endif. endif. ENDMODULE.

= 'CST'.

" STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. " display

FORM fldcat . CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'ZMYVBAK' CHANGING CT_FIELDCAT = lt_fcat[]. if lt_fcat[] is not initial. loop at lt_fcat assigning <fs>. if <fs>-fieldname = 'ERDAT'.

<fs>-col_pos = 3. elseif <fs>-fieldname = 'ERZET'. <fs>-col_pos = 2. <fs>-coltext = 'Creation time'. endif. endloop. endif. ENDFORM. " fldcat

PROGRAM7(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. DATA : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform display.

endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. " display

FORM fldcat . clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. ls_fcat-tooltip = 'Sales Document'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Time'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'.

append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. append ls_fcat to lt_fcat. ENDFORM. " fldcat

PROGRAM8(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container, o_dock type ref to cl_gui_docking_container. DATA : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data mode type i. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. set pf-status 'ABC'. CALL METHOD CL_GUI_ALV_GRID=>OFFLINE RECEIVING E_OFFLINE = mode. if mode eq 0. if o_cont is initial. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'.

CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. endif. else. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_dock. endif. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform display. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. " display

FORM fldcat . clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. ls_fcat-tooltip = 'Sales Document'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'.

ls_fcat-col_pos = 2. ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Time'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. append ls_fcat to lt_fcat. ENDFORM. " fldcat

PROGRAM9(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. DATA : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data : ls_layo type lvc_s_layo. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100.

MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform layout. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = ls_layo CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. " display

FORM fldcat . clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1.

ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. ls_fcat-tooltip = 'Sales Document'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Time'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. append ls_fcat to lt_fcat. ENDFORM. " fldcat

FORM layout . clear ls_layo. ls_layo-grid_title = 'SALES DOCUMENT HEADER DATA'. ls_layo-zebra = 'X'. ENDFORM. " layout

PROGRAM10(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, color(4) type c, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak.

data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. DATA : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data : ls_layo type lvc_s_layo. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform colourrows. perform layout. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select vbeln erdat erzet ernam from vbak into corresponding fields of table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata

FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = ls_layo CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. " display

FORM fldcat . clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. ls_fcat-tooltip = 'Sales Document'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Time'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. * ls_fcat-emphasize = 'C510'. "column coloring append ls_fcat to lt_fcat. ENDFORM. " fldcat

FORM colourrows . loop at lt_vbak into ls_vbak. if ls_vbak-erdat = '19970103'. ls_vbak-color = 'C016'.

elseif ls_vbak-erdat = '19970107'. ls_vbak-color = 'C103'. else. ls_vbak-color = 'C410'. endif. modify lt_vbak from ls_vbak transporting color. endloop. ENDFORM. " colourrows FORM layout . clear ls_layo. ls_layo-info_fname = 'COLOR'. ENDFORM. " layout

PROGRAM11(ALV REPORTING USING CLASSES):


report z730amalv1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, lights type c, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. data : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data : ls_layo type lvc_s_layo. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. module status_0100 output. if o_cont is initial. set pf-status 'ABC'. create object o_cont exporting container_name = 'CST'. create object o_grid exporting

i_parent

= o_cont.

perform getdata. if lt_vbak[] is not initial. perform fldcat. perform trafficlights. perform layout. perform display. endif. endif. endmodule. " STATUS_0100 OUTPUT

module user_command_0100 input. case sy-ucomm. when 'BACK'. leave program. endcase. endmodule. " USER_COMMAND_0100 INPUT form getdata . select vbeln erdat erzet ernam from vbak into corresponding fields of table lt_vbak where vbeln in so_vbeln. endform. " getdata form display . call method o_grid->set_table_for_first_display exporting is_layout = ls_layo changing it_outtab = lt_vbak[] it_fieldcatalog = lt_fcat[]. endform. " display

form fldcat . clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2.

ls_fcat-tooltip = 'Sales Document'.

ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Time'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. * ls_fcat-emphasize = 'C510'. "column coloring append ls_fcat to lt_fcat. endform. " fldcat

form trafficlights. loop at lt_vbak into ls_vbak. if ls_vbak-erdat = '19970103'. ls_vbak-lights = '1'. elseif ls_vbak-erdat = '19970107'. ls_vbak-lights = '2'. else. ls_vbak-lights = '3'. endif. modify lt_vbak from ls_vbak transporting lights. endloop. endform. " colourrows form layout . clear ls_layo. ls_layo-excp_fname = 'LIGHTS'. endform. " layout

PROGRAM12(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, product(10) type c, vbeln type vbak-vbeln, erdat type vbak-erdat,

erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. DATA : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data : ls_layo type lvc_s_layo. data : lt_drop type lvc_t_drop, ls_drop type lvc_s_drop. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform layout. perform dropdown. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase.

ENDMODULE.

" USER_COMMAND_0100 INPUT

FORM getdata . select vbeln erdat erzet ernam from vbak into corresponding fields of table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = ls_layo CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. FORM fldcat . clear ls_fcat. ls_fcat-fieldname = 'PRODUCT'. ls_fcat-tooltip = 'Course'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Course'. ls_fcat-outputlen = 10. ls_fcat-drdn_hndl = 25. ls_fcat-edit = 'X'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-tooltip = 'Sales Document'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Time'. " display

ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 5. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. * ls_fcat-emphasize = 'C510'. "column coloring append ls_fcat to lt_fcat. ENDFORM. " fldcat

FORM layout . clear ls_layo. ENDFORM.

" layout

FORM dropdown . clear ls_drop. ls_drop-handle = 25. ls_drop-value = 'ABAP'. append ls_drop to lt_drop. clear ls_drop. ls_drop-handle = 25. ls_drop-value = 'OOPSABAP'. append ls_drop to lt_drop. clear ls_drop. ls_drop-handle = 25. ls_drop-value = 'WEBDYNPRO'. append ls_drop to lt_drop. CALL METHOD O_GRID->SET_DROP_DOWN_TABLE EXPORTING IT_DROP_DOWN = lt_drop[]. ENDFORM. " dropdown

PROGRAM13(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat,

erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. DATA : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data : ls_layo type lvc_s_layo. data : lt_drop type lvc_t_drop, ls_drop type lvc_s_drop. data : lt_fcodes type ui_functions, lv_fcode type ui_func. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform layout. perform exclude. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'.

leave program. endcase. ENDMODULE.

" USER_COMMAND_0100 INPUT

FORM getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = ls_layo IT_TOOLBAR_EXCLUDING = lt_fcodes[] CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. FORM fldcat . clear ls_fcat. clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-tooltip = 'Sales Document'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. ls_fcat-style = cl_gui_alv_grid=>MC_STYLE_BUTTON. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Time'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'. append ls_fcat to lt_fcat. clear ls_fcat. " display

ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. * ls_fcat-emphasize = 'C510'. "column coloring append ls_fcat to lt_fcat. ENDFORM. " fldcat

FORM layout . clear ls_layo. ENDFORM.

" layout

FORM exclude . clear lv_fcode. lv_fcode = cl_gui_alv_grid=>mc_fc_find. append lv_fcode to lt_fcodes. clear lv_fcode. lv_fcode = cl_gui_alv_grid=>mc_fc_print. append lv_fcode to lt_fcodes. ENDFORM. " exclude

PROGRAM14(ALV REPORTING USING CLASSES):


REPORT Z730AMALV1. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, cellstyles type lvc_t_styl, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. DATA : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data : ls_layo type lvc_s_layo.

initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform styles. perform layout. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select vbeln erdat erzet ernam from vbak into corresponding fields of table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = ls_layo CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[].

ENDFORM. FORM fldcat . clear ls_fcat.

" display

clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-tooltip = 'Sales Document'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Time'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. append ls_fcat to lt_fcat. ENDFORM. " fldcat

FORM styles . data : ls_styl type lvc_s_styl. loop at lt_vbak into ls_vbak. if ls_vbak-erdat = '19970121'. ls_Styl-fieldname = 'VBELN'. ls_styl-style = cl_gui_alv_grid=>mc_style_button. append ls_styl to ls_vbak-cellstyles. modify lt_vbak from ls_vbak transporting cellstyles. endif. endloop.

ENDFORM.

" styles

FORM layout . clear ls_layo. ls_layo-stylefname = 'CELLSTYLES'. ENDFORM. " layout

PROGRAM15(ALV REPORTING USING CLASSES):


REPORT Z730AMALV14. data : lv_vbeln type vbak-vbeln. data : lv_matnr type matnr. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak. types : begin of ty_vbap, vbeln type vbap-vbeln, posnr type vbap-posnr, matnr type vbap-matnr, end of ty_vbap. data : lt_vbap type standard table of ty_vbap, ls_vbap type ty_vbap. types : begin of ty_mara, matnr type mara-matnr, mtart type mara-mtart, matkl type mara-matkl, end of ty_mara. data : lt_mara type standard table of ty_mara, ls_mara type ty_mara. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. data : o_grid1 type ref to cl_gui_alv_grid, o_cont1 type ref to cl_gui_custom_container. data : o_grid2 type ref to cl_gui_alv_grid, o_cont2 type ref to cl_gui_custom_container. DATA : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat.

data : ls_layo type lvc_s_layo. class lcl_eventreceiver definition. public section. methods : handle_hotspot_click for event hotspot_click of cl_gui_alv_grid importing e_row_id. methods : handle_double_click for event double_click of cl_gui_alv_grid importing e_row. methods : handle_button_click for event button_click of cl_gui_alv_grid importing es_row_no. endclass. class lcl_eventreceiver implementation. method handle_hotspot_click. read table lt_vbak into ls_vbak index e_row_id-index. if sy-subrc eq 0. lv_vbeln = ls_vbak-vbeln. if lv_vbeln is not initial. perform getvbap. if lt_vbap[] is not initial. call screen 200. endif. endif. endif. endmethod. method handle_double_click. read table lt_vbap into ls_vbap index e_row-index. if sy-subrc eq 0. lv_matnr = ls_vbap-matnr. if lv_matnr is not initial. perform getmara. if lt_mara[] is not initial. call screen 300. else. message 'No material data' type 'I'. endif. endif. endif. endmethod. method handle_button_click. read table lt_mara into ls_mara index es_row_no-row_id. if sy-subrc eq 0. clear lv_matnr. lv_matnr = ls_mara-matnr. set parameter id 'MAT' field lv_matnr. call transaction 'MM02'.

endif. endmethod. endclass. data ob type ref to lcl_eventreceiver. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform layout. perform register. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getdata FORM display .

CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = ls_layo CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. FORM fldcat . clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-tooltip = 'Sales Document'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. ls_fcat-hotspot = 'X'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Time'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. append ls_fcat to lt_fcat. ENDFORM. " fldcat " display

FORM layout . clear ls_layo. ls_layo-grid_title = 'SALES DOCUMENT HEADER DATA'. ENDFORM. " layout

FORM register . create object ob. set handler ob->handle_hotspot_click for o_grid. ENDFORM. " register FORM getvbap . select vbeln posnr matnr from vbap into table lt_vbap where vbeln = lv_vbeln. ENDFORM. " getvbap FORM fldcatvbap . refresh lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 10. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'POSNR'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Item No'. ls_fcat-outputlen = 5. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'MATNR'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Material'. ls_fcat-outputlen = 10. append ls_fcat to lt_fcat. ENDFORM. " fldcatvbap

MODULE STATUS_0200 OUTPUT. SET PF-STATUS 'PQR'. if o_cont1 is initial. CREATE OBJECT O_CONT1 EXPORTING CONTAINER_NAME = 'CST1'. CREATE OBJECT O_GRID1 EXPORTING I_PARENT = o_cont1. perform fldcatvbap.

perform layoutvbap. perform registerhandler. perform displayvbap. else. CALL METHOD O_GRID1->REFRESH_TABLE_DISPLAY. endif. ENDMODULE. " STATUS_0200 OUTPUT

FORM displayvbap . CALL METHOD O_GRID1->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = ls_layo CHANGING IT_OUTTAB = lt_vbap[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. " displayvbap

FORM layoutvbap . clear ls_layo. ls_layo-grid_title = 'SALES DOCUMENT ITEM DATA'. ENDFORM. " layoutvbap MODULE USER_COMMAND_0200 INPUT. case sy-ucomm. when 'BACK'. leave to screen 100. endcase. ENDMODULE. " USER_COMMAND_0200 INPUT FORM registerhandler . create object ob. set handler ob->handle_double_click for o_grid1. ENDFORM. " registerhandler FORM getmara . select single matnr mtart matkl from mara into ls_mara where matnr = lv_matnr. if sy-subrc eq 0. refresh lt_mara. append ls_mara to lt_mara. endif. ENDFORM. " getmara MODULE STATUS_0300 OUTPUT. SET PF-STATUS 'LMN'. if o_cont2 is initial.

CREATE OBJECT O_CONT2 EXPORTING CONTAINER_NAME CREATE OBJECT O_GRID2 EXPORTING I_PARENT = o_cont2.

= 'CST2'.

perform fldcatmara. perform layoutmara. perform register_handlers. perform displaymara. else. CALL METHOD O_GRID2->REFRESH_TABLE_DISPLAY. endif. ENDMODULE. " STATUS_0300 OUTPUT FORM fldcatmara . refresh lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'MATNR'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Material'. ls_fcat-outputlen = 10. ls_fcat-style = cl_gui_alv_grid=>MC_STYLE_BUTTON. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'MTART'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Material Type'. ls_fcat-outputlen = 10. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'MATKL'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Material Group'. ls_fcat-outputlen = 10. append ls_fcat to lt_fcat. ENDFORM. " fldcatmara

FORM layoutmara . clear ls_layo. ls_layo-grid_title = 'MATERIAL DATA'. ENDFORM. " layoutmara FORM displaymara . CALL METHOD O_GRID2->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = ls_layo

CHANGING IT_OUTTAB IT_FIELDCATALOG ENDFORM.

= lt_mara[] = lt_fcat[]. " displaymara

MODULE USER_COMMAND_0300 INPUT. case sy-ucomm. when 'BACK'. leave to screen 200. endcase. ENDMODULE. " USER_COMMAND_0300 INPUT FORM register_handlers . create object ob. set handler ob->handle_button_click for o_grid2. ENDFORM. " register_handlers

PROGRAM16(ALV REPORTING USING CLASSES):


report z730amalv16. type-pools icon. data : lv_vbeln type vbak-vbeln.

select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak, gt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. data : o_grid1 type ref to cl_gui_alv_grid, o_cont1 type ref to cl_gui_custom_container. data : lt_rows type lvc_t_row, ls_rows type lvc_s_row. data : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data : ls_layo type lvc_s_layo. data : ls_toolbar type stb_button. class lcl_eventreceiver definition.

public section. methods : handle_toolbar for event toolbar of cl_gui_alv_grid importing e_object. methods : handle_menu_button for event menu_button of cl_gui_alv_grid importing e_object e_ucomm. methods : handle_user_command for event user_command of cl_gui_alv_grid importing e_ucomm. endclass. class lcl_eventreceiver implementation. method handle_toolbar. * For disabling loop at e_object->mt_toolbar into ls_toolbar. if ls_toolbar-function = cl_gui_alv_grid=>mc_fc_find. ls_toolbar-disabled = 'X'. modify e_object->mt_toolbar from ls_toolbar transporting disabled. endif. endloop. * For adding custom pushbuttons clear ls_toolbar. ls_toolbar-function = 'P1'. ls_toolbar-icon = '@15@'. ls_toolbar-quickinfo = 'But1'. ls_toolbar-butn_type = 0. ls_toolbar-disabled = ''. ls_toolbar-text = 'Button1'. * ls_toolbar-checked = 'X'. append ls_toolbar to e_object->mt_toolbar. clear ls_toolbar. ls_toolbar-function = 'P2'. * ls_toolbar-icon = '@15@'. ls_toolbar-quickinfo = 'But2'. ls_toolbar-butn_type = 3. ls_toolbar-disabled = ''. ls_toolbar-text = 'Button2'. append ls_toolbar to e_object->mt_toolbar. clear ls_toolbar. ls_toolbar-function = 'P3'. ls_toolbar-icon = '@16@'. ls_toolbar-quickinfo = 'But3'. ls_toolbar-butn_type = 2. ls_toolbar-disabled = ''. ls_toolbar-text = 'Button3'. append ls_toolbar to e_object->mt_toolbar. endmethod.

method handle_menu_button. case e_ucomm. when 'P3'. call method e_object->add_function exporting fcode = 'MI1' text = 'Menu item1'. call method e_object->add_function exporting fcode = 'MI2' text = 'Menu item2'. call method e_object->add_function exporting fcode = 'MI3' text = 'Menu item3'. endcase. endmethod. method handle_user_command. case e_ucomm. when 'P1'. call method o_grid->get_selected_rows importing et_index_rows = lt_rows[]. if lt_rows[] is not initial. loop at lt_rows into ls_rows. read table lt_vbak into ls_vbak index ls_rows-index. if sy-subrc eq 0. append ls_vbak to gt_vbak. endif. endloop. if gt_vbak[] is not initial. call screen 200. endif. else. message 'Please select atleast one row' type 'I'. endif. endcase. endmethod. endclass. data ob type ref to lcl_eventreceiver. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln.

start-of-selection. call screen 100. module status_0100 output. if o_cont is initial. set pf-status 'ABC'. create object o_cont exporting container_name = 'CST'. create object o_grid exporting i_parent = o_cont. perform getdata. if lt_vbak[] is not initial. perform fldcat. perform layout. perform register. perform display. endif. endif. endmodule. " STATUS_0100 OUTPUT

module user_command_0100 input. case sy-ucomm. when 'BACK'. leave program. endcase. endmodule. " USER_COMMAND_0100 INPUT form getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. endform. " getdata form display . call method o_grid->set_table_for_first_display exporting is_layout = ls_layo changing it_outtab = lt_vbak[] it_fieldcatalog = lt_fcat[]. endform. form fldcat . " display

clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-tooltip = 'Sales Document'.

ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 12. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Date'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Time'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Creation Time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Person'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'Created by'. append ls_fcat to lt_fcat. endform. " fldcat

form layout . clear ls_layo. ls_layo-grid_title = 'SALES DOCUMENT HEADER DATA'. * ls_layo-edit = 'X'. ls_layo-sel_mode = 'A'. endform. " layout form register. create object ob. set handler ob->handle_toolbar for o_grid. set handler ob->handle_menu_button for o_grid. set handler ob->handle_user_command for o_grid. endform. " register module status_0200 output. set pf-status 'ABD'. if o_cont1 is initial. create object o_cont1 exporting container_name = 'CST1'.

create object o_grid1 exporting i_parent = o_cont1. call method o_grid1->set_table_for_first_display exporting is_layout = ls_layo changing it_outtab = gt_vbak[] it_fieldcatalog = lt_fcat[]. endif. endmodule. " STATUS_0200 OUTPUT

module user_command_0200 input. case sy-ucomm. when 'BACK'. leave to screen 100. endcase. endmodule. " USER_COMMAND_0200 INPUT

PROGRAM17(SPLITTER, TREE AND PICTURE):


report z730amalv17 . type-pools : cndp,cntl. data pic_url type cndp_url. types : begin of ty_nodes. include structure abdemonode. types end of ty_nodes. data : lt_nodes type standard table of ty_nodes, ls_nodes type ty_nodes. data : lt_events type table of cntl_simple_event, ls_event type cntl_simple_event. data : cust_cont type ref to cl_gui_custom_container, o_split type ref to cl_gui_splitter_container, o_cont1 type ref to cl_gui_container, o_cont2 type ref to cl_gui_container, o_tree type ref to cl_gui_simple_tree, o_pic type ref to cl_gui_picture. class lcl_eventreceiver definition. public section. methods handle_node_double_click for event node_double_click of cl_gui_simple_tree

importing node_key. endclass. class lcl_eventreceiver implementation. method handle_node_double_click. case node_key. when 'CSO'. call transaction 'VA01'. when 'CHSO'. call transaction 'VA02'. when 'CPO'. call transaction 'ME21'. when 'CHPO'. call transaction 'ME22'. endcase. endmethod. endclass. data ob type ref to lcl_eventreceiver. start-of-selection. call screen 100. module status_0100 output. set pf-status 'ABC'. if cust_cont is initial. create object cust_cont exporting container_name = 'CST'. create object o_split exporting parent = cust_cont rows =1 columns = 2. call method o_split->set_column_width exporting id =1 width = 6. call method o_split->set_column_width exporting id =2 width = 3. call method o_split->get_container exporting row =1 column = 1 receiving container = o_cont1. call method o_split->get_container

exporting row =1 column = 2 receiving container = o_cont2. perform picture. perform tree. endif. endmodule. " STATUS_0100 OUTPUT

module user_command_0100 input. case sy-ucomm. when 'BACK'. leave program. endcase. endmodule. " USER_COMMAND_0100 INPUT form picture . call function 'DP_PUBLISH_WWW_URL' exporting objid = 'ZALV8AM' lifetime = cndp_lifetime_transaction importing url = pic_url. create object o_pic exporting parent = o_cont2. call method o_pic->load_picture_from_url exporting url = pic_url. endform. " picture

form tree . create object o_tree exporting parent = o_cont1 node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single. clear ls_nodes. ls_nodes-node_key = 'RT'. ls_nodes-isfolder = 'X'. ls_nodes-expander = 'X'. ls_nodes-text = 'Transactions'. append ls_nodes to lt_nodes. clear ls_nodes.

ls_nodes-node_key = 'SO'. ls_nodes-relatkey = 'RT'. ls_nodes-isfolder = 'X'. ls_nodes-expander = 'X'. ls_nodes-text = 'Sales order'. append ls_nodes to lt_nodes. clear ls_nodes. ls_nodes-node_key = 'CSO'. ls_nodes-relatkey = 'SO'. ls_nodes-n_image = '@15@'. ls_nodes-text = 'Create Sales order'. append ls_nodes to lt_nodes. clear ls_nodes. ls_nodes-node_key = 'CHSO'. ls_nodes-relatkey = 'SO'. ls_nodes-n_image = '@15@'. ls_nodes-text = 'Change Sales order'. append ls_nodes to lt_nodes. clear ls_nodes. ls_nodes-node_key = 'PO'. ls_nodes-relatkey = 'RT'. ls_nodes-isfolder = 'X'. ls_nodes-expander = 'X'. ls_nodes-text = 'Purchase order'. append ls_nodes to lt_nodes. clear ls_nodes. ls_nodes-node_key = 'CPO'. ls_nodes-relatkey = 'PO'. ls_nodes-exp_image = '@16@'. ls_nodes-text = 'Create Purchase order'. append ls_nodes to lt_nodes. clear ls_nodes. ls_nodes-node_key = 'CHPO'. ls_nodes-relatkey = 'PO'. ls_nodes-exp_image = '@16@'. ls_nodes-text = 'Change Purchase order'. append ls_nodes to lt_nodes. create object ob. set handler ob->handle_node_double_click for o_tree. * Explicit registration clear ls_event. ls_event-eventid = cl_gui_simple_tree=>eventid_node_double_click. append ls_event to lt_events. call method o_tree->set_registered_events exporting events = lt_events[].

call method o_tree->add_nodes exporting table_structure_name = 'ABDEMONODE' node_table = lt_nodes[]. endform. " tree .

PROGRAM18(TOP OF PAGE , EDITING CELLS):


REPORT Z730AMALV18 data : lv_vbeln type vbeln. data : cust_cont type ref to cl_gui_custom_container, o_split type ref to cl_gui_splitter_container, o_cont1 type ref to cl_gui_container, o_cont2 type ref to cl_gui_container, o_cont3 type ref to cl_gui_container, vbak_grid type ref to cl_gui_alv_grid, vbap_grid type ref to cl_gui_alv_grid. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak. data : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data : ls_layo type lvc_s_layo. data : ls_modi type lvc_s_modi. select-options so_vbeln for lv_vbeln. class lcl_eventreceiver definition. public section. methods handle_data_changed for event data_changed of cl_gui_alv_grid importing ER_DATA_CHANGED. methods handle_top_of_page for event top_of_page of cl_gui_alv_grid importing E_DYNDOC_ID. methods handle_onf1 for event onf1 of cl_gui_alv_grid importing e_fieldname ER_EVENT_DATA. endclass. class lcl_eventreceiver implementation.

method handle_data_changed. read table er_data_changed->mt_mod_cells into ls_modi index 1. if sy-subrc eq 0. read table lt_vbak into ls_vbak index ls_modi-row_id. if sy-subrc eq 0. ls_vbak-ernam = ls_modi-value. modify table lt_vbak from ls_vbak transporting ernam. update vbak set ernam = ls_modi-value where vbeln = ls_vbak-vbeln. endif. endif. endmethod. method handle_top_of_page. CALL METHOD E_DYNDOC_ID->ADD_TEXT EXPORTING TEXT = text-001. CALL METHOD E_DYNDOC_ID->ADD_GAP EXPORTING WIDTH = 5. CALL METHOD E_DYNDOC_ID->ADD_TEXT EXPORTING TEXT = text-002. CALL METHOD E_DYNDOC_ID->NEW_LINE EXPORTING REPEAT = 2. CALL METHOD E_DYNDOC_ID->ADD_TEXT EXPORTING TEXT = text-003. CALL METHOD E_DYNDOC_ID->ADD_PICTURE EXPORTING PICTURE_ID = 'ZTOP'. CALL METHOD E_DYNDOC_ID->DISPLAY_DOCUMENT EXPORTING PARENT = o_cont1. endmethod. method handle_onf1. case e_fieldname. when 'VBELN'. er_event_data->M_EVENT_HANDLED = 'X'. CALL FUNCTION 'POPUP_TO_INFORM' EXPORTING TITEL = 'Custom F1 help' TXT1 = 'VBAK table'

TXT2 endcase. endmethod. endclass.

= 'Sales Document'.

data ob type ref to lcl_eventreceiver. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. SET PF-STATUS 'ABC'. if cust_cont is initial. CREATE OBJECT CUST_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_SPLIT EXPORTING PARENT = cust_cont ROWS =3 COLUMNS = 1. CALL METHOD O_SPLIT->SET_ROW_HEIGHT EXPORTING ID =1 HEIGHT = 4. CALL METHOD O_SPLIT->SET_ROW_HEIGHT EXPORTING ID =2 HEIGHT = 10. CALL METHOD O_SPLIT->SET_ROW_HEIGHT EXPORTING ID =3 HEIGHT = 7. CALL METHOD O_SPLIT->GET_CONTAINER EXPORTING ROW =1 COLUMN = 1 RECEIVING CONTAINER = o_cont1. CALL METHOD O_SPLIT->GET_CONTAINER EXPORTING ROW =2 COLUMN = 1 RECEIVING

CONTAINER = o_cont2. CALL METHOD O_SPLIT->GET_CONTAINER EXPORTING ROW =3 COLUMN = 1 RECEIVING CONTAINER = o_cont3. perform sales_header. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM sales_header . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. if lt_vbak[] is not initial. perform fldcatvbak. perform layoutvbak. CREATE OBJECT VBAK_GRID EXPORTING I_PARENT = o_cont2. perform register. perform displayvbak. endif. ENDFORM. " sales_header FORM fldcatvbak . clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. ls_fcat-outputlen = 10. ls_fcat-ref_table = 'VBAK'. ls_fcat-ref_field = 'VBELN'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'.

ls_fcat-col_pos = 2. ls_fcat-coltext = 'Creation date'. ls_fcat-outputlen = 10. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Creation time'. ls_fcat-outputlen = 10. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Created by'. ls_fcat-outputlen = 10. ls_fcat-edit = 'X'. append ls_fcat to lt_fcat. ENDFORM. " fldcatvbak FORM layoutvbak . clear ls_layo. ls_layo-grid_title = 'SALES DOCUMENT HEADER DATA'. ENDFORM. " layoutvbak FORM displayvbak . CALL METHOD VBAK_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IS_LAYOUT = ls_layo CHANGING IT_OUTTAB = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. " displayvbak

FORM register . create object ob. set handler ob->handle_data_changed for vbak_grid. * Explicit registration of data_changed event CALL METHOD VBAK_GRID->REGISTER_EDIT_EVENT EXPORTING I_EVENT_ID = cl_gui_alv_grid=>MC_EVT_MODIFIED. set handler ob->handle_top_of_page for vbak_grid. * Explicit registration of top_of_page event data k type ref to cl_dd_document. create object k. CALL METHOD VBAK_GRID->LIST_PROCESSING_EVENTS EXPORTING I_EVENT_NAME = 'TOP_OF_PAGE'

I_DYNDOC_ID

= k.

set handler ob->handle_onf1 for vbak_grid. ENDFORM. " register

PROGRAM19(ALV REPORTING USING CLASSES):


REPORT Z730AMALV7. data : lv_deptno type zdept-deptno. select-options : so_dno for lv_deptno. types : begin of ty_dpt, deptno type zdept-deptno, dname type zdept-dname, end of ty_dpt. data : lt_dpt type standard table of ty_dpt. types : begin of ty_dept. include structure zdept. types end of ty_dept. data : lt_dept type standard table of ty_dept, ls_dept type ty_dept. types : begin of ty_retval. include structure DDSHRETVAL. types end of ty_retval. data : lt_retval type standard table of ty_retval, ls_retval type ty_retval. data : o_grid type ref to cl_gui_alv_grid, o_cont type ref to cl_gui_custom_container. DATA : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat.

data : lt_f4 type lvc_t_f4, ls_f4 type lvc_s_f4. class lcl_eventreceiver definition. public section. methods handle_onf4 for event onf4 of cl_gui_alv_grid importing e_fieldname ES_ROW_NO. endclass. class lcl_eventreceiver implementation. method handle_onf4. case e_fieldname. when 'DEPTNO'. perform getf4data. if lt_dpt[] is not initial. CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

EXPORTING RETFIELD DYNPPROG DYNPNR DYNPROFIELD VALUE_ORG TABLES VALUE_TAB RETURN_TAB

= 'DEPTNO' = sy-repid = sy-dynnr = 'DEPTNO' = 'S' = lt_dpt[] = lt_retval[].

if lt_retval[] is not initial. read table lt_retval into ls_retval index 1. if sy-subrc eq 0. read table lt_dept into ls_dept index es_row_no-row_id. clear lv_deptno. lv_deptno = ls_dept-deptno. ls_dept-deptno = ls_retval-fieldval. modify lt_dept from ls_dept transporting deptno where deptno = lv_deptno. update zdept set deptno = ls_retval-fieldval where deptno = lv_deptno. CALL METHOD O_GRID->REFRESH_TABLE_DISPLAY. endif. endif. endif. endcase. endmethod. endclass. data ob type ref to lcl_eventreceiver. initialization. so_dno-low = 10. so_dno-high = 50. append so_dno. start-of-selection. call screen 100. MODULE STATUS_0100 OUTPUT. if o_cont is initial. set pf-status 'ABC'. CREATE OBJECT O_CONT EXPORTING CONTAINER_NAME = 'CST'. CREATE OBJECT O_GRID EXPORTING I_PARENT = o_cont.

perform getdata. if lt_dept[] is not initial. perform fldcat. perform register. perform display. endif. endif. ENDMODULE. " STATUS_0100 OUTPUT

MODULE USER_COMMAND_0100 INPUT. case sy-ucomm. when 'BACK'. leave program. endcase. ENDMODULE. " USER_COMMAND_0100 INPUT FORM getdata . select * from zdept into table lt_dept where deptno in so_dno. ENDFORM. " getdata FORM display . CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY CHANGING IT_OUTTAB = lt_dept[] IT_FIELDCATALOG = lt_fcat[]. ENDFORM. " display

FORM fldcat . clear ls_fcat. ls_fcat-fieldname = 'DEPTNO'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'DEPTNO'. ls_fcat-outputlen = 12. ls_fcat-tooltip = 'DEPTNO'. ls_fcat-f4availabl = 'X'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'DNAME'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'DNAME'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'DNAME'. append ls_fcat to lt_fcat. clear ls_fcat.

ls_fcat-fieldname = 'LOC'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'LOC'. ls_fcat-outputlen = 10. ls_fcat-tooltip = 'LOC'. append ls_fcat to lt_fcat. ENDFORM. " fldcat

FORM register . create object ob. set handler ob->handle_onf4 for o_grid. * Explicit registration of onf4. clear ls_f4. ls_f4-fieldname = 'DEPTNO'. ls_f4-register = 'X'. append ls_f4 to lt_f4. CALL METHOD O_GRID->REGISTER_F4_FOR_FIELDS EXPORTING IT_F4 = lt_f4[].

ENDFORM.

" register

FORM getf4data . select deptno dname from zdept into table lt_dpt where deptno in so_dno. ENDFORM. " getf4data

PROGRAM20(PRINT EVENTS):

REPORT Z730AMALV20 class lcl_eventreceiver definition. public section. methods : handle_print_top_of_page for event print_top_of_page of cl_gui_alv_grid, handle_print_top_of_list for event print_top_of_list of cl_gui_alv_grid, handle_print_end_of_page for event print_end_of_page of cl_gui_alv_grid, handle_print_end_of_list for event print_end_of_list of cl_gui_alv_grid. endclass.

class lcl_eventreceiver implementation. method handle_print_top_of_page. write :/ 'Print Top of page event'. endmethod. method handle_print_top_of_list. write :/ 'Print Top of list event'. endmethod. method handle_print_end_of_page. write :/ 'Print end of page event'. endmethod. method handle_print_end_of_list. write :/ 'Print end of list event'. endmethod. endclass. types : begin of ty_vbak, vbeln type vbak-vbeln, erdat type vbak-erdat, erzet type vbak-erzet, ernam type vbak-ernam, end of ty_vbak. data : lt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak. data : lt_fcat type lvc_t_fcat, ls_fcat type lvc_s_fcat. data : vbak_cont type ref to cl_gui_custom_container, vbak_Grid type ref to cl_gui_alv_grid. data : ls_print type lvc_s_prnt. data ob type ref to lcl_eventreceiver. start-of-selection. call screen 100. module STATUS_0100 output. SET PF-STATUS 'ABC'. if vbak_cont is initial. create object vbak_cont exporting container_name = 'CST'. create object vbak_grid exporting i_parent = vbak_cont. perform getdata.

if lt_vbak[] is not initial. perform fldcat. perform register. perform display. endif. endif. endmodule. " STATUS_0100 OUTPUT form getdata . select vbeln erdat erzet ernam from vbak into table lt_vbak up to 300 rows. endform. " getdata form fldcat . clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1. ls_fcat-coltext = 'Sales Doc'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2. ls_fcat-coltext = 'Creation date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-coltext = 'Creation time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-coltext = 'Created by'. append ls_fcat to lt_fcat. endform. " fldcat form display . ls_print-RESERVELNS = 2. call method vbak_grid->set_table_for_first_display * exporting * IS_PRINT = ls_print changing it_outtab = lt_vbak[] IT_FIELDCATALOG = lt_fcat[]. endform. " display

module USER_COMMAND_0100 input.

case sy-ucomm. when 'BACK'. leave program. endcase. endmodule. " USER_COMMAND_0100 INPUT

form register . create object ob. set handler ob->handle_print_top_of_page for vbak_grid. set handler ob->handle_print_top_of_list for vbak_grid. set handler ob->handle_print_end_of_page for vbak_grid. set handler ob->handle_print_end_of_list for vbak_grid. endform. " register

PROGRAM21(ALV FM1, IMAGE, EVENT HANDLING):


REPORT Z730AMALV21 . type-pools slis. data : lv_vbeln type vbak-vbeln. select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak. include structure zmyvbak. types end of ty_vbak. data : lt_vbak type standard table of ty_vbak. data : lt_fcat type SLIS_T_FIELDCAT_ALV. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. perform getvbak. if lt_vbak[] is not initial. perform fldcat. perform display. endif. FORM getvbak . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getvbak FORM fldcat . CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING

I_STRUCTURE_NAME CHANGING CT_FIELDCAT ENDFORM.

= 'ZMYVBAK' = lt_fcat[]. " fldcat

FORM display . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING IT_FIELDCAT = lt_fcat[] TABLES T_OUTTAB = lt_vbak[]. ENDFORM. " display

PROGRAM22(ALV FM1, IMAGE, EVENT HANDLING):


REPORT Z730AMALV21 type-pools slis. data : lv_vbeln type vbak-vbeln. .

select-options : so_vbeln for lv_vbeln. types : begin of ty_vbak. include structure zmyvbak. types end of ty_vbak. data : lt_vbak type standard table of ty_vbak, ls_vbak type ty_vbak. types : begin of ty_vbap, vbeln type vbap-vbeln, posnr type vbap-posnr, matnr type vbap-matnr, end of ty_vbap. data : lt_vbap type standard table of ty_vbap. data : lt_fcat type SLIS_T_FIELDCAT_ALV, ls_fcat like line of lt_fcat. data : lt_events type slis_t_event, ls_events like line of lt_events. data : lt_header type SLIS_T_LISTHEADER, ls_header like line of lt_header. initialization. so_vbeln-low = '4970'. so_vbeln-high = '4975'. append so_vbeln. start-of-selection. perform getvbak. if lt_vbak[] is not initial. perform fldcat. perform preparevents.

perform display. endif. FORM getvbak . select vbeln erdat erzet ernam from vbak into table lt_vbak where vbeln in so_vbeln. ENDFORM. " getvbak FORM fldcat . clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1. ls_fcat-seltext_m = 'Sales Doc'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERDAT'. ls_fcat-col_pos = 2. ls_fcat-seltext_m = 'Date'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERZET'. ls_fcat-col_pos = 3. ls_fcat-seltext_m = 'Time'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'ERNAM'. ls_fcat-col_pos = 4. ls_fcat-seltext_m = 'Created By'. append ls_fcat to lt_fcat. ENDFORM. " fldcat

FORM display . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = sy-repid IT_EVENTS = lt_events[] IT_FIELDCAT = lt_fcat[] TABLES T_OUTTAB = lt_vbak[]. ENDFORM. " display FORM preparevents . clear ls_events. ls_events-name = 'USER_COMMAND'. ls_events-form = 'ZITEM'.

append ls_events to lt_events. ENDFORM. " preparevents form zitem using ucomm type sy-ucomm sel type slis_selfield. read table lt_vbak into ls_vbak index sel-tabindex. if sy-subrc eq 0. clear lv_vbeln. lv_vbeln = ls_vbak-vbeln. if lv_vbeln is not initial. perform getvbap. if lt_vbap[] is not initial. perform fldcatvbap. perform regevents. perform displayvbap. endif. endif. endif. endform. FORM getvbap . select vbeln posnr matnr from vbap into table lt_vbap where vbeln = lv_vbeln. ENDFORM. " getvbap FORM fldcatvbap . refresh lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'VBELN'. ls_fcat-col_pos = 1. ls_fcat-seltext_m = 'Sales Doc'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'POSNR'. ls_fcat-col_pos = 2. ls_fcat-seltext_m = 'Item no'. append ls_fcat to lt_fcat. clear ls_fcat. ls_fcat-fieldname = 'MATNR'. ls_fcat-col_pos = 3. ls_fcat-seltext_m = 'Material'. append ls_fcat to lt_fcat. ENDFORM. " fldcatvbap

FORM displayvbap . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING

I_CALLBACK_PROGRAM = sy-repid IT_EVENTS = lt_events[] IT_FIELDCAT = lt_fcat[] TABLES T_OUTTAB = lt_vbap[]. ENDFORM. " displayvbap FORM regevents . clear ls_events. ls_events-name = 'TOP_OF_PAGE'. ls_events-form = 'PRINTHEADING'. append ls_events to lt_events. ENDFORM. " regevents form printheading. clear ls_header. ls_header-typ = 'H'. ls_header-info = 'SALES DOCUMENT ITEM DATA'. append ls_header to lt_header. clear ls_header. ls_header-typ = 'S'. ls_header-info = 'LINE ITEM DETAILS'. append ls_header to lt_header. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING IT_LIST_COMMENTARY = LT_HEADER[] I_LOGO = 'ZTOP'. endform.

PROGRAM23(ALV BLOCKED LIST):


REPORT Z730AMALV23. TABLES : VBAK. TYPE-POOLS SLIS.

SELECT-OPTIONS SO_VBELN FOR VBAK-VBELN. TYPES : BEGIN OF TY_VBAK, VBELN TYPE VBAK-VBELN, ERDAT TYPE VBAK-ERDAT, ERZET TYPE VBAK-ERZET, ERNAM TYPE VBAK-ERNAM, END OF TY_VBAK. DATA : LT_VBAK TYPE STANDARD TABLE OF TY_VBAK. TYPES : BEGIN OF TY_VBAP, VBELN TYPE VBAP-VBELN, POSNR TYPE VBAP-POSNR, MATNR TYPE VBAP-MATNR, NETWR TYPE VBAP-NETWR, END OF TY_VBAP.

DATA : LT_VBAP TYPE STANDARD TABLE OF TY_VBAP. DATA LS_LAYO TYPE SLIS_LAYOUT_ALV. DATA : LT_EVENTS TYPE SLIS_T_EVENT. DATA : LT_FCAT TYPE SLIS_T_FIELDCAT_ALV, LS_FCAT LIKE LINE OF LT_FCAT. INITIALIZATION. SO_VBELN-LOW = '4970'. SO_VBELN-HIGH = '4975'. APPEND SO_VBELN. START-OF-SELECTION. PERFORM INIT_BLOCK. PERFORM PERFORM PERFORM PERFORM LAYOUT. FLDCATVBAK. GETVBAK. APPENDVBAK.

PERFORM FLDCATVBAP. PERFORM GETVBAP. PERFORM APPENDVBAP. PERFORM DISPLAYBLOCK. FORM INIT_BLOCK . CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT' EXPORTING I_CALLBACK_PROGRAM = SY-REPID. ENDFORM. " init_block FORM LAYOUT . LS_LAYO-ZEBRA = 'X'. ENDFORM. " layout FORM FLDCATVBAK . CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'ZMYVBAK' CHANGING CT_FIELDCAT = LT_FCAT[]. ENDFORM. " fldcatvbak FORM GETVBAK . SELECT VBELN ERDAT ERZET ERNAM FROM VBAK INTO TABLE LT_VBAK WHERE VBELN IN SO_VBELN. ENDFORM. " getvbak

FORM APPENDVBAK . CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' EXPORTING IS_LAYOUT = LS_LAYO IT_FIELDCAT = LT_FCAT[] I_TABNAME = 'LT_VBAK[]' IT_EVENTS = LT_EVENTS[] TABLES T_OUTTAB = LT_VBAK[]. ENDFORM. " appendvbak

FORM FLDCATVBAP . REFRESH LT_FCAT. CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'ZMYVBAP' CHANGING CT_FIELDCAT = LT_FCAT[]. ENDFORM. " fldcatvbap FORM GETVBAP . SELECT VBELN POSNR MATNR NETWR FROM VBAP INTO TABLE LT_VBAP FOR ALL ENTRIES IN LT_VBAK WHERE VBELN = LT_VBAK-VBELN. ENDFORM. " getvbap FORM APPENDVBAP . CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' EXPORTING IS_LAYOUT = LS_LAYO IT_FIELDCAT = LT_FCAT[] I_TABNAME = 'LT_VBAP[]' IT_EVENTS = LT_EVENTS[] TABLES T_OUTTAB = LT_VBAP[]. ENDFORM. " appendvbap

FORM DISPLAYBLOCK . CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'. ENDFORM. " displayblock

PROGRAM24(HIERARCHIAL ALV):
REPORT Z730AMALV24 TABLES VBAK. TYPE-POOLS SLIS.

SELECT-OPTIONS : SO_VBELN FOR VBAK-VBELN.

DATA : LT_FCAT TYPE SLIS_T_FIELDCAT_ALV. TYPES : BEGIN OF TY_VBAK, VBELN TYPE VBAK-VBELN, ERDAT TYPE VBAK-ERDAT, ERZET TYPE VBAK-ERZET, ERNAM TYPE VBAK-ERNAM, END OF TY_VBAK. DATA : LT_VBAK TYPE STANDARD TABLE OF TY_VBAK. TYPES : BEGIN OF TY_VBAP, VBELN TYPE VBAP-VBELN, POSNR TYPE VBAP-POSNR, MATNR TYPE VBAP-MATNR, NETWR TYPE VBAP-NETWR, END OF TY_VBAP. DATA : LT_VBAP TYPE STANDARD TABLE OF TY_VBAP. DATA LS_KEYINFO TYPE SLIS_KEYINFO_ALV. INITIALIZATION. SO_VBELN-LOW = '4970'. SO_VBELN-HIGH = '4975'. APPEND SO_VBELN. START-OF-SELECTION. PERFORM GETVBAK. PERFORM GETVBAP. PERFORM FLDCATVBAK. PERFORM FLDCATVBAP. PERFORM KEYINFO. PERFORM DISPLAY. FORM GETVBAK . SELECT VBELN ERDAT ERZET ERNAM FROM VBAK INTO TABLE LT_VBAK WHERE VBELN IN SO_VBELN. ENDFORM. " getvbak FORM GETVBAP . SELECT VBELN POSNR MATNR NETWR FROM VBAP INTO TABLE LT_VBAP FOR ALL ENTRIES IN LT_VBAK WHERE VBELN = LT_VBAK-VBELN. ENDFORM. " getvbap

FORM FLDCATVBAK . CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_PROGRAM_NAME = SY-REPID I_INTERNAL_TABNAME = 'LT_VBAK[]' I_STRUCTURE_NAME = 'ZMYVBAK' CHANGING CT_FIELDCAT = LT_FCAT[]. ENDFORM. " fldcatvbak

FORM FLDCATVBAP . CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING I_PROGRAM_NAME = SY-REPID I_INTERNAL_TABNAME = 'LT_VBAP[]' I_STRUCTURE_NAME = 'ZMYVBAP' CHANGING CT_FIELDCAT = LT_FCAT[]. ENDFORM. " fldcatvbap

FORM KEYINFO . CLEAR LS_KEYINFO. LS_KEYINFO-HEADER01 = 'VBELN'. LS_KEYINFO-ITEM01 = 'VBELN'. LS_KEYINFO-HEADER02 = ''. LS_KEYINFO-ITEM02 = 'POSNR'. ENDFORM. " keyinfo FORM DISPLAY . CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' EXPORTING IT_FIELDCAT = LT_FCAT[] I_TABNAME_HEADER = 'LT_VBAK[]' I_TABNAME_ITEM = 'LT_VBAP[]' IS_KEYINFO = LS_KEYINFO TABLES T_OUTTAB_HEADER = LT_VBAK[] T_OUTTAB_ITEM = LT_VBAP[]. ENDFORM. " display

You might also like