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: 

ALV List Cell Coloring

Former Member
0 Kudos

Hi,

I have done the coding for coloring the row in an ALV list.

Can anyone guide me how to color a cell in the ALV list/Grid ?

8 REPLIES 8

Former Member
0 Kudos

Hi,

check this report:

&----


*& Report Z_VA05_REPORT

*&

&----


*&

*&

&----


REPORT z_va05_report MESSAGE-ID ZVKK.

TYPE-POOLS: slis.

TABLES: vbcom,vbak.

*Internal tables declaration

DATA: BEGIN OF it_vbak OCCURS 0,

audat LIKE vbak-audat,

auart LIKE vbak-auart,

vbeln LIKE vbak-vbeln,

kunnr LIKE vbak-kunnr,

erdat LIKE vbak-erdat,

ernam LIKE vbak-ernam,

END OF it_vbak.

DATA: BEGIN OF it_vbap OCCURS 0,

vbeln LIKE vbap-vbeln,

abgru LIKE vbap-abgru,

posnr LIKE vbap-posnr,

matnr LIKE vbap-matnr,

arktx LIKE vbap-arktx,

charg LIKE vbap-charg,

netpr LIKE vbap-netpr,

netwr LIKE vbap-netwr,

werks LIKE vbap-werks,

vstel LIKE vbap-vstel,

END OF it_vbap.

DATA:BEGIN OF it_vbep OCCURS 0,

vbeln TYPE vbep-vbeln,

posnr LIKE vbep-posnr,

wmeng LIKE vbep-wmeng,

bmeng LIKE vbep-bmeng,

wadat LIKE vbep-wadat,

edatu LIKE vbep-edatu,

END OF it_vbep.

DATA: BEGIN OF it_kna1 OCCURS 0,

kunnr LIKE kna1-kunnr,

name1 LIKE kna1-name1,

END OF it_kna1.

DATA: BEGIN OF it_vbkd OCCURS 0,

vbeln LIKE vbkd-vbeln,

posnr LIKE vbkd-posnr,

bstkd LIKE vbkd-bstkd,

END OF it_vbkd.

DATA: BEGIN OF it_status OCCURS 0,

vbeln LIKE vbuk-vbeln,

lfstk LIKE vbuk-lfstk,

statu LIKE vbmtv-statu,

END OF it_status.

DATA: BEGIN OF it_final OCCURS 0,

chk ,

audat LIKE vbak-audat,

auart LIKE vbak-auart,

abgru LIKE vbap-abgru,

posnr LIKE vbap-posnr,

vbeln LIKE vbak-vbeln,

kunnr LIKE vbak-kunnr,

name1 LIKE kna1-name1,

matnr LIKE vbap-matnr,

arktx LIKE vbap-arktx,

  • wmeng LIKE vbep-wmeng,

  • vrkme LIKE vbep-vrkme,

  • bmeng LIKE vbep-bmeng,

wmeng type p decimals 0,

bmeng type p decimals 0,

charg LIKE vbap-charg,

netpr LIKE vbap-netpr,

  • waerk LIKE vbap-waerk,

waers like tcurc-waers,

netwr LIKE vbap-netwr,

bstkd LIKE vbkd-bstkd,

wadat LIKE vbep-wadat,

edatu LIKE vbep-edatu,

lfstk LIKE vbuk-lfstk,

statu LIKE vbmtv-statu,

erdat LIKE vbak-erdat,

ernam LIKE vbak-ernam,

werks LIKE vbap-werks,

vstel LIKE vbap-vstel,

END OF it_final.

DATA: g_repid LIKE sy-repid,

v_tabix LIKE sy-tabix,

it_fieldcat TYPE slis_t_fieldcat_alv,

wa_fieldcat TYPE slis_fieldcat_alv,

wa_layout TYPE slis_layout_alv.

DATA:it_bdcdata TYPE bdcdata OCCURS 0 WITH HEADER LINE.

DATA: v_count TYPE i.

*selection screen

SELECT-OPTIONS : s_kunnr FOR vbak-kunnr NO-EXTENSION NO INTERVALS,

s_matnr FOR vbcom-matnr NO-EXTENSION NO INTERVALS,

s_bstkd FOR vbcom-bstkd NO-EXTENSION NO INTERVALS.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-003.

SELECT-OPTIONS: s_vkorg FOR vbak-vkorg NO-EXTENSION NO INTERVALS,

s_vtweg FOR vbak-vtweg NO-EXTENSION NO INTERVALS,

