Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Color for negative Values in ALV Report

Former Member
0 Kudos

I want to change the color for negative values displayed in ALV list diplay report. Eg. -5 in Quantity should be changed to orange. Kindly help me

Thanks

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

This thread will help you solve your problem.

REgards,

RIch Heilman

14 REPLIES 14

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

This thread will help you solve your problem.

REgards,

RIch Heilman

0 Kudos

RIch Heilman

Works Great....

Former Member
0 Kudos

Hi Senthil,

check the below code defenetly it will help you to color in alv

REPORT z_alv_line_color.

----


  • Example of ALV with Line color *

----


----


  • Macro definition

DEFINE m_fieldcat.

add 1 to ls_fieldcat-col_pos.

ls_fieldcat-fieldname = &1.

ls_fieldcat-ref_tabname = &2.

append ls_fieldcat to lt_fieldcat.

END-OF-DEFINITION.

TYPE-POOLS: slis. " ALV Global types

SELECTION-SCREEN :

SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED

PARAMETERS p_max(2) TYPE n DEFAULT '30' OBLIGATORY.

SELECTION-SCREEN END OF LINE.

DATA:

  • Data displayed

BEGIN OF gt_vbak OCCURS 0,

vkorg LIKE vbak-vkorg, " Sales organization

kunnr LIKE vbak-kunnr, " Sold-to party

vbeln LIKE vbak-vbeln, " Sales document

netwr LIKE vbak-netwr, " Net Value of the Sales Order

line_color(4), " Line color

END OF gt_vbak.

----


INITIALIZATION.

v_1 = 'Maximum of records to read'. "#EC NOTEXT

----


START-OF-SELECTION.

PERFORM f_read_data.

PERFORM f_fill_color.

PERFORM f_display_data.

----


  • Form f_read_data_vbak

----


FORM f_read_data.

SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak

FROM vbak UP TO p_max ROWS.

ENDFORM. " F_READ_DATA

----


  • Form f_fill_color

----


FORM f_fill_color.

DATA :

l_rnd_value LIKE datatype-integer2.

LOOP AT gt_vbak.

  • Random value

CALL FUNCTION 'RANDOM_I2'

EXPORTING

rnd_min = 0

rnd_max = 3

IMPORTING

rnd_value = l_rnd_value.

CASE l_rnd_value.

WHEN 0.

gt_vbak-line_color = 'C100'. " Blue.

WHEN 1.

gt_vbak-line_color = 'C300'. " Yellow.

WHEN 2.

gt_vbak-line_color = 'C500'. " Green.

WHEN 3.

gt_vbak-line_color = 'C600'. " Red.

ENDCASE.

MODIFY gt_vbak.

ENDLOOP.

ENDFORM. " F_FILL_COLOR

----


  • Form f_display_data

----


FORM f_display_data.

DATA:

ls_layout TYPE slis_layout_alv,

ls_fieldcat TYPE slis_fieldcat_alv,

lt_fieldcat TYPE slis_t_fieldcat_alv.

  • Build the field catalog

m_fieldcat 'VKORG' 'VBAK'.

m_fieldcat 'KUNNR' 'VBAK'.

m_fieldcat 'VBELN' 'VBAK'.

m_fieldcat 'NETWR' 'VBAK'.

  • Fill Layout - Name of the field with color

ls_layout-info_fieldname = 'LINE_COLOR'.

  • Display the list

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = ls_layout

it_fieldcat = lt_fieldcat

TABLES

t_outtab = gt_vbak.

ENDFORM. " F_DISPLAY_DATA

                                  • END OF PROGRAM Z_ALV_LINE_COLOR *********************

0 Kudos

This Works but it changes color for entire line i need to change for Particular Cell. Could you help me out..

Eg.

Qty1 Qty2 Qty3

-1 1 10

6 -5 -20

It should change only for that particular cell which has negative values.

Former Member
0 Kudos

Check the below program :

REPORT zsharad_test1.

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,

line_color(4) TYPE c, "Used to store row color attributes

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.

************************************************************************

*Start-of-selection.

START-OF-SELECTION.

PERFORM data_retrieval.

PERFORM build_fieldcatalog.

PERFORM build_layout.

PERFORM display_alv_report.

&----


*& 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.

fieldcatalog-fieldname = 'EBELN'.

fieldcatalog-seltext_m = 'Purchase Order'.

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 = 'Item change date'.

fieldcatalog-col_pos = 3.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'Material Number'.

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 = 'Order Unit'.

fieldcatalog-col_pos = 6.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.

fieldcatalog-seltext_m = 'Net Price'.

fieldcatalog-col_pos = 7.

fieldcatalog-outputlen = 15.

fieldcatalog-datatype = 'CURR'.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

fieldcatalog-fieldname = 'PEINH'.

fieldcatalog-seltext_m = 'Price Unit'.

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 = 'Totals'(201).

  • Set layout field for row attributes(i.e. color)

gd_layout-info_fieldname = 'LINE_COLOR'.

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for when double

  • "click(press f2)

  • gd_layout-zebra = 'X'.

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

ENDFORM. " BUILD_LAYOUT

&----


*& Form DISPLAY_ALV_REPORT

&----


  • Display report using ALV grid

----


FORM display_alv_report.

gd_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_LIST_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_XEVENTS

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.

DATA: ld_color(1) TYPE c.

SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh

UP TO 10 ROWS

FROM ekpo

INTO TABLE it_ekko.

*Populate field with color attributes

LOOP AT it_ekko INTO wa_ekko.

  • Populate color variable with colour properties

  • Char 1 = C (This is a color property)

  • Char 2 = 3 (Color codes: 1 - 7)

  • Char 3 = Intensified on/off ( 1 or 0 )

  • Char 4 = Inverse display on/off ( 1 or 0 )

  • i.e. wa_ekko-line_color = 'C410'

ld_color = ld_color + 1.

  • Only 7 colours so need to reset color value

IF ld_color = 8.

ld_color = 1.

ENDIF.

CONCATENATE 'C' ld_color '10' INTO wa_ekko-line_color.

  • wa_ekko-line_color = 'C410'.

MODIFY it_ekko FROM wa_ekko.

ENDLOOP.

ENDFORM. " DATA_RETRIEVAL

Thanks

Seshu

0 Kudos

This works fine but the entire line item is getting coloured. i need a field in particular line item to change its color when it is negeative.

Eg. Qty becomes negative change its color to green

0 Kudos

Check the below program and bold one are important ( which is similar to MD05 Traffic lights )

REPORT ZWM_BIN_STOCK_REQ no standard page heading

message-id zwave.

***********************************************************************

                    • D A T A D E C L A R A T I O N ****************************

***********************************************************************

  • Tables

tables :zpwvbap,

mara,

marc,

makt,

vbap,

zshift,

marm,

lqua.

TYPE-POOLS: SLIS.

  • Internal Table for Sales order

data : begin of i_vbap occurs 0,

matnr like zpwvbap-matnr," Material #

ZZCUTOFF like zpwvbak-ZZCUTOFF," Cutoff Time

vlpla like zpwvbap-vlpla,

kwmeng like zpwvbap-kwmeng," Quantity

vrkme like zpwvbap-vrkme, " Sales Unit

meins like zpwvbap-meins, " Unit of measure

end of i_vbap.

  • Internal Table for final Processing

data : begin of i_final occurs 0,

date(8) type c,

matnr like zpwvbap-matnr," Material #

zzshift like zshift-zzshift, " Wave Drop

maktx like makt-maktx," Desc

lgpla like lagp-lgpla, " Pick Bin

pverme like lqua-verme," Stock at Pick Bin

prverme like lqua-verme," Stock at Prod Bin

