Application Development and Automation 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: 
Read only

Interactive ALV ?

Former Member
0 Likes
741

Hi experts,

In my interactive ALV report I want to give different color to selected rows in my alv.

How to proceed with that in interactive alv?

Thanks,

Sakthi C

5 REPLIES 5
Read only

Former Member
0 Likes
723

Hi

Try using EMPHASIZE option of columns

EMPHASIZE

Comp. type

LVC_EMPHSZ

Defined Length

Char(4)

Value range

SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)

If the field is set to 'X', the ALV uses a pre-defined color for highlighting the column. If the character field begins with 'C' (color code), the remaining numbers have the following meaning:

x: color number

y: intensified display on/off

y: inverse display on/off

For more information on color coding, see the F1 help on the FORMAT statement.

Thanks

Vasudha

Read only

0 Likes
723

Hi,

Can you please bit more clear about that how to use that EMPHASIZE in the ALV.

With code ite really appriciatable...

Thanks.

Sakthi c

Read only

Former Member
0 Likes
723

The follow program demonstrates how to change the colour of individual rows of an ALV grid. Changes required

from a basic ALV grid include adding a new field to ALV grid data table(it_ekko), Populating this field with color

attribute and adding an entry to layout control table.

&---------------------------------------------------------------------
*& Report ZDEMO_ALVGRID *
*& *
&---------------------------------------------------------------------
*& *
*& Example of a simple ALV Grid Report *
*& ................................... *
*& *
*& The basic ALV grid, Enhanced to display each row in a different *
*& colour *
&---------------------------------------------------------------------

REPORT zdemo_alvgrid .

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_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_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

Read only

Former Member
0 Likes
723

REPORT ZDEMO_ALVGRID_EDIT .

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,

field_style TYPE lvc_t_styl, "FOR DISABLE

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.

DATA: it_fieldcat TYPE lvc_t_fcat, "slis_t_fieldcat_alv WITH HEADER LINE,

wa_fieldcat TYPE lvc_s_fcat,

gd_tab_group TYPE slis_t_sp_group_alv,

gd_layout TYPE lvc_s_layo, "slis_layout_alv,

gd_repid LIKE sy-repid.

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

*Start-of-selection.

START-OF-SELECTION.

PERFORM data_retrieval.

PERFORM set_specific_field_attributes.

PERFORM build_fieldcatalog.

PERFORM build_layout.

PERFORM display_alv_report.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


FORM build_fieldcatalog.

wa_fieldcat-fieldname = 'EBELN'.

wa_fieldcat-scrtext_m = 'Purchase Order'.

wa_fieldcat-col_pos = 0.

wa_fieldcat-outputlen = 10.

wa_fieldcat-emphasize = 'X'.

wa_fieldcat-key = 'X'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'EBELP'.

wa_fieldcat-scrtext_m = 'PO Item'.

wa_fieldcat-col_pos = 1.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'STATU'.

wa_fieldcat-scrtext_m = 'Status'.

wa_fieldcat-col_pos = 2.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'AEDAT'.

wa_fieldcat-scrtext_m = 'Item change date'.

wa_fieldcat-col_pos = 3.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MATNR'.

wa_fieldcat-scrtext_m = 'Material Number'.

wa_fieldcat-col_pos = 4.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MENGE'.

wa_fieldcat-scrtext_m = 'PO quantity'.

wa_fieldcat-col_pos = 5.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MEINS'.

wa_fieldcat-scrtext_m = 'Order Unit'.

wa_fieldcat-col_pos = 6.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'NETPR'.

wa_fieldcat-scrtext_m = 'Net Price'.

wa_fieldcat-edit = 'X'. "sets whole column to be editable

wa_fieldcat-col_pos = 7.

wa_fieldcat-outputlen = 15.

wa_fieldcat-datatype = 'CURR'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'PEINH'.

wa_fieldcat-scrtext_m = 'Price Unit'.

wa_fieldcat-col_pos = 8.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

ENDFORM. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


FORM build_layout.

  • Set layout field for field attributes(i.e. input/output)

gd_layout-stylefname = 'FIELD_STYLE'.

gd_layout-zebra = 'X'.

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'

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

EXPORTING

i_callback_program = gd_repid

  • i_callback_user_command = 'USER_COMMAND'

is_layout_lvc = gd_layout

it_fieldcat_lvc = it_fieldcat

i_save = 'X'

TABLES

t_outtab = it_ekko

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc ne 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 100 ROWS

FROM ekpo

INTO CORRESPONDING FIELDS OF TABLE it_ekko.

ENDFORM. " DATA_RETRIEVAL

&----


*& Form set_specific_field_attributes

&----


  • populate FIELD_STYLE table with specific field attributes

----


form set_specific_field_attributes .

DATA ls_stylerow TYPE lvc_s_styl .

DATA lt_styletab TYPE lvc_t_styl .

  • Populate style variable (FIELD_STYLE) with style properties

*

  • The NETPR field/column has been set to editable in the fieldcatalog...

  • The following code sets it to be disabled(display only) if 'NETPR'

  • is gt than 10.

LOOP AT it_ekko INTO wa_ekko.

IF wa_ekko-netpr GT 10.

ls_stylerow-fieldname = 'NETPR' .

ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.

"set field to disabled

APPEND ls_stylerow TO wa_ekko-field_style.

MODIFY it_ekko FROM wa_ekko.

ENDIF.

ENDLOOP.

endform. " set_specific_field_attributes

Read only

Former Member
0 Likes
723

Hi,

Have a look on the following code,you can get the solution.

Demo program to color particular row or column or cell of an ALV list using 'REUSE_ALV_LIST_DISPLAY'

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.

NOTE

Column and Row are colored with a coded color ‘Cxyz’.

Where C: Color (coding must begin with C)

X: Color Number

Y: Bold

Z: Inverse.

Thanks,

chandu.