Doc ID: Note:111587.1
Subject: How to get total number of pages for a report before printing?
Type: BULLETIN
Status: PUBLISHED
Content Type: TEXT/PLAIN
Creation Date: 01-JUN-2000
Last Revision Date: 28-NOV-2001
PURPOSE
-------
The purpose of this article is to provide users and analyst with information about
How to get how many pages in the report and also the number of the last page of the
report programmatically before printing the report to decide if you will print it or not.
How many pages to print. Also formatting his page number field.
SCOPE & APPLICATION
-------------------
This article is simple steps and coding for expert as well as intermediate users.
Suppose you have a report and you don't know in advance how many pages will be printed
when you run this report. This report may be huge one that you don?t want to print all the pages
and you want to stop printing the report after certain number of pages.
You may also would like to have the choice of having page number or not and how the page number looks like.
As an example; if you have a report that consists of 10 pages then you would like to have page number as follows
(page 1 of 10). In case that your report consists of only one page you don't want any page number for it.
How to print certain number of records
--------------------------------------
In BeforeReport trigger (after the query is parsed) you can call
SRW.Set_Maxrow(?query_name?, <number of records to be printed>);
Example:
function BeforeReport return boolean is
begin
SRW.SET_maxrow('Q_1', 5);
return (TRUE);
end;
You can also use a user parameter to dynamically specify the number of records that you want to print.
How to print certain number of pages
------------------------------------
First you have to know how many records are printed per page in your report which means that
you have to print at least one or two pages of your report first then count how many records are printed/page.
These two parameters will be used to control how many pages to be printed.
The number of records per printed page depends on many parameters such as report style, layout, font, template,
and Maximum Records per page property for each repeating frame.
Example
-------
Suppose that the number of records per printed page = 30 and you want to print 20 pages
then the number of records that you have to specify in the SRW.Set_Maxrow should be
No. of records per printed page * No. of pages that you want to print which would be 600
You can also use user parameters to dynamically control that.
How to get the total Number of pages of the report
--------------------------------------------------
1- Run your query first and count the number of records retrieved by this query.
2- Calculate the number of records/printed page.
3- To get the total number pages of the report you have to divide the
number of records retrieved by the query over the number of records per printed page.
From this information you can decide whether you want to print the whole report or not.
Also you can choose which page number format you want to use.
Hint: To choose between different Page Number format you have to create two fields in the
margin each one with different page number format. You can choose which one to display using
format trigger on those fields.
Disadvantage of above method that the query will be executed twice one for getting the count of records
and the second time to execute the query of the report itself. Which will cause a little bit longer time
to run the reports. To save more time write the same query in the same case to save the parsing time of
the query in the second time.
Related information
-------------------
SRW.SET_MAXROW built_in
Syntax
SRW.SET_MAXROW (query_name CHAR, maxnum PLS_INTEGER);
Parameters
query_name Is the query whose fetched records will be limited.
maxnum Is maximum number of records you want the query to fetch.
Restriction
- SRW.SET_MAXROW is only meaningful in a Before Report trigger
(i.e., after the query is parsed). If SRW.SET_MAXROW is called after the Before Report trigger
(i.e., after the queries have been executed), the SRW.MAXROW_UNSET packaged exception is raised.
- Because this procedure causes only the specified number of records to be fetched, the "unfetched"
records of the query are not used in computations, etc.
- If you specify that 0 records should be fetched, the query will still be parsed.
KEY WORDS
--------
SRW.SET_MAXROW; MAXROW; Maximum rows to fetch; pages; pagenumber; lastpage;
RELATED DOCUMENTATION
---------------------
note:61643.1 USING SRW PACKAGED PROCEDURES IN REPORTS
Oracle Reports Builder Online Help