kwmeng like zpwvbap-kwmeng," Requiremnet from Wave Drop

vrkme like zpwvbap-vrkme, " Sales Unit

  • meins like zpwvbap-meins," Unit of measure

end of i_final.

  • Internal Table for Output

data : begin of i_output occurs 0,

<b> field type c, " Traffic Lights</b>

zzshift like zshift-zzshift, " Wave Drop

matnr like zpwvbap-matnr," Material #

maktx like makt-maktx," Desc

lgpla like lagp-lgpla, " Pick Bin

pverme like lqua-verme," Stock at Pick Bin

prverme like lqua-verme," Stock at Prod Bin

kwmeng like zpwvbap-kwmeng," Requiremnet from Wave Drop

vrkme like zpwvbap-vrkme," Sales Unit

  • meins like zpwvbap-meins," Unit of measure

diff like zpwvbap-kwmeng, " Diffrence

end of i_output.

  • Work Area for Final Internal Table

data wa_final like i_final.

data : w_zzcutoff(12) TYPE c,

v_date type sy-datum,

v_time(4) type c,

v_fldate(12) type c,

v_fhdate(12) type c,

v_pverme like lqua-verme,

v_prverme like lqua-verme,

v_diff like zpwvbap-kwmeng.

  • Variables for new check box

data : v_nverme like lqua-verme.

  • Internal Table for Pick Bin

data : begin of i_verme occurs 0,

verme like lqua-verme,

end of i_verme.

  • Internal table for Prod Bin

data : begin of i_pverme occurs 0,

verme like lqua-verme,

end of i_pverme.

  • Variables for ALV

DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

FIELDCAT_LN LIKE LINE OF FIELDCAT,

SORTCAT TYPE SLIS_T_SORTINFO_ALV,

SORTCAT_LN LIKE LINE OF SORTCAT,

EVENTCAT TYPE SLIS_T_EVENT,

EVENTCAT_LN LIKE LINE OF EVENTCAT,

LAYOUT TYPE SLIS_LAYOUT_ALV,

C_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',

g_user_command TYPE slis_formname VALUE 'USER_COMMAND',

GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

DATA: COL_POS TYPE I,

P_LIGNAM TYPE SLIS_FIELDNAME VALUE 'FIELD'.

DATA : V_REPID LIKE SY-REPID,

flag type c.

************************************************************************

                            • S E L E C T I O N - S C R E E N *************************

************************************************************************

selection-screen : begin of block blk with frame title text-001.

parameter : p_plant like marc-werks obligatory default '1000'.

select-options : s_date for sy-datum obligatory ,

s_shift for zshift-zzshift,

s_matnr for mara-matnr,

s_dept for zpwvbap-zzdept,

s_pdept for marc-ZZPRODDEPT.

selection-screen: end of block blk.

parameters : p_check as checkbox ."default 'X'.

ranges r_cutoff for w_zzcutoff.

************************************************************************

                              • I N I T I A L I Z A T I O N ****************************

************************************************************************

initialization.

V_REPID = SY-REPID.

s_date-low = sy-datum + 1.

append s_date.

************************************************************************

                      • S T A R T - O F - S E L E C T I O N ***********************

************************************************************************

start-of-selection.

  • Get the Shift Data.

PERFORM GET_SHIFT_DETAILS.

  • Get the data from ZPWVBAP Table

PERFORM GET_DATA_VBAP.

***********************************************************************

                                • E N D - O F - S E L E C T I O N **********************

***********************************************************************

end-of-selection.

if not i_output[] is initial.

sort i_output by field zzshift matnr.

  • Reset the all Fiedcatlog.

PERFORM RESETVALUES.

  • Traffic Lights

PERFORM BUILD_LAYOUT.

  • Fill the fieldcatlog values

PERFORM FILL_FIELDCATLOG.

  • Call the List Function module

PERFORM CALL_lIST.

endif.

&----


*& Form GET_SHIFT_DETAILS

&----


  • Get the Cutoff Time.

----


FORM GET_SHIFT_DETAILS.

clear : v_fldate,

v_fhdate.

if not s_shift-low is initial.

clear: v_time,

v_date.

if s_shift-low = '1'.

v_time = '2000'.

elseif s_shift-low = '2'.

v_time = '2300'.

endif.

v_date = s_date-low - 1.

concatenate v_date v_time into v_fldate.

endif.

if not s_shift-high is initial.

clear : v_date,

v_time.

if s_shift-high = '1'.

v_time = '2000'.

elseif s_shift-high = '2'.

v_time = '2300'.

endif.

if not s_date-high is initial.

v_date = s_date-high - 1.

else.

v_date = s_date-low - 1.

endif.

concatenate v_date v_time into v_fhdate.

endif.

if not v_fhdate is initial.

r_cutoff-low = v_fldate.

r_cutoff-high = v_fhdate.

r_cutoff-sign = 'I'.

r_cutoff-option = 'BT'.

append r_cutoff.

endif.

ENDFORM. " GET_SHIFT_DETAILS

&----


*& Form GET_DATA_VBAP

&----


  • Get the data from ZPWVBAP Table

----


FORM GET_DATA_VBAP.

  • Get the data from ZPWVBAP and ZPWVBAK Table

if not v_fhdate is initial.

select matnr ZZCUTOFF vlpla sum( kwmeng ) vrkme meins

into table i_vbap

from zpwvbap as a inner join zpwvbak as b on

a~vbeln = b~vbeln

where a~werks = p_plant

and a~matnr in s_matnr

and b~vdatu in s_date

and a~zzdept in s_dept

and b~zzcutoff in r_cutoff

group by matnr zzcutoff vlpla vrkme meins.

elseif not v_fldate is initial.

select matnr ZZCUTOFF vlpla sum( kwmeng ) vrkme meins

into table i_vbap

from zpwvbap as a inner join zpwvbak as b on

a~vbeln = b~vbeln

where a~werks = p_plant

and a~matnr in s_matnr

and b~vdatu in s_date

and a~zzdept in s_dept

and b~zzcutoff = v_fldate

group by matnr zzcutoff vlpla vrkme meins.

else.

select matnr ZZCUTOFF vlpla sum( kwmeng ) vrkme meins

into table i_vbap

from zpwvbap as a inner join zpwvbak as b on

a~vbeln = b~vbeln

where a~werks = p_plant

and a~matnr in s_matnr

and b~vdatu in s_date

and a~zzdept in s_dept

and b~zzcutoff in r_cutoff

group by matnr zzcutoff vlpla vrkme meins .

endif.

if sy-subrc ne 0.

message i000(zwave) with 'No data found for given selection'.

stop.

endif.

sort i_vbap by zzcutoff matnr.

loop at i_vbap.

clear : v_pverme,

v_prverme.

  • Compare the data with pick method

select single zzpick from marc into marc-zzpick

where matnr = i_vbap-matnr

and werks = p_plant

and zzpick = '01'.

if sy-subrc ne 0.

continue.

endif.

  • Compare the data from MARC Table with Production Department

select single zzPRODdept from marc into marc-zzPRODdept

where matnr = i_vbap-matnr

and werks = p_plant

and zzPRODdept in s_pdept.

if sy-subrc ne 0.

continue.

endif.

  • Get the Material Description from MAKT Table

Select single maktx from makt into makt-maktx

where matnr = i_vbap-matnr

and spras = 'E'.

if sy-subrc eq 0.

i_final-maktx = makt-maktx.

endif.

  • Get the Pick Bin

i_final-lgpla = i_vbap-vlpla.

refresh i_verme.

clear i_verme.

  • Get the stock at Pick bin

select verme from lqua into table i_verme

where lgpla = i_vbap-vlpla

and matnr = i_vbap-matnr

and LGNUM = '100'.

