TYPE-POOLS: slis. "ALV Declarations *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,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
cellcolor TYPE lvc_t_scol,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid,
gt_events TYPE slis_t_event,
gd_prntparams TYPE slis_print_alv.
*&---------------------------------------------------------------------* *& Form BUILD_FIELDCATALOG *&---------------------------------------------------------------------* * Build Fieldcatalog for ALV Report *----------------------------------------------------------------------* FORM build_fieldcatalog.
* There are a number of ways to create a fieldcat. * For the purpose of this example i will build the fieldcatalog manualy * by populating the internal table fields individually and then * appending the rows. This method can be the most time consuming but can * also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are * populated. When using some of functionality available via ALV, such as * total. You may need to provide more information than if you were * simply displaying the result * I.e. Field type may be required in-order for * the 'TOTAL' function to work.
*&---------------------------------------------------------------------* *& Form DISPLAY_ALV_REPORT *&---------------------------------------------------------------------* * Display report using ALV grid *----------------------------------------------------------------------* FORM display_alv_report.
gd_repid = sy-repid. 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 = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[] * it_special_groups = gd_tabgroup * it_events = gt_events * is_print = gd_prntparams
i_save = 'X' * is_variant = z_template TABLES
t_outtab = it_ekko 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. ENDFORM. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------* *& Form DATA_RETRIEVAL *&---------------------------------------------------------------------* * Retrieve data form EKPO table and populate itab it_ekko *----------------------------------------------------------------------* FORM data_retrieval. SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh UP TO 10 ROWS FROM ekpo INTO CORRESPONDING FIELDS OF TABLE it_ekko. ENDFORM. " DATA_RETRIEVAL
*-------------------------------------------------------------------* * Form TOP-OF-PAGE * *-------------------------------------------------------------------* * ALV Report Header * *-------------------------------------------------------------------* FORM top-of-page. *ALV Header declarations DATA: t_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
t_line LIKE wa_header-info,
ld_lines TYPE i,
ld_linesc(10) TYPE c.
* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'. APPEND wa_header TO t_header. CLEAR wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '. CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date APPEND wa_header TO t_header. CLEAR: wa_header.
* Total No. of Records Selected DESCRIBE TABLE it_ekko LINES ld_lines.
ld_linesc = ld_lines. CONCATENATE 'Total No. of Records Selected: ' ld_linesc INTO t_line SEPARATED BY space.
wa_header-typ = 'A'.
wa_header-info = t_line. APPEND wa_header TO t_header. CLEAR: wa_header, t_line.
*&---------------------------------------------------------------------* *& Form SET_CELL_COLOURS *&---------------------------------------------------------------------* * Set colour of individual ALV cell, field *----------------------------------------------------------------------* FORM set_cell_colours . DATA: wa_cellcolor TYPE lvc_s_scol. DATA: ld_index TYPE sy-tabix.
LOOP AT it_ekko INTO wa_ekko.
ld_index = sy-tabix.
* Set colour of EBELN field to various colors based on sy-tabix value
wa_cellcolor-fname = 'EBELN'.
wa_cellcolor-color-col = sy-tabix. "color code 1-7, if outside rage defaults to 7
wa_cellcolor-color-int = '1'. "1 = Intensified on, 0 = Intensified off
wa_cellcolor-color-inv = '0'. "1 = text colour, 0 = background colour APPEND wa_cellcolor TO wa_ekko-cellcolor. MODIFY it_ekko FROM wa_ekko INDEX ld_index TRANSPORTING cellcolor.
* Set colour of NETPR field to color 4 if gt 0 IF wa_ekko-netpr GT 0.
wa_cellcolor-fname = 'NETPR'.
wa_cellcolor-color-col = 4. "color code 1-7, if outside rage defaults to 7
wa_cellcolor-color-int = '0'. "1 = Intensified on, 0 = Intensified off
wa_cellcolor-color-inv = '0'. "1 = text colour, 0 = background colour APPEND wa_cellcolor TO wa_ekko-cellcolor. MODIFY it_ekko FROM wa_ekko INDEX ld_index TRANSPORTING cellcolor. ENDIF.
* Set colour of AEDAT field text to red(6)
wa_cellcolor-fname = 'AEDAT'.
wa_cellcolor-color-col = 6. "color code 1-7, if outside rage defaults to 7
wa_cellcolor-color-int = '0'. "1 = Intensified on, 0 = Intensified off
wa_cellcolor-color-inv = '1'. "1 = text colour, 0 = background colour APPEND wa_cellcolor TO wa_ekko-cellcolor. MODIFY it_ekko FROM wa_ekko INDEX ld_index TRANSPORTING cellcolor. ENDLOOP.
ENDFORM.
Serkan AKKAVAK Computer Engineer ABAP Developer & SAP MM SD Consultant Contact : serkurumsal@yandex.com
Social Plugin