原贴地址:http://qiqeloveyou.blogbus.com/logs/28050604.html
版权声明 :转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://qiqeloveyou.blogbus.com/logs/28050604.html
TYPE-POOLS SLIS.
TYPES: BEGIN OF ST_ALVOUTPUT,
WEIGHT TYPE ZR2TRAIN-WEIGHT, "
WEIGHT_C(13),
CAR_SUM TYPE ZR2LIPS_S-CAR_SUM, "
UNAME LIKE SY-UNAME,
SEL(1), "选择标识
END OF ST_ALVOUTPUT,
*-----------------------------ALV DEFINE--------------------------------
DATA: is_layout TYPE slis_layout_alv, "ALV输出样式
it_fieldcat TYPE slis_t_fieldcat_alv, "ALV输出的头项目(内表)
wa_fieldcat TYPE slis_fieldcat_alv, "ALV输出的头项目(工作区)
wa_repid LIKE sy-repid."程序名
DATA: it_events TYPE slis_t_event, "事件(内表)
wa_events LIKE LINE OF it_events. "事件(工作区)
DATA: it_list_top_comments TYPE slis_t_listheader,
wa_list_top_comments LIKE LINE OF it_list_top_comments,
it_list_end_comments TYPE slis_t_listheader,
wa_list_end_comments LIKE LINE OF it_list_end_comments.
************SORT
DATA: WA_SORT TYPE SLIS_SORTINFO_ALV,
IT_SORT TYPE SLIS_T_SORTINFO_ALV.
*-----------------------------宏------------------------------------
DEFINE ADD_FIELDCAT.
WA_FIELDCAT-FIELDNAME = &1. "内表里的字段
WA_FIELDCAT-REPTEXT_DDIC = &2. "在ALV里显示的名字
WA_FIELDCAT-JUST = &3. "水平对齐方式,L左对齐,R右对齐。
WA_FIELDCAT-NO_OUT = &4. "
WA_FIELDCAT-INTLEN = &5. "输出列的宽度
WA_FIELDCAT-EMPHASIZE = &6. "输出背影色
APPEND WA_FIELDCAT TO IT_FIELDCAT.
END-OF-DEFINITION.
*------------------------显示格式,显示内容表头--------------------------
FORM fieldcat_init.
wa_repid = sy-repid. "得到程序名
IS_LAYOUT-ZEBRA = 'X'. "颜色相间显示
IS_LAYOUT-DETAIL_POPUP = 'X'. "是否弹出详细信息窗口
IS_LAYOUT-BOX_FIELDNAME = 'SEL'. "alv行选中的标志
IS_LAYOUT-F2CODE = '&ETA'. "设置出发弹出详细信息窗口的功能码,这里是双击
IS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "优化列宽选项
IS_LAYOUT-DETAIL_TITLEBAR = 'COOL'. "设置弹出窗口的标题栏
* IS_LAYOUT-DETAIL_INITIAL_LINES = 'X'. "
* is_layout-no_hline = 'X'. "这个设置行间隔线
* is_layout-no_vline = 'X'. "这个设置列间隔线
add_fieldcat '' '' '' '' '' ''. "调用宏定义内容显示表头
ENDFORM. "FIELDCAT_INIT
*-------------------------事件--------------------------------
FORM set_top_page.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = it_events. "得到事件内表
READ TABLE it_events
WITH KEY name = slis_ev_top_of_page "表头事件
INTO wa_events.
IF sy-subrc = 0.
MOVE 'ALV_TOP_OF_PAGE' TO wa_events-form. "表头事件对应的FORM
MODIFY it_events FROM wa_events INDEX sy-tabix.
ENDIF.
* READ TABLE it_events
* WITH KEY name = slis_ev_end_of_list
* INTO wa_events.
* IF sy-subrc = 0.
* MOVE 'ALV_END_OF_PAGE' TO wa_events-form.
* MODIFY it_events FROM wa_events INDEX sy-tabix.
* ENDIF.
ENDFORM. "SET_TOPEND_PAGE
*--------------------表头事件对应的FORM--------------------------
FORM alv_top_of_page.
CLEAR: it_list_top_comments.
wa_list_top_comments-typ = 'H'. "H=Header, S=Selection, A=Action
wa_list_top_comments-key = ''.
wa_list_top_comments-info = ''.
APPEND wa_list_top_comments TO it_list_top_comments.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_list_top_comments.
ENDFORM. "ALV_TOP_OF_PAGE
*-----------------------HTML表头的FORM----------------------------
FORM alv_top_of_page1 USING cl_dd TYPE REF TO cl_dd_document.
DATA: m_p TYPE i.
DATA: m_buff TYPE string.
*表头其实完全可以是一个html文件,自己使用html语言进行格式控制
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 '报表日期:' '2007' ' TO ' '2008' '<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.
ENDFORM. "ALV_top_of_page
*-------------------------增加ALV功能按钮--------------------------------
FORM set_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ALVTEST' EXCLUDING rt_extab.
ENDFORM. "SET_STATUS
*------------------------增加按钮事件---------------------------------
FORM user_command USING rf_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE rf_ucomm.
WHEN 'EXCEL'.
* PERFORM excel_output.
* CALL FUNCTION 'ZPETROCHINA_EXCEL_OUTPUT'
* EXPORTING
* excel_template = c_exceltemplate
* macro = 'write_cell'
* exit_program = wa_repid
* exit_subroutine = 'SUB_ADDITION_EXCEL'
* TABLES
* data_source = it_exceldata.
WHEN '&IC1'. "双击
R_UCOMM = '&ETA'. "强行将双击事件关联到F2
ENDCASE.
ENDFORM. "USER_COMMAND
*---------------------------调用ALV显示--------------------------------
FORM OUTPUT_DATA.
PERFORM fieldcat_init.
PERFORM set_top_page.
************SORT
WA_SORT-FIELDNAME = 'HKONT'. "排序的字段名字
WA_SORT-UP = 'X'. "按升序
WA_SORT-SPOS = '01'.
APPEND WA_SORT TO IT_SORT.
**************ENDSORT
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = wa_repid
i_callback_pf_status_set = 'SET_STATUS' "增加ALV功能按钮
i_callback_user_command = 'USER_COMMAND' "增加按钮响应代码
is_layout = is_layout "显示样式
it_sort = it_sort "排序/控制显示SORT
it_fieldcat = it_fieldcat "内容表头
i_save = 'A' "允许保存变式
* I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE1' "可以加入HTML格式的表头
* I_CALLBACK_HTML_END_OF_LIST = 'ALV_TOP_OF_PAGE1' "可以加入HTML格式的表尾
it_events = it_events
TABLES
t_outtab = . "数据来源内表
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.