if sy-subrc eq 0.

loop at i_verme.

v_pverme = v_pverme + i_verme-verme.

endloop.

if sy-subrc eq 0.

i_final-pverme = v_pverme.

endif.

endif.

refresh i_pverme.

clear i_pverme.

  • Get the stock at Production bin

select verme from lqua into table i_pverme

where matnr = i_vbap-matnr

and LGNUM = '100'

and ( lgpla = '9595959595' or

lgpla = '2222222222' or

lgpla = '5555555555' or

lgpla = '3232323232' or

lgpla = '8080808080' or

lgpla = '4040404040' or

lgpla = '9090909090' ).

if sy-subrc eq 0.

loop at i_pverme.

v_prverme = v_prverme + i_pverme-verme.

endloop.

if sy-subrc eq 0.

i_final-prverme = v_prverme.

endif.

endif.

  • Compare the unit of measure and sales unit

if i_vbap-vrkme ne i_vbap-meins.

  • Get the data from MARM Table ( Unit of measure )

select single * from marm into marm

where matnr = i_vbap-matnr

and meinh = i_vbap-vrkme.

if sy-subrc eq 0.

i_final-pverme = ( i_final-pverme * marm-umren ) / marm-umrez.

endif.

endif.

  • Material #

i_final-matnr = i_vbap-matnr.

  • Quantity from ZPWVBAP

i_final-kwmeng = i_vbap-kwmeng.

  • Unit of Measure

  • i_final-meins = i_vbap-meins.

  • Sales Unit

i_final-vrkme = i_vbap-vrkme.

  • Wave Drop

if i_vbap-ZZCUTOFF+8(4) = '2000' .

i_final-zzshift = '1'.

endif.

if i_vbap-zzcutoff+8(4) = '2300'.

i_final-zzshift = '2'.

endif.

i_final-date = i_vbap-zzcutoff+0(8).

append i_final.

clear : i_final,

i_vbap.

**Difference

*

  • i_output-diff = i_output-pverme - i_vbap-kwmeng.

*

    • Traffic Lights Depends on value

  • if i_output-pverme > i_output-kwmeng.

  • i_output-field = '3'.

  • elseif i_output-pverme < i_output-kwmeng.

  • i_output-field = '1'.

  • elseif i_output-pverme = i_output-kwmeng.

  • i_output-field = '2'.

  • endif.

*

  • append i_output.

  • clear : i_output,

  • i_vbap.

endloop.

refresh i_vbap.

sort i_final by date matnr zzshift.

  • Processing the internal table to get same material with pick quantity

  • deduction even it for 2nd shift

loop at i_final.

  • Move the data into work area in order remove #

move i_final to wa_final.

clear : flag.

at new matnr.

move : wa_final-matnr to i_output-matnr," Material #

wa_final-maktx to i_output-maktx," Desc

wa_final-lgpla to i_output-lgpla," Pick Bin

wa_final-kwmeng to i_output-kwmeng," Order qty

wa_final-zzshift to i_output-zzshift," Shift

wa_final-pverme to i_output-pverme, " Pick bin qty

wa_final-vrkme to i_output-vrkme," Sales Unit

wa_final-prverme to i_output-prverme. " Prod Bin Qty

  • Difference

i_output-diff = i_output-pverme - i_output-kwmeng.

  • New logic for Only HMR Department

<b> if p_check = 'X'.

if i_output-pverme < i_output-kwmeng.

v_nverme = i_output-pverme + i_output-prverme.

if v_nverme > i_output-kwmeng.

if i_output-pverme < i_output-kwmeng.

i_output-field = '2'.

else.

  • Traffic Lights Depends on value

i_output-field = '3'.

endif.

elseif v_nverme < i_output-kwmeng.

i_output-field = '1'.

elseif v_nverme = i_output-kwmeng.

i_output-field = '2'.

endif.

elseif i_output-pverme > i_output-kwmeng.

i_output-field = '3'.

elseif i_output-pverme = i_output-kwmeng.

i_output-field = '3'.

endif.

else.

  • Traffic Lights Depends on value

if i_output-pverme > i_output-kwmeng.

i_output-field = '3'.

elseif i_output-pverme < i_output-kwmeng.

i_output-field = '1'.

elseif i_output-pverme = i_output-kwmeng.

i_output-field = '2'.

endif.

endif.

move i_output-diff to v_diff.

flag = 'X'.

endat.</b>

if flag ne 'X'.

move : wa_final-matnr to i_output-matnr," Material #

wa_final-maktx to i_output-maktx," Desc

wa_final-lgpla to i_output-lgpla," Pick Bin

wa_final-kwmeng to i_output-kwmeng," Order qty

wa_final-zzshift to i_output-zzshift," Shift

wa_final-vrkme to i_output-vrkme," Sales Unit

wa_final-prverme to i_output-prverme. " Prod Bin Qty

  • Move Diffrence value

move v_diff to i_output-pverme.

clear: v_diff.

  • New logic for Only HMR Department

  • New logic for Only HMR Department

if p_check = 'X'.

if i_output-pverme < i_output-kwmeng.

v_nverme = i_output-pverme + i_output-prverme.

if v_nverme > i_output-kwmeng.

if i_output-pverme < i_output-kwmeng.

i_output-field = '2'.

else.

  • Traffic Lights Depends on value

i_output-field = '3'.

endif.

  • Traffic Lights Depends on value

  • i_output-field = '3'.

elseif v_nverme < i_output-kwmeng.

i_output-field = '1'.

elseif v_nverme = i_output-kwmeng.

i_output-field = '2'.

endif.

elseif i_output-pverme > i_output-kwmeng.

i_output-field = '3'.

elseif i_output-pverme = i_output-kwmeng.

i_output-field = '3'.

endif.

i_output-diff = i_output-pverme - i_output-kwmeng.

else.

  • Difference

i_output-diff = i_output-pverme - i_output-kwmeng.

  • Traffic Lights Depends on value

if i_output-pverme > i_output-kwmeng.

i_output-field = '3'.

elseif i_output-pverme < i_output-kwmeng.

i_output-field = '1'.

elseif i_output-pverme = i_output-kwmeng.

i_output-field = '2'.

endif.

endif.

endif.

append i_output.

clear : i_output,

wa_final,

i_final,

v_nverme.

endloop.

sort i_output by field zzshift matnr.

ENDFORM. " GET_DATA_VBAP

&----


*& Form RESETVALUES

&----


  • Reset the all fieldcatlogs

----


FORM RESETVALUES.

FIELDCAT_LN-KEY = SPACE.

FIELDCAT_LN-DO_SUM = SPACE.

FIELDCAT_LN-NO_OUT = SPACE.

FIELDCAT_LN-QFIELDNAME = SPACE.

FIELDCAT_LN-HOTSPOT = SPACE.

FIELDCAT_LN-OUTPUTLEN = '0'.

CLEAR: fieldcat_ln-seltext_l, fieldcat_ln-seltext_m,

fieldcat_ln-seltext_s, fieldcat_ln-reptext_ddic.

ENDFORM. " RESETVALUES

&----


*& Form FILL_FIELDCATLOG

&----


  • Fill the Fieldcatlog values

----


FORM FILL_FIELDCATLOG.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

  • Trafiic Light

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'FIELD'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 7.

LS_FIELDCAT-col_pos = '1'.

ls_fieldcat-seltext_L = 'Lights'.

ls_fieldcat-seltext_s = 'Lights'.

ls_fieldcat-seltext_m = 'Lights'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Wave Drop

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'ZZSHIFT'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 9.

LS_FIELDCAT-col_pos = '2'.

ls_fieldcat-seltext_L = 'Wave Drop'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Material

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'MATNR'.

