Abap Alv Grid Renklendirme

*&———————————————————————*
*& Report Z_ALV_RENKLI
*&
*&———————————————————————*
*&
*&
*&———————————————————————*

report z_alv_renkli.

tables: ekko.

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.

************************************************************************
*Start-of-selection.
start-of-selection.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform set_cell_colours.
perform display_alv_report.

*&———————————————————————*
*& Form BUILD_FIELDCATALOG
*&———————————————————————*
* Build Fieldcatalog for ALV Report
*———————————————————————-*
form build_fieldcatalog.

fieldcatalog-fieldname = ‘EBELN’.
fieldcatalog-seltext_m = ‘Sipariş Numarası’.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = ‘X’.
fieldcatalog-key = ‘X’.
* fieldcatalog-do_sum = ‘X’.
* fieldcatalog-no_zero = ‘X’.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = ‘EBELP’.
fieldcatalog-seltext_m = ‘PO Item’.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = ‘STATU’.
fieldcatalog-seltext_m = ‘Status’.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = ‘AEDAT’.
fieldcatalog-seltext_m = ‘Değiştirme Tarihi’.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = ‘MATNR’.
fieldcatalog-seltext_m = ‘Malzeme Numarası’.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = ‘MENGE’.
fieldcatalog-seltext_m = ‘PO quantity’.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = ‘MEINS’.
fieldcatalog-seltext_m = ‘Sip. Birim’.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = ‘NETPR’.
fieldcatalog-seltext_m = ‘Net Fiyat’.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-do_sum = ‘X’. “do_sum kolonu toplama işlevi için
fieldcatalog-datatype = ‘CURR’.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = ‘PEINH’.
fieldcatalog-seltext_m = ‘Birim Fiyat’.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. ” BUILD_FIELDCATALOG

*&———————————————————————*
*& Form BUILD_LAYOUT
*&———————————————————————*
* Build layout for ALV grid report
*———————————————————————-*
form build_layout.
gd_layout-no_input = ‘X’.
gd_layout-colwidth_optimize = ‘X’.
gd_layout-totals_text = ‘Toplam ::'(201).
gd_layout-coltab_fieldname = ‘CELLCOLOR’. “CTAB_FNAME
endform. ” BUILD_LAYOUT

*&———————————————————————*
*& 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 15 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 = ‘Satın Alma Tablosu’.
append wa_header to t_header.
clear wa_header.

* Date
wa_header-typ = ‘S’.
wa_header-key = ‘Tarih: ‘.
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 ‘Toplam Kayıt: ‘ 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.

call function ‘REUSE_ALV_COMMENTARY_WRITE’
exporting
it_list_commentary = t_header.
* i_logo = ‘Z_LOGO’.
endform. “top-of-page

*&———————————————————————*
*& 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 = metin rengi, 0 = arkaplan
“rengi
append wa_cellcolor to wa_ekko-cellcolor.
modify it_ekko from wa_ekko index ld_index transporting cellcolor.

* NETPR değeri 0 dan büyükse renk kodu 4
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 = metin rengi, 0 = arkaplan
“rengi
append wa_cellcolor to wa_ekko-cellcolor.
modify it_ekko from wa_ekko index ld_index transporting cellcolor.
endif.

” Malzeme Numarası boş ise renk kodu 1 olsun
if wa_ekko-matnr eq ‘ ‘.
wa_cellcolor-fname = ‘MATNR’.
wa_cellcolor-color-col = 1. “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 = metin rengi, 0 = arkaplan
“rengi
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 = metin rengi, 0 = arkaplan
“rengi
append wa_cellcolor to wa_ekko-cellcolor.
modify it_ekko from wa_ekko index ld_index transporting cellcolor.
endloop.

endform. ” SET_CELL_COLOURS

You may also like...

1 Response

  1. web yazılım dedi ki:

    Çok iyi paylaşımlarda bulunuyorsunuz sağolun

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Bu site, istenmeyenleri azaltmak için Akismet kullanıyor. Yorum verilerinizin nasıl işlendiği hakkında daha fazla bilgi edinin.