s_spart FOR vbak-spart NO-EXTENSION NO INTERVALS,

s_vkbur FOR vbak-vkbur NO-EXTENSION NO INTERVALS,

s_vkgrp FOR vbak-vkgrp NO-EXTENSION NO INTERVALS.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_audat FOR vbcom-audat,

s_ernam FOR vbak-ernam NO-EXTENSION NO INTERVALS.

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-002.

PARAMETERS: p_open RADIOBUTTON GROUP rad1,

p_all RADIOBUTTON GROUP rad1 DEFAULT 'X'.

PARAMETERS: p_chk AS CHECKBOX .

SELECTION-SCREEN END OF BLOCK b3.

AT SELECTION-SCREEN.

IF P_CHK = 'X'.

IF S_ERNAM IS INITIAL.

MESSAGE E000." WITH text-007.

endif.

ENDIF.

*INITIALIZATION

INITIALIZATION.

g_repid = sy-repid.

START-OF-SELECTION.

PERFORM get_data.

END-OF-SELECTION.

PERFORM prepare_fieldcat.

PERFORM alv_layout.

PERFORM grid_alvdisp.

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data .

if p_chk = 'X'.

SELECT audat

auart

vbeln

kunnr

erdat

ernam

FROM vbak

INTO TABLE it_vbak

WHERE kunnr IN s_kunnr AND

audat IN s_audat AND

vkorg IN s_vkorg AND

vtweg IN s_vtweg AND

spart IN s_spart AND

vkbur IN s_vkbur AND

vkgrp IN s_vkgrp AND

ernam in s_ernam.

else.

SELECT audat

auart

vbeln

kunnr

erdat

ernam

FROM vbak

INTO TABLE it_vbak

WHERE kunnr IN s_kunnr AND

audat IN s_audat AND

vkorg IN s_vkorg AND

vtweg IN s_vtweg AND

spart IN s_spart AND

vkbur IN s_vkbur AND

vkgrp IN s_vkgrp.

endif.

if it_vbak[] is not initial.

SELECT vbeln

abgru

posnr

matnr

arktx

charg

netpr

netwr

werks

vstel

FROM vbap

INTO TABLE it_vbap

FOR ALL ENTRIES IN it_vbak

WHERE matnr IN s_matnr AND

vbeln = it_vbak-vbeln.

endif.

if it_vbap[] is not initial.

SELECT vbeln

posnr

wmeng

bmeng

wadat

edatu FROM vbep

INTO TABLE it_vbep

FOR ALL ENTRIES IN it_vbap

WHERE vbeln = it_vbap-vbeln

AND posnr = it_vbap-posnr.

endif.

if it_vbap[] is not initial.

SELECT vbeln

posnr

bstkd FROM vbkd

INTO TABLE it_vbkd

FOR ALL ENTRIES IN it_vbap

WHERE vbeln = it_vbap-vbeln

AND posnr = it_vbap-posnr

AND bstkd IN s_bstkd.

endif.

if it_vbak[] is not initial.

SELECT kunnr

name1 FROM kna1

INTO TABLE it_kna1

FOR ALL ENTRIES IN it_vbak

WHERE kunnr = it_vbak-kunnr .

endif.

if it_vbak[] is not initial.

SELECT vbeln

lfstk FROM vbuk

INTO CORRESPONDING FIELDS OF TABLE it_status

FOR ALL ENTRIES IN it_vbak

WHERE vbeln = it_vbak-vbeln.

endif.

LOOP AT it_status.

IF it_status-lfstk = 'A'.

it_status-statu = 'Not delivered'.

ELSEIF it_status-lfstk = 'B'.

it_status-statu = 'Partially completed'.

ELSEIF it_status-lfstk = 'C'.

it_status-statu = 'Completed'.

ENDIF .

MODIFY it_status INDEX sy-tabix.

CLEAR it_status.

ENDLOOP.

LOOP AT it_vbak.

*loop at it_vbap where vbeln = it_vbak-vbeln.

MOVE: it_vbak-audat TO it_final-audat,

it_vbak-auart TO it_final-auart,

it_vbak-vbeln TO it_final-vbeln,

it_vbak-kunnr TO it_final-kunnr,

it_vbak-erdat TO it_final-erdat,

it_vbak-ernam TO it_final-ernam.

READ TABLE it_vbap WITH KEY vbeln = it_vbak-vbeln.

IF sy-subrc = 0.

MOVE: it_vbap-abgru TO it_final-abgru,