LS_FIELDCAT-ref_fieldname = 'MATNR'.

LS_FIELDCAT-ref_tabname = 'MARA'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 18.

LS_FIELDCAT-col_pos = '3'.

ls_fieldcat-seltext_L = 'Material'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Description

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'MAKTX'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 40.

LS_FIELDCAT-col_pos = '4'.

ls_fieldcat-seltext_L = 'Description'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Pick Bin

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'LGPLA'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 15.

LS_FIELDCAT-col_pos = '5'.

ls_fieldcat-seltext_L = 'Pick Bin'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Trafiic Light

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'PVERME'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 16.

LS_FIELDCAT-col_pos = '6'.

ls_fieldcat-seltext_L = 'Stock at Pick Bin'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Stock at Prod Bin

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'PRVERME'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 16.

LS_FIELDCAT-col_pos = '7'.

ls_fieldcat-seltext_L = 'Stock at Prod Bin'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Req from wave drop

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'KWMENG'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 23.

LS_FIELDCAT-col_pos = '8'.

ls_fieldcat-seltext_L = 'Requirement from Wave Drop'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Sales Unit

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'VRKME'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 12.

LS_FIELDCAT-col_pos = '9'.

ls_fieldcat-seltext_L = 'Sales Unit'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Unit of Measure

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'MEINS'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 9.

LS_FIELDCAT-col_pos = '10'.

ls_fieldcat-seltext_L = 'UNIT'.

ls_fieldcat-no_out = 'X'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Diffference

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'DIFF'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 12.

LS_FIELDCAT-col_pos = '11'.

ls_fieldcat-seltext_L = 'Difference'.

APPEND LS_FIELDCAT TO FIELDCAT.

ENDFORM. " FILL_FIELDCATLOG

&----


*& Form CALL_lIST

&----


  • Use ALV Function module to display output

----


FORM CALL_lIST.

  • Top - of - Page

PERFORM COMMENT_BUILD USING GT_LIST_TOP_OF_PAGE[].

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = V_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = g_user_command

I_CALLBACK_TOP_OF_PAGE = C_TOP_OF_PAGE

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = LAYOUT

IT_FIELDCAT = FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_ADD_FIELDCAT =

  • IT_HYPERLINK =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IT_EXCEPT_QINFO =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = I_OUTPUT

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. " CALL_lIST

&----


*& Form BUILD_LAYOUT

&----


  • text

----


FORM BUILD_LAYOUT.

LAYOUT-GET_SELINFOS = 'X'.

      • Now we want a traffic light to say if the Truck is deleted

      • the variable p_lignam contains the name in IREPO which stores the

      • value for the traffic light

LAYOUT-LIGHTS_FIELDNAME = P_LIGNAM.

layout-HEADER_TEXT = 'Lights'.

LAYOUT-LIGHTS_CONDENSE = 'X'.

ENDFORM. " BUILD_LAYOUT

&----


*& Form COMMENT_BUILD

&----


  • text

----


  • -->P_GT_LIST_TOP_OF_PAGE[] text

----


FORM COMMENT_BUILD USING LT_TOP_OF_PAGE TYPE

SLIS_T_LISTHEADER.

data : v_day(2) type c,

v_mon(2) type c,

v_year(4) type c,

v_ldate(10) type c,

v_hdate(10) type c.

DATA: LS_LINE TYPE SLIS_LISTHEADER.

data: d_date like sy-datum.

clear : v_ldate,

v_hdate.

  • Header Information.

  • LIST HEADING LINE: TYPE H

CLEAR LS_LINE.

LS_LINE-TYP = 'H'.

  • LS_LINE-KEY: NOT USED FOR THIS TYPE

LS_LINE-INFO = 'Bin Replenishment report for HMR'.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

  • STATUS LINE: TYPE S

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = TEXT-003.

  • LS_LINE-INFO = TEXT-003.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

  • STATUS LINE: TYPE S

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

  • LS_LINE-KEY = TEXT-003.

  • LS_LINE-INFO = TEXT-003.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

  • Get the data ( s_date_low) into proper format.

v_year = s_date-low+0(4).

v_mon = s_date-low+4(2).

v_day = s_date-low+6(2).

concatenate v_mon '/' v_day '/' v_year into v_ldate.

clear : v_mon,

v_year,

v_day.

  • Get the data ( s_date_high) into proper format.

v_year = s_date-high+0(4).

v_mon = s_date-high+4(2).

v_day = s_date-high+6(2).

concatenate v_mon '/' v_day '/' v_year into v_hdate.

clear : v_mon,

v_year,

v_day.

  • Delivery date

if not s_date-low is initial .

if not s_date-high is initial.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Delivery date From:'.

LS_LINE-INFO = v_ldate.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Delivery date To :'.

LS_LINE-INFO = v_hdate.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

endif.

endif.

if not s_date-low is initial.

if s_date-high is initial.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Delivery date :'.

LS_LINE-INFO = v_ldate.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

endif.

endif.

  • Wave Drop

if not S_SHIFT-LOW is initial.

if not S_SHIFT-high is initial.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Wave Drop From :'.

LS_LINE-INFO = s_shift-low.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Wave Drop to :'.

LS_LINE-INFO = s_shift-high.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

endif.

endif.

if not S_SHIFT-LOW is initial.

if S_SHIFT-high is initial.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Wave Drop :'.

LS_LINE-INFO = s_shift-low.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

  • CLEAR LS_LINE.

  • LS_LINE-TYP = 'S'.

  • LS_LINE-KEY = 'Wave Drop to :'.

  • LS_LINE-INFO = s_shift-high.

  • APPEND LS_LINE TO LT_TOP_OF_PAGE.

endif.

endif.

  • Department

if not s_dept-low is initial .

if not s_dept-high is initial.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Department From :'.

LS_LINE-INFO = s_dept-low.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Department to :'.

LS_LINE-INFO = s_dept-high.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

endif.

endif.

if not s_dept-low is initial .

if s_dept-high is initial.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Department :'.

LS_LINE-INFO = s_dept-low.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

endif.

endif.

  • Production Department

if not S_PDEPT-LOW is initial.

if not S_PDEPT-high is initial.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Production Department From :'.

LS_LINE-INFO = S_PDEPT-LOW.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Production Department to :'.

LS_LINE-INFO = S_PDEPT-high.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

endif.

endif.

if not S_PDEPT-LOW is initial.

if S_PDEPT-high is initial.

CLEAR LS_LINE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Production Department :'.

LS_LINE-INFO = S_PDEPT-LOW.

APPEND LS_LINE TO LT_TOP_OF_PAGE.

endif.

endif.

ENDFORM. " COMMENT_BUILD

----


  • FORM TOP_OF_PAGE *

----


  • ........ *

----


FORM TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE

  • I_LOGO =

  • I_END_OF_LIST_GRID =

.

ENDFORM.

----


  • FORM USER_COMMAND *

----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield. "#EC CALLED

CASE R_UCOMM.

WHEN '&IC1'.

read table i_output index rs_selfield-tabindex.

SET PARAMETER ID 'MAT' FIELD i_output-matnr.

SET PARAMETER ID 'WRK' FIELD p_plant.

if not i_output-matnr is initial.

call transaction 'MD04' and skip first screen.

endif.

ENDCASE.

ENDFORM.

the above code i mentioned 1,2 ,3 values ,1 will have green color,2 will have yellow color,3 will have red color.

Thanks

Seshu

kesavadas_thekkillath
Active Contributor
0 Kudos

First you have to include the field CELLCOLOR TYPE LVC_T_SCOL in u r final itab.

then WA_COLOR TYPE LVC_S_SCOL, in u r alv declarations

then before calling the functional module apply this

LOOP AT itab_final.

