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

ALV

Former Member
0 Likes
480

Hi all,

How many colors using ALV?

Send me about ALV colors details?

Reply me soon.

tx,

s.suresh.

3 REPLIES 3
Read only

Former Member
0 Likes
445

Coloring an Entire Row

Coloring a row is a bit (really a bit) more complicated. To enable row coloring, you should add an additional field to your list data table. It should be of character type and length at least 4. This field will contain the color code for the row. modify declaration of our list data table “gt_list”.

Internal table holding list data

DATA BEGIN OF gt_list OCCURS 0 .

INCLUDE STRUCTURE SFLIGHT .

DATA rowcolor(4) TYPE c .

DATA END OF gt_list .

you pass the name of the field containing color codes to the field “INFO_FNAME” of the layout structure.

e.g.

ps_layout-info_fname = <field_name_containing_color_codes>. “e.g. ‘ROWCOLOR’

You can fill that field anytime during execution. But, of course, due to the flow logic of screens, it will be reflected to your list display as soon as an ALV refresh occurs.

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

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

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 .

plz reward if useful

keep rockin

vivek

Read only

Former Member
0 Likes
445

Hi..

to color a particular cell use slis_specialcol..

in your internal table add a field with type slis_specialcol..

enter field name and color number .

In General we have to give BLUE color for the primary key field and we have to give other color to other filelds.

If we mention KEY filed in FIELD CATALOG we get BLUE color for that filed.

wa_fieldcat-tabname = 'IT_SALESORDER'. "

wa_fieldcat-fieldname = 'VBELN'. " Field Name

wa_fieldcat-key = 'X'. " Blue Color

wa_fieldcat-hotspot = 'X'. " Hand Appears.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

FOR OTHER COLOR FOR THE FILEDS WE HAVE TO USE

emphasize parameter.I have to mention the code below check it once..

wa_fieldcat-tabname = 'IT_SALESORDER'. "

wa_fieldcat-fieldname = 'MATNR. " Field Name

wa_fieldcat-hotspot = 'X'. " Hand Appears.

wa_fieldcat-emphasize = 'C310'. " Color

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

these links will help you do so

hi.

Simple ALV report

http://www.sapgenie.com/abap/controls/alvgrid.htm

http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox

ALV

1. Please give me general info on ALV.

http://www.sapfans.com/forums/viewtopic.php?t=58286

http://www.sapfans.com/forums/viewtopic.php?t=76490

http://www.sapfans.com/forums/viewtopic.php?t=20591

http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.

2. How do I program double click in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=11601

http://www.sapfans.com/forums/viewtopic.php?t=23010

3. How do I add subtotals (I have problem to add them)...

http://www.sapfans.com/forums/viewtopic.php?t=20386

http://www.sapfans.com/forums/viewtopic.php?t=85191

http://www.sapfans.com/forums/viewtopic.php?t=88401

http://www.sapfans.com/forums/viewtopic.php?t=17335

4. How to add list heading like top-of-page in ABAP lists?

http://www.sapfans.com/forums/viewtopic.php?t=58775

http://www.sapfans.com/forums/viewtopic.php?t=60550

http://www.sapfans.com/forums/viewtopic.php?t=16629

5. How to print page number / total number of pages X/XX in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)

6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.

http://www.sapfans.com/forums/viewtopic.php?t=64320

http://www.sapfans.com/forums/viewtopic.php?t=44477

7. How can I set the cell color in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=52107

8. How do I print a logo/graphics in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=81149

http://www.sapfans.com/forums/viewtopic.php?t=35498

http://www.sapfans.com/forums/viewtopic.php?t=5013

9. How do I create and use input-enabled fields in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=84933

http://www.sapfans.com/forums/viewtopic.php?t=69878

10. How can I use ALV for reports that are going to be run in background?

http://www.sapfans.com/forums/viewtopic.php?t=83243

http://www.sapfans.com/forums/viewtopic.php?t=19224

11. How can I display an icon in ALV? (Common requirement is traffic light icon).

http://www.sapfans.com/forums/viewtopic.php?t=79424

http://www.sapfans.com/forums/viewtopic.php?t=24512