it_vbap-posnr TO it_final-posnr,

it_vbap-matnr TO it_final-matnr,

it_vbap-arktx TO it_final-arktx,

it_vbap-charg TO it_final-charg,

it_vbap-netpr TO it_final-netpr,

it_vbap-netwr TO it_final-netwr,

it_vbap-werks TO it_final-werks,

it_vbap-vstel TO it_final-vstel.

ENDIF.

READ TABLE it_vbep WITH KEY vbeln = it_vbap-vbeln

posnr = it_vbap-posnr.

IF sy-subrc = 0.

MOVE: it_vbep-wmeng TO it_final-wmeng,

it_vbep-bmeng TO it_final-bmeng,

it_vbep-wadat TO it_final-wadat,

it_vbep-edatu TO it_final-edatu.

ENDIF.

READ TABLE it_vbkd WITH KEY vbeln = it_vbap-vbeln

posnr = it_vbap-posnr.

IF sy-subrc = 0.

MOVE: it_vbkd-bstkd TO it_final-bstkd.

ENDIF.

READ TABLE it_kna1 WITH KEY kunnr = it_vbak-kunnr.

IF sy-subrc = 0.

MOVE: it_kna1-name1 TO it_final-name1.

ENDIF.

READ TABLE it_status WITH KEY vbeln = it_vbak-vbeln.

IF sy-subrc = 0.

MOVE: it_status-lfstk TO it_final-lfstk.

MOVE: it_status-statu TO it_final-statu.

ENDIF.

it_final-waers = 'JPY'.

APPEND it_final.

CLEAR it_final.

  • endloop.

ENDLOOP.

SORT it_final BY vbeln DESCENDING

posnr ASCENDING.

IF p_open = 'X'.

LOOP AT it_final WHERE lfstk NE 'A'.

DELETE it_final.

ENDLOOP.

ENDIF.

ENDFORM. " get_data

&----


*& Form prepare_fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM prepare_fieldcat .

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = g_repid

i_internal_tabname = 'IT_FINAL'

  • I_STRUCTURE_NAME = I_STRUCTURE_NAME

  • I_CLIENT_NEVER_DISPLAY = 'X'

i_inclname = g_repid

  • I_BYPASSING_BUFFER = I_BYPASSING_BUFFER

  • I_BUFFER_ACTIVE = I_BUFFER_ACTIVE

CHANGING

ct_fieldcat = it_fieldcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 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.

LOOP AT it_fieldcat INTO wa_fieldcat.

v_tabix = sy-tabix.

wa_fieldcat-key = ' '.

CASE wa_fieldcat-fieldname.

WHEN 'WMENG'.

wa_fieldcat-seltext_s = 'Order Qty'.

wa_fieldcat-seltext_l = 'Order Quantity'.

  • wa_fieldcat-datatype = 'QUAN'.

  • wa_fieldcat-decimals_out = '0'.

    • wa_fieldcat-ref_tabname = 'IT_FINAL'.

    • wa_fieldcat-ref_fieldname = 'VRKME'.

WHEN 'BMENG'.

wa_fieldcat-seltext_s = 'Confirmed Qty'.

wa_fieldcat-seltext_l = 'Confirmed Quantity'.

WHEN 'WAERS'.

wa_fieldcat-no_out = 'X'.

WHEN 'CHK'.

wa_fieldcat-no_out = 'X'.

WHEN 'NETPR'.

wa_fieldcat-tabname = 'IT_FINAL'.

wa_fieldcat-Cfieldname = 'WAERS'.

WHEN 'NETWR'.

wa_fieldcat-tabname = 'IT_FINAL'.

wa_fieldcat-Cfieldname = 'WAERS'.

ENDCASE.

MODIFY it_fieldcat FROM wa_fieldcat INDEX v_tabix.

ENDLOOP.

ENDFORM. " prepare_fieldcat

&----


*& Form alv_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM alv_layout .

wa_layout-box_fieldname = 'CHK'.

*WA_LAYOUT-edit = 'X'.

ENDFORM. " alv_layout

&----


*& Form GRID_ALVDISP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM grid_alvdisp .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = g_repid

i_callback_pf_status_set = 'PF_STATUS'

i_callback_user_command = 'USER_COMMAND'

i_callback_top_of_page = 'TOP-OF-PAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME = I_STRUCTURE_NAME

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE = I_GRID_TITLE

  • I_GRID_SETTINGS = I_GRID_SETTINGS

is_layout = wa_layout