if itab-final-<field name> < 1.

MOVE: '<your field name>' TO WA_COLOR-FNAME.

MOVE '7' TO WA_COLOR-COLOR-COL.

MOVE '0' TO WA_COLOR-COLOR-INT.

MOVE '1' TO WA_COLOR-COLOR-INV.

APPEND WA_COLOR TO MESSAGES-CELLCOLOR.

MODIFY MESSAGES TRANSPORTING CELLCOLOR.

endloop.

then put this in u r alv ents

WK_LAYOUT-COLTAB_FIELDNAME = 'CELLCOLOR'.

***********************************SAMPLE PROGRAM***********************************

Check for the above code in thsi prg...u will get it

REPORT ZBDC_POSTING

NO STANDARD PAGE HEADING LINE-SIZE 255

MESSAGE-ID ZPP.

******************

INCLUDE BDCRECX1.

******************

*PARAMETERS: dataset(132) LOWER CASE.

TYPE-POOLS :SLIS.

TABLES : MAKT, MKAL.

DATA: WK_ELPRO TYPE MKAL-ALORT,

WK_MAKT TYPE MAKT-MAKTX,

WK_SUCCESS(5) TYPE C,

WK_FAILURE(5) TYPE C,

L_MSTRING(480),

T_DATE TYPE ZSERVICE_DATE,

WK_LINES(5) TYPE C,

LINES(5) TYPE C,

WK_LEN(150) TYPE C,

WK_ALP TYPE I,

LENT TYPE I,

B(4).

DATA: ALVFLD TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,

V_EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE,

WK_EVENTS LIKE LINE OF V_EVENTS,

IT_LIST_COMMENTS TYPE SLIS_T_LISTHEADER,

WK_LIST_COMMENTS LIKE LINE OF IT_LIST_COMMENTS,

WA_COLOR TYPE LVC_S_SCOL,

WK_LAYOUT TYPE SLIS_LAYOUT_ALV.

CONSTANTS: C_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME

VALUE 'F_TOP_OF_PAGE'.

--


TO STORE FINAL DATA TO BE POSTED--

      • Generated data section with specific formatting - DO NOT CHANGE ***

DATA: BEGIN OF RECORD OCCURS 0,

BUDAT_002(010),

BKTXT_004(025),

MATNR_005(018),

WERKS_006(004),

ALORT_007(004),

ERFMG_008(017),

END OF RECORD.

      • End generated data section ***

----


DATA: BEGIN OF MESSAGES OCCURS 0, "TO STORE FINAL STATUS DISPLAY

BUDAT_002(010),

BKTXT_004(025),

MATNR_005(018),

MAKTX TYPE MAKT-MAKTX,

WERKS_006(004),

ALORT_007(004),

ERFMG_008(017),

MSG_W(100),

MSG_E(100),

MSG_S(100),

MSGTYP TYPE C,

CELLCOLOR TYPE LVC_T_SCOL,

END OF MESSAGES.

DATA: BEGIN OF ST_RECORD1 ,

MATNR_005(018),

WERKS_006(004),

BUDAT_002(010),

BKTXT_004(025),

ERFMG_007(017),

ERFMG_008(017),

ALORT_007(004),

END OF ST_RECORD1.

DATA : RECORD1 LIKE TABLE OF ST_RECORD1 WITH HEADER LINE,

IT_EXCEL LIKE TABLE OF ALSMEX_TABLINE WITH HEADER LINE,

MESSTAB1 LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE,

IT_ACC LIKE TABLE OF RECORD WITH HEADER LINE,

IT_REJ LIKE TABLE OF RECORD WITH HEADER LINE.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002.

PARAMETERS: P_FILE TYPE LOCALFILE OBLIGATORY .

SELECTION-SCREEN END OF BLOCK B1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

STATIC = 'X'

CHANGING

FILE_NAME = P_FILE.

AT SELECTION-SCREEN ON P_FILE.

WK_LEN = P_FILE.

CONDENSE WK_LEN NO-GAPS.

LENT = STRLEN( WK_LEN ).

WK_ALP = LENT - 4.

B = WK_LEN+WK_ALP(LENT).

IF ( B NE '.txt' ) AND ( B NE '.xls' ).

MESSAGE E939.

CLEAR P_FILE.

STOP.

ENDIF.

START-OF-SELECTION.

PERFORM UPLOAD_FUN.

PERFORM OPEN_GROUP.

PERFORM FILL_BDC_TABLE.

PERFORM CLOSE_GROUP.

PERFORM ASSIGN_COLORS.

PERFORM F_EVENT_BUILD.

SORT MESSAGES BY MATNR_005 ASCENDING.

PERFORM ASSIGN_COLUMNS.

PERFORM COUNT.

IF CTU = 'X'.

PERFORM ALV.

ENDIF.

FREE:MESSAGES,MESSTAB1,RECORD1.

END-OF-SELECTION.

--


FORM UPLOAD_FUN--

FORM UPLOAD_FUN.

REFRESH: RECORD1, IT_ACC, IT_REJ, RECORD, MESSAGES, MESSTAB1, IT_EXCEL.

PERFORM FETCH_FROM_FLAT_FILE.

CLEAR IT_EXCEL.

DESCRIBE TABLE IT_EXCEL.

IF SY-TFILL = 0.

MESSAGE I937.

STOP.

ENDIF.

LOOP AT IT_EXCEL.

CASE IT_EXCEL-COL.

WHEN '0001'.

MOVE: IT_EXCEL-VALUE TO RECORD1-MATNR_005.

WHEN '0002'.

MOVE: IT_EXCEL-VALUE TO RECORD1-WERKS_006.

WHEN '0003'.

MOVE: IT_EXCEL-VALUE TO RECORD1-BUDAT_002.

WHEN '0004'.

MOVE: IT_EXCEL-VALUE TO RECORD1-BKTXT_004.

WHEN '0005'.

MOVE: IT_EXCEL-VALUE TO RECORD1-ERFMG_007.

WHEN '0006'.

MOVE: IT_EXCEL-VALUE TO RECORD1-ERFMG_008.

WHEN '0007'.

MOVE: IT_EXCEL-VALUE TO RECORD1-ALORT_007.

ENDCASE.

AT END OF ROW.

APPEND RECORD1.

CLEAR RECORD1.

ENDAT.

ENDLOOP.

CLEAR RECORD1.

DELETE RECORD1 WHERE MATNR_005 EQ ' '.

--


DO NOT UPLOAD WHERE PRD QTY = 0--

DELETE RECORD1 WHERE ( ERFMG_007 = 0 OR ERFMG_007 = ' ' )

AND ( ERFMG_008 = 0 OR ERFMG_008 = ' ' ).

DESCRIBE TABLE RECORD1[].

IF SY-TFILL > 0.

--


MOVE ACCEPTED QTY AND FETCH THE RESPECTIVE STGLOC-**

LOOP AT RECORD1 WHERE ERFMG_007 NE 0 AND ERFMG_007 NE ' '.

MOVE: RECORD1-BUDAT_002 TO IT_ACC-BUDAT_002,

RECORD1-BKTXT_004 TO IT_ACC-BKTXT_004,

RECORD1-MATNR_005 TO IT_ACC-MATNR_005,

RECORD1-WERKS_006 TO IT_ACC-WERKS_006,

RECORD1-ERFMG_007 TO IT_ACC-ERFMG_008.

APPEND IT_ACC.

CLEAR: IT_ACC,RECORD1.

ENDLOOP.

--


MOVE ELPRO FOR THE ACCEPTED ENTRIES--

LOOP AT IT_ACC.

SELECT SINGLE ELPRO INTO WK_ELPRO FROM MKAL CLIENT SPECIFIED

