Example: 1. ALV Interactive Reporting using Function Modules
2. Displaying Images in ALV TOP_OF_PAGE Area using F.M 3. ALV Blocked List Report Program: REPORT Z8AMALV7. include z8amalv7_inc. start-of-SELECTION. perform get_salesheaderdata. if t_vbak is not INITIAL. perform fldcat_salesheader. perform prepareevents. perform display_salesheaderdata. endif. Include Program: data gv_vbeln type vbak-vbeln. select-options so_vbeln for gv_vbeln DEFAULT '4980' to '4985'. data : t_fcat type SLIS_T_FIELDCAT_ALV, wa_fcat like line of t_fcat. types : begin of ty_vbak. include type zcstvbak. 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 zcstvbap. types end of ty_vbap. data : t_vbap type table of ty_vbap, wa_vbap type ty_vbap. types : begin of ty_marc, matnr type marc-matnr, werks type marc-werks, ekgrp type marc-ekgrp, end of ty_marc. data t_marc type table of ty_marc. types : begin of ty_mard, matnr type mard-matnr, werks type mard-werks, lgort type mard-lgort, end of ty_mard. data t_mard type table of ty_mard. data : t_events type SLIS_T_EVENT, wa_events like line of t_events. data wa_layo type SLIS_LAYOUT_ALV. FORM GET_SALESHEADERDATA . select vbeln erdat erzet ernam from vbak into table t_vbak where vbeln in so_vbeln. ENDFORM. " GET_SALESHEADERDATA FORM FLDCAT_SALESHEADER . clear wa_fcat. wa_fcat-fieldname = 'VBELN'. wa_fcat-col_pos = 1. wa_fcat-seltext_m = 'Sales Doc No'. wa_fcat-hotspot = 'X'. append wa_fcat to t_fcat. clear wa_fcat. wa_fcat-fieldname = 'ERDAT'. wa_fcat-col_pos = 2. wa_fcat-seltext_m = '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-seltext_m = '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-seltext_m = 'Created By'. wa_fcat-outputlen = 22. append wa_fcat to t_fcat. ENDFORM. " FLDCAT_SALESHEADER FORM DISPLAY_SALESHEADERDATA . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = sy-repid I_GRID_TITLE = 'SALES DOCUMENTS HEADER DATA' IT_FIELDCAT = t_fcat IT_EVENTS = t_events TABLES T_OUTTAB = t_vbak. ENDFORM. " DISPLAY_SALESHEADERDATA FORM PREPAREEVENTS . clear wa_events. wa_events-name = 'USER_COMMAND'. "std.event wa_events-form = 'SALESITEMS'. "user-defined subroutine where event business logic is implemented append wa_events to t_events. ENDFORM. " PREPAREEVENTS *form salesitems. "leads to runtime error as event parameters are not received * message 'salesitems' type 'I'. *endform. form salesitems using ucomm type sy-ucomm sel type slis_selfield. if sel-fieldname = 'VBELN'. clear wa_vbak. read table t_vbak into wa_vbak index sel-tabindex TRANSPORTING vbeln. if sy-subrc eq 0. perform get_salesitemsdata. if t_vbap is not INITIAL. perform fldcat_salesitems. perform reg_events. perform display_salesitemsdata. else. message 'No Sales items' type 'I'. endif. endif.
FORM GET_SALESITEMSDATA . select vbeln posnr matnr netwr from vbap into table t_vbap where vbeln = wa_vbak-vbeln. ENDFORM. " GET_SALESITEMSDATA FORM FLDCAT_SALESITEMS . refresh t_fcat. clear wa_fcat. wa_fcat-fieldname = 'VBELN'. wa_fcat-col_pos = 1. wa_fcat-seltext_m = 'Sales Doc No'. append wa_fcat to t_fcat. clear wa_fcat. wa_fcat-fieldname = 'POSNR'. wa_fcat-col_pos = 2. wa_fcat-seltext_m = 'Item No'. wa_fcat-outputlen = 12. append wa_fcat to t_fcat. clear wa_fcat. wa_fcat-fieldname = 'MATNR'. wa_fcat-col_pos = 3. wa_fcat-seltext_m = 'Material No'. wa_fcat-outputlen = 12. append wa_fcat to t_fcat. clear wa_fcat. wa_fcat-fieldname = 'NETWR'. wa_fcat-col_pos = 4. wa_fcat-seltext_m = 'Net Value'. wa_fcat-outputlen = 12. append wa_fcat to t_fcat. ENDFORM. FORM DISPLAY_SALESITEMSDATA . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = sy-repid I_GRID_TITLE = 'SALES ITEMS DATA' IT_FIELDCAT = t_fcat IT_EVENTS = t_events TABLES T_OUTTAB = t_vbap. ENDFORM. " DISPLAY_SALESITEMSDATA FORM REG_EVENTS . refresh t_events. clear wa_events. wa_events-name = 'TOP_OF_PAGE'. wa_events-form = 'TOPOFPAGEHEADING'. append wa_events to t_events. clear wa_events. wa_events-name = 'USER_COMMAND'. wa_events-form = 'MATERIALDATA'. append wa_events to t_events. ENDFORM. " REG_EVENTS form topofpageheading. data : t_header type SLIS_T_LISTHEADER, wa_header like line of t_header. clear wa_header. wa_header-typ = 'H'. wa_header-key = 'SAP Training'. wa_header-info = 'GENSOFT TECHNOLOGIES'. append wa_header to t_header. clear wa_header. wa_header-typ = 'S'. wa_header-key = 'OOPS ABAP Training'. wa_header-info = 'SAP Street, Ameerpet'. append wa_header to t_header. clear wa_header. wa_header-typ = 'A'. wa_header-key = 'ALV Reporting'. wa_header-info = 'Hyderabad,INDIA'. append wa_header to t_header. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING IT_LIST_COMMENTARY = t_header I_LOGO = 'ZBUTTERFLY'. endform. form materialdata using ucomm type sy-ucomm sel type slis_selfield. if sel-fieldname = 'MATNR'. clear wa_vbap. read table t_vbap into wa_vbap index sel-tabindex TRANSPORTING matnr. if sy-subrc eq 0. perform material_plant_storage_data. endif. else. message 'Please double click on material' type 'I'. endif. endform. FORM MATERIAL_PLANT_STORAGE_DATA . * initialize ALV Blocked List (one time job) CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT' EXPORTING I_CALLBACK_PROGRAM = sy-repid. * get data for block 1 (material plant data) perform get_materialplantdata. if t_marc is not INITIAL. * fieldcatalog for block 1 fields perform fldcat_materialplant. * layout for block 1 perform layo_materialplant. * events for block 1 refresh t_events. * append block1 perform append_block1. endif. * get data for block 2 (material storage data) perform get_materialstoragedata. if t_mard is not initial. * fieldcatalog for block 2 fields perform fldcat_materialstorage. * layout for block 2(set any fields if required) * events for block 2 (prepare events if required) * append block 2 perform append_block2. endif. * display the ALV blocked list (one time job) CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'. ENDFORM. " MATERIAL_PLANT_STORAGE_DATA FORM GET_MATERIALPLANTDATA . select matnr werks ekgrp from marc into table t_marc where matnr = wa_vbap-matnr. ENDFORM. " GET_MATERIALPLANTDATA FORM FLDCAT_MATERIALPLANT . refresh t_fcat. clear wa_fcat. wa_fcat-fieldname = 'MATNR'. wa_fcat-col_pos = 1. wa_fcat-seltext_m = 'Material No'. append wa_fcat to t_fcat. clear wa_fcat. wa_fcat-fieldname = 'WERKS'. wa_fcat-col_pos = 2. wa_fcat-seltext_m = 'Plant'. append wa_fcat to t_fcat. clear wa_fcat. wa_fcat-fieldname = 'EKGRP'. wa_fcat-col_pos = 3. wa_fcat-seltext_m = 'Purchasing Group'. wa_fcat-outputlen = 15. append wa_fcat to t_fcat. ENDFORM. " FLDCAT_MATERIALPLANT FORM LAYO_MATERIALPLANT . clear wa_layo. wa_layo-zebra = 'X'. ENDFORM. " LAYO_MATERIALPLANT FORM APPEND_BLOCK1 . CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' EXPORTING IS_LAYOUT = wa_layo IT_FIELDCAT = t_fcat I_TABNAME = 'T_MARC' IT_EVENTS = t_events TABLES T_OUTTAB = t_marc. ENDFORM. " APPEND_BLOCK1 FORM GET_MATERIALSTORAGEDATA . select matnr werks lgort from mard into table t_mard where matnr = wa_vbap-matnr. ENDFORM. " GET_MATERIALSTORAGEDATA FORM FLDCAT_MATERIALSTORAGE . refresh t_fcat. clear wa_fcat. wa_fcat-fieldname = 'MATNR'. wa_fcat-col_pos = 1. wa_fcat-seltext_m = 'Material No'. append wa_fcat to t_fcat. clear wa_fcat. wa_fcat-fieldname = 'WERKS'. wa_fcat-col_pos = 2. wa_fcat-seltext_m = 'Plant'. append wa_fcat to t_fcat. clear wa_fcat. wa_fcat-fieldname = 'LGORT'. wa_fcat-col_pos = 3. wa_fcat-seltext_m = 'Storage Location'. wa_fcat-outputlen = 15. append wa_fcat to t_fcat. ENDFORM. " FLDCAT_MATERIALSTORAGE FORM APPEND_BLOCK2 . CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND' EXPORTING IS_LAYOUT = wa_layo IT_FIELDCAT = t_fcat I_TABNAME = 'T_MARD' IT_EVENTS = t_events TABLES T_OUTTAB = t_mard. ENDFORM.