it_fieldcat = it_fieldcat

  • IT_EXCLUDING = IT_EXCLUDING

  • IT_SPECIAL_GROUPS = IT_SPECIAL_GROUPS

  • IT_SORT = IT_SORT

  • IT_FILTER = IT_FILTER

  • IS_SEL_HIDE = IS_SEL_HIDE

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT = IS_VARIANT

  • IT_EVENTS = IT_EVENTS

  • IT_EVENT_EXIT = IT_EVENT_EXIT

  • IS_PRINT = IS_PRINT

  • IS_REPREP_ID = IS_REPREP_ID

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS = IT_ALV_GRAPHICS

  • IT_HYPERLINK = IT_HYPERLINK

  • IT_ADD_FIELDCAT = IT_ADD_FIELDCAT

  • IT_EXCEPT_QINFO = IT_EXCEPT_QINFO

  • IR_SALV_FULLSCREEN_ADAPTER = IR_SALV_FULLSCREEN_ADAPTER

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER = E_EXIT_CAUSED_BY_CALLER

  • ES_EXIT_CAUSED_BY_USER = ES_EXIT_CAUSED_BY_USER

TABLES

t_outtab = it_final

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

&----


*& Form pf_status

&----


  • text

----


  • -->I_EXTAB text

----


FORM pf_status USING i_extab TYPE slis_t_extab.

SET PF-STATUS 'HEADER'.

ENDFORM. "pf_status

&----


*& Form TOP-OF-PAGE

&----


  • text

----


FORM top-of-page.

DATA: t_header TYPE slis_t_listheader,

wa_header TYPE slis_listheader.

  • Title

wa_header-typ = 'H'.

wa_header-info = 'List of Sales Orders'.

APPEND wa_header TO t_header.

CLEAR wa_header.

READ TABLE it_final INDEX sy-tabix.

wa_header-typ = 'S'.

wa_header-key = 'Sold-to party'.

wa_header-info = it_final-kunnr.

APPEND wa_header TO t_header.

CLEAR: wa_header.

wa_header-typ = 'S'.

wa_header-info = it_final-name1.

APPEND wa_header TO t_header.

CLEAR: wa_header.

wa_header-typ = 'S'.

wa_header-key = 'Doc.date'.

CONCATENATE s_audat-low+6(2) '.'

s_audat-low+4(2) '.'

s_audat-low+0(4)

'To' s_audat-high+6(2) '.'

s_audat-high+4(2) '.'

s_audat-high+0(4)

INTO wa_header-info.

APPEND wa_header TO t_header.

CLEAR: wa_header.

*

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header.

ENDFORM. "TOP-OF-PAGE

&----


*& Form user_command

&----


  • text

----


  • -->P_UCOMM text

  • -->P_SELFIELD text

----


FORM user_command USING p_ucomm LIKE sy-ucomm

p_selfield TYPE slis_selfield.

READ TABLE it_final INDEX p_selfield-tabindex.

CASE p_ucomm.

WHEN 'HEADER'.

PERFORM get_header.

ENDCASE.

ENDFORM. "user_command

&----


*& Form get_header

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_header .

CLEAR v_count.

LOOP AT it_final WHERE chk = 'X'.

v_count = v_count + 1.

IF v_count GT 1.

MESSAGE E001 WITH 'Choose only one record'.

ENDIF.

ENDLOOP.

REFRESH it_bdcdata.

PERFORM bdc_dynpro USING 'SAPMV45A' '0102'.

PERFORM bdc_field USING 'BDC_CURSOR'

'VBAK-VBELN'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'VBAK-VBELN'

it_final-vbeln.

PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=KKAU'.

CALL TRANSACTION 'VA03' USING it_bdcdata

MODE 'E'.

ENDFORM. " get_header

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->PROGRAM text

  • -->DYNPRO text

----


FORM bdc_dynpro USING program dynpro.

CLEAR it_bdcdata.

it_bdcdata-program = program.

it_bdcdata-dynpro = dynpro.

it_bdcdata-dynbegin = 'X'.

APPEND it_bdcdata.

ENDFORM. "bdc_dynpro

&----


*& Form bdc_field

&----


  • text

----


  • -->FNAM text

  • -->FVAL text

----


FORM bdc_field USING fnam fval.

IF fval <> space.

CLEAR it_bdcdata.

it_bdcdata-fnam = fnam.

it_bdcdata-fval = fval.

APPEND it_bdcdata.

ENDIF.

ENDFORM. "bdc_field

Thanks,

Keerthi.

Former Member
0 Kudos

