‎2006 Dec 08 8:16 AM
How can I color any row in my ALV?
I defined a filed in my List data and passes the color code to it.In my Layout structure I am passing the color code. But it is not working. Am I missing any step?
‎2006 Dec 08 8:18 AM
Hi Anurita ,
Are you using function modules or objects to implement the ALV.
And yes in the layout have you populated the field <b>ctab_fname</b>
Regards
Arun
Message was edited by:
Arun Ramachandran
‎2006 Dec 08 8:19 AM
‎2006 Dec 08 8:23 AM
HI ANURITA WAGHE ,
simply chk this link.
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
example code is there. It will help u.
Regards,
Kumar
‎2006 Dec 08 8:26 AM
hi..
ls_fieldcat-emphasize = 'X'.
u wud hav missed the above statement in ur code or u wud hav made a mistake in coding the above statement.
check that out.
also go through these links:
http://help.sap.com/saphelp_erp2004/helpdata/en/7f/e477e5fba211d2b48f006094192fe3/content.htm
http://www.sap-basis-abap.com/abap/color-a-column-value-in-alv-report.htm
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
all the best.
‎2006 Dec 08 8:26 AM
chk if u had forgot any of these ,
1. Say you fieldname in internal table is COLOR(4).
2.In ur layout wa_layout-info_fieldname = 'COLOR'.
3.loop at itab.
itab-color = 'C410'.
modify itab index sy-tabix transporting color.
endloop.
‎2006 Dec 08 8:27 AM
‎2006 Dec 08 8:51 AM
hi,
here is the sample code.mark points if usefl.
----
Mod# Modified By Mod.Date Requested by Approved by *
?? ????? ??/??/?? ????????? ?????? *
Reason for changes : Initial version. *
Changes Description:
======================================================================
----
Constants Declaration *
----
constants: c_filetype type fileformat value 'ASC', "File Format
c_report type rsvar-report value 'PPARCHA1'."Report Name
----
Data Declaration *
----
data: v_file_name type localfile, " File Name
v_error(50) type c, " Error Text
v_message(90),
v_message1(90).
----
Structure Declaration
----
*--Following structures are used for conversion of date format from
data: begin of x_cdate,
year(4) type n, " Year
month(2) type n, " Month
date(2) type n, " Date
end of x_cdate.
data: begin of x_ndate,
year type i, " Year
month type i, " Month
date type i, " Date
end of x_ndate.
Used for the creation of new variant
data: x_varid type varid. " Structure for varid
----
Type Declaration *
----
types : begin of t_var,
var_name(14), "001-014 Variant Name
var_desc(30), "015-045 Variant Description
auart(4), "046-050 Order Type
werks(4), "051-055 Plant
fgstrp(10), "056-066 From Date
tgstrp(10), "067-077 To Date
comments(60), "078-138 Short Text For Archiving
ordnum(10), "139-149 Maximum number of orders
dbnum(10), "150-160 Archiving:Block size
afcrea, "161-162 Archive File check box
end of t_var.
----
Internal Table Declaration *
----
*-- Internal table to store the details of input file
data: it_var type standard table of t_var with header line,
*--Internal Table that stores the details of the Structure RSPARAMS
it_var_sel type standard table of rsparams with header line,
*--Internal Table that stores the details of the Structure RSPARAMS
it_value type standard table of rsparams with header line,
*--Internal Table that stores the details of the Structure vANZ
it_objects type standard table of vanz with header line,
*--Internal Table that stores the details of the Standard table VARIT
it_varit type standard table of varit with header line.
*--Internal table to store the variants of the archiving program
data : begin of it_valuetab occurs 0,
variant like varid-variant, " Variant name
end of it_valuetab.
----Internal table for the Search Help
data: it_return_tab like ddshretval occurs 0 with header line.
----
Selection-Screen *
----
selection-screen begin of block blk1 with frame title text-001.
parameters: p_ifile type localfile obligatory, " Filename
p_vari type rsvar-variant obligatory." Variant Name
selection-screen end of block blk1.
----
Includes *
----
*--Standard Page Header routines.
*include zsrepthd.
----
Top of Page *
----
top-of-page.
*-- Perform that prints the header
perform print_header.
skip.
----
At Selection Screen *
----
at selection-screen.
*--Validating the variant name
perform validate_variant.
at selection-screen on value-request for p_ifile.
*--Possible entries for the input file
perform display_possible_entries using p_ifile.
at selection-screen on value-request for p_vari.
*--Possible entries for the variant
perform display_variants."using p_vari.
----
Start-of-Selection *
----
start-of-selection.
*--Subroutine to initialize the fields in table BHDGD for printing the
*--the report heading.
perform init_page_head.
*--Subroutine to open the text file
perform open_file changing v_message.
if not v_message is initial.
write:/ v_message.
exit.
endif.
*--Subroutine that gets the variant from the program
perform get_variant changing v_message1.
if not v_message1 is initial.
write: / v_message1.
endif.
*--Subroutine to formate the variant
perform format_variant.
----
End-of-Selection *
*----
&----
*& Form validate_variant
&----
Validating the variant entered
----
form validate_variant.
*--local data declaration
data : lv_report like rsvar-report,
lv_variant like rsvar-variant,
lv_subrc type sy-subrc.
lv_report = c_report.
lv_variant = p_vari.
call function 'RS_VARIANT_EXISTS'
exporting
report = lv_report
variant = lv_variant
importing
r_c = lv_subrc
exceptions
not_authorized = 1
no_report = 2
report_not_existent = 3
report_not_supplied = 4
others = 5.
if lv_subrc <> 0.
set cursor field 'P_VARI'.
message e600 with 'Varaint doesnt exist'.
endif.
endform. " validate_variant
&----
*& Form DISPLAY_POSSIBLE_ENTRIES
&----
Providing possible entries for file name
----
form display_possible_entries using p_p_io_file.
*--local data declaration
data: lv_program_name like sy-repid, "Program Name
lv_dynpro_number like sy-dynnr, "Screen Number
lv_field_name like dynpread-fieldname, "Field Name
lv_file_name like ibipparms-path. "File Path
lv_field_name = 'P_P_IO_FILE'.
lv_program_name = sy-repid.
lv_dynpro_number = sy-dynnr.
*--Calling the function module to get all possible entries of the file
call function 'F4_FILENAME'
exporting
program_name = lv_program_name
dynpro_number = lv_dynpro_number
field_name = lv_field_name
importing
file_name = lv_file_name
exceptions
others = 1.
if sy-subrc = 0.
p_p_io_file = lv_file_name.
endif.
endform. " DISPLAY_POSSIBLE_ENTRIES
&----
*& Form display_variants
&----
F4 help for variants
----
form display_variants." using p_p_vari.
*--local data declaration
data: lv_retfield type dfies-fieldname, " Field Name
lv_maxline type i. " Maximum no of records
lv_retfield = 'P_VARI'.
*--Selecting varinats of the program given from VARID
select variant
from varid
into table it_valuetab
where report = c_report.
*--If there exists Variants for the archiving program then giving
them an F4 help
if sy-subrc = 0.
*--Calling the function module for F4 help.
call function 'F4IF_INT_TABLE_VALUE_REQUEST'
exporting
retfield = lv_retfield
value_org = 'S'
tables
value_tab = it_valuetab[]
return_tab = it_return_tab
exceptions
parameter_error = 1
no_values_found = 2
others = 3.
if sy-subrc = 0.
read table it_return_tab index 1.
p_vari = it_return_tab-fieldval.
endif.
else.
write 😕 'Program doesnt have any variants'.
endif.
endform. " display_variants
&----
*& Form INIT_PAGE_HEAD
&----
*This subroutine initializes the fields in table BHDGD for printing *
the report heading.
----
form init_page_head.
bhdgd-line1 = 'Bristol-Myers Squibb Company'(h01).
bhdgd-line2 = sy-title.
bhdgd-lines = sy-linsz.
bhdgd-fcpyrt = sy-uline.
bhdgd-inifl = '0'.
endform. " init_page_head
&----
*& Form OPEN_FILE
&----
Opens Local file
----
form open_file changing value(pv_message).
*--local data declaration
data: lv_filename type string,
lv_data_tab type standard table of t_var with header line.
lv_filename = p_ifile.
refresh lv_data_tab.
*--Populating IT_VAR with the contents of flat file
call function 'GUI_UPLOAD'
exporting
filename = lv_filename
filetype = 'ASC'
has_field_separator = 'X'
tables
data_tab = lv_data_tab
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
if sy-subrc <> 0.
pv_message =
'PLEASE ENTER A FILE WHICH EXISTS AND HAS RELAVENT DATA'(e01).
exit.
endif.
if lv_data_tab[] is initial.
pv_message =
'FILE OPENED DOESNT HAVE DATA'(e02).
exit..
endif.
it_var[] = lv_data_tab[].
*--For Changing the date formate in the internal table IT_VAR
which it has been taken from the flat file
loop at it_var.
replace '/' with ' ' into it_var-fgstrp.
replace '/' with ' ' into it_var-fgstrp.
split it_var-fgstrp at ' ' into x_cdate-month x_cdate-date
x_cdate-year.
move-corresponding x_cdate to x_ndate.
move-corresponding x_ndate to x_cdate.
move x_cdate to it_var-fgstrp.
clear x_cdate.
clear x_ndate.
replace '/' with ' ' into it_var-tgstrp.
replace '/' with ' ' into it_var-tgstrp.
split it_var-tgstrp at ' ' into x_cdate-month x_cdate-date
x_cdate-year.
move-corresponding x_cdate to x_ndate.
move-corresponding x_ndate to x_cdate.
move x_cdate to it_var-tgstrp.
clear x_cdate.
clear x_ndate.
*--converting the variant name to uppercase.
translate it_var-var_name to upper case.
modify it_var.
clear: it_var-fgstrp,
it_var-tgstrp.
endloop.
endform. " FOMR_OPEN_FILE
&----
*& Form GET_VARIANT
&----
Get the Existing Variant
----
form get_variant changing value(pv_message1).
*--local data declaration
data: lv_report like rsvar-report,
lv_variant like rsvar-variant,
lv_valuetab type standard table of rsparams with header line ,
lv_objects type standard table of vanz with header line.
refresh : it_value,
it_objects.
refresh : lv_valuetab,
lv_objects.
lv_report = c_report.
lv_variant = p_vari.
*--Getting a model variant from the program PPARCHA1
call function 'RS_VARIANT_CONTENTS'
exporting
report = lv_report " PPARCHA1
variant = lv_variant " Model Variant
tables
valutab = lv_valuetab
objects = lv_objects
exceptions
variant_non_existent = 1
variant_obsolete = 2
report_not_existent = 3
others = 4.
if sy-subrc <> 0.
pv_message1 =
'Variant entered is invalid'(e03).
exit..
endif.
it_value[] = lv_valuetab[].
it_objects[] = lv_objects[].
endform. " GET_VARIANT
&----
*& Form FORMAT_VARIANT
&----
Formats the variants
----
form format_variant.
*--Looping at the IT_VAR table so as to get all the variant details into
IT_VAR_SEL.
loop at it_var.
clear it_var_sel.
refresh it_var_sel.
loop at it_objects.
clear it_var_sel.
case it_objects-name.
*--Checking for Short Text For Archiving
when 'NOTICE'.
it_var_sel-selname = 'NOTICE'.
it_var_sel-kind = it_objects-kind.
it_var_sel-low = it_var-comments.
*--Checking for Maximum number of orders
when 'DEL_MAX'.
it_var_sel-selname = 'DEL_MAX'.
it_var_sel-kind = it_objects-kind.
it_var_sel-low = it_var-ordnum.
*--Checking for Block size for database access
when 'ORD_PACK'.
it_var_sel-selname = 'ORD_PACK'.
it_var_sel-kind = it_objects-kind.
it_var_sel-low = it_var-dbnum.
*--Checking for Order Type
when 'AUART'.
if not it_var-auart is initial.
it_var_sel-selname = it_objects-name.
it_var_sel-kind = it_objects-kind.
it_var_sel-sign = 'I'.
it_var_sel-option = 'EQ'.
it_var_sel-low = it_var-auart.
endif.
*--Checking for Plant
when 'WERKS'.
it_var_sel-selname = it_objects-name.
it_var_sel-kind = it_objects-kind.
if not it_var-werks is initial.
it_var_sel-sign = 'I'.
it_var_sel-option = 'EQ'.
it_var_sel-low = it_var-werks.
endif.
*--Checking for Account Radio button
when 'CREATE'.
it_var_sel-selname = it_objects-name.
it_var_sel-kind = it_objects-kind.
it_var_sel-low = it_var-afcrea.
*--Checking for Basic Date
when 'GSTRP'.
it_var_sel-selname = it_objects-name.
it_var_sel-kind = it_objects-kind.
if not it_var-fgstrp is initial and it_var-tgstrp
is initial.
it_var_sel-sign = 'I'.
it_var_sel-option = 'EQ'.
it_var_sel-low = it_var-fgstrp.
else.
it_var_sel-sign = 'I'.
it_var_sel-option = 'BT'.
it_var_sel-low = it_var-fgstrp.
it_var_sel-high = it_var-tgstrp.
endif.
when others.
it_var_sel-selname = it_objects-name.
it_var_sel-kind = it_objects-kind.
endcase.
append it_var_sel.
endloop.
clear it_varit.
refresh it_varit.
*---Populating IT_VARIT internal table
it_varit-mandt = sy-mandt.
it_varit-langu = 'EN'.
it_varit-report = c_report.
it_varit-variant = it_var-var_name.
it_varit-vtext = it_var-var_desc.
append it_varit.
clear x_varid.
*--Populating the structure X_VARID
x_varid-mandt = sy-mandt.
x_varid-report = c_report.
x_varid-variant = it_var-var_name.
x_varid-environmnt = 'A'.
*--Subroutine to create the variant for PPARCHA1
perform create_variant.
endloop.
endform. " FORMAT_VARIANT
&----
*& Form create_variant
&----
Formats the variants
----
form create_variant.
*--local data declaration
data :lv_curr_report like rsvar-report,
lv_curr_variant like rsvar-variant,
lv_vari_contents type standard table of rsparams with header line,
lv_vari_text type standard table of varit with header line.
lv_curr_report = c_report.
lv_curr_variant = it_var-var_name.
lv_vari_contents[] = it_var_sel[].
lv_vari_text[] = it_varit[].
clear it_varit.
*--Function Module to create the variant
call function 'RS_CREATE_VARIANT'
exporting
curr_report = lv_curr_report
curr_variant = lv_curr_variant
vari_desc = x_varid
tables
vari_contents = lv_vari_contents
vari_text = lv_vari_text
exceptions
illegal_report_or_variant = 1
illegal_variantname = 2
not_authorized = 3
not_executed = 4
report_not_existent = 5
report_not_supplied = 6
variant_exists = 7
variant_locked = 8
others = 9.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
clear v_error.
*--To output the error message
case sy-subrc.
when 1.
v_error = 'ILLEGAL_REPORT_OR_VARIANT'.
when 2.
v_error = 'ILLEGAL_VARIANTNAME'.
when 3.
v_error = 'NOT_AUTHORIZED'.
when 4.
v_error = 'NOT_EXECUTED'.
when 5.
v_error = 'REPORT_NOT_EXISTENT'.
when 6.
v_error = 'REPORT_NOT_SUPPLIED'.
when 7.
v_error = 'VARIANT_EXISTS'.
when 8.
v_error = 'VARIANT_LOCKED'.
when 9.
v_error = 'OTHERS'.
endcase.
format color col_normal.
write : / 'Variant',
it_var-var_name, " Variant Name
'for report',
c_report+0(10),
'could not be created. ',
'Error : ',
v_error. " Error Message
else.
write : / 'Variant',
it_var-var_name, " Variant Name
'for report',
c_report+0(10),
'was created successfully. '.
endif.
clear it_var-var_name.
endform. " create_variant
regards,
deepthi reddy
‎2006 Dec 08 9:07 AM
Hi Anu,
INFO_FNAME : Field name in output table for coloring rows.
1).Define the layout structure of type LVC_S_LAYO .
2).Add a four-digit character field to your output table, as shown in the example below:
DATA: BEGIN OF GT_OUTTAB OCCURS 0.
INCLUDE STRUCTURE <DDIC-Struktur>.
DATA: linecolor(4) type c. "Color for corresponding line
DATA: END OF GT_OUTTAB.
3).Select your data and copy it into the output table.
4).Read one row of the output table at a time in a loop. To change the color of a row, assign a four-digit color code to the character field.
For more information on color codes, see field EMPHASIZE of the field catalog (see Output Options of Columns).
5).Assign the name of the internal table to field INFO_FNAME of the layout structure (in our case 'LINECOLOR' , see step 2).
6).Pass the layout structure and the output table with method set_table_for_first_display.
Regards
Abhishek
‎2006 Dec 08 9:17 AM
Hey Anu,
This program gives u exactly wt u want to do.......
Very simple copy paste this program in editor & see the magic........
REPORT zabhi_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
‎2006 Dec 08 9:49 AM
Hello,
Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
TYPE-POOLS: slis. " ALV Global types
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '30' OBLIGATORY. "#EC *
SELECTION-SCREEN END OF LINE.
TYPES:
BEGIN OF ty_vbak,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
line_color(4), " Line color
END OF ty_vbak.
DATA:
Data displayed
gt_vbak TYPE TABLE OF ty_vbak.
----
INITIALIZATION.
v_1 = 'Maximum of records to read'.
----
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_fill_color.
PERFORM f_display_data.
----
Form f_read_data
----
FORM f_read_data.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
FROM vbak UP TO p_max ROWS.
ENDFORM. " F_READ_DATA
----
Form f_fill_color
----
FORM f_fill_color.
DATA l_rnd_value TYPE integer2.
FIELD-SYMBOLS <vbak> TYPE ty_vbak.
LOOP AT gt_vbak ASSIGNING <vbak>.
Random value
CALL FUNCTION 'RANDOM_I2'
EXPORTING
rnd_min = 0
rnd_max = 3
IMPORTING
rnd_value = l_rnd_value.
CASE l_rnd_value.
WHEN 0.
<vbak>-line_color = 'C100'. " Blue.
WHEN 1.
<vbak>-line_color = 'C300'. " Yellow.
WHEN 2.
<vbak>-line_color = 'C500'. " Green.
WHEN 3.
<vbak>-line_color = 'C600'. " Red.
ENDCASE.
ENDLOOP.
ENDFORM. " F_FILL_COLOR
----
Form f_display_data
----
FORM f_display_data.
DATA:
ls_layout TYPE slis_layout_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
Build the field catalog
m_fieldcat 'VKORG' 'VBAK'.
m_fieldcat 'KUNNR' 'VBAK'.
m_fieldcat 'VBELN' 'VBAK'.
m_fieldcat 'NETWR' 'VBAK'.
Fill Layout - Name of the field with color
ls_layout-info_fieldname = 'LINE_COLOR'.
Display the list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_vbak.
ENDFORM. " F_DISPLAY_DATA
Regs,
Venkat Ramanan N
‎2006 Dec 08 10:03 AM
Hi ANURITA WAGHE ,
1> Say the name of the field in the list data is "color_field"
2> Say the name of your layout structure is "layout"
3> Assign colour code , say "C610" , to "color_field"
4> Assign the "info_fname" component of "layout" as "COLOR_FIELD" (case-sensitive) .
Say , " layout-info_fname = 'COLOR_FIELD' "
Try this out and please do let me know the status .
Regards ,
Dhera Kamlesh H. R.