WHERE MANDT = SY-MANDT

AND MATNR = IT_ACC-MATNR_005

AND WERKS = IT_ACC-WERKS_006.

MOVE WK_ELPRO TO IT_ACC-ALORT_007.

MODIFY IT_ACC.

CLEAR: WK_ELPRO, IT_ACC.

ENDLOOP.

--


MOVE PRD QTY FOR REJECTED QTY--

LOOP AT RECORD1 WHERE ERFMG_008 NE 0 AND ERFMG_008 NE ' '.

MOVE: RECORD1-BUDAT_002 TO IT_REJ-BUDAT_002,

RECORD1-BKTXT_004 TO IT_REJ-BKTXT_004,

RECORD1-MATNR_005 TO IT_REJ-MATNR_005,

RECORD1-WERKS_006 TO IT_REJ-WERKS_006,

RECORD1-ERFMG_008 TO IT_REJ-ERFMG_008,

RECORD1-ALORT_007 TO IT_REJ-ALORT_007.

APPEND IT_REJ.

CLEAR: IT_REJ, RECORD1.

ENDLOOP.

--


MOVE ACCEPTED AND REJECTED READINGS TO FINAL TABLE

APPEND LINES OF IT_ACC TO RECORD.

APPEND LINES OF IT_REJ TO RECORD.

FREE : IT_REJ, IT_ACC, RECORD1.

ELSE.

MESSAGE I937.

STOP.

ENDIF.

ENDFORM. " UPLOAD_FUN

--


FORM fill_bdc_table--

FORM FILL_BDC_TABLE.

IF NOT RECORD[] IS INITIAL.

LOOP AT RECORD.

PERFORM BDC_DYNPRO USING 'SAPLBARM' '0800'.

PERFORM BDC_FIELD USING 'BDC_CURSOR' 'RM61B-BKTXT'.

PERFORM BDC_FIELD USING 'BDC_OKCODE' '=ISTDA'.

PERFORM BDC_FIELD USING 'RM61B-BUDAT' RECORD-BUDAT_002.

PERFORM BDC_FIELD USING 'RM61B-BKTXT' RECORD-BKTXT_004.

PERFORM BDC_FIELD USING 'RM61B-MATNR' RECORD-MATNR_005.

PERFORM BDC_FIELD USING 'RM61B-WERKS' RECORD-WERKS_006.

PERFORM BDC_FIELD USING 'RM61B-ALORT' RECORD-ALORT_007.

PERFORM BDC_FIELD USING 'RM61B-ERFMG' RECORD-ERFMG_008.

PERFORM BDC_DYNPRO USING 'SAPLCOWB' '0130'.

PERFORM BDC_FIELD USING 'BDC_OKCODE' '=WEIT'.

PERFORM BDC_FIELD USING 'BDC_CURSOR' 'G_COWB_HEADER-MNGTXT'.

PERFORM BDC_TRANSACTION USING 'MFBF'.

CLEAR MESSTAB.

APPEND LINES OF MESSTAB TO MESSTAB1.

CLEAR MESSTAB1.

LOOP AT MESSTAB1 WHERE MSGTYP = 'S' OR MSGTYP = 'E' OR MSGTYP = 'W'.

SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB1-MSGSPRA

AND ARBGB = MESSTAB1-MSGID

AND MSGNR = MESSTAB1-MSGNR.

IF SY-SUBRC = 0.

L_MSTRING = T100-TEXT.

IF L_MSTRING CS '&1'.

REPLACE '&1' WITH MESSTAB1-MSGV1 INTO L_MSTRING.

REPLACE '&2' WITH MESSTAB1-MSGV2 INTO L_MSTRING.

REPLACE '&3' WITH MESSTAB1-MSGV3 INTO L_MSTRING.

REPLACE '&4' WITH MESSTAB1-MSGV4 INTO L_MSTRING.

ELSE.

REPLACE '&' WITH MESSTAB1-MSGV1 INTO L_MSTRING.

REPLACE '&' WITH MESSTAB1-MSGV2 INTO L_MSTRING.

REPLACE '&' WITH MESSTAB1-MSGV3 INTO L_MSTRING.

REPLACE '&' WITH MESSTAB1-MSGV4 INTO L_MSTRING.

ENDIF.

CONDENSE L_MSTRING.

IF MESSTAB1-MSGTYP = 'W'.

MOVE L_MSTRING TO MESSAGES-MSG_W.

ELSEIF MESSTAB1-MSGTYP = 'E'.

MOVE L_MSTRING TO MESSAGES-MSG_E.

MOVE 'E' TO MESSAGES-MSGTYP.

ELSEIF MESSTAB1-MSGTYP = 'S'.

MOVE L_MSTRING TO MESSAGES-MSG_S.

MOVE 'S' TO MESSAGES-MSGTYP.

ENDIF.

ENDIF.

CLEAR L_MSTRING.

ENDLOOP.

MOVE-CORRESPONDING RECORD TO MESSAGES.

SELECT SINGLE MAKTX INTO WK_MAKT FROM MAKT CLIENT SPECIFIED

WHERE MANDT = SY-MANDT

AND MATNR = MESSAGES-MATNR_005.

MOVE:WK_MAKT TO MESSAGES-MAKTX.

APPEND MESSAGES.

CLEAR: MESSAGES, WK_MAKT, MESSTAB1.

REFRESH MESSTAB1.

ENDLOOP.

ENDIF.

ENDFORM. "fill_bdc_table

--


FORM assign_columns--

FORM ASSIGN_COLUMNS .

REFRESH ALVFLD.

MOVE :'1' TO ALVFLD-COL_POS.

MOVE :'MATNR_005' TO ALVFLD-FIELDNAME.

MOVE :'PART NO' TO ALVFLD-SELTEXT_M.

MOVE :'X' TO ALVFLD-FIX_COLUMN.

APPEND ALVFLD.CLEAR ALVFLD.

MOVE :'2' TO ALVFLD-COL_POS.

MOVE :'MAKTX' TO ALVFLD-FIELDNAME.

MOVE :'DESCRIPTION' TO ALVFLD-SELTEXT_M.

APPEND ALVFLD.CLEAR ALVFLD.

MOVE :'3' TO ALVFLD-COL_POS.

MOVE :'WERKS_006' TO ALVFLD-FIELDNAME.

MOVE :'PLANT' TO ALVFLD-SELTEXT_M.

APPEND ALVFLD.CLEAR ALVFLD.

MOVE :'4' TO ALVFLD-COL_POS.

MOVE :'BUDAT_002' TO ALVFLD-FIELDNAME.

MOVE :'POSTING DATE' TO ALVFLD-SELTEXT_M.

APPEND ALVFLD.CLEAR ALVFLD.

MOVE :'5' TO ALVFLD-COL_POS.

MOVE :'BKTXT_004' TO ALVFLD-FIELDNAME.

MOVE :'SHIFT' TO ALVFLD-SELTEXT_M.

APPEND ALVFLD.CLEAR ALVFLD.

MOVE :'6' TO ALVFLD-COL_POS.

MOVE :'ERFMG_008' TO ALVFLD-FIELDNAME.

MOVE :'QTY' TO ALVFLD-SELTEXT_M.

APPEND ALVFLD.CLEAR ALVFLD.

MOVE :'7' TO ALVFLD-COL_POS.

MOVE :'ALORT_007' TO ALVFLD-FIELDNAME.

MOVE :'STGLOC' TO ALVFLD-SELTEXT_M.

APPEND ALVFLD.CLEAR ALVFLD.

MOVE :'8' TO ALVFLD-COL_POS.

MOVE :'MSG_E' TO ALVFLD-FIELDNAME.

MOVE :'ERRORS' TO ALVFLD-SELTEXT_M.