In type pool SLIS there is one field KEY in field catalog work area : slis_fieldcat_main0---

key(1) type c, " column with key-color

goto ABAP Programming and provide there corresponding key values (0--9) .

I think you might got the required output.

Reg,

venkat.

Former Member
0 Kudos

http://www.saptechnical.com/Tutorials/ALV/ColorSALV/Demo.htm

REPORT ZALV_LIST1.

TABLES:

SPFLI.

TYPE-POOLS:

SLIS.

PARAMETERS:

P_COL TYPE I ,

P_ROW TYPE I,

P_COLOR(4) TYPE C .

DATA:

T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

FS_FIELDCAT LIKE LINE OF T_FIELDCAT,

FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,

W_COLOR(4) ,

W_ROW TYPE I,

W_FIELDNAME(20),

W_PROG TYPE SY-REPID.

DATA:

BEGIN OF T_SPFLI OCCURS 0,

COLOR(4),

CHECKBOX ,

CELL TYPE SLIS_T_SPECIALCOL_ALV,

CARRID TYPE SPFLI-CARRID,

CONNID TYPE SPFLI-CONNID,

CITYFROM TYPE SPFLI-CITYFROM,

CITYTO TYPE SPFLI-CITYTO,

DISTANCE TYPE SPFLI-DISTANCE,

END OF T_SPFLI.

DATA:

FS_CELL LIKE LINE OF T_SPFLI-CELL.

SELECT *

FROM SPFLI

INTO CORRESPONDING FIELDS OF TABLE T_SPFLI.

W_COLOR = P_COLOR.

T_SPFLI-COLOR = P_COLOR.

IF P_COL IS INITIAL AND P_ROW GT 0.

MODIFY T_SPFLI INDEX P_ROW TRANSPORTING COLOR.

ENDIF.

FS_FIELDCAT-FIELDNAME = 'CARRID'.

FS_FIELDCAT-REF_TABNAME = 'SPFLI'.

FS_FIELDCAT-COL_POS = 1.

FS_FIELDCAT-KEY = 'X'.

FS_FIELDCAT-HOTSPOT = 'X'.

APPEND FS_FIELDCAT TO T_FIELDCAT.

CLEAR FS_FIELDCAT .

FS_FIELDCAT-FIELDNAME = 'CONNID'.

FS_FIELDCAT-REF_TABNAME = 'SPFLI'.

FS_FIELDCAT-COL_POS = 2.

FS_FIELDCAT-KEY = 'X'.

FS_FIELDCAT-HOTSPOT = 'X'.

APPEND FS_FIELDCAT TO T_FIELDCAT.

CLEAR FS_FIELDCAT .

FS_FIELDCAT-FIELDNAME = 'DISTANCE'.

FS_FIELDCAT-REF_TABNAME = 'SPFLI'.

FS_FIELDCAT-COL_POS = 3.

FS_FIELDCAT-KEY = ' '.

FS_FIELDCAT-EDIT = 'X'.

APPEND FS_FIELDCAT TO T_FIELDCAT.

CLEAR FS_FIELDCAT.

FS_FIELDCAT-FIELDNAME = 'CITYFROM'.

FS_FIELDCAT-REF_TABNAME = 'SPFLI'.

FS_FIELDCAT-COL_POS = 4.

FS_FIELDCAT-KEY = ' '.

APPEND FS_FIELDCAT TO T_FIELDCAT.

LOOP AT T_FIELDCAT INTO FS_FIELDCAT.

IF FS_FIELDCAT-COL_POS EQ P_COL.

FS_FIELDCAT-EMPHASIZE = P_COLOR.

W_FIELDNAME = FS_FIELDCAT-FIELDNAME.

IF P_ROW IS INITIAL AND P_COL GT 0.

MODIFY T_FIELDCAT FROM FS_FIELDCAT TRANSPORTING EMPHASIZE.

ENDIF.

ENDIF.

ENDLOOP.

FS_CELL-FIELDNAME = W_FIELDNAME .

FS_CELL-COLOR-COL = 6.

FS_CELL-NOKEYCOL = 'X'.

APPEND FS_CELL TO T_SPFLI-CELL.

IF P_ROW IS NOT INITIAL AND P_COL IS NOT INITIAL.

MODIFY T_SPFLI INDEX P_ROW TRANSPORTING CELL.

ENDIF.

FS_LAYOUT-INFO_FIELDNAME = 'COLOR'.

FS_LAYOUT-BOX_FIELDNAME = 'CHECKBOX'.

