Printing ALV along with Page numbers

By Joyjit Ghosh, IBM India

Expected Layout of the ALV report (when printing):

Printing ALV along with Page numbers

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.
Printing ALV along with Page numbers

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();