APPEND ALVFLD.CLEAR ALVFLD.

MOVE :'9' TO ALVFLD-COL_POS.

MOVE :'MSG_W' TO ALVFLD-FIELDNAME.

MOVE :'WARNINGS' TO ALVFLD-SELTEXT_M.

APPEND ALVFLD.CLEAR ALVFLD.

MOVE :'10' TO ALVFLD-COL_POS.

MOVE :'MSG_S' TO ALVFLD-FIELDNAME.

MOVE :'STATUS' TO ALVFLD-SELTEXT_M.

APPEND ALVFLD.CLEAR ALVFLD.

ENDFORM. " assign_columns

--


FORM f_event_build--

FORM F_EVENT_BUILD .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = V_EVENTS[].

READ TABLE V_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE

INTO WK_EVENTS.

WK_LAYOUT-COLTAB_FIELDNAME = 'CELLCOLOR'. "FOR COLOUMN COLOR

WK_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

IF SY-SUBRC = 0.

MOVE C_FORMNAME_TOP_OF_PAGE TO WK_EVENTS-FORM.

MODIFY V_EVENTS FROM WK_EVENTS INDEX SY-TABIX.

ENDIF.

ENDFORM. " f_event_build

--


FORM f_top_of_page--

FORM F_TOP_OF_PAGE.

WRITE SY-DATUM TO T_DATE.

CLEAR: IT_LIST_COMMENTS[].

WK_LIST_COMMENTS-TYP = 'H'. "H=Header, S=Selection, A=Action

WK_LIST_COMMENTS-KEY = ''.

WK_LIST_COMMENTS-INFO = 'UPLOAD STATUS FOR PRODUCTION POSTING'.

APPEND WK_LIST_COMMENTS TO IT_LIST_COMMENTS.

CLEAR WK_LIST_COMMENTS.

WK_LIST_COMMENTS-TYP = 'S'. "H=Header, S=Selection, A=Action

WK_LIST_COMMENTS-KEY = ''.

CONCATENATE 'Uploaded Date:' T_DATE INTO WK_LIST_COMMENTS-INFO

SEPARATED BY SPACE.

APPEND WK_LIST_COMMENTS TO IT_LIST_COMMENTS.

CLEAR WK_LIST_COMMENTS.

DESCRIBE TABLE MESSAGES LINES WK_LINES.

LINES = WK_LINES.

WK_LIST_COMMENTS-TYP = 'S'. "H=Header, S=Selection, A=Action

WK_LIST_COMMENTS-KEY = ''.

CONCATENATE 'Total No of records:' LINES INTO WK_LIST_COMMENTS-INFO

SEPARATED BY SPACE.

APPEND WK_LIST_COMMENTS TO IT_LIST_COMMENTS.

CLEAR WK_LIST_COMMENTS.

WK_LIST_COMMENTS-TYP = 'S'. "H=Header, S=Selection, A=Action

WK_LIST_COMMENTS-KEY = ''.

CONCATENATE 'Successfull Entries:' WK_SUCCESS INTO

WK_LIST_COMMENTS-INFO SEPARATED BY SPACE.

APPEND WK_LIST_COMMENTS TO IT_LIST_COMMENTS.

CLEAR WK_LIST_COMMENTS.

WK_LIST_COMMENTS-TYP = 'S'. "H=Header, S=Selection, A=Action

WK_LIST_COMMENTS-KEY = ''.

CONCATENATE 'Failed Entries:' WK_FAILURE INTO WK_LIST_COMMENTS-INFO

SEPARATED BY SPACE.

APPEND WK_LIST_COMMENTS TO IT_LIST_COMMENTS.

CLEAR WK_LIST_COMMENTS.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

I_LOGO = 'ENJOYSAP_LOGO'

IT_LIST_COMMENTARY = IT_LIST_COMMENTS.

ENDFORM. "F_TOP_OF_PAGE

--


FORM assign_colors--

FORM ASSIGN_COLORS .

LOOP AT MESSAGES.

CASE MESSAGES-MSGTYP.

WHEN 'E'.

MOVE: 'MATNR_005' TO WA_COLOR-FNAME.

MOVE '6' TO WA_COLOR-COLOR-COL.

MOVE '0' TO WA_COLOR-COLOR-INT.

MOVE '0' TO WA_COLOR-COLOR-INV.

APPEND WA_COLOR TO MESSAGES-CELLCOLOR.

MODIFY MESSAGES TRANSPORTING CELLCOLOR.

ENDCASE.

MOVE: 'MSG_E' TO WA_COLOR-FNAME.

MOVE '6' TO WA_COLOR-COLOR-COL.

MOVE '0' TO WA_COLOR-COLOR-INT.

MOVE '1' TO WA_COLOR-COLOR-INV.

APPEND WA_COLOR TO MESSAGES-CELLCOLOR.

MODIFY MESSAGES TRANSPORTING CELLCOLOR.

MOVE: 'MSG_W' TO WA_COLOR-FNAME.

MOVE '7' TO WA_COLOR-COLOR-COL.

MOVE '0' TO WA_COLOR-COLOR-INT.

MOVE '1' TO WA_COLOR-COLOR-INV.

APPEND WA_COLOR TO MESSAGES-CELLCOLOR.

MODIFY MESSAGES TRANSPORTING CELLCOLOR.

MOVE: 'MSG_S' TO WA_COLOR-FNAME.

MOVE '5' TO WA_COLOR-COLOR-COL.

MOVE '0' TO WA_COLOR-COLOR-INT.

MOVE '1' TO WA_COLOR-COLOR-INV.

APPEND WA_COLOR TO MESSAGES-CELLCOLOR.

MODIFY MESSAGES TRANSPORTING CELLCOLOR.

ENDLOOP.

ENDFORM. " assign_colors

--


FORM COUNT--

FORM COUNT .

LOOP AT MESSAGES.

CASE MESSAGES-MSGTYP.

WHEN 'E'.

ADD 1 TO WK_FAILURE.

WHEN 'S'.

ADD 1 TO WK_SUCCESS.

ENDCASE.

ENDLOOP.

ENDFORM. " COUNT

--


FORM ALV--

FORM ALV .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

I_BACKGROUND_ID = 'ALV_BACKGROUND'

IS_LAYOUT = WK_LAYOUT

IT_FIELDCAT = ALVFLD[]

IT_EVENTS = V_EVENTS[]

TABLES

T_OUTTAB = MESSAGES

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

ENDFORM. " ALV

--


FETCH_FROM_FLAT_FILE--

FORM FETCH_FROM_FLAT_FILE .

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_FILE

I_BEGIN_COL = 1 "From 1st Column

I_BEGIN_ROW = 2 "From 2nd row

I_END_COL = 7 "Till &th Column

I_END_ROW = 65000 "Till Row

TABLES

INTERN = IT_EXCEL

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

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. " FETCH_FROM_FLAT_FILE

0 Kudos

Seshu,

The code is big for me understand. Could you show change of color in particular field in the previous program u have sent which was easy for me to understand.

Thanks for your time

0 Kudos

Check the simple program :

report zxyz.

type-pools : slis.

tables : mara.

  • Internal table ( Data preparation)

data : begin of itab occurs 0,

matnr like mara-matnr,

qty like mara-BRGEW,

end of itab.

  • Internal Table for Output

data : begin of i_output occurs 0,

field type c, " Traffic Lights

matnr like mara-matnr,

qty like mara-BRGEW,

end of i_output.

DATA : V_REPID LIKE SY-REPID.

  • Variables for ALV

DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

FIELDCAT_LN LIKE LINE OF FIELDCAT,

SORTCAT TYPE SLIS_T_SORTINFO_ALV,

