Printing ALV along with Page numbers
By Joyjit Ghosh, IBM India
Expected Layout of the ALV report (when printing):
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.
Limitations:
- 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.
- 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.