12. How can I display a checkbox in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=88376

http://www.sapfans.com/forums/viewtopic.php?t=40968

http://www.sapfans.com/forums/viewtopic.php?t=6919

Award points if helpful.

GAURAV J.

Edited by: GAURAV on Feb 3, 2008 1:27 PM

Read only

Former Member
0 Likes
445

Hi,

The below links will give you enough information for adding colors in ALV.

http://help.sap.com/saphelp_erp2004/helpdata/en/fa/efb529f8a611d2b48d006094192fe3/frameset.htm

http://help.sap.com/saphelp_erp2004/helpdata/en/fa/efb529f8a611d2b48d006094192fe3/frameset.htm

Plz go thru these links for sample pgm

http://www.sap-img.com/abap/line-color-in-alv-example.htm

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm

Below is an example

Create an executable program and paste in the code below.

Then use SE51 and create a screen '0100' for program ZR_COLORS. Place a custom container on it. Give the custom container the name of 'CUSTOM_GRID_CONTAINER'.

Save and activate all... and there you go.


REPORT ZR_Colors.

data: begin of i_vbak2 occurs 0.
include structure vbak.
data: end of i_vbak2.

data: begin of i_vbak occurs 0.
include structure vbak.
data: cellcolors type lvc_t_scol. " note that is an int table within
data: end of i_vbak. " an int table !!!

types: begin of r_vbak.
include structure vbak.
types: cellcolors type lvc_t_scol.
types: end of r_vbak.

data: i_vbak_out type table of r_vbak.

data: cellcolor type lvc_s_scol.
data: layout type LVC_S_LAYO.

data: grid1 type ref to cl_gui_alv_grid,
field_catalog type lvc_t_fcat,
grid1_container type ref to cl_gui_custom_container.
data: lt_fieldcat type LVC_T_FCAT.
data: wa_fieldcat type LVC_s_FCAT.


start-of-selection.
select * from vbak into table i_vbak2
where erdat > '20041201'
and erdat < '.

loop at i_vbak2.
move-corresponding i_vbak2 to i_vbak.
append i_vbak.
endloop.

layout-zebra = 'X'.
layout-cwidth_opt = 'X'.



Set first cell in Net value column. 
read table i_vbak index 2.
cellcolor-fname = 'NETWR'.
cellcolor-color-col = '3'.
cellcolor-color-int = '1'.
cellcolor-NOKEYCOL = 'X'.
append cellcolor to i_vbak-cellcolors.
modify i_vbak index 2.


Set 2nd cell in Net value column. 
read table i_vbak index 4.
cellcolor-fname = 'NETWR'.
cellcolor-color-col = '6'.
cellcolor-color-int = '1'.
cellcolor-NOKEYCOL = 'X'.
append cellcolor to i_vbak-cellcolors.
modify i_vbak index 4.


Identify the internal table name with the colors reference. 
layout-CTAB_FNAME = 'CELLCOLORS'.


Instantiate the grid container. 
create object grid1_container
exporting
container_name = 'CUSTOM_GRID_CONTAINER'.


Instantiate the grid itself within the container. 
create object grid1
exporting
i_parent = grid1_container
i_appl_events = 'X'.

i_vbak_out] = i_vbak[.

layout-frontend = 'E'.


Call method of grid1 class object to build/display the grid. 
call method grid1->set_table_for_first_display
EXPORTING i_structure_name = 'VBAK'
is_layout = layout
changing
it_outtab = i_vbak_out.

it_fieldcatalog = lt_fieldcat. 

call screen '0100'.

&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
&---------------------------------------------------------------------

text 
----------------------------------------------------------------------
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'E100'.
SET TITLEBAR '100'.

ENDMODULE. " STATUS_0100 OUTPUT

&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
&---------------------------------------------------------------------

text 
----------------------------------------------------------------------
MODULE USER_COMMAND_0100 INPUT.
case sy-ucomm.
when 'EXIT' or 'BACK' or 'CANCEL'.
leave program.
endcase.

ENDMODULE. " USER_COMMAND_0100 INPUT

Regards,

Chandru