How to find out Total No of Pages of a Report Output

I want to find out total no of pages of a report output.  This no I have to print in TOP-OF-PAGE event.

Check this below code. You will get the clear idea.

  REPORT YJAM_WA no standard page heading line-count 60(5).

  data: v_totpage type i.
  data: v_temp(3) type c.
  Start-of-selection.
   do 100 times.
       write:/ sy-index.
   enddo.

  end-of-selection.
   v_temp = v_totpage.
   do v_totpage times.
      read line 1 of page sy-index.
      replace '@@@' in sy-lisel with  v_temp.
      modify line 1 of page sy-index.
   enddo.

  top-of-page.
   write:/60 'page', sy-pagno, '/','@@@'.
   v_totpage = sy-pagno.
 

Here is  a sample:

* 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.

ABAP Tips by : Jameel, Nitin

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

ABAP Tips
ABAP - Samples Program Codes for Abapers

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.