有些客户希望某些功能性的报表在输出报表内容时,能同时看到选择屏幕上的输入参数,并
希望能反复地输入选择条件进行查询。实现这个功能的办法就是在选择屏幕上输出报表内容。
一般情况下,大家都是直接从SAP的系统中找到相应的例程,然后进行加工修改。不过SAP系
统的例程是面向对象的开发,不大符合我们这一群老鸟的习惯。本人仔细研究了一下这个例程,
将其更改我们常用的编程模式。代码见附件,具体说明如下:
选择屏幕也是一个屏幕,与一般创建的屏幕不同的是:它没有PBO、PAI事件,报表程序中的
INITIALIZATION就是选择屏幕的PBO事件,其它事件是选择屏幕的PAI事件。具体事件与程序功能
代码如下:
INITIALIZATION.
PERFORM sub_init_cond. "初始化选择屏幕字段
PERFORM sub_create_fieldcat.
PERFORM sub_init_layout.
PERFORM sub_create_object. "创建选择屏幕上的对象
START-OF-SELECTION.
PERFORM sub_process_cond. "对选择条件进行处理
PERFORM sub_query_t006a . "查询相关数据
END-OF-SELECTION.
PERFORM sub_refresh_table. "刷新内表里的数据
我们在INITIALIZATION事件下创建ALV GRID输出需要的对象。如果输出内表 GT_RESULT[]为
空,则跳过这段代码;如果输出内表 GT_RESULT[]内容不为空工,则创建ALV GRID需要的对象,
并在选择屏幕上的BLOCK下面输出相应的内容。
系统MEMORY ID sy-cprog 是用来存储结果内表数据的一个全局存储区。如果感觉不方便,也
可以定义一个新的内表来保存结果内表的数据。只要在IMPORT MEMORY ID时将它的内容赋给结果
内表,在EXPORT MEMORY ID时将结果内表的数据赋给这个新内表即可。
本程序还有一个重点就是如何在选择屏幕上创建ALV所需要的对象,代码如下:
CREATE OBJECT go_dock
EXPORTING
repid = sy-cprog
dynnr = sy-dynnr
ratio = 85
side = cl_gui_docking_container=>dock_at_bottom
name = 'DOCK_CONT'.
然后再创建ALV所需要的CONTAINER对象。有了ALV所需要的对象,ALV报表基本上就没什么难
砂锅豆腐的做法家常
点了。
*&---------------------------------------------------------------------*马比赛
*& Report ZFFI010R02 计量单位查询清单
*&
*&---------------------------------------------------------------------*
*& Created by Xavery Hsueh(薛现军)
*& Created on 2011-02-23
树叶画手工贴画*& Function Description
*& Generates the ALV on the Selection Screen itlf
*&---------------------------------------------------------------------*
REPORT zffi010r02 NO STANDARD PAGE HEADING.
*@=====================================================================@
*@ 声明数据库表
*@=====================================================================@
TABLES:t006a.
*@=================
====================================================@
*@ 定义结构类型
*@=====================================================================@
*@=====================================================================@
*@ 定义全局变量、内表与工作区
*@=====================================================================@
榨苹果汁
DATA:gt_result TYPE TABLE OF t006a.
*@---------------------------------------------------------------------@
班组文化墙*@ ALV屏幕相关的对象与变量
DATA: go_dock TYPE REF TO cl_gui_docking_container,
go_cont TYPE REF TO cl_gui_container,
gt_fcat TYPE lvc_t_fcat,
gr_grid_d1001 TYPE REF TO cl_gui_alv_grid.
*@=====================================================================@
*@ 定义宏
*@=====================================================================@
*@=====================================================================@
*@ SELECT-SCREEN 选择屏幕
*@=====================================================================@
SELECTION-SCREEN BEGIN OF BLOCK xavery WITH FRAME TITLE name.
PARAMETERS: p_spras TYPE spras OBLIGATORY. "语言代码
SELECT-OPTIONS:s_mhi FOR t006a-mhi. "期间
SELECTION-SCREEN END OF BLOCK xavery.
*@=====================================================================@
*@ 执行程序事件
*@=====================================================================@
INITIALIZATION.
PERFORM sub_init_cond. "初始化选择屏幕字段
PERFORM sub_create_fieldcat.
PERFORM sub_init_layout.
PERFORM sub_create_object. "创建选择屏幕上的对象
START-OF-SELECTION.
PERFORM sub_process_cond. "对选择条件进行处理
PERFORM sub_query_t006a . "查询相关数据
END-OF-SELECTION.
PERFORM sub_refresh_table. "刷新内表里的数据
*&---------------------------------------------------------------------*
*& Form SUB_INIT_COND
*&---------------------------------------------------------------------*
* 设置选择屏幕上的初始值
*----------------------------------------------------------------------*
FORM sub_init_cond .
p_spras = sy-langu.
name = '查询条件'.
ENDFORM. " SUB_INIT_COND
*&---------------------------------------------------------------------*
*& Form SUB_CREATE_OBJECT
*&---------------------------------------------------------------------*
* 创建选择屏幕上的对象
*----------------------------------------------------------------------*
FORM sub_create_object.
IMPORT data = gt_result FROM MEMORY ID sy-cprog.
FREE MEMORY ID sy-cprog.
CHECK NOT gt_result IS INITIAL.
CREATE OBJECT go_dock
EXPORTING
repid = sy-cprog
dynnr = sy-dynnr
ratio = 85
side = cl_gui_docking_container=>dock_at_bottom
name = 'DOCK_CONT'.
IF sy-subrc <> 0.
MESSAGE 'Error in the Docking control' TYPE 'S'.
歌颂友谊的诗句ENDIF.
内蒙古警官学校CHECK gr_grid_d1001 IS IN
ITIAL.
go_cont ?= go_dock.
CREATE OBJECT gr_grid_d1001
EXPORTING
i_parent = go_cont.
CALL METHOD gr_grid_d1001->t_table_for_first_display
EXPORTING
i_buffer_active = space
i_bypassing_buffer = space
CHANGING
it_outtab = gt_result[]
it_fieldcatalog = gt_fcat.
ENDFORM. "SUB_CREATE_OBJECT
*&---------------------------------------------------------------------*
*& Form SUB_PROCESS_COND
*&---------------------------------------------------------------------*
* 对选择条件进行处理
*----------------------------------------------------------------------*
FORM sub_process_cond .
ENDFORM. " SUB_PROCESS_COND
*&---------------------------------------------------------------------*
人生只合住湖州*& Form SUB_QUERY_T006A
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM sub_query_t006a .
SELECT * FROM t006a
INTO CORRESPONDING FIELDS OF TABLE gt_result
WHERE spras EQ p_spras AND
mhi IN s_mhi.
ENDFORM. " SUB_QUERY_T006A
*&---------------------------------------------------------------------*
*& Form SUB_CREATE_FIELDCAT
*&---------------------------------------------------------------------*
* 通过函数,直接得到输出内表的字段目录与字段相应的属性值
*----------------------------------------------------------------------*
FORM sub_create_fieldcat .
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_buffer_active = space
i_structure_name = 'T006A'
i_client_never_display = 'X'
i_bypassing_buffer = space
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
ENDFORM. " SUB_CREATE_FIELDCAT
*&---------------------------------------------------------------------*
*& Form SUB_INIT_LAYOUT
*&---------------------------------------------------------------------*
* 设置ALV输出的属性值与整体属性值
*----------------------------------------------------------------------*
FORM sub_init_layout .
ENDFORM. " SUB_INIT_LAYOUT
*&---------------------------------------------------------------------*
*& Form SUB_REFRESH_TABLE
*&---------------------------------------------------------------------*
* 将数据输出到程序MEMORY ID里面,并清空内表
*----------------------------------------------------------------------*
FORM sub_refresh_table .
EXPORT data = gt_result TO MEMORY ID sy-cprog.
CLEAR gt_result[].
ENDFORM. " SUB_REFRESH_TABLE