FS_LAYOUT-COLTAB_FIELDNAME = 'CELL'.

FS_LAYOUT-F2CODE = '&ETA'.

W_PROG = SY-REPID.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = W_PROG

IS_LAYOUT = FS_LAYOUT

IT_FIELDCAT = T_FIELDCAT

TABLES

T_OUTTAB = T_SPFLI

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.

Former Member
0 Kudos

Hi,

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

  • Use of colours in ALV grid (cell, line and column) *

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

  • Table

TABLES : mara.

  • Type

TYPES : BEGIN OF ty_mara,

matnr LIKE mara-matnr,

matkl LIKE mara-matkl,

counter(4) TYPE n,

free_text(15) TYPE c,

color_line(4) TYPE c, " Line color

color_cell TYPE lvc_t_scol, " Cell color

END OF ty_mara.

  • Structures

DATA : wa_mara TYPE ty_mara,

wa_fieldcat TYPE lvc_s_fcat,

is_layout TYPE lvc_s_layo,

wa_color TYPE lvc_s_scol.

  • Internal table

DATA : it_mara TYPE STANDARD TABLE OF ty_mara,

it_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,

it_color TYPE TABLE OF lvc_s_scol.

  • Variables

DATA : okcode LIKE sy-ucomm,

w_alv_grid TYPE REF TO cl_gui_alv_grid,

w_docking_container TYPE REF TO cl_gui_docking_container.

PARAMETERS : p_column AS CHECKBOX,

p_line AS CHECKBOX,

p_cell AS CHECKBOX.

START-OF-SELECTION.

PERFORM get_data.

END-OF-SELECTION.

PERFORM fill_catalog.

PERFORM fill_layout.

CALL SCREEN 2000.

&----


*& Module status_2000 OUTPUT

&----


  • text

----


MODULE status_2000 OUTPUT.

SET PF-STATUS '2000'.

ENDMODULE. " status_2000 OUTPUT

&----


*& Module user_command_2000 INPUT

&----


  • text

----


MODULE user_command_2000 INPUT.

DATA : w_okcode LIKE sy-ucomm.

MOVE okcode TO w_okcode.

CLEAR okcode.

CASE w_okcode.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " user_command_2000 INPUT

&----


*& Module alv_grid OUTPUT

&----


  • text

----


MODULE alv_grid OUTPUT.

IF w_docking_container IS INITIAL.

PERFORM create_objects.

PERFORM display_alv_grid.

ENDIF.

ENDMODULE. " alv_grid OUTPUT

&----


*& Form create_objects

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM create_objects.

  • Ratio must be included in [5..95]

CREATE OBJECT w_docking_container

EXPORTING

ratio = 95

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

others = 6.

CREATE OBJECT w_alv_grid

EXPORTING

i_parent = w_docking_container.

ENDFORM. " create_objects

&----


*& Form display_alv_grid

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_alv_grid.

CALL METHOD w_alv_grid->set_table_for_first_display

EXPORTING

is_layout = is_layout

CHANGING

it_outtab = it_mara

it_fieldcatalog = it_fieldcat

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

ENDFORM. " display_alv_grid

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data.

SELECT * FROM mara UP TO 5 ROWS.

CLEAR : wa_mara-color_line, wa_mara-color_cell.

MOVE-CORRESPONDING mara TO wa_mara.

ADD 1 TO wa_mara-counter.

MOVE 'Blabla' TO wa_mara-free_text.

IF wa_mara-counter = '0002'

AND p_line = 'X'.

  • Color line

MOVE 'C410' TO wa_mara-color_line.

ELSEIF wa_mara-counter = '0004'

AND p_cell = 'X'.

  • Color cell

MOVE 'FREE_TEXT' TO wa_color-fname.

MOVE '5' TO wa_color-color-col.

MOVE '1' TO wa_color-color-int.

MOVE '1' TO wa_color-color-inv.

APPEND wa_color TO it_color.

wa_mara-color_cell[] = it_color[].

ENDIF.

APPEND wa_mara TO it_mara.

ENDSELECT.

ENDFORM. " get_data

&----


*& Form fill_catalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fill_catalog.

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

  • Colour code : *

  • Colour is a 4-char field where : *

  • - 1st char = C (color property) *

  • - 2nd char = color code (from 0 to 7) *

  • 0 = background color *

  • 1 = blue *

  • 2 = gray *

  • 3 = yellow *

  • 4 = blue/gray *

  • 5 = green *

  • 6 = red *

  • 7 = orange *

  • - 3rd char = intensified (0=off, 1=on) *

  • - 4th char = inverse display (0=off, 1=on) *

  • *

  • Colour overwriting priority : *

  • 1. Line *

  • 2. Cell *

  • 3. Column *

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