SORTCAT_LN LIKE LINE OF SORTCAT,

EVENTCAT TYPE SLIS_T_EVENT,

EVENTCAT_LN LIKE LINE OF EVENTCAT,

LAYOUT TYPE SLIS_LAYOUT_ALV,

C_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',

g_user_command TYPE slis_formname VALUE 'USER_COMMAND',

GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

DATA: COL_POS TYPE I,

P_LIGNAM TYPE SLIS_FIELDNAME VALUE 'FIELD'.

start-of-selection.

  • Postive qty

itab-matnr = '300'.

itab-qty = '10'.

append itab.

  • Zero qty

itab-matnr = '200'.

itab-qty = '0'.

append itab.

  • Negative qty

itab-matnr = '100'.

itab-qty = '-1'.

append itab.

sort itab by matnr.

loop at itab.

if itab-qty = 0.

  • Traffic Light - Yellow color Light

i_output-field = '2'.

elseif itab-qty < 0.

  • Traffic Light - Red color Light

i_output-field = '1'.

elseif itab-qty > 0.

  • Traffic Light - Green color Light

i_output-field = '3'.

endif.

move itab-matnr to i_output-matnr.

move itab-qty to i_output-qty.

append i_output.

clear : i_output,

itab.

endloop.

end-of-selection.

perform print_data.

end-of-selection.

&----


*& Form print_data

&----


  • ALV Data

----


FORM print_data.

  • Traffic Lights

PERFORM BUILD_LAYOUT.

perform fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = V_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = g_user_command

  • I_CALLBACK_TOP_OF_PAGE = C_TOP_OF_PAGE

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = LAYOUT

IT_FIELDCAT = FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_ADD_FIELDCAT =

  • IT_HYPERLINK =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IT_EXCEPT_QINFO =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = I_OUTPUT

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. " print_data

&----


*& Form fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fieldcat.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

  • Trafiic Light

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'FIELD'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 7.

LS_FIELDCAT-col_pos = '1'.

ls_fieldcat-seltext_L = 'Lights'.

ls_fieldcat-seltext_s = 'Lights'.

ls_fieldcat-seltext_m = 'Lights'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Material

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'MATNR'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 18.

LS_FIELDCAT-col_pos = '2'.

ls_fieldcat-seltext_L = 'Material #'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Qty

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'QTY'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 15.

LS_FIELDCAT-col_pos = '3'.

ls_fieldcat-seltext_L = 'Qty'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Description

ENDFORM. " fieldcat

&----


*& Form BUILD_LAYOUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BUILD_LAYOUT.

LAYOUT-GET_SELINFOS = 'X'.

LAYOUT-LIGHTS_FIELDNAME = P_LIGNAM.

layout-HEADER_TEXT = 'Lights'.

LAYOUT-LIGHTS_CONDENSE = 'X'.

ENDFORM. " BUILD_LAYOUT

Thanks

Seshu

0 Kudos

Seshu,

I need the particular negative value to be displayed in a color. But this program have traffic light and is seperate row. Could you help out. Thanks for your time

0 Kudos

How about this program :

report zxyz.

type-pools : slis.

tables : mara.

  • Internal table ( Data preparation)

data : begin of itab occurs 0,

matnr like mara-matnr,

qty like mara-BRGEW,

end of itab.

  • Internal Table for Output

data : begin of i_output occurs 0,

  • field type c, " Traffic Lights

matnr like mara-matnr,

qty like mara-BRGEW,

line_color(4) TYPE c, "Used to store row color attributes

end of i_output.

DATA : V_REPID LIKE SY-REPID.

  • Variables for ALV

DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

FIELDCAT_LN LIKE LINE OF FIELDCAT,

SORTCAT TYPE SLIS_T_SORTINFO_ALV,

SORTCAT_LN LIKE LINE OF SORTCAT,

EVENTCAT TYPE SLIS_T_EVENT,

EVENTCAT_LN LIKE LINE OF EVENTCAT,

LAYOUT TYPE SLIS_LAYOUT_ALV,

C_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',

g_user_command TYPE slis_formname VALUE 'USER_COMMAND',

GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

DATA: COL_POS TYPE I,

P_LIGNAM TYPE SLIS_FIELDNAME VALUE 'FIELD'.

start-of-selection.

  • Postive qty

itab-matnr = '300'.

itab-qty = '10'.

append itab.

  • Zero qty

itab-matnr = '200'.

itab-qty = '0'.

append itab.

  • Negative qty

itab-matnr = '100'.

itab-qty = '-1'.

append itab.

sort itab by matnr.

loop at itab.

if itab-qty < 0.

CONCATENATE 'C' '5' '10' INTO i_output-line_color.

  • i_output-line_color = '1'.

endif.

  • Traffic Light - Red color Light

move itab-matnr to i_output-matnr.

move itab-qty to i_output-qty.

append i_output.

clear : i_output,

itab.

endloop.

end-of-selection.

perform print_data.

end-of-selection.

&----


*& Form print_data

&----


  • ALV Data

----


FORM print_data.

  • Traffic Lights

PERFORM BUILD_LAYOUT.

perform fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = V_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = g_user_command

  • I_CALLBACK_TOP_OF_PAGE = C_TOP_OF_PAGE

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = LAYOUT

IT_FIELDCAT = FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_ADD_FIELDCAT =

  • IT_HYPERLINK =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IT_EXCEPT_QINFO =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = I_OUTPUT

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. " print_data

&----


*& Form fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fieldcat.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

    • Trafiic Light

  • CLEAR LS_FIELDCAT.

  • LS_FIELDCAT-FIELDNAME = 'FIELD'.

  • LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

  • LS_FIELDCAT-OUTPUTLEN = 7.

  • LS_FIELDCAT-col_pos = '1'.

  • ls_fieldcat-seltext_L = 'Lights'.

  • ls_fieldcat-seltext_s = 'Lights'.

  • ls_fieldcat-seltext_m = 'Lights'.

  • APPEND LS_FIELDCAT TO FIELDCAT.

  • Material

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'MATNR'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 18.

LS_FIELDCAT-col_pos = '2'.

ls_fieldcat-seltext_L = 'Material #'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Qty

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = 'QTY'.

LS_FIELDCAT-TABNAME = 'I_OUTPUT'.

LS_FIELDCAT-OUTPUTLEN = 15.

LS_FIELDCAT-col_pos = '3'.

ls_fieldcat-seltext_L = 'Qty'.

APPEND LS_FIELDCAT TO FIELDCAT.

  • Description

ENDFORM. " fieldcat

&----


*& Form BUILD_LAYOUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BUILD_LAYOUT.

layout-no_input = 'X'.

layout-colwidth_optimize = 'X'.

*layout-totals_text = 'Totals'(201).

  • Set layout field for row attributes(i.e. color)

layout-info_fieldname = 'LINE_COLOR'.

  • LAYOUT-GET_SELINFOS = 'X'.

  • LAYOUT-LIGHTS_FIELDNAME = P_LIGNAM.

  • layout-HEADER_TEXT = 'Lights'.

  • LAYOUT-LIGHTS_CONDENSE = 'X'.

*

ENDFORM. " BUILD_LAYOUT

colors will vary,Right now i setup green color for negative value

if itab-qty < 0.

CONCATENATE 'C' '<b>5'</b> '10' INTO i_output-line_color.

endif.

see the bold one - here it is 5 - Green color,if you need other color test them like 1 ,2,3,4,6,7 ( You can setup upto 7 color's).

Thanks

Seshu

0 Kudos

Seshu.

I am not getting any color change for negative values from above program u provided.

Thanks

0 Kudos

Seshu

The Program changes color for the entire line. I need to change only the particular CELL. Since i have number of Qty fields in Buckets.

Thanks