Printing ALV along with Page numbers

本文介绍如何使用SAP ALV控件实现报告中每个新文档显示在新的页面上,并重置页码为1的方法。通过编写自定义代码并注册TOP_OF_PAGE事件来控制页码显示,确保每份文档的页码从1开始。此外,还介绍了如何展示ALV报告及打印预览时页码的表现。

By Joyjit Ghosh, IBM India

Expected Layout of the ALV report (when printing):

Demo.h1.gif

Step 1: Display each new document in a new page<?XML:NAMESPACE PREFIX = O />

To achieve this below routine is written to populate the IT_SORT table parameter of ALV function module REUSE_ALV_GRID_DISPLAY. And ALV will automatically insert page break whenever a new document is encountered.






Step 2: Reset page number to 1 for each new document

From ALV function module we cannot control the page numbers as it will automatically increment the page counter whenever a new page is printed. So to achieve this we have written our custom code within the TOP_OF_PAGE routine.

Register TOP_OF_PAGE routine with the TOP_OF_PAGE event in IT_EVENTS table parameter of the ALV function module.





Custom code to control the page number in TOP_OF_PAGE routine

Code block marked in bold are used to control the page number. As in our case we are using ALV grid to display the report so during report display page number is not visible. It is only visible in print preview or at the time of printing.
















































Step 3: Display report

Display the ALV report using 'REUSE_ALV_GRID_DISPLAY' function module.

Result:

Report is displayed in ALV grid. Note that no page number is displayed. Now press the print preview button


Report is displayed in print preview with page numbers.
Demo.h3.jpg

Limitations:

  1. For positioning the page number in the report we have to calculate the position based on the list width. As in this case we are using the formula

Page number position = sy-linsz – 10. But if you want you can change it.

  1. In print preview only 1st page number is visible for every document i.e. if a document spreading multiple pages only the 1st page number will be visible. You can see all the page numbers at the time of actual printing.

<!-- google_ad_client = "pub-1086451200925480"; google_alternate_color = "0000FF"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_ad_type = "text"; //2007-04-05: 336 x 280 google_ad_channel = "5227776827"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "008000"; //-->window.google_render_ad();
### SAP ALV Top of Page 配置 在SAP ABAP环境中,`TOP_OF_PAGE`事件允许开发者自定义报表每一页顶部的内容。为了实现这一功能,在创建ALV网格或列表时需注册该事件并编写相应的处理逻辑。 对于OO ALV(对象导向的ALV),可以通过设置事件处理器来响应`TOP_OF_PAGE`事件[^1]。具体来说: #### 定义页面头部输出方法 首先需要在一个类中定义一个静态方法作为`TOP_OF_PAGE`事件的处理程序。此方法负责构建要显示在页面顶端的信息结构体,并调用函数模块如`REUSE_ALV_COMMENTARY_WRITE`以实际绘制这些信息。 ```abap METHOD top_of_page_handler. DATA: lt_commentary TYPE STANDARD TABLE OF gdc_com, ls_commentary LIKE LINE OF lt_commentary. " 填充ls_commentary字段... APPEND ls_commentary TO lt_commentary. CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE' EXPORTING i_logo = space " 如果不需要LOGO则为空 it_listheader = lt_commentary. " 页面顶部文字内容表 ENDMETHOD. ``` #### 注册事件处理器 接着是在初始化阶段将上述方法绑定至`CL_GUI_CUSTOM_CONTAINER=>SET_TOP_OF_PAGE_EVENT_HANDLER()`接口参数内指定的对象实例上。这一步骤确保每当发生翻页动作时都会自动执行之前所编写的页面头部渲染代码。 ```abap DATA: lo_alv_grid TYPE REF TO cl_gui_alv_grid, lo_container TYPE REF TO cl_gui_custom_container. CREATE OBJECT lo_container EXPORTING container_name = 'MY_CONTAINER'. CREATE OBJECT lo_alv_grid EXPORTING i_parent = lo_container. lo_alv_grid->set_top_of_page_event_handler( me ). ``` 以上过程展示了如何通过面向对象的方式配置SAP OO ALV组件中的Top-of-Page区域输出[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值