DATA : w_position TYPE i VALUE '1'.

CLEAR wa_fieldcat.

MOVE w_position TO wa_fieldcat-col_pos.

MOVE 'MATNR' TO wa_fieldcat-fieldname.

MOVE 'MARA' TO wa_fieldcat-ref_table.

MOVE 'MATNR' TO wa_fieldcat-ref_field.

APPEND wa_fieldcat TO it_fieldcat.

ADD 1 TO w_position.

CLEAR wa_fieldcat.

MOVE w_position TO wa_fieldcat-col_pos.

MOVE 'MATKL' TO wa_fieldcat-fieldname.

MOVE 'MARA' TO wa_fieldcat-ref_table.

MOVE 'MATKL' TO wa_fieldcat-ref_field.

  • Color column

IF p_column = 'X'.

MOVE 'C610' TO wa_fieldcat-emphasize.

ENDIF.

APPEND wa_fieldcat TO it_fieldcat.

ADD 1 TO w_position.

CLEAR wa_fieldcat.

MOVE w_position TO wa_fieldcat-col_pos.

MOVE 'COUNTER' TO wa_fieldcat-fieldname.

MOVE 'N' TO wa_fieldcat-inttype.

MOVE '4' TO wa_fieldcat-intlen.

MOVE 'Counter' TO wa_fieldcat-coltext.

APPEND wa_fieldcat TO it_fieldcat.

ADD 1 TO w_position.

CLEAR wa_fieldcat.

MOVE w_position TO wa_fieldcat-col_pos.

MOVE 'FREE_TEXT' TO wa_fieldcat-fieldname.

MOVE 'C' TO wa_fieldcat-inttype.

MOVE '20' TO wa_fieldcat-intlen.

MOVE 'Text' TO wa_fieldcat-coltext.

APPEND wa_fieldcat TO it_fieldcat.

ENDFORM. " fill_catalog

&----


*& Form fill_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM fill_layout.

  • Field that identify color line in internal table

MOVE 'COLOR_LINE' TO is_layout-info_fname.

  • Field that identify cell color in inetrnal table

MOVE 'COLOR_CELL' TO is_layout-ctab_fname.

ENDFORM. " fill_layout

Flow logic code

PROCESS BEFORE OUTPUT.

MODULE status_2000.

MODULE alv_grid.

PROCESS AFTER INPUT.

MODULE user_command_2000.

Thanks,

Bindu.

Former Member
0 Kudos

Hi ManjuNath..

Answer to ur query is:

Coloring Individual Cells

The procedure is similar to coloring an entire row. However, since an individual cell can be addressed with two parameters we will need something more. What is meant by “more” is a table type structure to be included into the structure of the list data table. It seems strange, because including it will make our list data structure deep. But anyhow ALV Grid control handles this.

The structure that should be included must be of type “LVC_T_SCOL”. If you want to color the entire row, this inner table should contain only one row with field “fname” is set to space, some color value at field “col”, “0” or “1” at fields “int” (intensified) and “inv” (inverse).

If you want to color individual cells, then for each cell column, append a line to this inner table which also contains the column name at field “fname”. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table. But, it is also obvious that, this will be more time consuming than the method at section C.6.1.

Again key field coloring will override your settings. That’s why, we have another field in this inner table called “nokeycol”. For each field represented in the inner table, set this field to ‘X’ to prevent overriding of key color settings.

In this procedure, again we must tell the control the name of the inner table containing color data. The field “CTAB_FNAME” of the layout structure is used for this purpose.

Code Part 14 – Adding inner table that will contain cell color data

Internal table holding list data

DATA BEGIN OF gt_list OCCURS 0 .

INCLUDE STRUCTURE SFLIGHT .

DATA rowcolor(4) TYPE c .

DATA cellcolors TYPE lvc_t_scol .

DATA END OF gt_list .

Code Part 15 – A sample code to make the cell at row 5 and column ‘SEATSOCC’ colored

DATA ls_cellcolor TYPE lvc_s_scol .

...

READ TABLE gt_list INDEX 5 .

ls_cellcolor-fname = 'SEATSOCC' .

ls_cellcolor-color-col = '7' .

ls_cellcolor-color-int = '1' .

