05-11-2009 2:29 PM
Hi experts,
i have to display the output in alv format with few cells in color based on the condition.. and if user download this output in excel, the colors should be remain same.. (not in block color)..
please help me out...
venkatreddy...
05-11-2009 2:36 PM
Hi,
Try this for output with cell colors. But for downloading to excel, still something needs to be worked out.
Step 1: Include a field called cellcolor in output table as below. Create a work area for the cellcolor.
TYPES : BEGIN OF ty.
INCLUDE STRUCTURE mara.
For cell coloring
TYPES : cellcolor TYPE lvc_t_scol,
END OF ty.
Data : w_cellcolor TYPE lvc_s_scol, "For cell color
Step 2: In layout, mention the field name for ctab_fname
Setting layout
w_layout-ctab_fname = 'CELLCOLOR'."For cell coloring
Step 3: Mention the field name for coloring and then set the color, intensified and inverse options.
Colouring a cell
clear w_cellcolor.
w_cellcolor-fname = 'ERSDA'.
w_cellcolor-color-col = '5'.
w_cellcolor-color-int = '1'.
w_cellcolor-color-inv = '1'.
APPEND w_cellcolor TO wa-cellcolor.
MODIFY itab FROM wa INDEX 7 TRANSPORTING cellcolor.
Here you can set the col to different numbers(1 to 9) and then give intensified/ inverse values either 0 or 1 to know the variations.
Step 4: Pass the required parameters for set_table_for_first_display as below.
Displaying the output
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
is_variant = w_variant
i_save = 'A'
is_layout = w_layout
CHANGING
it_outtab = itab
it_fieldcatalog = i_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
05-11-2009 2:51 PM
We have build a macro in excel which changes the cell color in excel with the same conditions as we use it in the ALV for cellcoloring.
I haven't found any sollution how you can keep the cellcolors in the export.
(but also curious if somebody has some smart sollution)
kind regards
arthur
05-12-2009 12:07 AM
Another work around that I do is exporting the output from ALV in to HTML Format and then copy 'n paste the HTML table content from browser into spread sheet...which retains the cell colors as it is...little effort..but it works !!!
Regards,
Trikanth
05-12-2009 12:26 AM
Here is an example
DATA : X_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
...
PREFORM PREPARE_FIELDCAT .
...
FORM PREPARE_FIELDCAT .
...
First field to appear in ALV list
X_FIELDCAT-COL_POS = 1.
* Name of the field in the internal table
X_FIELDCAT-FIELDNAME = 'NACHN'.
* Name of the internal table
X_FIELDCAT-TABNAME = 'it_data'.
* Heading for the column
X_FIELDCAT-SELTEXT_M = 'Last Name'.
*>>>>>>
* It is going to be the key field.The color for this field is going to
* be different
X_FIELDCAT-KEY = 'X'.
* The field will be colored differently(Cxyz)
X_FIELDCAT-EMPHASIZE = 'C511'.
*<<<<<<
...
...
05-12-2009 3:23 AM
HI..
Do like below..to set color to particular cell:
g_r_fieldcat-fieldname = p_fname .
g_r_fieldcat-col_pos = p_col_pos .
g_r_fieldcat-coltext = p_col_text.
g_r_fieldcat-hotspot = p_hotspot .
g_r_fieldcat-outputlen = p_outlen .
g_r_fieldcat-key = p_key .
g_r_fieldcat-convexit = p_convexit.
g_r_fieldcat-emphasize = p_emphasize. ( whr p_emphasize have value eg C510)
Hope this helps.
Praveen
05-12-2009 4:14 AM
05-12-2009 4:18 AM
https://wiki.sdn.sap.com/wiki/display/Snippets/Addcolortocellin+ALV
https://wiki.sdn.sap.com/wiki/display/Snippets/ColoringacellinanALVconditionally
hey check this
you can find such things in wiki
before posting just check it
cheers
s.janagar