2、3年前写的代码,之后由于各种内因外因,没能继续测试下去。欢迎有兴趣的同学继续测试各个参数。
*&---------------------------------------------------------------------*
*& Report ZLG_ALV *
*& *
*&---------------------------------------------------------------------*
*& 测试alv各项参数 *
*& 未完全 - v01 - 20081212 *
*& 未完全 - v02 - 20090731 *
*&---------------------------------------------------------------------*
*& ALV显示可以用的FM包括: *
*& 1、REUSE_ALV_GRID_DISPLAY *
*& 2、REUSE_ALV_GRID_DISPLAY_LVC *
*& 3、REUSE_ALV_BLOCK_LIST_DISPLAY *
*& *
*& ALV显示相关FM包括: *
*& 1、REUSE_ALV_FIELDCATALOG_MERGE - 制作类型的 fieldcatalog *
*& 2、LVC_FIELDCATALOG_MERGE - 制作 LVC_T_FCAT 类型的 fieldcatalog *
*& 3、REUSE_ALV_BLOCK_LIST_INIT *
*& 4、REUSE_ALV_BLOCK_LIST_APPEND *
*& 5、REUSE_ALV_EVENTS_GET *
*& *
*&---------------------------------------------------------------------*
*& ALV(REUSE_ALV_GRID_DISPLAY)输出必须的内容: *
*& 1、output itab *
*& 2、fieldcatalog *
*&---------------------------------------------------------------------*
*& 相关FM注意事项 *
*& 一、REUSE_ALV_FIELDCATALOG_MERGE *
*& 1、I_INTERNAL_TABNAME所用的变量对应结构体必须用DATA+BEGIN申明, *
*& 不可以使用DATA+TYPE line type,否则不会返回Fieldcatalog。 *
*& 2、修改了I_INTERNAL_TABNAME对应结构体后, *
*& 必须/N后重新进去SE38时,才会生效。 *
*& 3、程序代码每行不能太长,不然容易报错, *
*& 具体内容见FORM f_fieldcatalog。 *
*& *
*& *
*& 二、REUSE_ALV_GRID_DISPLAY *
*& 1、使用标准GUI:STANDARD_FULLSCREEN *
*& 2、标准GUI中的&OLO中显示的列名取决于fieldcatalog中的设置 *
*& *
*& 三、REUSE_ALV_BLOCK_LIST_DISPLAY *
*& 1、首先用 REUSE_ALV_BLOCK_LIST_INIT 初始化 *
*& 2、然后用 REUSE_ALV_BLOCK_LIST_APPEND 添加需要显示的ALV *
*& 3、最后用 REUSE_ALV_BLOCK_LIST_DISPLAY 显示 *
*& *
*&---------------------------------------------------------------------*
*& 参考自:
*& https://www.doczj.com/doc/8a8035066.html,/viewthread.php?tid=1051462&highlight=ALV%2B%D7%DC%BD %E1
*&---------------------------------------------------------------------* REPORT zlg_alv .
*&---------------------------------------------------------------------*
*& 导入 *
*&---------------------------------------------------------------------*
*include:
*-----------------------------------------------------------------------
* Instead of statement 'INCLUDE
* statement 'TYPE-POOLS: icon.' directly.
*-----------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& 类型池引用申明 *
*&---------------------------------------------------------------------* TYPE-POOLS:slis.
TYPE-POOLS:icon."代替 include
*&---------------------------------------------------------------------*
*& 类型定义 *
*&---------------------------------------------------------------------*
*ALV输出表类型
TYPES:BEGIN OF typ_alv,
icon TYPE icon-id,
box(1) TYPE c,
c10(10) TYPE c,
n10(10) TYPE n,
n5(5) TYPE n,
c TYPE c,
d TYPE d,
t TYPE t,
x TYPE x,
i TYPE i, "普通I型数字
i2 TYPE i, "负数普通显示
i3 TYPE i, "no_sign
i4 TYPE i, "负号前置
quantity TYPE p DECIMALS 5,"数量
qunit TYPE meins,"数量参考单位
p TYPE p DECIMALS 5,
cp(33) TYPE c, "放置P,32+1?
currency TYPE p DECIMALS 5,
cunit TYPE bkpf-waers,
cunit2 TYPE c LENGTH 5,
f TYPE f,
string TYPE string, "内表型类型?
xstring TYPE xstring,"内表型类型?
bname TYPE bname,
bnamel(30) TYPE c, "与bname对齐方式不同
bnamel2(30) TYPE c, "热点
matnr TYPE matnr, "F4help - 1 datum TYPE datum, "F4help - 2 linecolor(4) TYPE c, "用于保存行颜色代码
cellcolor TYPE slis_t_specialcol_alv,"用于保存单元格颜色代码END OF typ_alv.
*&---------------------------------------------------------------------* *& 变量定义 * *&---------------------------------------------------------------------* *ALV输出用内表相关
DATA:itab_alv TYPE STANDARD TABLE OF typ_alv,
wa_alv TYPE typ_alv.
*ALV Layout相关
DATA:wa_layout TYPE slis_layout_alv.
*ALV Sort相关
DATA:itab_alv_sort TYPE slis_t_sortinfo_alv,
wa_alv_sort TYPE slis_sortinfo_alv.
*ALV Event相关
DATA:itab_alv_event TYPE slis_t_event,
wa_alv_event TYPE slis_alv_event.
*ALV Fieldcatalog相关
DATA:itab_alv_fieldcatalog TYPE slis_t_fieldcat_alv,
wa_alv_fieldcatalog TYPE slis_fieldcat_alv.
*只用于REUSE_ALV_FIELDCATALOG_MERGE
DATA:BEGIN OF cns_alv,
icon LIKE icon-id,"这里只能用like,用type会无效
box(1) TYPE c,
c10(10) TYPE c,
n10(10) TYPE n,
n5(5) TYPE n,
c TYPE c,
d TYPE d,
t TYPE t,
x TYPE x,
i TYPE i,
i2 TYPE i, "负数
i3 TYPE i, "显示no_sign效果
i4 TYPE i, "显示负号前置效果
quantity TYPE p DECIMALS 5,"数量
qunit TYPE meins,"数量参考单位
p TYPE p,
cp(33) TYPE c, "放置P,32+1?
currency TYPE p DECIMALS 5,
cunit TYPE bkpf-waers,
cunit2 TYPE c LENGTH 5,"货币单位没有被FM加入fieldcatlog中
f TYPE f,
string TYPE string, "内表型类型?
xstring TYPE xstring,"内表型类型?
bname TYPE bname,
bnamel(30) TYPE c, "与bname对齐方式不同
bnamel2(30) TYPE c, "热点
matnr TYPE matnr, "F4help - 1 datum TYPE datum, "F4help - 2 linecolor(4) TYPE c, "用于保存行颜色代码
cellcolor TYPE slis_t_specialcol_alv,"用于保存单元格颜色代码END OF cns_alv.
*隐藏标准按钮
DATA:itab_alv_excluding TYPE slis_t_extab ,
wa_alv_excluding TYPE slis_extab .
*全局常量
DATA:cns_tabname TYPE slis_tabname VALUE 'CNS_ALV',
cns_repid TYPE sy-repid VALUE 'ZLG_ALV'," sy-repid cns_pf_status_set TYPE slis_tabname VALUE '',
cns_user_command TYPE slis_formname VALUE 'F_USER_COMMAND',
cns_html_top_of_page TYPE slis_formname VALUE 'F_HTML_TOP_OF_PAGE', cns_grid_title TYPE lvc_title VALUE 'ALV title',
cns_l(1) TYPE c VALUE 'L',
cns_c(1) TYPE c VALUE 'C',
cns_r(1) TYPE c VALUE 'R',
cns_a(1) TYPE c VALUE 'A',
cns_u(1) TYPE c VALUE 'U',
cns_x(1) TYPE c VALUE 'X',
cns_space(1) TYPE c VALUE space,
cns_half TYPE i VALUE '0.5'.
*全局变量
DATA:g_color_id(1) TYPE c,
g_cellcolor TYPE slis_specialcol_alv,
g_datum TYPE datum,
g_flg_alv TYPE i,"ALV类型标识
g_flg_random TYPE i."分歧变量
*&---------------------------------------------------------------------* *& 选择屏幕 * *&---------------------------------------------------------------------* *与form f_check_alv_type相关
PARAMETERS:fagd TYPE c RADIOBUTTON GROUP alv DEFAULT 'X',"alv grid
fagdlvc TYPE c RADIOBUTTON GROUP alv,"alv grid lvc
fabl TYPE c RADIOBUTTON GROUP alv."alv block list
*&---------------------------------------------------------------------* *& 初始化 * *&---------------------------------------------------------------------* INITIALIZATION.
CLEAR:itab_alv_fieldcatalog.
*生成随机数
PERFORM f_get_random.
*&---------------------------------------------------------------------* *& 填充数据及部分设置 *
*&---------------------------------------------------------------------* START-OF-SELECTION.
*ALV输出用内表 - 填充
PERFORM f_get_data.
*&---------------------------------------------------------------------* *& 设置及显示 * *&---------------------------------------------------------------------* END-OF-SELECTION.
*判断显示哪种ALV
PERFORM f_check_alv_type CHANGING g_flg_alv.
*ALV Fieldcatalog - 设置
PERFORM f_fieldcatalog_all .
*ALV layout - 设置
PERFORM f_layout_all.
*ALV Sort - 设置
PERFORM f_sort_all.
*ALV Evnet - 设置
PERFORM f_event_all.
*ALV GUI - 设置
PERFORM f_gui_all.
*ALV输出结果
PERFORM f_show_alv_all.
*&---------------------------------------------------------------------* *& Form f_get_data
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* FORM f_get_data .
g_datum = sy-datum.
DO 100 TIMES .
CLEAR wa_alv."清空内表型组件(如cellcolor)的值
wa_alv-icon = '@0A@'."red light 可以查看类型池ICON中的值
wa_alv-c10 = sy-index.
wa_alv-n10 = sy-index ** 2.
wa_alv-i = sy-index.
wa_alv-i2 = wa_alv-i * -1.
wa_alv-i3 = wa_alv-i2.
wa_alv-i4 = wa_alv-i2 * wa_alv-i * wa_alv-i.
CASE sy-index.
WHEN 1.
wa_alv-p = 1.
WHEN 2.
wa_alv-p = '1.5436'.
WHEN OTHERS.
wa_alv-p = '0.5436'.
ENDCASE.
wa_alv-quantity = sy-index * 1000.
wa_alv-qunit = 'MT'.
CASE sy-index.
WHEN 1.
wa_alv-qunit = 'MT'.
WHEN 2.
wa_alv-qunit = 'MT'.
WHEN OTHERS.
wa_alv-qunit = 'KG'.
ENDCASE.
wa_alv-cp = wa_alv-p.
wa_alv-currency = 1000.
CASE sy-index.
WHEN 1.
wa_alv-cunit = 'RMB'.
WHEN 2.
wa_alv-cunit = 'CNY'.
WHEN OTHERS.
wa_alv-cunit = 'JPY'.
ENDCASE.
wa_alv-cunit2 = wa_alv-cunit.
wa_alv-datum = g_datum.
g_datum = g_datum + 1.
wa_alv-bname = sy-uname.
wa_alv-bnamel = sy-uname.
wa_alv-bnamel2 = sy-uname.
*--颜色相关
PERFORM f_alv_color.
APPEND wa_alv TO itab_alv.
ENDDO .
ENDFORM. " f_get_data
*&---------------------------------------------------------------------* *& Form f_check_alv_type
*&---------------------------------------------------------------------* * 判断显示哪种ALV
*----------------------------------------------------------------------* * <--P_FLG_ALV ALV种类
*----------------------------------------------------------------------* FORM f_check_alv_type CHANGING p_flg_alv.
*----------------------------------------------------------------------* * 注意修改各个ALL中的CASE语句:
*FORM f_layout_all .
*FORM f_fieldcatalog_all .
*FORM f_sort_all .
*FORM f_gui_all .
*FORM f_show_alv_all .
*----------------------------------------------------------------------* IF fagd = 'X'.
p_flg_alv = 1.
ELSEIF fagdlvc = 'X'.
p_flg_alv = 2.
ELSEIF fabl = 'X'.
p_flg_alv = 3.
ENDIF.
ENDFORM. " f_check_alv_type
*&---------------------------------------------------------------------* *& Form f_layout_all
*&---------------------------------------------------------------------* * 各种ALV处理LAYOUT相关设置
*----------------------------------------------------------------------* FORM f_layout_all .
CASE g_flg_alv.
WHEN 1 OR 3.
PERFORM f_layout CHANGING wa_layout.
WHEN 2.
WHEN OTHERS.
ENDCASE.
ENDFORM. " f_layout_all
*&---------------------------------------------------------------------* *& Form f_fieldcatalog_reuse
*&---------------------------------------------------------------------* * REUSE_ALV_FIELDCATALOG_MERGE
*----------------------------------------------------------------------* * -->P_REPID text
* -->P_TABNAME text
* <--PT_FIELDCATALOG text
*----------------------------------------------------------------------* *form f_fieldcatalog_reuse tables
* PT_FIELDCATALOG1 structure wa_alv_fieldcatalog
FORM f_fieldcatalog_reuse USING p_repid TYPE sy-repid
p_tabname LIKE cns_tabname
CHANGING pt_fieldcatalog LIKE
itab_alv_fieldcatalog. *----------------------------------------------------------------------* *即使是注释也不能太长。
*原因:FM“K_KKB_FIELDCAT_MERGE”以下代码可能会报错:
* line:363
* read report l_prog_tab_local into l_abap_source.
* check sy-subrc eq 0.
*----------------------------------------------------------------------* *& 其它功能实现相关处理内容:
*& 1、颜色设置
*& 2、F1帮助
*&
*----------------------------------------------------------------------* *& 1、不能使用structure line of:系统提示参数数量不匹配
*& 只能使用structure
*& 2、对于REUSE_ALV_FIELDCATALOG_MERGE,只能用changing传内表,
*& 因为tables产生的是带有表头的内表参数
*& 3、不同名但同数据元素(数据库字段)会作为重复而排除
*& 但基本类型不会有这个问题
*&---------------------------------------------------------------------* CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = p_repid
i_internal_tabname = p_tabname
* i_structure_name = ' '
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = p_repid
i_bypassing_buffer = 'X'"
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = pt_fieldcatalog
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.
ELSE.
LOOP AT pt_fieldcatalog INTO wa_alv_fieldcatalog.
*-----
PERFORM f_fieldcatalog_single.
*-----更新
MODIFY pt_fieldcatalog FROM wa_alv_fieldcatalog
* TRANSPORTING seltext_l
* emphasize
.
ENDLOOP.
ENDIF.
ENDFORM. " f_fieldcatalog_reuse
*&---------------------------------------------------------------------* *& Form f_fieldcatalog_all
*&---------------------------------------------------------------------* * 各种控制ALV列显示
*----------------------------------------------------------------------* FORM f_fieldcatalog_all .
CASE g_flg_alv.
WHEN 1 OR 3.
PERFORM f_fieldcatalog_reuse USING cns_repid
cns_tabname
CHANGING itab_alv_fieldcatalog.
WHEN 2.
WHEN OTHERS.
ENDCASE.
ENDFORM. " f_fieldcatalog_all
*&---------------------------------------------------------------------* *& Form f_layout
*&---------------------------------------------------------------------* * 处理LAYOUT相关设置
*----------------------------------------------------------------------* * <--P_LAYOUT ALV的LAYOUT结构体变量
*----------------------------------------------------------------------* *& 其它功能实现相关处理内容:
*& 1、颜色设置
*& 2、求和(数字、字符型数字)
*&
*----------------------------------------------------------------------* FORM f_layout CHANGING pa_layout LIKE wa_layout.
*types: begin of slis_layout_alv.
*58项?
* dummy,
* no_colhead(1) type c, " no headings
* no_hotspot(1) type c, " headings not as hotspot
* zebra(1) type c, " striped pattern
* no_vline(1) type c, " columns separated by space
* no_hline(1) type c, "rows separated by space B20K8A0N5D * cell_merge(1) type c, " not suppress field replication * edit(1) type c, " for grid only
* edit_mode(1) type c, " for grid only
* numc_sum(1) type c, " totals for NUMC-Fields possib. * no_input(1) type c, " only display fields
* f2code like sy-ucomm, "
* reprep(1) type c, " report report interface active * no_keyfix(1) type c, " do not fix keycolumns
* expand_all(1) type c, " Expand all positions
* no_author(1) type c, " No standard authority check
** PF-status
* def_status(1) type c, " default status space or 'A'
* item_text(20) type c, " Text for item button
* countfname type lvc_fname,
** Display options
* colwidth_optimize(1) type c,
* no_min_linesize(1) type c, " line size = width of the list * min_linesize like sy-linsz, " if initial min_linesize = 80
* max_linesize like sy-linsz, " Default 250
* window_titlebar like sy-title,
* no_uline_hs(1) type c,
** Exceptions
* lights_fieldname type slis_fieldname," fieldname for exception * lights_tabname type slis_tabname, " fieldname for exception
*lights_rollname like dfies-rollname," rollname f. exceptiondocu
* lights_condense(1) type c, " fieldname for exception
** Sums
* no_sumchoice(1) type c, " no choice for summing up
* no_totalline(1) type c, " no total line
* no_subchoice(1) type c, " no choice for subtotals
* no_subtotals(1) type c, " no subtotals possible
* no_unit_splitting type c, " no sep. tot.lines by inh.units * totals_before_items type c, " diplay totals before the items * totals_only(1) type c, " show only totals
*totals_text(60) type c, " text for 1st col. in total line
* subtotals_text(60) type c, " text for 1st col. in subtotals ** Interaction
* box_fieldname type slis_fieldname, " fieldname for checkbox
* box_tabname type slis_tabname," tabname for checkbox
* box_rollname like dd03p-rollname," rollname for checkbox
*expand_fieldname type slis_fieldname, " fieldname flag 'expand'
*hotspot_fieldname type slis_fieldname, " fieldname flag hotspot
* confirmation_prompt, " confirm. prompt when leaving
* key_hotspot(1) type c, " keys as hotspot " K_KEYHOT
* flexible_key(1) type c, " key columns movable,...
* group_buttons(1) type c, " buttons for COL1 - COL5
* get_selinfos(1) type c, " read selection screen
* group_change_edit(1) type c, " Settings by user for new group * no_scrolling(1) type c, " no scrolling
** Detailed screen
* detail_popup(1) type c, " show detail in popup
* detail_initial_lines(1) type c, " show also initial lines
* detail_titlebar like sy-title," Titlebar for detail
** Display variants
* header_text(20) type c, " Text for header button
* default_item(1) type c, " Items as default
** colour
* info_fieldname type slis_fieldname, " infofield for listoutput * coltab_fieldname type slis_fieldname, " colors
** others
* list_append(1) type c, " no call screen
* xifunckey type aqs_xikey, " eXtended interaction(SAPQuery) * xidirect type flag, " eXtended INTeraction(SAPQuery) * dtc_layout type dtc_s_layo, "Layout for configure the Tabstip *types: end of slis_layout_alv.
**************补完以下参数******************
* dummy,
*--没有列名行
* no_colhead(1) type c, " no headings
* pa_layout-no_colhead = 'X'.
*--
* no_hotspot(1) type c, " headings not as hotspot
* pa_layout-no_hotspot = 'X'."效果?
*--在非编辑状态ALV界面深蓝与浅蓝色交替显示行底色
* pa_layout-zebra = 'X'.
*--用空格分隔各列,fieldcatalog部分除外。
* pa_layout-no_vline = 'X'.
*--用空格分隔各行
* pa_layout-no_hline = 'X'.
*--
* cell_merge(1) type c, " not suppress field replication *--ALV处于可编辑状态,会自动出现最前端的BOX
* pa_layout-edit = 'X'." for grid only
*--
* edit_mode(1) type c, " for grid only
*--是否可以为字符型数字类型求和
* numc_sum(1) type c, " totals for NUMC-Fields possib. * pa_layout-numc_sum = 'X'.
* no_input(1) type c, " only display fields
*--修改“显示详细”功能代码,默认为F2键
* f2code like sy-ucomm,
* pa_layout-layout-f2code = '&ETA'."设置成双击
* reprep(1) type c, " report report interface active * no_keyfix(1) type c, " do not fix keycolumns
* expand_all(1) type c, " Expand all positions
* no_author(1) type c, " No standard authority check
**--------PF-status--------------------------------------------------
*--
* def_status(1) type c, " default status space or 'A'
* item_text(20) type c, " Text for item button
* countfname type lvc_fname,
**--------Display options--------------------------------------------
*--所有列宽度最优化
* pa_layout-colwidth_optimize = 'X'.
*--
* no_min_linesize(1) type c, " line size = width of the list * min_linesize like sy-linsz, " if initial min_linesize = 80
* max_linesize like sy-linsz, " Default 250
*--ALV窗口标题栏
pa_layout-window_titlebar = 'window_titlebar'."like sy-title
*--
* no_uline_hs(1) type c,
**--------Exceptions-------------------------------------------------
* lights_fieldname type slis_fieldname," fieldname for exception * lights_tabname type slis_tabname, " fieldname for exception
*lights_rollname like dfies-rollname," rollname f. exceptiondocu
* lights_condense(1) type c, " fieldname for exception
**--------Sums-------------------------------------------------------
* no_sumchoice(1) type c, " no choice for summing up
* no_totalline(1) type c, " no total line
* no_subchoice(1) type c, " no choice for subtotals
* no_subtotals(1) type c, " no subtotals possible
* no_unit_splitting type c, " no sep. tot.lines by inh.units *--求和
pa_layout-totals_before_items = 'X'." 在ALV最顶端显示求和结果
* pa_layout-totals_only = 'X'."只显示总和(无效?)
*totals_text(60) type c, " text for 1st col. in total line
* pa_layout-totals_text = '最长60字符,总和'."无效?
* subtotals_text(60) type c, " text for 1st col. in subtotals **--------Interaction------------------------------------------------
* box_fieldname type slis_fieldname, " fieldname for checkbox
* box_tabname type slis_tabname," tabname for checkbox
* box_rollname like dd03p-rollname," rollname for checkbox
*expand_fieldname type slis_fieldname, " fieldname flag 'expand'
*hotspot_fieldname type slis_fieldname, " fieldname flag hotspot
* confirmation_prompt, " confirm. prompt when leaving
* key_hotspot(1) type c, " keys as hotspot " K_KEYHOT
* flexible_key(1) type c, " key columns movable,...
* group_buttons(1) type c, " buttons for COL1 - COL5
* get_selinfos(1) type c, " read selection screen
* group_change_edit(1) type c, " Settings by user for new group *--无效?
* no_scrolling(1) type c, " no scrolling
* pa_layout-no_scrolling = 'X'.
**--------Detailed screen--------------------------------------------
*--是否在弹出窗口中显示详细(F2)
* pa_layout-detail_popup = 'X'."无效?
* detail_initial_lines(1) type c, " show also initial lines
*--弹出窗口标题栏
* detail_titlebar like sy-title," Titlebar for detail
pa_layout-detail_titlebar = '详细内容'."系统默认为“细节”
**--------Display variants-------------------------------------------
* header_text(20) type c, " Text for header button
* default_item(1) type c, " Items as default
**--------colour-----------------------------------------------------
*----颜色具体设置见FORM f_get_data、FORM f_alv_color
*--行颜色显示控制
* 指定颜色字段指定后fieldcatalog中该字段失效
* pa_layout-info_fieldname = 'LINECOLOR'." infofield for listoutput
*--单元格颜色显示控制
* 注意该字段为内表,可以添加该行多个字段名
* pa_layout-coltab_fieldname = 'CELLCOLOR'.
**--------others-----------------------------------------------------
* list_append(1) type c, " no call screen
* xifunckey type aqs_xikey, " eXtended interaction(SAPQuery) * xidirect type flag, " eXtended INTeraction(SAPQuery) * dtc_layout type dtc_s_layo, "Layout for configure the Tabstip ENDFORM. " f_layout
*&---------------------------------------------------------------------* *& Form f_alv_color
*&---------------------------------------------------------------------* * ALV颜色相关处理
*----------------------------------------------------------------------* FORM f_alv_color .
*----------------------------------------------------------------------* *颜色设置的优先级顺序从大到小:
*单元格(在内表字段及layout中控制)
*行(在内表字段及layout中控制)
*列(在fieldcatalog中控制)
*即若同时使用了上述3中更改颜色的方法,则列的颜色会被行的颜色覆盖掉,而行
*的颜色又会背单元格的颜色覆盖掉,最终只会显示出单元格的颜色.
*----------------------------------------------------------------------* *& ALV中的颜色代码共有4位,
*& 第1位是固定为“C”(代表COLOR),
*& 第2位代表是颜色编码(1到7),
*& 第3位是加强颜色的设置(1表示打开,0表示关闭),
*& 第4位是减弱颜色(1表示打开,0表示关闭),
*& 在强化关闭的情况下,相反的作用是背景和字体的变化。
*& CX00:底色较柔和、前景色为黑色
*& CX01:底色为灰色、前景色为较肉色彩色
*& CX10:底色为强彩色、前景色为黑色
*& CX11:同CX10
*----------------------------------------------------------------------* *--行颜色相关
PERFORM f_row_color.
*--列颜色设置(见fieldcatalog)
*fieldcatalog-emphasize = '颜色代码'.
*--单元格颜色相关
PERFORM f_cell_color.
ENDFORM. " f_alv_color
*&---------------------------------------------------------------------* *& Form f_row_color
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* FORM f_row_color .
*----------------------------------------------------------------------* *& 必须在layout的info_fieldname中设置颜色字段名
*& 本例为:layout-info_fieldname = 'LINECOLOR'.
*----------------------------------------------------------------------* g_color_id = g_color_id + 1 .
IF g_color_id = 8 .
g_color_id = 1 .
ENDIF .
CONCATENATE 'C' g_color_id '00' INTO wa_alv-linecolor .
ENDFORM. " f_row_color
*&---------------------------------------------------------------------* *& Form f_cell_color
*&---------------------------------------------------------------------* * 控制单元格显示颜色
*----------------------------------------------------------------------* FORM f_cell_color .
*----------------------------------------------------------------------* *& 必须在layout的coltab_fieldname中设置颜色字段名
*& 本例为:coltab_fieldname = 'CELLCOLOR'.
*----------------------------------------------------------------------* *& 可以设置多个字段显示成不同的颜色
*& 只要向组件cellcolor(内表)中添加多条记录
*----------------------------------------------------------------------* CLEAR:g_cellcolor.
CASE wa_alv-c10+8(1).
WHEN 1 OR 3 OR 5 OR 7 OR 9.
g_cellcolor-fieldname = 'C10' . " 要修改颜色的字段名
g_cellcolor-color-col = 6 . " 颜色(1-7)
g_cellcolor-color-inv = 1 . " 前景字体(int代表背景颜色)APPEND g_cellcolor TO wa_alv-cellcolor .
WHEN 2 OR 4 OR 6 OR 8.
g_cellcolor-fieldname = 'C10' . " 要修改颜色的字段名
g_cellcolor-color-col = 5 . " 颜色(1-7)
g_cellcolor-color-inv = 1 . " 前景字体(int代表背景颜色)APPEND g_cellcolor TO wa_alv-cellcolor .
WHEN OTHERS.
g_cellcolor-fieldname = 'C10' . " 要修改颜色的字段名
g_cellcolor-color-col = 1 . " 颜色(1-7)
g_cellcolor-color-inv = 1 . " 前景字体(int代表背景颜色)APPEND g_cellcolor TO wa_alv-cellcolor .
ENDCASE.
ENDFORM. " f_cell_color
*&---------------------------------------------------------------------* *& Form f_fieldcatalog_single
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* FORM f_fieldcatalog_single .
*----------------------------------------------------------------------* *& 其它功能实现相关处理内容:
*& 1、颜色设置
*& 2、F1帮助
*& 3、求和
*----------------------------------------------------------------------* *types: begin of slis_fieldcat_alv.
* row_pos like sy-curow, " output in row
* col_pos like sy-cucol, " position of the column
* fieldname type slis_fieldname,
* tabname type slis_tabname,
* currency(5) type c,
* cfieldname type slis_fieldname, " field with currency unit * ctabname type slis_tabname, " and table
* ifieldname type slis_fieldname, " initial column
* quantity(3) type c,
* qfieldname type slis_fieldname, " field with quantity unit * qtabname type slis_tabname, " and table
* round type i, " round in write statement
* exponent(3) type c, " exponent for floats
* key(1) type c, " column with key-color
* icon(1) type c, " as icon
* symbol(1) type c, " as symbol
* checkbox(1) type c, " as checkbox
* just(1) type c, " (R)ight (L)eft (C)ent.
* lzero(1) type c, " leading zero
* no_sign(1) type c, " write no-sign
* no_zero(1) type c, " write no-zero
* no_convext(1) type c,
* edit_mask type slis_edit_mask, "
* emphasize(4) type c, " emphasize
* fix_column(1) type c, " Spalte fixieren
* do_sum(1) type c, " sum up
* no_out(1) type c, " (O)blig.(X)no out
* tech(1) type c, " technical field
* outputlen like dd03p-outputlen,
* offset type dd03p-outputlen, " offset
* seltext_l like dd03p-scrtext_l, " long key word
* seltext_m like dd03p-scrtext_m, " middle key word
* seltext_s like dd03p-scrtext_s, " short key word
* ddictxt(1) type c, " (S)hort (M)iddle (L)ong
* rollname like dd03p-rollname,
* datatype like dd03p-datatype,
* inttype like dd03p-inttype,
* intlen like dd03p-intlen,
* lowercase like dd03p-lowercase,
* ref_fieldname like dd03p-fieldname,
* ref_tabname like dd03p-tabname,
* roundfieldname type slis_fieldname,
* roundtabname type slis_tabname,
* decimalsfieldname type slis_fieldname,
* decimalstabname type slis_tabname,
* decimals_out(6) type c, " decimals in write statement * text_fieldname type slis_fieldname,
* reptext_ddic like dd03p-reptext, " heading (ddic)
* ddic_outputlen like dd03p-outputlen,
* key_sel(1) type c, " field not obligatory
* no_sum(1) type c, " do not sum up
* sp_group(4) type c, " group specification
* reprep(1) type c, " selection for rep/rep
* input(1) type c, " input
* edit(1) type c, " internal use only
* hotspot(1) type c, " hotspot
*types: end of slis_fieldcat_alv.
* row_pos like sy-curow, " output in row
* col_pos like sy-cucol, " position of the column
* fieldname type slis_fieldname,
* tabname type slis_tabname,
*--
* currency(5) type c,
* cfieldname type slis_fieldname, " field with currency unit * ctabname type slis_tabname, " and table PERFORM f_currency_setting.
*--效果不明
* perform f_filed_ifieldname.
*--
* quantity(3) type c,
* qfieldname type slis_fieldname, " field with quantity unit * qtabname type slis_tabname, " and table PERFORM f_field_quantity.
*--移动小数位
* round type i, " round in write statement PERFORM f_field_round.
*--
* exponent(3) type c, " exponent for floats
*--关键列
* key(1) type c, " column with key-color PERFORM f_field_key.
*--图标
* icon(1) type c, " as icon
PERFORM f_field_icon.
* symbol(1) type c, " as symbol
*--多选框
* checkbox(1) type c, " as checkbox
PERFORM f_field_checkbox.
*--对齐方式
* just(1) type c, " (R)ight (L)eft (C)ent.
PERFORM f_field_just.
*--左端补零
* lzero(1) type c, " leading zero
PERFORM f_field_lzero.
*--没有符号
* no_sign(1) type c, " write no-sign
PERFORM f_field_nosign.
*--
* no_zero(1) type c, " write no-zero
*--
* no_convext(1) type c,
*--输出格式控制
* edit_mask type slis_edit_mask,
PERFORM f_field_editmask.
*--列颜色控制
* emphasize(4) type c, " emphasize PERFORM f_column_color.
*--固定列
* fix_column(1) type c, " Spalte fixieren PERFORM f_field_fix.
*--单列求和
* do_sum(1) type c, " sum up
PERFORM f_field_dosum.
*--
* no_out(1) type c, " (O)blig.(X)no out
*--
* tech(1) type c, " technical field
*--列的字符宽度
* outputlen like dd03p-outputlen,
PERFORM f_field_outputlen.
*--
* offset type dd03p-outputlen, " offset
*--列描述设置
* seltext_l like dd03p-scrtext_l, " long key word
* seltext_m like dd03p-scrtext_m, " middle key word * seltext_s like dd03p-scrtext_s, " short key word PERFORM f_field_seltext.
* ddictxt(1) type c, " (S)hort (M)iddle (L)ong *--F1帮助
* rollname like dd03p-rollname,
PERFORM f_field_f1help.
*--ABAP 字典中的数据类型
* datatype like dd03p-datatype,
*--ABAP 数据类型(C,D,N,...)
* inttype like dd03p-inttype,
*--以字节计的内部长度
* intlen like dd03p-intlen,
*--是否允许输入小写字母?
* lowercase like dd03p-lowercase,
PERFORM f_field_lowercase.
*--F4帮助
* ref_fieldname like dd03p-fieldname,
* ref_tabname like dd03p-tabname,
PERFORM f_field_f4help.
* roundfieldname type slis_fieldname,
* roundtabname type slis_tabname,
* decimalsfieldname type slis_fieldname,
* decimalstabname type slis_tabname,
*--控制小数位输出
PERFORM f_field_decimalsout.
* text_fieldname type slis_fieldname,
* reptext_ddic like dd03p-reptext, " heading (ddic)
* ddic_outputlen like dd03p-outputlen,
* key_sel(1) type c, " field not obligatory
* no_sum(1) type c, " do not sum up
* sp_group(4) type c, " group specification
* reprep(1) type c, " selection for rep/rep
* input(1) type c, " input
* edit(1) type c, " internal use only PERFORM f_field_edit.
*--热点
* hotspot(1) type c, " hotspot
PERFORM f_field_hotspot.
ENDFORM. " f_fieldcatalog_single
*&---------------------------------------------------------------------* *& Form f_column_color
*&---------------------------------------------------------------------* * text
*----------------------------------------------------------------------* FORM f_column_color .
*----------------------------------------------------------------------* *&
*&
*&
*&
*----------------------------------------------------------------------* CASE wa_alv_fieldcatalog-fieldname.
WHEN 'F'.
wa_alv_fieldcatalog-emphasize = 'C711'.
WHEN OTHERS.
ENDCASE.
ENDFORM. " f_column_color
*&---------------------------------------------------------------------* *& Form f_field_f1help
*&---------------------------------------------------------------------*