10-14-2008 6:13 AM
Hi All,
I wanted to do the formatting in ALV report output. How I can do that?
Formatting means colour the field, & all.
If possible send me any sample code..
Regards,
Poonam
10-14-2008 6:17 AM
hey,
Just search in SDN there are lots of examples.........
Regards,
Midhun Abraham
10-14-2008 6:17 AM
hey,
Just search in SDN there are lots of examples.........
Regards,
Midhun Abraham
10-14-2008 6:19 AM
hi Poonam,
check it.
saptechnical.com/Tutorials/ALV/ColorOnCondition/Program.htm
it may help you.
thanks n regards
Sachin
10-14-2008 6:21 AM
Dear ponum. your question is ok.but i advice you to first try by your self searching.and try to send such question which answers u unable to find.
10-14-2008 6:28 AM
hi
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. So, lets modify declaration of our list data table gt_list.
Code Part 13 Adding the field that will contain row color data
As you guess, you should fill the color code to this field. Its format will be the same as explained before at section C.6.3. But how will ALV Grid know that you have loaded the color data for the row to this field. So, you make it know this by 1/0: intensifiedon/off - - 1/0: inverseon/off
Color numbers
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 .
Passing 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. You can color an entire row as described in the next section. However, this method is less time consuming.
Here is a sample program.
report zrich_0002 .
*****************************************************************
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.
at selection-screen output.
perform get_data.
perform fill_catalog.
if w_docking_container is initial.
perform create_objects.
endif.
&----
*& Form create_objects
&----
form create_objects.
create object w_docking_container
exporting
ratio = 60
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.
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.
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.
&----
*& Form get_data
&----
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 '6' 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.
&----
*& Form fill_catalog
&----
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.
Copy and paste this program, click a checkbox from the right and click execute. The program will color the line, column, or cell.
chk this 4 more info...
regards
Satish
10-14-2008 6:32 AM
Hi!
Take a look at this sample.
You can also search in SDN. There are lots of examples here.
PERFORM get_layout USING s_layout.
PERFORM get_sort USING it_sort.
PERFORM get_fieldcat USING it_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gv_repid
i_grid_title = 'Posted Depreciation by Asset and Posting Period'
is_layout = s_layout
it_fieldcat = it_fieldcat
it_sort = it_sort
TABLES
t_outtab = it_alv_report.
*&---------------------------------------------------------------------*
*& Form get_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_layout USING p_layout TYPE slis_layout_alv.
* p_layout-box_fieldname = c_sel. "Selection box
* p_layout-zebra = c_x. "Striped list
p_layout-allow_switch_to_list = 'X'.
p_layout-colwidth_optimize = 'X'.
ENDFORM. "get_layout
*&---------------------------------------------------------------------*
*& Form get_sort
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_sort USING p_sort TYPE slis_t_sortinfo_alv.
DATA: ls_sort LIKE LINE OF p_sort.
CLEAR ls_sort.
ls_sort-up = 'X'.
ls_sort-fieldname = 'BUKRS'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO p_sort.
CLEAR ls_sort.
ls_sort-up = 'X'.
ls_sort-fieldname = 'ANLN1'.
ls_sort-subtot = ''.
APPEND ls_sort TO p_sort.
CLEAR ls_sort.
* ls_sort-up = 'X'.
ls_sort-fieldname = 'TXT50'.
ls_sort-subtot = ''.
APPEND ls_sort TO p_sort.
CLEAR ls_sort.
ls_sort-up = 'X'.
ls_sort-fieldname = 'ANLN2'.
ls_sort-subtot = ''.
APPEND ls_sort TO p_sort.
CLEAR ls_sort.
ls_sort-up = 'X'.
ls_sort-fieldname = 'PERAF'.
ls_sort-subtot = ''.
APPEND ls_sort TO p_sort.
ENDFORM. "get_sort
*&---------------------------------------------------------------------*
*& Form get_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_fieldcat USING p_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BUKRS'.
ls_fieldcat-seltext_m = 'Company Code'.
ls_fieldcat-outputlen = 5.
ls_fieldcat-no_out = 'X'. "Hide column
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ANLN1'.
ls_fieldcat-seltext_l = 'Asset'.
ls_fieldcat-outputlen = 10.
ls_fieldcat-emphasize = 'C410'. "will color the column
ls_fieldcat-no_zero = 'X'. "remove zeros
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'TXT50'.
ls_fieldcat-seltext_l = 'Asset Description'.
ls_fieldcat-outputlen = 50.
ls_fieldcat-emphasize = 'C410'.
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ANLN2'.
ls_fieldcat-seltext_m = 'Sub-number'.
ls_fieldcat-outputlen = 11.
ls_fieldcat-emphasize = 'C410'.
ls_fieldcat-no_zero = 'X'.
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'PERAF'.
ls_fieldcat-seltext_l = 'Per.'.
ls_fieldcat-outputlen = 6.
ls_fieldcat-lzero = 'X'.
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'NAFAZ'.
ls_fieldcat-seltext_l = 'Ordinary Depreciat.'.
ls_fieldcat-outputlen = 19.
ls_fieldcat-cfieldname = 'WAERS01'. "currency field
ls_fieldcat-do_sum = 'X'. "Display column total
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WAERS01'.
ls_fieldcat-seltext_m = 'Currency'.
ls_fieldcat-outputlen = 10.
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'AAFAZ'.
ls_fieldcat-seltext_l = 'Unplanned Depr.'.
ls_fieldcat-outputlen = 36.
ls_fieldcat-cfieldname = 'WAERS02'.
ls_fieldcat-do_sum = 'X'.
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WAERS02'.
ls_fieldcat-seltext_m = 'Currency'.
ls_fieldcat-outputlen = 10.
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SAFAZ'.
ls_fieldcat-seltext_l = 'Special Depr.'.
ls_fieldcat-outputlen = 35.
ls_fieldcat-cfieldname = 'WAERS03'.
ls_fieldcat-do_sum = 'X'.
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WAERS03'.
ls_fieldcat-seltext_m = 'Currency'.
ls_fieldcat-outputlen = 10.
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ZINSZ'.
ls_fieldcat-seltext_m = 'Interest'.
ls_fieldcat-outputlen = 14.
ls_fieldcat-cfieldname = 'WAERS04'.
ls_fieldcat-do_sum = 'X'. "Display column total
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WAERS04'.
ls_fieldcat-seltext_m = 'Currency'.
ls_fieldcat-outputlen = 10.
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MAFAZ'.
ls_fieldcat-seltext_m = 'Reserves Transf.'.
ls_fieldcat-outputlen = 22.
ls_fieldcat-cfieldname = 'WAERS05'.
ls_fieldcat-do_sum = 'X'. "Display column total
APPEND ls_fieldcat TO p_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'WAERS05'.
ls_fieldcat-seltext_m = 'Currency'.
ls_fieldcat-outputlen = 10.
APPEND ls_fieldcat TO p_fieldcat.
ENDFORM. "get_fieldcat
10-14-2008 6:56 AM
Hi Poonam,
I hope that this snippet wil be of use to you.
REPORT ZTEST_ALV_CHECK message-id zz .
TYPE-POOLS: SLIS.
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
L_LAYOUT type slis_layout_alv,
x_events type slis_alv_event,
it_events type SLIS_T_EVENT.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
MALE type i,
female type i,
END OF ITAB.
SELECT VBELN
POSNR
FROM VBAP
UP TO 20 ROWS
INTO TABLE ITAB.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-SELTEXT_L = 'VBELN'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 1.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-SELTEXT_L = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 2.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'MALE'.
X_FIELDCAT-SELTEXT_L = 'MALE'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 3.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'FEMALE'.
X_FIELDCAT-SELTEXT_L = 'FEMALE'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 3.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
x_events-NAME = SLIS_EV_TOP_OF_PAGE.
x_events-FORM = 'TOP_OF_PAGE'.
APPEND x_events TO iT_EVENTS.
CLEAR x_events .
L_LAYOUT-NO_COLHEAD = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = L_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
it_events = it_events
TABLES
T_OUTTAB = ITAB
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.
FORM TOP_OF_PAGE.
*-To display the headers for main list
FORMAT COLOR COL_HEADING.
WRITE: / SY-ULINE(103).
WRITE: / SY-VLINE,
(8) ' ' ,
SY-VLINE,
(8) ' ' ,
SY-VLINE,
(19) 'SEX'(015) centered,
sy-vline.
WRITE: / SY-VLINE,
(8) 'VBELN'(013) ,
SY-VLINE,
(8) 'POSNR'(014) ,
SY-VLINE,
(8) 'MALE'(016) ,
sy-vline,
(8) 'FMALE'(017) ,
sy-vline.
FORMAT COLOR OFF.
ENDFORM.
10-14-2008 7:02 AM
Hi,
For colours you can use the following snippet.
1.
You can use to get COLOR on TOP_OF_PAGE using this.
WRITE 'XYZ' COLOR 2.
2.
Define variable COLOR like this in ur final table which u pass to REUSE_ALV_LIST or GRID_DISPLAY.
DATA: BEGIN OF i_mard OCCURS 0,
color(3) TYPE c,
werks TYPE mard-werks,
lgort TYPE mard-lgort,
matnr TYPE mard-matnr,
insme TYPE mard-insme,
einme TYPE mard-einme,
speme TYPE mard-speme,
END OF i_mard.
3.
a.
If u want to change Rows color
LOOP AT i_mard .
IF sy-tabix BETWEEN 10 AND 20 .
i_mard-color = 'C71'.
MODIFY i_mard INDEX sy-tabix.
ENDIF.
ENDLOOP.
b.
If u want to display COLOR for Column
set this for perticular column.
w_fieldcatalog-Emphasize = 'X'.
4.
Declare w_layout TYPE slis_layout_alv.(Should be Global)
w_layout-info_fieldname = 'COLOR'.
and pass structure to REUSE_ALV_LIST or GRID_DISPLAY.
Cheers.
10-14-2008 7:06 AM
11-20-2008 1:02 PM