*---方式一、alv
*------- Data definition ---------------------------------------------
data: begin of gt_output occurs 0.
include type spfli.
data: status type char2. "在输出内表中定义:‘1’红色,'2'黄色,‘3’绿色
data: end of gt_output.
*---Alv data definition
type-pools: slis.
data: gs_layout type slis_layout_alv.
gs_layout-zebra = 'X'.
gs_layout-colwidth_optimize = 'X'.
gs_layout-lights_fieldname = 'STATUS'. "在layout中定义
data: gt_fieldcat type slis_t_fieldcat_alv with header line.
define m_alv_head.
clear gt_fieldcat.
gt_fieldcat-fieldname = '&1'.
gt_fieldcat-seltext_m = '&2'.
gt_fieldcat-no_zero = ''.
append gt_fieldcat.
end-of-definition.
*------- Start-of-selection ------------------------------------------
start-of-selection.
select * into table gt_output
from spfli.
loop at gt_output.
if gt_output-carrid = 'AA'.
gt_output-status = '3'. "123 红黄绿
else.
gt_output-status = '1'.
endif.
modify gt_output.
endloop.
*------- End-of-selection --------------------------------------------
end-of-selection.
*---Set fields
clear gt_fieldcat[].
m_alv_head carrid carrid.
m_alv_head connid connid.
if gt_output[] is initial.
message '没有数据!' type 'S'.
leave list-processing.
endif.
*---Set titlebar
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
is_layout = gs_layout
it_fieldcat = gt_fieldcat[] "'[]' is necessary
i_save = 'A'
tables
t_outtab = gt_output
exceptions
program_error = 1
others = 2.
*---方式二、wirte
data: begin of itab occurs 0,
icon(4) type c,
int1 type i,
end of itab.
data: wa like line of itab.
wa-int1 = '-3'.
append wa to itab.
wa-int1 = '3'.
append wa to itab .
start-of-selection.
loop at itab into wa .
if wa-int1 < 0 .
wa-icon = '@5C@'.
else.
wa-icon = '@5B@'.
endif. .
modify itab from wa.
endloop.
start-of-selection.
loop at itab into wa .
write: / wa-icon , wa-int1.
endloop.
评论