Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Printing total no of pages in report for background job.

govind_parmar
Participant
0 Kudos

Hi Experts,

I am having a report which is executed in background. I need to print 1/3, 2/3, 3/3 on corresponding pages.

I have used the following logic.

*Declare a variable

DATA L_PAGE_COUNT(5) TYPE C.

*Copy this code to the end of program

*Page count will be printed on each page here

WRITE SY-PAGNO TO L_PAGE_COUNT LEFT-JUSTIFIED.

DO SY-PAGNO TIMES.

READ LINE 1 OF PAGE SY-INDEX.

REPLACE '-----' WITH L_PAGE_COUNT INTO SY-LISEL.

MODIFY CURRENT LINE.

ENDDO.

TOP-OF-PAGE.

WRITE: /(70) 'Heading' CENTERED, 70 SY-PAGNO,'of ', '-----'.

but it prints the last 1/'--' , 2/'--', 1/3.

while debugging the report in background, it is known that SY-LISEL contains the line of the last page in every iteration of DO loop.

Is there any alternative way to know the total no. of pages other than the logic below:

total no of records in output internal table / sy-linct.

As there are too many internal table for printing, so it is very difficult to know the total no of records.

Thanks.

2 REPLIES 2

Former Member
0 Kudos

REPLACE '*****' WITH NUM_PAGES_C INTO SY-LISEL .This line does not work from your code

You can calculate the total no of pages alternatively.

Just get the total no of records from your data.Add header lines if you are printing them at the start of report.Then divide this count by sy-linct,which can give you total no of pages & then use it to print heading for each page.

***************8

In general there are two ways to get total number of pages for a list:

1) guessing like in the following example - which can get nasty, when you have variable headers; subtotals, which occur depending how often some key fields change...

  • zlines number of lines in the table

  • sy-srows number of lines in screen

  • sy-cpage current page

  • zpages total number of pages type i

  • temp temporary number type f

describe table itab lines zlines.

temp = zlines / sy-srows.

zpages = trunc( temp ).

temp = frac( temp ).

if temp > 0.

zpages = zpages + 1.

endif.

  • zpages is the number of pages

write: /'Page ',sy-cpage, ' of ', zpages.

2) writing the complete list, re-reading the spool out of spool system, modifying the output and adding correct total number on each page and re-saving the spool.

This option is a little bit easier when running in foreground, there with some special statements read line, hide, modify line the update of the output can be done.

If guessing isn't enough, maybe a legend on the last page indicates: here is the end - that was for some customers sufficient. Otherwise it will be easier to change to smartforms (or sapscript), then implementing option two (I know of one realization, it's really not worth the effort)!

Former Member
0 Kudos

Hi Govind, did you get the solution for your problem. as i need to print total no of pages but sy-lisel is just updating the last page with total no of pages . for eg:- the first page show 1 of @@@    second page shows 2 of @@@  and the final page shows 5 of 5. please help as its urgent .