REPORT ZTUFI091

.

*&---------------------------------------------------------------------*
*& Report ZDEMO_ALVGRID

*

*&

*

*&---------------------------------------------------------------------*
*&

*

*& Example of a simple ALV Grid Report

*

*& ...................................

*

*&

*

*& The basic requirement for this demo is to display a number of
*& fields from the EKKO table.

*

*&---------------------------------------------------------------------*
*REPORT zdemo_alvgrid

TABLES:

.

ekko.

type-pools: slis.
*Data Declaration
*---------------TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,

"ALV Declarations

*

perform build_fieldcatalog. gt_events type slis_t_event.meins TYPE ekpo-meins. gd_repid like sy-repid. gd_tab_group type slis_t_sp_group_alv. netpr TYPE ekpo-netpr. perform data_retrieval. perform build_events. peinh TYPE ekpo-peinh. START-OF-SELECTION. ************************************************************************ *Start-of-selection. *ALV data declarations data: fieldcatalog type slis_t_fieldcat_alv with header line. END OF t_ekko. perform build_print_params. . gd_prntparams type slis_print_alv. perform build_layout. wa_ekko TYPE t_ekko. gd_layout type slis_layout_alv. DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0.

When using some of functionality available via ALV. *&---------------------------------------------------------------------* *& Form BUILD_FIELDCATALOG *&---------------------------------------------------------------------* * Build Fieldcatalog for ALV Report *----------------------------------------------------------------------* form build_fieldcatalog. such as * total. * For the purpose of this example i will build the fieldcatalog manualy * by populating the internal table fields individually and then * appending the rows. You may need to provide more information than if you were * simply displaying the result * * I. * There are a number of ways to create a fieldcat. fieldcatalog-col_pos = 0. you need to ensure that all fields required are * populated. This method can be the most time consuming but can * also allow you more control of the final product. * Beware though. . Field type may be required in-order for the 'TOTAL' function to work.perform display_alv_report.e. fieldcatalog-seltext_m = 'Purchase Order'. fieldcatalog-fieldname = 'EBELN'.

append fieldcatalog to fieldcatalog. fieldcatalog-seltext_m = 'Item change date'. append fieldcatalog to fieldcatalog. clear fieldcatalog. . * fieldcatalog-do_sum = 'X'. clear fieldcatalog. fieldcatalog-seltext_m = 'Status'.fieldcatalog-outputlen = 10. fieldcatalog-key = 'X'. * fieldcatalog-no_zero = 'X'. append fieldcatalog to fieldcatalog. append fieldcatalog to fieldcatalog. clear fieldcatalog. fieldcatalog-seltext_m = 'PO Item'. fieldcatalog-fieldname = 'EBELP'. fieldcatalog-col_pos = 2. fieldcatalog-col_pos = 1. fieldcatalog-col_pos = 3. fieldcatalog-emphasize = 'X'. fieldcatalog-fieldname = 'STATU'. fieldcatalog-fieldname = 'AEDAT'. clear fieldcatalog.

fieldcatalog-col_pos = 7. fieldcatalog-col_pos = 6. fieldcatalog-fieldname = 'NETPR'. fieldcatalog-fieldname = 'MEINS'. fieldcatalog-seltext_m = 'Material Number'. clear fieldcatalog. append fieldcatalog to fieldcatalog. fieldcatalog-outputlen = 15.fieldcatalog-fieldname = 'MATNR'. append fieldcatalog to fieldcatalog. fieldcatalog-fieldname = 'MENGE'. fieldcatalog-seltext_m = 'Net Price'. append fieldcatalog to fieldcatalog. fieldcatalog-seltext_m = 'Order Unit'. clear fieldcatalog. clear fieldcatalog. append fieldcatalog to fieldcatalog. . clear fieldcatalog. fieldcatalog-col_pos = 5. fieldcatalog-col_pos = 4. fieldcatalog-seltext_m = 'PO quantity'. fieldcatalog-datatype = 'CURR'.

"Sets fcode for when double * "click(press f2) * gd_layout-zebra = 'X'. fieldcatalog-seltext_m = 'Price Unit'. gd_layout-no_input = 'X'. * gd_layout-header_text endform.fieldcatalog-fieldname = 'PEINH'. " BUILD_FIELDCATALOG *&---------------------------------------------------------------------* *& Form BUILD_LAYOUT *&---------------------------------------------------------------------* * Build layout for ALV grid report *----------------------------------------------------------------------* form build_layout. gd_layout-colwidth_optimize = 'X'. * gd_layout-f2code = 'DISP'. * gd_layout-group_change_edit = 'X'. endform. = 'X'. = 'helllllo'. fieldcatalog-col_pos = 8. clear fieldcatalog. " BUILD_LAYOUT . gd_layout-totals_text * gd_layout-totals_only = 'Totals'(201). append fieldcatalog to fieldcatalog.

