`
guanhuaing
  • 浏览: 1239509 次
文章分类
社区版块
存档分类
最新评论

abap--关于在REUSE_ALV_GRID_DISPLAY将单元或行标识不同的颜色的处理收集

 
阅读更多

一、指定行显示不同颜色
参见:http://blog.csdn.net/CompassButton/archive/2006/09/08/1195672.aspx

二、不同列显示不同颜色
1)对于非key字段则可以通过设置字段格式(slis_fieldcat_alv)的emphasize指定,代码如下:
data: wa_fieldcat type slis_fieldcat_alv.
clear wa_fieldcat.
wa_fieldcat-ref_fieldname = im_ref_field.
wa_fieldcat-ref_tabname = im_ref_table.
wa_fieldcat-fieldname = im_fieldname.
wa_fieldcat-tabname = im_tabname.
wa_fieldcat-key = ‘’.
wa_fieldcat-fix_column = IM_fix.
wa_fieldcat-checkbox = im_checkbox.
wa_fieldcat-do_sum = im_dosum.
wa_fieldcat-no_zero = im_zero.
wa_fieldcat-no_out = im_out.
wa_fieldcat-seltext_l = im_seltex_l.
wa_fieldcat-seltext_m = im_seltex_l.
wa_fieldcat-seltext_s = im_seltex_l.
wa_fieldcat-outputlen = im_outputlen.
wa_fieldcat-decimals_out = im_dec.
wa_fieldcat--emphasize = 'C500'.
* wa_fieldcat-col_pos = IM_colpos.
append wa_fieldcat to re_field.
2)对于key字段的设置参见单元颜色设置一个特例(整列的所有单元)

三、指定单元格显示不同颜色(参见红色代码)
代码
report Ztest_fullscreencolor.
type-pools: slis.
class cl_gui_resources definition load.
types: begin of g_ty_s_test,
select_amount type i,
color_rows type i occurs 0,
color_fields_column type lvc_fname occurs 0,
color_fields_cell type lvc_fname occurs 0,
end of g_ty_s_test,

begin of g_ty_s_outtab_slis.
include type alv_t_t2.
*定义颜色设置字段
types: color(4) type c,
tabcolor type slis_t_specialcol_alv,
end of g_ty_s_outtab_slis,
g_ty_t_outtab_slis type table of g_ty_s_outtab_slis.

constants: con_true type char1 value 'X'.

field-symbols: <gt_outtab> type standard table.

data: gs_test type g_ty_s_test,
gt_outtab_slis type g_ty_t_outtab_slis,
g_repid type sy-repid.

data: g_field type lvc_s_fcat-fieldname,
g_int_field type i.
*----------------------------------------------------------------------*
* SELECTION-SCREEN *
*----------------------------------------------------------------------
selection-screen begin of block col with frame title text-col.
parameters:
p_col01 as checkbox.
select-options:
p_colf01 for g_int_field no intervals default 1.
parameters:
p_col02 as checkbox default 'X'.
select-options:
p_colf02 for g_field no intervals default 'CARRID'.
parameters:
p_col03 as checkbox .
select-options:
p_colf03 for g_field no intervals default 'CONNID'.
selection-screen end of block col.

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST *
*----------------------------------------------------------------------*
at selection-screen on value-request for p_colf02-low.
perform f01_f4_fcode changing p_colf02-low.

at selection-screen on value-request for p_colf03-low.
perform f01_f4_fcode changing p_colf03-low.

*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
start-of-selection.
g_repid = sy-repid.

gs_test-select_amount = 30.

if p_col01 eq con_true.
loop at p_colf01.
if not p_colf01-low is initial.
append p_colf01-low to gs_test-color_rows.
endif.
endloop.
endif.
if p_col02 eq con_true.
loop at p_colf02.
if not p_colf02-low is initial.
append p_colf02-low to gs_test-color_fields_column.
endif.
endloop.
endif.
if p_col03 eq con_true.
loop at p_colf03.
if not p_colf03-low is initial.
append p_colf03-low to gs_test-color_fields_cell.
endif.
endloop.
endif.
*----------------------------------------------------------------------*
* END-OF-SELECTION *
*----------------------------------------------------------------------*
end-of-selection.
perform f01_call_fullscreen.

*&---------------------------------------------------------------------*
*& Form f01_call_fullscreen
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f01_call_fullscreen .
data: ls_layo type slis_layout_alv,
lt_fcat type slis_t_fieldcat_alv.
perform f01_get_outtab.
perform f01_set_layo changing ls_layo.
perform f01_set_fcat changing lt_fcat.
perform f01_set_color changing lt_fcat ls_layo.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = g_repid
*传入控制信息
is_layout = ls_layo
it_fieldcat = lt_fcat
tables
t_outtab = <gt_outtab>
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. " f01_call_fullscreen
*&---------------------------------------------------------------------*
*& Form f01_get_outtab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f01_get_outtab.
select * from alv_t_t2
into corresponding fields of table gt_outtab_slis
up to gs_test-select_amount rows
order by primary key.

assign gt_outtab_slis to <gt_outtab>.
endform. " f01_get_outtab
*&---------------------------------------------------------------------*
*& Form f01_set_layo
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f01_set_layo changing cs_layo type slis_layout_alv.

data: l_text00 type sy-title,
l_text01 type sy-title,
l_text02 type sy-title,
l_text03 type sy-title.
*... Display options
cs_layo-colwidth_optimize = space.
cs_layo-no_colhead = space.
cs_layo-no_hotspot = space.
cs_layo-zebra = space.
cs_layo-no_vline = space.
cs_layo-no_hline = space.
cs_layo-cell_merge = space.
cs_layo-no_min_linesize = space.
cs_layo-min_linesize = space.
cs_layo-max_linesize = space.
sy-title = 'Test'.
set titlebar 'D0100' with cs_layo-window_titlebar.
cs_layo-no_uline_hs = space.
cs_layo-countfname = space.
*... Exceptions
cs_layo-lights_fieldname = space.
cs_layo-lights_tabname = space.
cs_layo-lights_rollname = space.
cs_layo-lights_condense = space.
*... Sums
cs_layo-no_sumchoice = space.
cs_layo-no_totalline = space.
cs_layo-totals_before_items = space.
cs_layo-totals_only = space.
cs_layo-totals_text = space.
cs_layo-no_subchoice = space.
cs_layo-no_subtotals = space.
cs_layo-subtotals_text = space.
cs_layo-numc_sum = space.
cs_layo-no_unit_splitting = space.
*... Interaction
cs_layo-box_fieldname = space.
cs_layo-box_tabname = space.
cs_layo-box_rollname = space.
cs_layo-expand_fieldname = space.
cs_layo-hotspot_fieldname = space.
cs_layo-no_input = space.
cs_layo-f2code = space.
cs_layo-confirmation_prompt = space.
cs_layo-key_hotspot = space.
cs_layo-flexible_key = space.
cs_layo-reprep = space.
cs_layo-group_buttons = space.
cs_layo-no_keyfix = space.
cs_layo-get_selinfos = space.
cs_layo-group_change_edit = space.
cs_layo-no_scrolling = space.
cs_layo-expand_all = space.
cs_layo-no_author = space.
*... Detailed screen
cs_layo-detail_popup = space.
cs_layo-detail_initial_lines = space.
cs_layo-detail_titlebar = space.
*... PF-status
cs_layo-def_status = space.
*... Display variants
cs_layo-header_text = space.
cs_layo-item_text = space.
cs_layo-default_item = space.
*... colour
cs_layo-info_fieldname = space.
cs_layo-coltab_fieldname = space.
*... others
cs_layo-list_append = space.
endform. " f01_set_layo

*&---------------------------------------------------------------------*
*& Form f01_set_fcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f01_set_fcat changing ct_fcat type slis_t_fieldcat_alv.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ALV_T_T2'
changing
ct_fieldcat = ct_fcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
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. " f01_set_fcat

*&---------------------------------------------------------------------*
*& Form f01_set_color
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f01_set_color changing ct_fcat type slis_t_fieldcat_alv
cs_layo type slis_layout_alv.
field-symbols: <ls_outtab> type any,
<ls_fcat> type slis_fieldcat_alv,
<l_any> type any,
<lt_table> type standard table.
data: l_row type i,
l_field type lvc_fname,
l_color_index type i,
lt_fcat type slis_t_fieldcat_alv,
lt_color_lvc type lvc_t_scol,
ls_color_lvc type lvc_s_scol,
lt_color_slis type slis_t_specialcol_alv,
ls_color_slis type slis_specialcol_alv.
*Set Row Color through info_fieldname
*对不同行对Color字段填写不同颜色值

cs_layo-info_fieldname = 'COLOR'.
loop at gs_test-color_rows into l_row.
read table <gt_outtab> assigning <ls_outtab> index l_row.
if sy-subrc eq 0.
assign component 'COLOR' of structure <ls_outtab> to <l_any>.
if sy-subrc eq 0.
<l_any> = 'C610'.
endif.
endif.
endloop.
lt_fcat = ct_fcat.
delete lt_fcat where tech ne space or no_out ne space.
*对于非关键字段可以通过emphasize设置颜色
loop at gs_test-color_fields_column into l_field.
read table lt_fcat assigning <ls_fcat>
with key fieldname = l_field.
if sy-subrc eq 0 and <ls_fcat>-key eq space.
read table ct_fcat assigning <ls_fcat>
with key fieldname = <ls_fcat>-fieldname.
if sy-subrc eq 0.
<ls_fcat>-emphasize = 'C500'.
endif.
else.
*对于关键字段可以通过则通过cs_layo-coltab_fieldname = 'TABCOLOR'来设置颜色
ls_color_slis-fieldname = <ls_fcat>-fieldname.
ls_color_slis-color-col = cl_gui_resources=>list_col_positive.
ls_color_slis-color-int = cl_gui_resources=>list_intensified.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
append ls_color_slis to lt_color_slis.
loop at <gt_outtab> assigning <ls_outtab>.
assign component 'TABCOLOR' of structure <ls_outtab> to <l_any>.
if sy-subrc eq 0.
<l_any> = lt_color_slis.
endif.
endloop.
endif.
endloop.

cs_layo-coltab_fieldname = 'TABCOLOR'.
*TABCOLOR表可以填写多条,也就可以同行控制多个单元的颜色。
loop at <gt_outtab> assigning <ls_outtab>.
add 1 to l_color_index.
clear lt_color_slis.
case l_color_index.
when 1.
ls_color_slis-color-col = cl_gui_resources=>list_col_background.
ls_color_slis-color-int = 0.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 2.
ls_color_slis-color-col = cl_gui_resources=>list_col_background.
ls_color_slis-color-int = cl_gui_resources=>list_intensified.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 3.
ls_color_slis-color-col = cl_gui_resources=>list_col_heading.
ls_color_slis-color-int = 0.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 4.
ls_color_slis-color-col = cl_gui_resources=>list_col_heading.
ls_color_slis-color-int = cl_gui_resources=>list_intensified.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 5.
ls_color_slis-color-col = cl_gui_resources=>list_col_normal.
ls_color_slis-color-int = 0.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 6.
ls_color_slis-color-col = cl_gui_resources=>list_col_normal.
ls_color_slis-color-int = cl_gui_resources=>list_intensified.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 7.
ls_color_slis-color-col = cl_gui_resources=>list_col_total.
ls_color_slis-color-int = 0.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 8.
ls_color_slis-color-col = cl_gui_resources=>list_col_total.
ls_color_slis-color-int = cl_gui_resources=>list_intensified.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 9.
ls_color_slis-color-col = cl_gui_resources=>list_col_key.
ls_color_slis-color-int = 0.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 10.
ls_color_slis-color-col = cl_gui_resources=>list_col_key.
ls_color_slis-color-int = cl_gui_resources=>list_intensified.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 11.
ls_color_slis-color-col = cl_gui_resources=>list_col_positive.
ls_color_slis-color-int = 0.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 12.
ls_color_slis-color-col = cl_gui_resources=>list_col_positive.
ls_color_slis-color-int = cl_gui_resources=>list_intensified.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 13.
ls_color_slis-color-col = cl_gui_resources=>list_col_negative.
ls_color_slis-color-int = 0.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 14.
ls_color_slis-color-col = cl_gui_resources=>list_col_negative.
ls_color_slis-color-int = cl_gui_resources=>list_intensified.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 15.
ls_color_slis-color-col = cl_gui_resources=>list_col_group.
ls_color_slis-color-int = 0.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
when 16.
ls_color_slis-color-col = cl_gui_resources=>list_col_group.
ls_color_slis-color-int = cl_gui_resources=>list_intensified.
ls_color_slis-color-inv = 0.
ls_color_slis-nokeycol = con_true.
clear l_color_index.
endcase.
*查找同行多少列需要设置颜色,则生成多条颜色纪录
loop at gs_test-color_fields_cell into l_field.
read table lt_fcat assigning <ls_fcat>
with key fieldname = l_field.
if sy-subrc eq 0.
ls_color_slis-fieldname = <ls_fcat>-fieldname.
append ls_color_slis to lt_color_slis.
endif.
endloop.
*将颜色纪录添加到数据输出表的TABCOLOR字段
assign component 'TABCOLOR' of structure <ls_outtab> to <lt_table>.
if sy-subrc eq 0.
append lines of lt_color_slis to <lt_table>.
endif.
endloop.
endform. " f01_set_color
*&---------------------------------------------------------------------*
*& Form f01_f4_fcode
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f01_f4_fcode changing c_value type lvc_s_fcat-fieldname.

data: lt_fcat type slis_t_fieldcat_alv,
ls_fcat type slis_fieldcat_alv.
data: lt_values type table of seahlpres,
lt_fields type table of dfies,
lt_return type table of ddshretval,
ls_value type seahlpres,
ls_field type dfies,
ls_return type ddshretval.
perform f01_set_fcat changing lt_fcat.
clear ls_field.
ls_field-fieldname = 'FIELDNAME'.
ls_field-intlen = 30.
ls_field-leng = 30.
ls_field-outputlen = 30.
ls_field-scrtext_s = ls_field-fieldname.
ls_field-scrtext_m = ls_field-fieldname.
ls_field-scrtext_l = ls_field-fieldname.
ls_field-reptext = ls_field-fieldname.
append ls_field to lt_fields.
loop at lt_fcat into ls_fcat where tech eq space.
ls_value-string = ls_fcat-fieldname.
append ls_value to lt_values.
endloop.
call function 'F4IF_INT_TABLE_VALUE_REQUEST'
exporting
retfield = 'FIELDNAME'
display = space
tables
value_tab = lt_values
field_tab = lt_fields
return_tab = lt_return
exceptions
parameter_error = 1
no_values_found = 2
others = 3.
if sy-subrc <> 0 and sy-subrc ne 3.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
read table lt_return into ls_return with key fieldname = 'FIELDNAME'.
if sy-subrc eq 0.
c_value = ls_return-fieldval.
endif.
endform. " f01_f4_fcode

分享到:
评论

相关推荐

    abap-ALV.rar_ABAP系统ALV_abap_abap开发alv

    描述中提到“ABAP ALV总结,ALV格式,REUSE_ALV_GRID_DISPLAY_LVC函数使用”,这表明我们将重点关注ALV的基本概念、数据格式以及如何通过REUSE_ALV_GRID_DISPLAY_LVC函数来实现ALV的显示。 ALV格式通常涉及如何组织...

    REUSE_ALV_GRID_DISPLAY超详细讲解

    REUSE_ALV_GRID_DISPLAY是一个功能强大的ABAP函数模块,主要用于在ABAP程序中显示ALV网格控件。该函数模块提供了大量的参数和事件,使得开发者可以根据需要自定义ALV网格控件的外观和行为。 功能模块的调用: CALL...

    ABAP_ALV_知识整理

    - **调用REUSE_ALV_GRID_DISPLAY**: 使用此函数模块来创建标准ALV网格显示。 - **设置列属性**: 设置列的标题、宽度、对齐方式等。 - **设置数据源**: 指定数据源表。 - **设置排序**: 可以设置默认排序规则。 **...

    ABAP开发ALV中自定义按钮实现

    在ABAP开发中,ALV(Accelerated List Viewer)是一种常用的数据展示工具,它提供了灵活的表格布局和交互性。用户通常需要对ALV进行定制,以满足特定的需求,例如添加自定义按钮来实现数据的打印或导出到Excel。本篇...

    ABAP中的ALV操作

    - `CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'`: 调用标准函数来显示ALV网格,并传递容器名称和数据表。 2. **ALV的列布局设置**: - `DATA: WA_LAYOUT TYPE LVC_S_LAYO`: 创建一个`LVC_S_LAYO`类型的变量来存储列...

    SAP ABAP ALV分页显示

    3. **ALV调用**:通过调用函数`REUSE_ALV_GRID_DISPLAY`来显示`IT_ZZP2`中的数据。此函数接收多个参数,包括字段目录(`IT_FIELDCAT`)、回调程序ID(`GD_REPID`)以及输出表(`T_OUTTAB`)等。 4. **分页控制**:使用`SET...

    ALV EDIT_MASK字段的使用.rar_ABAP EDIT_MASK_ALV EDIT_MASK字段的使用_ALVEDIT

    这通常通过在`CALL REPORT`或`CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'`等语句中使用`SET_EDIT_MASK`方法来实现。例如: ``` DATA: ls_edit_mask TYPE lvc_s_fdef, lv_fieldname LIKE LINE OF it_fieldname. ls...

    abap_alv工具栏修改

    本文将详细介绍如何在ABAP_ALV工具栏上添加或移除按钮,以及如何编写相关的事件处理程序。 #### 二、基础知识概述 在开始之前,我们需要了解一些基础概念: - **GUI Status**:GUI状态是指ALV网格视图中的功能区或...

    绝版的从实例到精通abap 学习--ALV控件的使用

    此外,教程可能还会介绍如何使用其他相关类和接口,如`IF_GUI_ALV_COLUMN`(用于定义列行为)、`IF_ABAP_ALV_GRID_DISPLAY`(用于显示和控制ALV行为)等,以及如何实现个性化定制,如更改颜色、添加按钮、自定义排序...

    SAP ABAP ALV 详解

    REUSE_ALV_GRID_DISPLAY 函数用于输出 GRID 型列表,REUSE_ALV_GRID_DISPLAY_LVC 函数用于输出 GRID 型列表。 此外,ALV 还提供了一些预定义的功能,例如筛选、汇总等,用户也可以根据需要增加新的功能。例如,使用...

    SAP_ABAP_ALV技术

    1. **激活ALV函数库**:在ABAP程序中包含所需的ABAP类和函数模块,如CL_GUI_ALV_GRID和REUSE_ALV_GRID_DISPLAY。 2. **创建数据结构**:定义用于存储数据库查询结果的数据结构。 3. **填充数据**:执行SQL查询,将...

    [ABAP]Function实现ALV Table 二:ALV的弹出窗口形式

    接下来,调用`REUSE_ALV_GRID_DISPLAY`或`REUSE_ALV_LIST_DISPLAY`函数。这两个函数的主要参数包括: 1. **I_PROGRAM_NAME**: 调用该Function的程序名。 2. **I_WINDOW**: 窗口号,对于弹出窗口,通常设置为0。 3. ...

    SAP-ABAP-OO-实现-CL-SALV-TABLE

    传统的 ALV 显示通常采用的是面向过程的方式,即通过函数模块 `REUSE_ALV_GRID_DISPLAY` 来实现。但是随着 ABAP 面向对象技术的发展,现在可以通过面向对象的方式来实现 ALV 的显示。 面向对象的 ALV 显示主要依赖...

    【SAP ABAP开发】 ALV报表开发教程

    最后一步是在`start-of-selection`事件处理器中调用`REUSE_ALV_GRID_DISPLAY`函数模块,这将触发ALV网格的显示。在调用时,需要传递之前设置好的参数以及数据源。 - `CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'` - `...

    ABAP向在线用户发送系统消息(自动刷新ALV)

    - `DISPLAY_ALV`过程负责调用`REUSE_ALV_GRID_DISPLAY`函数,正式展现ALV网格,并设置回调程序、状态栏和用户命令处理等。 5. **异常处理** - 在ALV显示过程中,程序使用了异常处理结构,通过`PROGRAM_ERROR`和`...

    alv abap sap 总结

    最后,在子 FORM(如 F_DISPLAY)中,通过调用相应的 ALV 函数(如 `REUSE_ALV_GRID_DISPLAY` 或 `REUSE_ALV_GRID_DISPLAY_LVC`),将内表数据传递给 ALV 进行显示。 1. 添加表头标题: 要添加表头,可以在显示 ...

    SAP ALV功能总结

    本文将重点介绍`REUSE_ALV_GRID_DISPLAY`函数,并结合具体示例来探讨其在SAP ABAP编程中的应用。 #### 二、`REUSE_ALV_GRID_DISPLAY`函数详解 `REUSE_ALV_GRID_DISPLAY`是SAP ALV的一个核心函数模块,用于展示表格...

    SAP ALV标准范例

    * BALVSD11:使用了REUSE_ALV_FIELDCATALOG_MERGE和REUSE_ALV_LIST_DISPLAY等FM。 * BALVHD01:使用了REUSE_ALV_VARIANT_DEFAULT_GET、REUSE_ALV_FIELDCATALOG_MERGE、REUSE_ALV_EVENTS_GET等FM,用于显示分级层次式...

    SAP系统中ALV报表

    接下来,我们将通过一个具体的示例来进一步了解如何使用`REUSE_ALV_GRID_DISPLAY`函数模块创建一个简单的ALV报表。示例程序名为`Z_ALV_TEST01`,其主要步骤包括: 1. **初始化数据结构**:定义数据表结构,如`IT_...

Global site tag (gtag.js) - Google Analytics