08-28-2007 4:43 PM
Hi Abaper,
As of my requirement i want to display output of the report for certain lines in a color iam using ALV method,
Plz help me ASAP
answer will be reward.
Thanks in advance
hema
08-28-2007 4:46 PM
Hi,
Go through this hope u can analyze and do as per ur need.
Color a line
To color a line the structure of the table must include a Char 4 field for color properties
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for line color
types: line_color(4) type c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
Loop trough the table to set the color properties of each line. The color properties field is
Char 4 and the characters is set as follows:
Char 1 = C = This is a color property
Char 2 = 6 = Color code (1 - 7)
Char 3 = Intensified on/of = 1 = on
Char 4 = Inverse display = 0 = of
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-line_color = 'C610'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Name of the color field
gs_layout-info_fname = 'LINE_COLOR'.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
Reward points if helpful.
Thanks
Naveen khan
08-28-2007 4:46 PM
Hi,
Go through this hope u can analyze and do as per ur need.
Color a line
To color a line the structure of the table must include a Char 4 field for color properties
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for line color
types: line_color(4) type c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
Loop trough the table to set the color properties of each line. The color properties field is
Char 4 and the characters is set as follows:
Char 1 = C = This is a color property
Char 2 = 6 = Color code (1 - 7)
Char 3 = Intensified on/of = 1 = on
Char 4 = Inverse display = 0 = of
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-line_color = 'C610'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Name of the color field
gs_layout-info_fname = 'LINE_COLOR'.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
Reward points if helpful.
Thanks
Naveen khan
08-28-2007 4:50 PM
If you want to color a line and you are using the function module, here is an example.
report zrich_0004
no standard page heading.
type-pools slis.
data: fieldcat type slis_t_fieldcat_alv.
data: begin of imara occurs 0,
matnr type mara-matnr,
mtart type mara-mtart,
maktx type makt-maktx,
color_line(4) type c,
end of imara.
data: xcolor type slis_specialcol_alv.
start-of-selection.
perform get_data.
perform write_report.
************************************************************************
* Get_Data
************************************************************************
form get_data.
imara-matnr = 'ABC'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for ABC'.
append imara.
imara-matnr = 'DEF'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for DEF'.
append imara.
imara-matnr = 'GHI'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for GHI'.
append imara.
loop at imara.
if sy-tabix = 2.
imara-color_line = 'C410'. " color line
endif.
modify imara.
endloop.
endform.
************************************************************************
* WRITE_REPORT
************************************************************************
form write_report.
data: layout type slis_layout_alv.
layout-info_fieldname = 'COLOR_LINE'.
perform build_field_catalog.
* CALL ABAP LIST VIEWER (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
is_layout = layout
it_fieldcat = fieldcat
tables
t_outtab = imara.
endform.
************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.
data: fc_tmp type slis_t_fieldcat_alv with header line.
clear: fieldcat. refresh: fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Number'.
fc_tmp-fieldname = 'MATNR'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '18'.
append fc_tmp to fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Type'.
fc_tmp-fieldname = 'MTART'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '4'.
append fc_tmp to fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material'.
fc_tmp-fieldname = 'MAKTX'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '40'.
append fc_tmp to fieldcat.
endform.
Regards,
Rich Heilman
08-29-2007 5:10 AM
Hi Hema..
this is The code for Applying the colors For Lines or Cells also..
report yacpr0007.
This must be included in order to create the fieldcatalog.
type-pools: slis.
parameters: p_dummy type c.
types: begin of ty_data,
select type c,
f1 type i,
f2 type i,
f3 type i,
color_line(4) type c, " Line color
color_cell type lvc_t_scol, " Cell color
end of ty_data.
constants: c_true type boolean_flg value 'X',
c_false type boolean_flg value space.
data: i_data type table of ty_data,
i_field_cat type slis_t_fieldcat_alv,
s_layout type slis_layout_alv.
start-of-selection.
perform f_create_field_cat.
perform f_set_layout.
perform f_create_data.
end-of-selection.
perform f_display_grid.
&----
*& @FORMS
&----
&----
*& Form f_create_data
&----
Create some sample data.
----
form f_create_data.
data: lw_data type ty_data,
lw_color_cell like line of lw_data-color_cell.
do 15 times.
clear lw_data.
lw_data-f1 = sy-index.
case sy-index.
when 3.
**/ Set the row or cell to color
lw_data-color_line = 'C410'.
when 8.
lw_color_cell-color-col = 6.
lw_color_cell-fname = 'F1'.
append lw_color_cell to lw_data-color_cell. "/ .
endcase.
lw_data-f2 = sy-index * 2.
lw_data-f3 = lw_data-f1 + lw_data-f2.
append lw_data to i_data.
enddo.
endform. "f_create_data
&----
*& Form f_create_field_cat
&----
Create the fieldcatalog. This needs to contain a minimum of
the names of the fields you wish to display. However there are
numerous other things which can be added such as position, colour etc.
----
form f_create_field_cat.
**/ Add data to the field catalog
perform f_append_row using: 'F1' 'field one' 3,
'F2' 'field two' 2,
'F3' 'field three' 1. "/ .
endform. "f_create_field_cat
&----
*& Form f_append_row
&----
Append a single row to the field catalog.
----
-->L_NAME The name of the field to be added.
-->L_DESC The description for the column heading.
-->L_POS The column number for the field.
----
form f_append_row using pv_name pv_desc pv_pos.
data: lw_field_cat like line of i_field_cat.
**/ Append the field catalog record.
lw_field_cat-fieldname = pv_name.
lw_field_cat-seltext_l = pv_desc.
lw_field_cat-col_pos = pv_pos.
append lw_field_cat to i_field_cat. "/ .
endform. "f_append_row
&----
*& Form f_set_layout
&----
Set the layout including the field names used to indicate the
cells or rows should be coloured.
----
form f_set_layout.
s_layout-colwidth_optimize = space.
s_layout-no_colhead = space.
s_layout-zebra = space.
s_layout-no_vline = space.
**/ Field that identify color line in internal table
s_layout-info_fieldname = 'COLOR_LINE'.
Field that identify cell color in inetrnal table
s_layout-coltab_fieldname = 'COLOR_CELL'. "/ .
endform. "f_create_layout
&----
*& Form f_display_grid
&----
Call the function to display the grid.
----
form f_display_grid.
**/ You need to pass in a minimum of the fieldcatalog and the table of data
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
*/ .
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = ' '
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
is_layout = s_layout
**/ the field catalog. Tells SAP what to display
it_fieldcat = i_field_cat
*/ .
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
I_HTML_HEIGHT_TOP =
I_HTML_HEIGHT_END =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
**/ The table of data and exceptions
tables
t_outtab = i_data
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. "f_display_grid
<b>reward if Helpful</b>
08-29-2007 7:57 AM
Hi Naveen , Rich and Narayana
Iam really thankful to all of you who took an effort to answer my query .Thanx for your precious time.
Regards,
Hema.