Events in alv and their FM Please tell me what are the main events in alv and their FM and why we use these: 1. SLIS_PRINT_ALV. 2. SLIS_T_LISTHEADER. 3. SLIS_T_EVENT. 4. SLIS_T_SORTINFO_ALV. 5. SLIS_T_LAYOUT_ALV. 6. SLIS_T_FIELDCAT_ALV. and in classic reports what is the sequence of events: === Events are At selection-screen output. Initialization. At selection-screen on field At selection-screen on end of field At selection-screen on Radiobutton Group R1. (If you have any radio buttons) At selection-screen on block b1. (If you have any blocks) Start-of-selection. Get node. (if the data is retreived from a logical database) Get node late. (if the data is retreived from a logical database) Top-of-page. (if the write statement is in the end-of-selection event or we can say that before the first write statement) end-of-selection. and fuction modules are LISTHEADER - Is used to print the header information in the ALV List. Name, Date, Time, ALV Name and other details are called as Header information. EVENT - Basically this is the FM to handle Event's. When the user needs to do some event operation like when double clicking the a particular field we need to perform some operation. These events are captured by this FM. LAYOUT - This FM is used to define the layout of the List. There are many options available in this FM to define the Layout style. FIELDCAT - These are used to populate the List header. We can change them according to our req. These are some of the FM. I hope it is useful. 1 ALV Grid List with sub-totals REPORT z_demo_alv_sort. *---------------------------------------------------------------------* * This program lists orders (VBAK) with sort and sub-total for * * 'sold-to-party' (KUNNR) and 'Sales organization' (VKORG) * *---------------------------------------------------------------------* TABLES : vbak. TYPE-POOLS: slis. " ALV Global types SELECT-OPTIONS : s_vkorg FOR vbak-vkorg, s_kunnr FOR vbak-kunnr, s_vbeln FOR vbak-vbeln. " Sales organization " Sold-to party " Sales document SELECTION-SCREEN : SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY. SELECTION-SCREEN END OF LINE. DATA: BEGIN OF gt_vbak OCCURS 0, vkorg LIKE vbak-vkorg, kunnr LIKE vbak-kunnr, vbeln LIKE vbak-vbeln, netwr LIKE vbak-netwr, waerk LIKE vbak-waerk, END OF gt_vbak. " " " " " Sales organization Sold-to party Sales document Net Value of the Sales Order Document currency *---------------------------------------------------------------------* INITIALIZATION. v_1 = 'Maximum of records to read'. *---------------------------------------------------------------------* START-OF-SELECTION. PERFORM f_read_data. PERFORM f_display_data. *---------------------------------------------------------------------* * Form f_read_data *---------------------------------------------------------------------* FORM f_read_data. SELECT * INTO FROM UP WHERE AND AND CORRESPONDING FIELDS OF TABLE gt_vbak vbak TO p_max ROWS kunnr IN s_kunnr vbeln IN s_vbeln vkorg IN s_vkorg. ENDFORM. " F_READ_DATA *---------------------------------------------------------------------* 2 * Form f_display_data *---------------------------------------------------------------------* FORM f_display_data. DEFINE m_fieldcat. add 1 to ls_fieldcat-col_pos. ls_fieldcat-fieldname = &1. ls_fieldcat-ref_tabname = 'VBAK'. ls_fieldcat-do_sum = &2. ls_fieldcat-cfieldname = &3. append ls_fieldcat to lt_fieldcat. END-OF-DEFINITION. DEFINE m_sort. add 1 to ls_sort-spos. ls_sort-fieldname = &1. ls_sort-up = 'X'. ls_sort-subtot = &2. append ls_sort to lt_sort. END-OF-DEFINITION. DATA: ls_fieldcat lt_fieldcat lt_sort ls_sort ls_layout m_fieldcat m_fieldcat m_fieldcat m_fieldcat m_fieldcat TYPE TYPE TYPE TYPE TYPE 'VKORG' 'KUNNR' 'VBELN' 'NETWR' 'WAERK' slis_fieldcat_alv, slis_t_fieldcat_alv, slis_t_sortinfo_alv, slis_sortinfo_alv, slis_layout_alv. '' '' '' 'X' '' ''. ''. ''. 'WAERK'. ''. m_sort 'VKORG' 'X'. m_sort 'KUNNR' 'X'. m_sort 'VBELN' ''. " Sort by vkorg and subtotal " Sort by kunnr and subtotal " Sort by vbeln ls_layout-cell_merge = 'X'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING is_layout = ls_layout it_fieldcat = lt_fieldcat it_sort = lt_sort TABLES t_outtab = gt_vbak. ENDFORM. " F_DISPLAY_DATA ***************** END OF PROGRAM Z_DEMO_ALV_SORT ********************** 3 Auto Refresh ALV List REPORT z_alv_auto_refresh. *>********************************************************************* * This report displays User's info (SM04) using the FM : * * REUSE_ALV_LIST_DISPLAY * * The list is auto-refreshed (refresh time : 5 seconds) * *---------------------------------------------------------------------* TYPE-POOLS: slis. " ALV Global Types DATA : gt_user LIKE uinfo OCCURS 0 WITH HEADER LINE. " User info in SM04 *---------------------------------------------------------------------* START-OF-SELECTION. PERFORM f_read_data. PERFORM f_display_data. *---------------------------------------------------------------------* * Form F_LIRE_DATA *---------------------------------------------------------------------* FORM f_read_data. REFRESH gt_user. * Get User's info CALL FUNCTION 'THUSRINFO' TABLES usr_tabl = gt_user. * Wait in a task PERFORM f_call_rfc_wait. ENDFORM. " F_READ_DATA *---------------------------------------------------------------------* * Form F_DISPLAY_DATA *---------------------------------------------------------------------* FORM f_display_data. DEFINE m_sort. add 1 to ls_sort-spos. ls_sort-fieldname = &1. append ls_sort to lt_sort. END-OF-DEFINITION. DEFINE m_event_exit. clear ls_event_exit. ls_event_exit-ucomm = &1. ls_event_exit-after = 'X'. append ls_event_exit to lt_event_exit. END-OF-DEFINITION. DATA : ls_layout TYPE slis_layout_alv, 4 lt_sort ls_sort lt_event_exit ls_event_exit TYPE TYPE TYPE TYPE slis_t_sortinfo_alv, slis_sortinfo_alv, slis_t_event_exit, slis_event_exit. * Build Sort Table m_sort 'ZEIT'. * Build Event Exit Table m_event_exit '&NTE'. " Refresh ls_layout-zebra = 'X'. ls_layout-colwidth_optimize = 'X'. CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY' EXPORTING i_callback_program = sy-cprog i_callback_user_command = 'USER_COMMAND' is_layout = ls_layout i_structure_name = 'UINFO' it_sort = lt_sort it_event_exit = lt_event_exit TABLES t_outtab = gt_user. ENDFORM. " F_DISPLAY_DATA *---------------------------------------------------------------------* * FORM USER_COMMAND * *---------------------------------------------------------------------* FORM user_command USING i_ucomm TYPE syucomm is_selfield TYPE slis_selfield. "#EC CALLED CASE i_ucomm. WHEN '&NTE'. PERFORM f_read_data. is_selfield-refresh = 'X'. SET USER-COMMAND '&OPT'. ENDCASE. " Optimize columns width ENDFORM. " USER_COMMAND *---------------------------------------------------------------------* * Form F_CALL_RFC_WAIT *---------------------------------------------------------------------* FORM f_call_rfc_wait. DATA lv_mssg(80). "#EC NEEDED * Wait in a task CALL FUNCTION 'RFC_PING_AND_WAIT' STARTING NEW TASK '001' PERFORMING f_task_end ON END OF TASK EXPORTING seconds = 5 " Refresh time busy_waiting = space EXCEPTIONS RESOURCE_FAILURE = 1 communication_failure = 2 MESSAGE lv_mssg system_failure = 3 MESSAGE lv_mssg 5 OTHERS = 4. ENDFORM. " F_CALL_RFC_WAIT *---------------------------------------------------------------------* * Form F_TASK_END *---------------------------------------------------------------------* FORM f_task_end USING u_taskname. DATA lv_mssg(80). "#EC NEEDED * Receiving task results RECEIVE RESULTS FROM FUNCTION 'RFC_PING_AND_WAIT' EXCEPTIONS RESOURCE_FAILURE = 1 communication_failure = 2 MESSAGE lv_mssg system_failure = 3 MESSAGE lv_mssg OTHERS = 4. CHECK sy-subrc EQ 0. SET USER-COMMAND '&NTE'. " Refresh ENDFORM. " F_TASK_END *************** END OF PROGRAM Z_ALV_AUTO_REFRESH ********************* An ALV program that calls a ME21N via BDC Tips by: Sam Hearn Here is an ALV program that calls a ME21N via BDC. There is a LOT of code here you don't need (ex: the ability to run the ALV in background for huge amounts of data yet keep the ALV sort & mod abilities, the ability for different users to set their own sort combinations etc), but if you go to the CALL_CRYSTAL form, you will see I do another perform, called BUILD_BDC. This will show you how to use the CALL TRANSACTION, with a message table. I have a loop inside the message table after I return from ME21N to display an info message with the doc number. Using this loop, you can find your delivery numbers for your second BDC. *---------------------------------------------------------------------* * Author : Sam Hearn * * Date : 2004-08-31 * * * * Description : This program was copied from the ZMRP21 * * * *--------------------------------------------------[START OF REPORT]--* report zjmrp message-id zaberd no standard page heading line-count 65(1) line-size 162. 6 *-----------------------------------------------------------[TABLES]--* tables: mara, " General Material Data marc, " sscrfields. " Fields on selection screens type-pools: slis. *----------------------------------------------[INTERNAL WORK AREAS]--* *------------------------ for MD_ABBL_REPORTING ----------------------* data: i_crpes like crpes. data begin of i_mdps occurs 100. include structure mdps. data end of i_mdps. *--------------------------- SORTING TABLES --------------------------* data begin of i_sortord occurs 100. include structure zsort_list. data end of i_sortord. data: fname(5). data: f01(10),f02(10),f03(10),f04(10),f05(10),f06(10),f07(10),f08(10), f09(10),f10(10),f11(10),f12(10),f13(10),f14(10),f15(10),f16(10), f17(10),f18(10),f19(10),f20(10). field-symbols <fs1>. *-----------------------FILENAME DEFINITION---------------------------* data: sap1filp(132) value '/usr/sap/interfaces/reports/zmrp21_'. data: sap1fil(132), getfil(132). ranges s_wrkst ranges s_groes for mara-wrkst. for mara-groes. data: begin of disp_tab occurs 0, ckbox(1) type c, matkl like mara-matkl, matnr like mara-matnr, maktx like makt-maktx, bismt like mara-bismt, wrkst like mara-wrkst, groes like mara-groes, werks like marc-werks, dispo like marc-dispo, bstmi like marc-bstmi, lbkum like mbew-lbkum, "Internal table for ALV data " Selection Box (input) " Material Group " Material Number " Description " Old material " Basic material " Size/dimension " Plant " MRP controller " Min Run Length " On Hand 7 eisbe like idprq like deprq like reqrq like storq like convert like deldat like end of disp_tab. marc-eisbe, mdps-mng01, mdps-mng01, mdps-mng01, mdps-mng01, mdps-mng01, sy-datum, " " " " " " " Safety stock Independant Req Dependant Req Requisitions STO's Qty to convert (input) Delivery date (input) data: begin of i_fldw, "Storage area for DISP_TAB data ckbox(1) type c, " Selection Box (input) matkl like mara-matkl, " Material Group matnr like mara-matnr, " Material Number maktx like makt-maktx, " Description bismt like mara-bismt, " Old material wrkst like mara-wrkst, " Basic material groes like mara-groes, " Size/dimension werks like marc-werks, " Plant dispo like marc-dispo, " MRP controller bstmi like marc-bstmi, " Min Run Length lbkum like mbew-lbkum, " On Hand eisbe like marc-eisbe, " Safety stock idprq like mdps-mng01, " Independant Req deprq like mdps-mng01, " Dependant Req reqrq like mdps-mng01, " Requisitions storq like mdps-mng01, " STO's convert like mdps-mng01, " Qty to convert deldat like sy-datum, " Delivery date (input) end of i_fldw. * data: begin of i_fcc occurs 100, chkbox(1), " Checkbox matkl(10), " Material Group matnr(18), " Material Number maktx(40), " Description bismt(18), " Old material wrkst(48), " Basic material groes(32), " Size/dimension werks(04), " Plant dispo(03), " MRP controller bstmi(13), " Min Run Length lbkum(13), " On Hand eisbe(13), " Safety stock idprq(25), " Independant Req deprq(25), " Dependant Req reqrq(25), " Requisitions storq(25), " STO's convert(25), " Qty to convert deldat(10), " Delivery date end of i_fcc. data begin of bdcdata occurs 20. include structure bdcdata. data end of bdcdata. data begin of messtab occurs 10. 8 include structure bdcmsgcoll. data end of messtab. data: i_fieldcat_alv w_fieldcat_alv wa_repid w_variant wx_variant w_callback_ucomm w_variant_save(1) w_exit(1) w_layout lst_is_print lin type like type type type type type type type type type slis_t_fieldcat_alv, line of i_fieldcat_alv, sy-repid, disvariant, disvariant, slis_formname, c, c, slis_layout_alv, slis_print_alv, i. *********************************************************************** * *********************************************************************** * *********************************************************************** * selection-screen: begin of block main with frame title text-008. select-options: w_wrkst for mara-wrkst no intervals no-extension, w_groes for mara-groes no intervals no-extension, w_matnr for mara-matnr no intervals no-extension, w_matkl for mara-matkl no intervals no-extension, w_dispo for marc-dispo, w_date for sy-datum no intervals no-extension. parameter: p_modes type c default 'N' no-display. parameter: w_ast as checkbox default 'X'. selection-screen: selection-screen: selection-screen: parameters: selection-screen: selection-screen: begin of block immed with frame title text-001. begin of line. comment 1(29) text-002. "Output directly to printer? pa_print as checkbox. end of line. end of block immed. selection-screen: begin of block variant with frame title text-003. parameters: p_vari type slis_vari. selection-screen: end of block variant. selection-screen begin of block sub2 with frame title text-007. parameter: w_new radiobutton group rad1. parameter: w_fil radiobutton group rad1. parameter: w_save as checkbox. parameter: sapfil(132) type c default '001.dat' lower case obligatory. selection-screen end of block sub2. selection-screen function key 1. selection-screen function key 2. selection-screen: end of block main. *$*$------------------------------------------------------------------* *$*$ Initialization 9 *$*$------------------------------------------------------------------* initialization. perform init_variant. perform variant_default using p_vari. perform added_inits. *$*$------------------------------------------------------------------* *$*$ At Selection Screen *$*$------------------------------------------------------------------* at selection-screen. perform variant_fill. perform added_functions. *$*$------------------------------------------------------------------* *$*$ At Selection Screen Value Request *$*$------------------------------------------------------------------* at selection-screen on value-request for p_vari. perform variant_f4 using p_vari. *********************************************************************** * *********************************************************************** * *********************************************************************** * start-of-selection. perform perform perform perform perform get_data. fieldcat_build. layout_build. save_list_order. call_crystal. end-of-selection. *&--------------------------------------------------------------------* *& Form init_variant *&--------------------------------------------------------------------* form init_variant. clear: w_variant. wa_repid w_variant-report w_variant-username w_variant_save = = = = sy-repid. wa_repid. sy-uname. 'A'. "All types endform. *&--------------------------------------------------------------------* *& Form variant_default 10 *&--------------------------------------------------------------------* form variant_default using p_variant. wx_variant = w_variant. if not p_variant is initial. wx_variant-variant = p_variant. endif. call function 'LVC_VARIANT_DEFAULT_GET' exporting i_save = w_variant_save changing cs_variant = wx_variant exceptions wrong_input = 1 not_found = 2 program_error = 3 others = 4. case sy-subrc. when 0. p_variant = wx_variant-variant. when 2. clear: p_variant. endcase. endform. *&--------------------------------------------------------------------* *& Form variant_fill *&--------------------------------------------------------------------* form variant_fill. clear: w_variant. if p_vari is initial. w_variant-variant = 'STANDARD'. w_variant-report = wa_repid. else. w_variant-variant = p_vari. w_variant-report = wa_repid. call function 'LVC_VARIANT_EXISTENCE_CHECK' exporting i_save = w_variant_save changing cs_variant = w_variant exceptions others = 01. if sy-subrc ne 0. message i005. endif. endif. 11 endform. *&--------------------------------------------------------------------* *& Form variant_f4 *&--------------------------------------------------------------------* form variant_f4 using p_variant. call function 'LVC_VARIANT_F4' exporting is_variant = w_variant i_save = w_variant_save importing e_exit = w_exit es_variant = wx_variant exceptions not_found = 1 program_error = 2 others = 3. if sy-subrc <> 0. message i006. endif. if w_exit is initial. w_variant-variant = wx_variant-variant. p_variant = wx_variant-variant. endif. endform. *&--------------------------------------------------------------------* *& Form get_data *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* form get_data. concatenate sap1filp sapfil into sap1fil. if w_new = 'X'. clear disp_tab. select matkl matnr bismt wrkst groes into (disp_tab-matkl, disp_tab-matnr, disp_tab-bismt, disp_tab-wrkst, disp_tab-groes) from mara where matnr in w_matnr and matkl in w_matkl and groes in s_groes and wrkst in s_wrkst and mstae = ''. i_fldw = disp_tab. 12 select matnr werks dispo eisbe into (disp_tab-matnr, disp_tab-werks, disp_tab-dispo, disp_tab-eisbe) from marc where matnr = disp_tab-matnr and werks eq '7000' and dispo in w_dispo. select single lbkum into disp_tab-lbkum from where matnr = disp_tab-matnr and bwkey = disp_tab-werks. mbew refresh i_mdps. call function 'MD_ABBL_REPORTING' exporting ematnr = disp_tab-matnr ewerks = disp_tab-werks ecrpes = i_crpes tables mdpsx = i_mdps exceptions error_matmaster = 1 others = 2. if sy-subrc = 0. if w_date[] is initial. w_date-low = '99991231'. w_date-sign = 'I'. w_date-option = 'EQ'. append w_date. endif. loop at i_mdps. case i_mdps-delkz. when 'U1'. if i_mdps-dat00 le w_date-low. disp_tab-deprq = disp_tab-deprq endif. when 'VC'. if i_mdps-dat00 le w_date-low. disp_tab-idprq = disp_tab-idprq endif. when 'BA'. disp_tab-reqrq = disp_tab-reqrq + when 'BE'. disp_tab-storq = disp_tab-storq + endcase. endloop. endif. + i_mdps-mng01. + i_mdps-mng01. i_mdps-mng01. i_mdps-mng01. select single bstmi into disp_tab-bstmi from where matnr = disp_tab-matnr and werks = disp_tab-werks. marc select single maktx into disp_tab-maktx from where matnr = disp_tab-matnr and spras = 'E'. makt 13 if disp_tab-lbkum > disp_tab-idprq > disp_tab-deprq > disp_tab-reqrq > disp_tab-storq > append disp_tab. endif. disp_tab = i_fldw. 0 or 0 or 0 or 0 or 0. endselect. endselect. else. * Open the datainfil. open dataset sap1fil in text mode. if sy-subrc <> 0. write:/ 'Upload File Not Found'. exit. endif. refresh i_fcc. * Loop At data set. do. read dataset sap1fil into i_fcc. if sy-subrc <> 0. exit. endif. move-corresponding i_fcc to disp_tab. append disp_tab. enddo. * Close Dataset. close dataset sap1fil. endif. endform. " get_data *&--------------------------------------------------------------------* *& Form fieldcat_build *&--------------------------------------------------------------------* * Build up the headers for the fields in the Grid Display, and set * the key-fields for freeze while scrolling. *********************************************************************** * form fieldcat_build. call function 'REUSE_ALV_FIELDCATALOG_MERGE' exporting i_program_name = wa_repid i_internal_tabname = 'DISP_TAB' i_inclname = wa_repid changing ct_fieldcat = i_fieldcat_alv. 14 loop at i_fieldcat_alv into w_fieldcat_alv. case w_fieldcat_alv-fieldname. when 'CKBOX'. w_fieldcat_alv-seltext_s = text-011. w_fieldcat_alv-seltext_m = text-011. w_fieldcat_alv-seltext_l = text-011. w_fieldcat_alv-reptext_ddic = text-011. w_fieldcat_alv-key = 'X'. w_fieldcat_alv-edit = 'X'. w_fieldcat_alv-checkbox = 'X'. when 'MATKL'. w_fieldcat_alv-key = 'X'. when 'MATNR'. w_fieldcat_alv-key = 'X'. w_fieldcat_alv-hotspot = 'X'. when 'WERKS'. w_fieldcat_alv-key = ''. when 'IDPRQ'. w_fieldcat_alv-seltext_s = text-009. w_fieldcat_alv-seltext_m = text-009. w_fieldcat_alv-seltext_l = text-009. w_fieldcat_alv-reptext_ddic = text-009. w_fieldcat_alv-key = ''. when 'DEPRQ'. w_fieldcat_alv-seltext_s = text-004. w_fieldcat_alv-seltext_m = text-004. w_fieldcat_alv-seltext_l = text-004. w_fieldcat_alv-reptext_ddic = text-004. w_fieldcat_alv-key = ''. when 'REQRQ'. w_fieldcat_alv-seltext_s = text-005. w_fieldcat_alv-seltext_m = text-005. w_fieldcat_alv-seltext_l = text-005. w_fieldcat_alv-reptext_ddic = text-005. w_fieldcat_alv-key = ''. when 'STORQ'. w_fieldcat_alv-seltext_s = text-006. w_fieldcat_alv-seltext_m = text-006. w_fieldcat_alv-seltext_l = text-006. w_fieldcat_alv-reptext_ddic = text-006. w_fieldcat_alv-key = ''. when 'CONVERT'. w_fieldcat_alv-seltext_s = text-010. w_fieldcat_alv-seltext_m = text-010. w_fieldcat_alv-seltext_l = text-010. w_fieldcat_alv-reptext_ddic = text-010. w_fieldcat_alv-key = ''. w_fieldcat_alv-edit = 'X'. when 'DELDAT'. w_fieldcat_alv-seltext_s = text-012. w_fieldcat_alv-seltext_m = text-012. w_fieldcat_alv-seltext_l = text-012. w_fieldcat_alv-reptext_ddic = text-012. w_fieldcat_alv-key = ''. w_fieldcat_alv-edit = 'X'. when others. 15 endcase. modify i_fieldcat_alv from w_fieldcat_alv. endloop. endform. *&--------------------------------------------------------------------* *& Form layout_build *&--------------------------------------------------------------------* form layout_build. w_layout-zebra w_layout-no_vline w_layout-colwidth_optimize w_layout-detail_popup w_layout-detail_initial_lines = = = = = 'X'. ''. 'X'. 'X'. 'X'. endform. *&--------------------------------------------------------------------*& Form call_crystal *&--------------------------------------------------------------------* text *---------------------------------------------------------------------form call_crystal. w_callback_ucomm = 'CALLBACK_UCOMM'. * If Batch write to list for spool output availability if sy-batch = 'X' or pa_print = 'X'. if pa_print = 'X'. lst_is_print-print endif. = 'X1'. call function 'REUSE_ALV_LIST_DISPLAY' exporting i_callback_program = wa_repid i_default = 'X' i_save = 'A' is_variant = w_variant is_layout = w_layout i_callback_user_command = w_callback_ucomm it_fieldcat = i_fieldcat_alv is_print = lst_is_print tables t_outtab = disp_tab. if sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif. else. call function 'REUSE_ALV_GRID_DISPLAY' exporting 16 i_background_id i_callback_program i_default i_save is_variant is_layout i_callback_user_command it_fieldcat tables t_outtab = = = = = = = = 'SIWB_WALLPAPER' wa_repid 'X' 'A' w_variant w_layout w_callback_ucomm i_fieldcat_alv = disp_tab. if sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. else. loop at disp_tab where ckbox = ' '. delete disp_tab. endloop. describe table disp_tab lines lin. if lin ne 0. perform build_bdc. endif. endif. endif. endform. " call_crystal *&--------------------------------------------------------------------* *& Form added_functions *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * --> p1 text * <-- p2 text *---------------------------------------------------------------------* form added_functions. refresh:s_wrkst, s_groes. loop at w_wrkst. if w_ast = 'X'. concatenate w_wrkst-low '*' into w_wrkst-low. w_wrkst-option = 'CP'. endif. move-corresponding w_wrkst to s_wrkst. translate s_wrkst-low to upper case. append s_wrkst. translate s_wrkst-low to lower case. append s_wrkst. endloop. loop at w_groes. if w_ast = 'X'. concatenate '*' w_groes-low '*' into w_groes-low. 17 w_groes-option = 'CP'. endif. move-corresponding w_groes to s_groes. translate s_groes-low to upper case. append s_groes. translate s_groes-low to lower case. append s_groes. endloop. * if sscrfields-ucomm = 'FC01'. call function 'Z_POPUP_TO_LIST_SORT_ORDER' exporting t_title = 'Setup Sorting Order' w_popup = 'X' tables sortlist = i_sortord. endif. if sscrfields-ucomm = 'FC02'. call function 'Z_POPUP_TO_LIST_FILES' exporting t_title = 'Basic Material Search Files' dir_name = '/usr/sap/interfaces/reports' file_mask = 'zmrp21_*' importing selfilename = getfil. if not getfil is initial. sapfil = getfil. endif. endif. endform. " added_functions *&--------------------------------------------------------------------* *& Form added_inits *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * --> p1 text * <-- p2 text *---------------------------------------------------------------------* form added_inits. move move 'Setup Sorting Order ' to sscrfields-functxt_01. 'Display Files on Server' to sscrfields-functxt_02. refresh i_sortord. 18 i_sortord-fieldname = 'matkl'. i_sortord-ddtext = 'Material Group'. append i_sortord. i_sortord-fieldname = 'matnr'. i_sortord-ddtext = 'Material Number'. append i_sortord. i_sortord-fieldname = 'maktx'. i_sortord-ddtext = 'Material Description'. append i_sortord. i_sortord-fieldname = 'bismt'. i_sortord-ddtext = 'Old material'. append i_sortord. i_sortord-fieldname = 'wrkst'. i_sortord-ddtext = 'Basic material'. append i_sortord. i_sortord-fieldname = 'groes'. i_sortord-ddtext = 'Size/dimension'. append i_sortord. i_sortord-fieldname = 'werks'. i_sortord-ddtext = 'Plant'. append i_sortord. i_sortord-fieldname = 'dispo'. i_sortord-ddtext = 'MRP controller'. append i_sortord. i_sortord-fieldname = 'bstmi'. i_sortord-ddtext = 'Min lot size'. append i_sortord. i_sortord-fieldname = 'lbkum'. i_sortord-ddtext = 'On Hand'. append i_sortord. i_sortord-fieldname = 'eisbe'. i_sortord-ddtext = 'Safety stock'. append i_sortord. i_sortord-fieldname = 'idprq'. i_sortord-ddtext = 'Independant Req'. append i_sortord. i_sortord-fieldname = 'deprq'. i_sortord-ddtext = 'Dependant Req'. append i_sortord. i_sortord-fieldname = 'reqrq'. i_sortord-ddtext = 'Requisitions'. append i_sortord. i_sortord-fieldname = 'storq'. 19 i_sortord-ddtext = 'STO''s'. append i_sortord. endform. " added_inits *&--------------------------------------------------------------------* *& Form save_list_order *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * --> p1 text * <-- p2 text *---------------------------------------------------------------------* form save_list_order. call function 'Z_POPUP_TO_LIST_SORT_ORDER' exporting t_title = 'Setup Sorting Order' w_popup = ' ' tables sortlist = i_sortord. loop at i_sortord. write sy-tabix to fname right-justified. translate fname using ' 0'. concatenate 'f' fname+2(2) into fname. assign (fname) to <fs1>. <fs1> = i_sortord-fieldname. translate <fs1> to upper case. endloop. sort disp_tab ascending by (f01) (f02) (f03) (f04) (f05) (f06) (f07) (f08) (f09) (f10) (f11) (f12) (f13) (f14) (f15) (f16) (f17) (f18) (f19) (f20). endform. " save_list_order *---------------------------------------------------------------------* * FORM user_command * *---------------------------------------------------------------------* form callback_ucomm using r_ucomm like sy-ucomm rs_selfield type slis_selfield. case r_ucomm. when '&IC1'. if rs_selfield-sel_tab_field = 'DISP_TAB-MATNR'. set parameter id 'MAT' field rs_selfield-value. set parameter id 'WRK' field '7000'. set parameter id 'BERID' field ' '. call transaction 'MD04'. endif. when others. endcase. endform. 20 *&--------------------------------------------------------------------* *& Form build_bdc *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* form build_bdc. data: lgpro like marc-lgpro, first(1) type c, wa_date like sy-datum. * PREPARE BDC refresh bdcdata. clear bdcdata. perform bdchead perform bdcitem perform bdcitem perform bdcitem using 'SAPLMEGUI' '0014'. using 'BDC_OKCODE' '=MEDOCTYPE'. using 'MEPO_TOPLINE-BSART' 'UB'. using 'MEPO_TOPLINE-BEDAT' sy-datum. * perform bdchead perform bdcitem perform bdcitem using 'SAPLMEGUI' '0014'. using 'BDC_OKCODE' '=MEV4000BUTTON'. using 'MEPO_TOPLINE-SUPERFIELD' '5200'. * perform bdchead perform bdcitem using 'SAPLMEGUI' '0014'. using 'BDC_OKCODE' '=TABHDT9'. * perform bdchead perform bdcitem perform bdcitem perform bdcitem perform bdcitem using 'SAPLMEGUI' '0014'. using 'BDC_OKCODE' '=MEV4001BUTTON'. using 'MEPO1222-EKORG' '7000'. using 'MEPO1222-EKGRP' 'J10'. using 'MEPO1222-BUKRS' 'ABFI'. * first = 'Y'. loop at disp_tab. clear lgpro. if not wa_date is initial and disp_tab-deldat is initial. disp_tab-deldat = wa_date. endif. 21 select single lgpro into lgpro from marc where matnr = disp_tab-matnr and werks = '7000'. * perform bdchead perform bdcitem perform bdcitem perform bdcitem perform bdcitem perform bdcitem perform bdcitem using 'SAPLMEGUI' '0014'. using 'BDC_OKCODE' '/00'. using 'MEPO1211-EMATN(01)' disp_tab-matnr. using 'MEPO1211-MENGE(01)' disp_tab-convert. using 'MEPO1211-EEIND(01)' disp_tab-deldat. using 'MEPO1211-NAME1(01)' '7000'. using 'MEPO1211-LGOBE(01)' lgpro. * if first = 'Y'. first = 'N'. wa_date = disp_tab-deldat. perform bdchead using 'SAPLMEGUI' '0014'. perform bdcitem using 'BDC_OKCODE' '=MEPO1211EDITFILTER'. * perform bdchead perform bdcitem using 'SAPLSKBH' '1500'. using 'BDC_OKCODE' '=DTC_WLSE'. * perform bdchead perform bdcitem using 'SAPLSKBH' '1500'. using 'BDC_OKCODE' '=DTC_CONT'. * perform bdchead perform bdcitem using 'SAPLSSEL' '1104'. using 'BDC_OKCODE' '=%00411050000197408'. * perform bdchead perform bdcitem using 'SAPLALDB' '3000'. using 'BDC_OKCODE' '=NOINT'. * perform bdchead perform bdcitem perform bdcitem perform bdcitem using 'SAPLALDB' '3000'. using 'BDC_OKCODE' '=ACPT'. using 'RSCSEL-ILOW_E(01)' '1'. using 'RSCSEL-IHIGH_E(01)' '99999'. * 22 perform bdchead perform bdcitem using 'SAPLSSEL' '1104'. using 'BDC_OKCODE' '=CRET'. endif. * endloop. * perform bdchead perform bdcitem using 'SAPLMEGUI' '0014'. using 'BDC_OKCODE' '=MESAVE'. * call transaction 'ME21N' using bdcdata mode p_modes update 'S' messages into messtab. loop at messtab. if messtab-msgv2+0(4) = '4500'. message i001 with messtab-msgv1 messtab-msgv2 'created'. endif. endloop. endform. " build_bdc *&--------------------------------------------------------------------* *& Form bdchead *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->P_1713 text * -->P_1714 text *---------------------------------------------------------------------* form bdchead using p_program p_dynpro. clear bdcdata. move : p_program to bdcdata-program, p_dynpro to bdcdata-dynpro, 'X' to bdcdata-dynbegin. append bdcdata. endform. " bdchead *&--------------------------------------------------------------------* *& Form bdcitem *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* * -->P_1718 text * -->P_1719 text 23 *---------------------------------------------------------------------* form bdcitem using p_fnam p_fval. clear bdcdata. move p_fnam to bdcdata-fnam. write p_fval to bdcdata-fval left-justified. append bdcdata. endform. " bdcitem Add Button to ALV Toolbar with REUSE_ALV_LIST_DISPLAY How to add button to ALV toolbar using REUSE_ALV_LIST_DISPLAY? In the program which calls ALV using REUSE_ALV_LIST_DISPLAY, I have to add a new button. I saw the demo program BCALV_GRID_08, which is written using ABAP-Controls. In that example, the button is added using TOOLBAR event of cl_gui_alv_grid. Could you help me to implement the same logic using REUSE_ALV_LIST_DISPLAY parameters. you should copy the 'STANDARD' GUI status from program SAPLKKBL using transaction SE90 -->Programming SubObjects--> Gui Status. Execute this transaction to get to next screen. select status using checkbox. click on GUI Status --> Copy. Enter your Z program name and the name you what for this status - you can keep it as 'STANDARD' to be simple. Then you can edit the new status to add or delete buttons. This will also bring in the standard SAP ALV functionality such as sorting/subtotaling etc... When you call 'REUSE_ALV_GRID_DISPLAY' make sure you pass it the new status name. an example of one of mine: call function 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = 'ZSDBOLST_REPORT' i_callback_pf_status_set = 'STANDARD' <--------i_callback_user_command = 'USER_COMMAND' i_structure_name = 'I_BOLACT' 24 i_grid_title = 'BOL Action Report'(031) is_layout = gs_layout it_fieldcat = gt_fieldcat[] i_save = 'A' is_variant = v_variant TABLES t_outtab = i_bolact EXCEPTIONS program_error = 1 others = 2. I just tried the same procedure ,but my entire application toolbar disappeared and a lock icon appears next to the application toolbar in my copied pf-status. Could you advice what might have gone wrong ? As identified with the FM's help you can do the following. 1). Using SE80 (I think) you can copy a GUI status from one program to another. It mentions which one in the FM's help. 2). Create a form named like so: Code: ***************************************************************** * Form Set_pf_status * Notes: Called by FM REUSE_ALV_GRID_DISPLAY ***************************************************************** FORM set_pf_status USING rt_extab TYPE slis_t_extab. SET PF-STATUS 'ZSTANDARD'. ENDFORM. "Set_pf_status In the above case the GUI status copied was named ZSTANDARD and adjusted accordingly, adding and removing the desired buttons. A button was added called '%DELETE'. 3). Create the following report: Code: ***************************************************************** * Form User_command * Notes: Called by FM REUSE_ALV_GRID_DISPLAY * Detects whether the icon/button for * 'Return Tag Deletion' has been pressed. If it has then * detect whether any rows have been highlighted and then * set the delete flag. 25 ***************************************************************** FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. DATA: li_count TYPE I. IF r_ucomm EQ '%DELETE'. LOOP AT %g00 WHERE mark EQ 'X'. ADD 1 TO li_count. ENDLOOP. IF li_count GT 0. gc_delete_flag = 'X'. r_ucomm = '&F03'. "Back arraow ELSE. MESSAGE W000 WITH 'Please highlight the rows to be deleted!'. ENDIF. ENDIF. ENDFORM. "User_command As I've added an extra button to indicate which records should be deleted I need to identify a form to be called to process when this button is chosen. Then when you call the ALV function you to specify the following extra details: Code: call function 'REUSE_ALV_GRID_DISPLAY' exporting i_callback_program = gc_repid I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS' I_CALLBACK_USER_COMMAND = 'USER_COMMAND' i_grid_title = lc_grid_title is_layout = lc_layout it_fieldcat = gt_fieldcat it_sort = sort i_save = l_save is_reprep_id = l_bbs_id is_variant = l_variant tables t_outtab = %g00 exceptions program_error =1 others = 2. The parameters in capitals are the extra ones that need to be added. That should be it! Make you sure that you also read the help against the ALV function Color a Column Value in ALV Report 26 Example of how to color a column value in ALV Report. REPORT z_colour NO STANDARD PAGE HEADING . TABLES :pa0002. TYPE-POOLS: slis. "ALV Declarations DATA : BEGIN OF it OCCURS 0, pernr LIKE pa0001-pernr, rufnm LIKE pa0002-rufnm, cell_colour TYPE lvc_t_scol, "Cell colour END OF it. SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME. SELECT-OPTIONS :s_pnum FOR pa0002-pernr . SELECTION-SCREEN END OF BLOCK main. *ALV data declarations DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE, gd_layout TYPE slis_layout_alv, gd_repid LIKE sy-repid, gt_sort TYPE slis_t_sortinfo_alv. * To colour a cell. DATA ls_cellcolour TYPE lvc_s_scol. START-OF-SELECTION. PERFORM data_retrieval. PERFORM build_fieldcatalog. PERFORM build_layout. PERFORM display_alv_report. END-OF-SELECTION. FREE : it. FORM build_fieldcatalog . fieldcatalog-fieldname = 'PERNR'. fieldcatalog-seltext_m = 'Personnel No.'. fieldcatalog-col_pos = 0. APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. fieldcatalog-fieldname = 'RUFNM'. fieldcatalog-seltext_m = 'Name'. fieldcatalog-col_pos = 0. 27 APPEND fieldcatalog TO fieldcatalog. CLEAR fieldcatalog. ENDFORM. FORM build_layout . gd_layout-no_input = 'X'. gd_layout-colwidth_optimize = 'X'. gd_layout-totals_text = 'Totals'(256). gd_layout-coltab_fieldname = 'CELL_COLOUR'. ENDFORM. " build_layout FORM display_alv_report . gd_repid = sy-repid. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_callback_program = gd_repid is_layout = gd_layout it_fieldcat = fieldcatalog[] i_save = 'A' TABLES t_outtab = it EXCEPTIONS program_error =1 OTHERS = 2. IF sy-subrc <> 0. ENDIF. ENDFORM. " display_alv_report FORM data_retrieval . select pernr rufnm from pa0002 into corresponding fields of table it where pernr in s_pnum. LOOP AT it. *Now based on the value of the field pernr we can change the cell colour of the field rufnm or pernr. IF it-pernr eq '10001' . ls_cellcolour-fname = 'RUFNM'. ls_cellcolour-color-col = '5'. ls_cellcolour-color-int = '1'. ls_cellcolour-color-inv = '0'. APPEND ls_cellcolour TO it-cell_colour. IF sy-subrc EQ 0. MODIFY it. ENDIF. ENDIF. 28 ENDLOOP. ENDFORM. To Call Transaction In ALV In my report, I am using ALV grid display to display purchase order number, material docu. number. If I click on purchasing docu number it has to call transaction ME23N for the purchase order number that I have clicked and if I click material document number it has to call trainsaction MIGO for the corresponding material document number. How can I do it in ALV? Check out the following code that may help: *&---------------------------------------------------------------------* *& Report Z_TEST001 *& *&---------------------------------------------------------------------* REPORT Z_TEST001. TYPE-POOLS: slis. tables: rseg. DATA: begin of TAB_ARSEG occurs 0. INCLUDE STRUCTURE RSEG. DATA: END OF TAB_ARSEG. DATA: T_FIELDCAT TYPE slis_t_fieldcat_alv. DATA: c_user_command TYPE slis_formname VALUE 'USER_COMMAND'. START-OF-SELECTION. ********* <<< YOUR CODE >>> *********************** select * from rseg into table tab_arseg where BELNR = '5300000022'. END-OF-SELECTION. perform build_fieldcat. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING i_buffer_active = space i_callback_program = sy-repid I_CALLBACK_USER_COMMAND = c_user_command * I_STRUCTURE_NAME = * IS_LAYOUT = IT_FIELDCAT = T_FIELDCAT[] 29 TABLES T_OUTTAB = TAB_ARSEG EXCEPTIONS PROGRAM_ERROR =1 OTHERS = 2. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. **&--------------------------------------------------------------------* **& Form USER_COMMAND **&--------------------------------------------------------------------* FORM USER_COMMAND USING F_UCOMM LIKE SY-UCOMM I_SELFIELD TYPE SLIS_SELFIELD. DATA: F_SUBRC LIKE SY-SUBRC, s_arseg like tab_arseg. READ TABLE tab_arseg INDEX i_selfield-tabindex INTO s_arseg. CASE F_UCOMM. WHEN '&IC1'. CASE i_SELFIELD-SEL_TAB_FIELD. WHEN 'TAB_ARSEG-BELNR'. CHECK NOT S_ARSEG-BELNR IS INITIAL. SET PARAMETER ID 'RBN' FIELD S_ARSEG-BELNR. SET PARAMETER ID 'GJR' FIELD S_ARSEG-GJAHR. CALL TRANSACTION 'MIR4' AND SKIP FIRST SCREEN. ENDCASE. ENDCASE. ENDFORM. **&--------------------------------------------------------------------* **& Form build_fieldcat **&--------------------------------------------------------------------* FORM build_fieldcat . DATA: FIELDCAT TYPE SLIS_FIELDCAT_ALV. CLEAR FIELDCAT. FIELDCAT-FIELDNAME = 'BELNR'. FIELDCAT-TABNAME = 'TAB_ARSEG'. FIELDCAT-REF_TABNAME = 'RSEG'. 30 FIELDCAT-REF_FIELDNAME = 'BELNR'. fieldcat-hotspot = 'X'. FIELDCAT-COL_POS = 1. APPEND FIELDCAT TO t_fieldcat. CLEAR FIELDCAT. FIELDCAT-FIELDNAME = 'GJAHR'. FIELDCAT-TABNAME = 'TAB_ARSEG'. FIELDCAT-REF_TABNAME = 'RSEG'. FIELDCAT-REF_FIELDNAME = 'GJAHR'. FIELDCAT-COL_POS = 2. APPEND FIELDCAT TO t_fieldcat. ENDFORM. " build_fieldcat 31