ALV屏幕输出小结
Posted salah
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ALV屏幕输出小结相关的知识,希望对你有一定的参考价值。
2019-10-09
用 ALV 输出的基本流程:
PERFORM get_data.
PERFORM event_build.
PERFORM layout_build.
PERFORM fields.
PERFORM output_alv.
1. 定义 ALV 用到的变量.TYPE-POOLS: slis. "packageDATA: i_alv_fieldcat TYPE slis_t_fieldcat_alv.
DATA: i_alv_field TYPE slis_fieldcat_alv.
DATA: i_layout TYPE slis_layout_alv.
DATA: w_repid LIKE sy-repid.
DATA: i_events TYPE slis_t_event,
i_event_exit TYPE slis_t_event_exit,
i_list_comments TYPE slis_t_listheader, "用来填充表单标题区域
i_excluding TYPE slis_t_extab.
DATA: w_variant LIKE disvariant,
w_variant_save(1) TYPE c,
w_events LIKE LINE OF i_events,
w_list_comments LIKE LINE OF i_list_comments,i_sort TYPE STANDARD TABLE OF slis_sortinfo_alv,
w_sort LIKE LINE OF i_sort.
2. 定义INITIALIZATION部分CLEAR: w_variant.
w_repid = sy-repid.
w_variant-report = w_repid.
w_variant-username = sy-uname.
w_variant_save = ‘A‘. "All types3. 对标题区和页尾区赋值FORM event_build .CALL FUNCTION ‘REUSE_ALV_EVENTS_GET‘ "获得事件名称及 form 的内表, 后面去填补 form"
EXPORTING
i_list_type = 0
IMPORTING
et_events = i_events.
READ TABLE i_events WITH KEY name = slis_ev_top_of_page INTO w_events.
IF sy-subrc = 0.
MOVE ‘ALV_TOP_OF_PAGE‘ TO w_events-form. "将标题区数据赋值给 W_EVENTS
MODIFY i_events FROM w_events INDEX sy-tabix.
ENDIF.
READ TABLE i_events WITH KEY name = slis_ev_end_of_list INTO w_events.
IF sy-subrc = 0.
MOVE ‘ALV_END_OF_LIST‘ TO w_events-form. "将页尾数据赋值给 W_EVENTS
MODIFY i_events FROM w_events INDEX sy-tabix.
ENDIF.
READ TABLE i_events WITH KEY name = slis_ev_end_of_page INTO w_events.
IF sy-subrc = 0.
MOVE ‘ALV_END_OF_PAGE‘ TO w_events-form. "将页脚区数据赋值给 W_EVENTS.
MODIFY i_events FROM w_events INDEX sy-tabix.
ENDIF.ENDFORM.定义上面用到的子函数FORM alv_top_of_page.DATA: p_werks(40).
CLEAR: i_list_comments[].
w_list_comments-typ = ‘H‘. "H=Header, S=Selection, A=Action
w_list_comments-key = ‘‘.
w_list_comments-info = ‘USI 同一 PO 分批收料报表‘.
APPEND w_list_comments TO i_list_comments.
* w_list_comments-typ = ‘S‘. "H = Header, S = Selection, A = Action
* w_list_comments-key = ‘‘.
* CONCATENATE ‘厂别‘ ‘1000‘ INTO p_werks.
* w_list_comments-info = p_werks.
* APPEND w_list_comments TO i_list_comments.
*
* w_list_comments-typ = ‘S‘. "H = Header, S = Selection, A = Action
* w_list_comments-key = ‘‘.
* CONCATENATE ‘厂别‘ ‘2000‘ INTO p_werks.
* w_list_comments-info = p_werks.
* APPEND w_list_comments TO i_list_comments.
CALL FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE‘
EXPORTING
i_logo = ‘ENJOYSAP_LOGO‘
it_list_commentary = i_list_comments.ENDFORM. "alv_top_of_page*&---------------------------------------------------------------------*4. Layout设置
*& Form alv_end_of_list
*&---------------------------------------------------------------------*
FORM alv_end_of_list.
clear: i_list_comments[].
w_list_comments-typ = ‘H‘. "H=Header, S=Selection, A=Action
w_list_comments-key = ‘‘.
w_list_comments-info = ‘页脚显示‘.
APPEND w_list_comments to i_list_comments.
call FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE‘
EXPORTING
it_list_commentary = i_list_comments
i_logo = ‘ENJOYSAP_LOGO‘
i_end_of_list_grid = ‘X‘.
ENDFORM. "alv_end_of_list
*&---------------------------------------------------------------------*
*& Form alv_end_of_page
*&---------------------------------------------------------------------*
FORM alv_end_of_page.
* CLEAR: i_list_comments[].
* w_list_comments-typ = ‘A‘. "H=Header, S=Selection, A=Action
* w_list_comments-key = ‘‘.
* w_list_comments-info = ‘END OF PAGE‘.
* APPEND w_list_comments TO i_list_comments.
*
* CALL FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE‘
* EXPORTING
* it_list_commentary = i_list_comments
* i_logo = ‘ENJOYSAP_LOGO‘
* i_end_of_list_grid = ‘X‘.
ENDFORM. "alv_end_of_pageFORM layout_build .w_repid = sy-repid. "当前程式i_layout-zebra = ‘X‘. "斑马条纹间隔i_layout-colwidth_optimize = ‘X‘. "优化列宽* i_layout-no_vline = ‘X‘. "用来设置是否有列间隔线i_layout-detail_initial_lines = ‘X‘.i_layout-detail_titlebar = ‘详细内容‘. "设置弹出窗口的标题栏i_layout-detail_popup = ‘X‘. "是否弹出详细信息窗口i_layout-f2code = ‘&ETA‘. "设置触发弹出详细窗口的功能码,这里是双击* i_layout-info_fieldname = ‘COLOR‘ ."设置颜色属性,设置ALV输出报表每一行的颜色,"其参数为输出内表的栏位名称,要注意的是,使用
"该属性需要同时在内表中定义一个与该参数所定义
"字段相同的栏位,然后往该栏位位填值. "先介绍ALV里色码.就是颜色编码,4位CHAR型.
Cxyz---
Color X:1-7
Y:1/0: 强化 开/关
Z:1/0: 相反 开/关
其中C是固定的第一位,第二位代表是颜色编码(1到7),第三位是加强的设置,第四位是相反,个人理解,在强化关闭的情况下,相反的作用是背景和字体的变化.
颜色编码:
x 颜色 主要使用在
1 Gray-blue headers
2 Light gray List bodies
3 yellow totals
4 Blue-green Key columns
5 green Positive threshold value
6 red Negative threshold value
7 orange Control levels
ENDFORM. " LAYOUT_BUILD5. Fieldcat设置pos = pos + 1.
PERFORM set_fieldcat USING pos ‘EXCESS‘ ‘Excess‘ ‘C500‘.FORM set_fieldcat USING p_pos p_field_name p_field_text p_color.w_fieldcat-col_pos = p_pos.
w_fieldcat-fieldname = p_field_name.
w_fieldcat-seltext_m = p_field_text.
w_fieldcat-emphasize = p_color. "设置列的颜色,注意:行的颜色会覆盖列的颜色
w_fieldcat-do_sum = ‘X‘. "对列求和w_fieldcat-just = ‘R‘. "对齐试(R, L, C)w_fieldcat-lzero = ‘X‘. "前导0的形式显示* w_fieldcat-no_sign = ‘X‘. "将定义栏位的符号设置为不显示
* w_fieldcat-hotspot = ‘X‘. "设置栏位是否有热点
APPEND w_fieldcat TO i_fieldcat.ENDFORM. " SET_FIELDCAT
6. 输出REUSE_ALV_GRID_DISPLAYREUSE_ALV_LIST_DISPLAY
7. 颜色的显示FORM output_alv .
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY‘
EXPORTING
i_callback_program = w_repid
i_save = ‘A‘
i_default = ‘X‘
is_layout = i_layout
it_fieldcat = i_alv_fieldcat
it_events = i_eventsit_sort = i_sort[]i_callback_html_top_of_page = ‘DGL_HTML_TOP_OF_PAGE‘ "覆盖 i_events中定义的.
TABLES
t_outtab = it_output[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.ALV中每行颜色显示都是通过LAYOUT控制的, 要实现每行颜色的控制step 1.
在输出内表中新增一个字段, 用于保存颜色的属性.step 2.给内表的颜色字段赋值.step 3.在LAYOUT中指定内表中定义的颜色字段名称.i_layout-info_fieldname = ‘COLOR‘ ."设置颜色属性,设置ALV输出报表每一行的颜色,8. ALV输出值的排序及汇总该属性设置在IT_SORT接口之中.IT_SORT 的属性有如下:SPOS: 排序顺序,多个字段排序时使用.FIELDNAME: 排序字段名称.UP/DOWN: 升序/降序排序.GROUP: 控制中断.SUBTOT: 对指定字段小计输出. 要实现小计, 首先要保证ALV输出内表的合并功能, FIELDCAT 的DO_SUM字段设置为‘X‘.FORM set_sort .w_sort-fieldname = ‘MATKL‘.w_sort-up = ‘X‘.w_sort-group = ‘*‘.w_sort-subtot = ‘X‘.APPEND w_sort TO i_sort.ENDFORM.这样相同的那列就会合并,如果要避免合并,请在布局中设置"no_merging"为"X" .9. ALV 标题中的表头
表头信息可以通过ALV的接口"I_CALLBACK_HTML_TOP_OF_PAGE"实现.其实表头完全是个HTML文件,所以可参考HTML语法.FORM dgl_html_top_of_page USING r_ddoc TYPE REF TO cl_dd_document.DATA: text TYPE sdydo_text_element.
CALL METHOD r_ddoc->initialize_document. "定义表头文本
DEFINE write_inf.
call method r_ddoc->new_line. "换行
call method r_ddoc->add_icon "输出图标
exporting
sap_icon = &1.
call method r_ddoc->add_text "输出文本
exporting
text = &2.
END-OF-DEFINITION.
CALL METHOD r_ddoc->add_text
EXPORTING
text = ‘Justin Test‘
sap_emphasis = ‘STRONG‘.
write_inf ‘ICON_GREEN_LIGHT‘ ‘: 商品库存‘.
write_inf ‘ICON_RED_LIGHT‘ ‘: 商品无可用库存‘.
ENDFORM.data: m_buff TYPE string.
data: m_p TYPE i.m_buff = ‘<html>‘.
CALL METHOD cl_dd->html_insert
EXPORTING
contents = m_buff
CHANGING
position = m_p.
m_buff = ‘<center><H2>配件报废品种汇总表</H2></Center>‘.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = m_buff
CHANGING
POSITION = m_p.
CONCATENATE ‘报表日期:‘ S_DATE-LOW ‘ TO ‘ S_DATE-HIGH ‘<BR>‘ into m_buff.
CALL METHOD CL_DD->HTML_INSERT
EXPORTING
CONTENTS = m_buff
CHANGING
POSITION = m_p.
m_buff = ‘</html>‘.
CALL METHOD cl_dd->html_insert
EXPORTING
contents = m_buff
CHANGING
position = m_p.