Printing ALV along with Page numbers

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值