APPEND ls_cellcolor TO gt_list-cellcolors .

MODIFY gt_list INDEX 5 .

A

Please reward if helpful

regards

- Rishika bawa

Former Member
0 Kudos

Hi Manjunath

To add color to a cell in ALV, we've one field attribute in the fieldcatalog structure i.e. emphasize.

Value 'CXYZ' is to be passed to the field attribute 'emphasize'.

Here the range of values for X, Y is 1 to 9

for value of Z, we've '0' and '1'

i.e. '1' is for Inverse color

'0' for normal.

'Inverse' includes background color too.

eg. data : cat type slis_fieldcat_alv,

fcat type slis_t_fieldcat_alv.

cat-fieldname = ' '.

cat-tabname = ' '.

cat-ref_fieldname = ' '.

cat_ref_tabname = ' '.

cat-emphasize = 'c110'.

append cat to fcat.

If u find it helpful, reward me plz.

Thanks

Suren

venkat_o
Active Contributor
0 Kudos

Hi Manjunath, Check the simple program. Description has been mentioned wherever it is needed. Just check.


 REPORT  zvenkat_alv_color_col.
*&---------------------------------------------------------------------*
" Declaration
"types
TYPES:
     BEGIN OF t_pa0001,
       pernr    TYPE pa0001-pernr,
       ename    TYPE pa0001-ename,
     END OF t_pa0001.
"Work area
DATA:
      w_pa0001 TYPE t_pa0001.
"Internal tables
DATA:
      i_pa0001 TYPE STANDARD TABLE OF t_pa0001.
*&---------------------------------------------------------------------*
* ALV Declarations
*----------------------------------------------------------------------*
* Types Pools
TYPE-POOLS:
   slis.
* Types
TYPES:
   t_fieldcat         TYPE slis_fieldcat_alv,
   t_layout           TYPE slis_layout_alv.
* Workareas
DATA:
   w_fieldcat         TYPE t_fieldcat,
   w_layout           TYPE t_layout.
* Internal Tables
DATA:
   i_fieldcat         TYPE STANDARD TABLE OF t_fieldcat.
*&---------------------------------------------------------------------*
*&START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION .
  PERFORM get_data.
*&---------------------------------------------------------------------*
*&END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM fieldcat.
  PERFORM dispaly .
*&---------------------------------------------------------------------*
  " Form  fieldcat
  "emphasize ===== Set this to highlight column in color
  " Value range: SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)
  " 'X' = The column is highlighted in the default color for color highlighting.
  " 'Cxyz' = The column is highlighted in the coded color:
  " C: Color (coding must start with C)
  " x: Color number
  " y: Intensified
  " z: Inverse
*&---------------------------------------------------------------------*
FORM fieldcat .

  CLEAR :
  w_fieldcat,i_fieldcat[].

  w_fieldcat-col_pos   = 1.
  w_fieldcat-row_pos   = 1.
  w_fieldcat-fieldname = 'PERNR'.
  w_fieldcat-tabname   = 'I_PA0001'.
  w_fieldcat-emphasize = 'C71'.               "Setting Color for Column
  w_fieldcat-seltext_m = 'Employee No'.
  w_fieldcat-no_zero   = 'PERNR'.
  APPEND w_fieldcat TO i_fieldcat.
  CLEAR w_fieldcat.

  w_fieldcat-col_pos   = 2.
  w_fieldcat-row_pos   = 1.
  w_fieldcat-outputlen   = '200'.
  w_fieldcat-fieldname = 'ENAME'.
  w_fieldcat-tabname   = 'I_PA0001'.
  w_fieldcat-seltext_l = 'ENAME'.
  APPEND w_fieldcat TO i_fieldcat.
  CLEAR w_fieldcat.

ENDFORM.                    " fieldcat
*&---------------------------------------------------------------------*
*&      Form  dispaly
*&---------------------------------------------------------------------*
FORM dispaly .

  DATA :l_program TYPE sy-repid.
  l_program = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program          = l_program
      is_layout                   = w_layout
      it_fieldcat                 = i_fieldcat
    TABLES
      t_outtab                    = i_pa0001.
  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.                    " dispaly
*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
FORM get_data .
  DO 20 TIMES.
    SELECT pernr ename
    FROM pa0001
    APPENDING CORRESPONDING FIELDS OF TABLE i_pa0001
    UP TO 10 ROWS.
  ENDDO.
ENDFORM.                    " get_data 

Regards, Venkat.O

Former Member
0 Kudos

I Myself solved the issue.