. call function 'REUSE_ALV_GRID_DISPLAY' exporting i_callback_program = gd_repid i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM i_callback_user_command = 'USER_COMMAND' * * i_grid_title is_layout = gd_layout it_fieldcat = fieldcatalog[] it_special_groups it_events * = outtext = gd_tabgroup = gt_events is_print = gd_prntparams i_save = 'X' is_variant = z_template tables t_outtab = it_ekko exceptions program_error others if sy-subrc <> 0. gd_repid = sy-repid.*&---------------------------------------------------------------------* *& Form DISPLAY_ALV_REPORT *&---------------------------------------------------------------------* * Display report using ALV grid *----------------------------------------------------------------------* form display_alv_report. =1 = 2.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. " DATA_RETRIEVAL *-------------------------------------------------------------------* * Form TOP-OF-PAGE * *-------------------------------------------------------------------* * ALV Report Header *-------------------------------------------------------------------* Form top-of-page. " DISPLAY_ALV_REPORT *&---------------------------------------------------------------------* *& Form DATA_RETRIEVAL *&---------------------------------------------------------------------* * Retrieve data form EKPO table and populate itab it_ekko *----------------------------------------------------------------------* form data_retrieval. * . endform. select ebeln ebelp statu aedat matnr menge meins netpr peinh up to 10 rows from ekpo into table it_ekko. endform. endif.

ld_linesc(10) type c. * Title wa_header-typ = 'H'.' sy-datum+4(2) '. ld_lines type i. clear wa_header. . of Records Selected describe table it_ekko lines ld_lines.' sy-datum(4) INTO wa_header-info.*ALV Header declarations data: t_header type slis_t_listheader. * Date wa_header-typ = 'S'. "todays date append wa_header to t_header. * Total No. wa_header type slis_listheader. clear: wa_header. append wa_header to t_header. CONCATENATE sy-datum+6(2) '. ld_linesc = ld_lines. wa_header-info = 'EKKO Table Report'. wa_header-key = 'Date: '. t_line like wa_header-info.

WHEN '&IC1'. wa_header-typ = 'A'. wa_header-info = t_line. . *------------------------------------------------------------------* * FORM USER_COMMAND * *------------------------------------------------------------------* * --> R_UCOMM * * --> RS_SELFIELD * *------------------------------------------------------------------* FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. t_line.concatenate 'Total No. of Records Selected: ' ld_linesc into t_line separated by space. append wa_header to t_header. clear: wa_header. * Check function code CASE r_ucomm. * i_logo = 'Z_LOGO'. call function 'REUSE_ALV_COMMENTARY_WRITE' exporting it_list_commentary = t_header. endform.

using index of row user clicked on READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex. and skip initial data entry screen CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN. call function 'REUSE_ALV_EVENTS_GET' exporting i_list_type = 0 importing et_events = gt_events[]. * Set parameter ID for transaction screen field SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln. ENDFORM. * Read data table. ENDCASE. data: ls_event type slis_alv_event.* Check field clicked on within ALVgrid report IF rs_selfield-fieldname = 'EBELN'. * Sxecute transaction ME23N. *&---------------------------------------------------------------------* *& Form BUILD_EVENTS *&---------------------------------------------------------------------* * Build events table *----------------------------------------------------------------------* form build_events. . ENDIF.

endif. endform. move 'END_OF_PAGE' to ls_event-form. gd_prntparams-reserve_lines = '3'. read table gt_events with key name = slis_ev_end_of_list into ls_event. move 'END_OF_LIST' to ls_event-form. endform. append ls_event to gt_events. if sy-subrc = 0. endif.read table gt_events with key name = slis_ev_end_of_page into ls_event. " BUILD_PRINT_PARAMS . append ls_event to gt_events. "Lines reserved for footer gd_prntparams-no_coverpage = 'X'. if sy-subrc = 0. " BUILD_EVENTS *&---------------------------------------------------------------------* *& Form BUILD_PRINT_PARAMS *&---------------------------------------------------------------------* * Setup print parameters *----------------------------------------------------------------------* form build_print_params.

ld_page(10) type c. endform. data: listwidth type i. data: listwidth type i. ld_pagepos(10) type c. skip. sy-pagno . write:/40 'Page:'. ld_page(10) type c. ld_pagepos(10) type c. *&---------------------------------------------------------------------* *& Form END_OF_LIST *&---------------------------------------------------------------------* form END_OF_LIST. write: sy-uline(50). . endform. sy-pagno .*&---------------------------------------------------------------------* *& Form END_OF_PAGE *&---------------------------------------------------------------------* form END_OF_PAGE. skip. write:/40 'Page:'.

Sign up to vote on this title
UsefulNot useful