none
Using global variables (Page Numbers) in the report body

    Question

  • Why it is not allowed to use Global variables (built-in parameters) like Page Number and Total Pages in the report body but allowed only in report header/footer? Logically, when a page has a page number associated, it should be possible to show it anywhere in the report; similarly, Total Pages in the report. Can someone please help me understand the reason behind this limitation in the tool..?

    Thanks


    ..hegde
    Thursday, March 26, 2009 9:56 AM
    Answerer

Answers

  • Hi hegde,

     

    May be I was not clear enough in my previous post. There is no sequence between the two areas. So, in the test I mentioned above, the global variable sumGroup will reset to zero after processing the page area or processing the body area. You cannot pass variable between two areas. That means there is no relationship between page header/footer area and body area in Reporting Services 2005.

     

    Base on my research, there are several technical reasons for this, particularly in RS 2000 and RS 2005.  Most of them have to do with the fact that in those RS versions the report body contents can be fully pre-calculated (including all textbox values) without any pagination applied, or with the page height/width settings changed later without the need to re-evaluate expressions.  

     

    Basically, there are two copies of the ReportObjectModel (with different lifetimes) exposed to RDL expressions at runtime – one that is exposed to expressions in the report body, another that is exposed to expressions in the page header/footer.  Page header/footer areas can reference textbox values on the current page of the report body though. 

     

    Globals!ExecutionTime is different.  It is just a timestamp that is constant throughout the entire report execution.  That timestamp is exposed on both ReportObjectModels for the report body and the page header/footer.

     

    Starting with Reporting Services 2008 we have a different pagination and rendering approach, which could make adding such a feature somewhat easier in a future release, but one underlying challenge here is that due to the CanGrow behavior on textboxes, the textbox in the body that is supposed to contain the actual current page number could grow and then no longer fit on the current page, ultimately requiring repagination steps with page number updates until things fit on the page. If you are interested in this, here is a document about fields in Page Header (2008) wrote by Robert Bruckner.

     

    Regards,

    Raymond

    Tuesday, March 31, 2009 7:21 AM
    Moderator

All replies

  • Hi hegde,

     

    As I know, the processing of page header and footer are different from body area. In body area, the processing sequence of reporting services engine is: table header, table footer, group header, group footer, details then the next recursion cycle. That is the reason why we cannot handle aggregates of aggregates. And there is another processing flow: page header -> page footer. They have no relationship. That is the reason why we cannot use global variables in report body just as we cannot use data field in report header and footer area. Here is a test:

     

    1.      Copy the following code into Code area in report properties.

     

    Dim sumGroup as Integer 

    Function AddValue(ByVal newValue As Decimal) as Integer 

    sumGroup = newValue 

    return sumGroup 

    End Function 

     

    Function GetSum() as object 

    return  sumGroup 

    End Function  

     

    2.      Create a textbox in report footer, set the expression to be: =code.AddValue(Globals!PageNumber)

     

    3.      Create a textbox in report header, set the expression to be:

    =code.GetSum()

     

    4.      In body area, create a table with some filed, set one of cell expression to be: =code.GetSum()

     

    5.      After that, click preview, you will find the processing sequence of page header and footer area. And the cell in table with expression =code.GetSum()” display zero all the time.

     

    6.      You set the expression in table with =code.AddValue(Fields!<data>.Value), and =code.GetSum()” in page header. You will get the same results, the global variables sumGroup will reset to zero after processing the page area and body area.

     

    This is just my thought. Hope this helps.

     

    Regards,

    Raymond

     

    Monday, March 30, 2009 10:01 AM
    Moderator
  • Thanks Raymond for the reply.

    So, are you saying that report header and footer part is processed after the report body and the page numbers are generated during report header/footer processing?  Other global parameters like “Execution Time” are generated before processing the report body?

    Also, this means, it’s something to do with how reporting services processes the report rather than from a feature perspective.  I was hoping that reporting services will somewhere keep the mapping of page and a page number and irrespective of whether it is a header or a body the page number corresponds to a page. But looks like that’s not the case… Thanks again.


    ..hegde
    Monday, March 30, 2009 2:48 PM
    Answerer
  • Hi hegde,

     

    May be I was not clear enough in my previous post. There is no sequence between the two areas. So, in the test I mentioned above, the global variable sumGroup will reset to zero after processing the page area or processing the body area. You cannot pass variable between two areas. That means there is no relationship between page header/footer area and body area in Reporting Services 2005.

     

    Base on my research, there are several technical reasons for this, particularly in RS 2000 and RS 2005.  Most of them have to do with the fact that in those RS versions the report body contents can be fully pre-calculated (including all textbox values) without any pagination applied, or with the page height/width settings changed later without the need to re-evaluate expressions.  

     

    Basically, there are two copies of the ReportObjectModel (with different lifetimes) exposed to RDL expressions at runtime – one that is exposed to expressions in the report body, another that is exposed to expressions in the page header/footer.  Page header/footer areas can reference textbox values on the current page of the report body though. 

     

    Globals!ExecutionTime is different.  It is just a timestamp that is constant throughout the entire report execution.  That timestamp is exposed on both ReportObjectModels for the report body and the page header/footer.

     

    Starting with Reporting Services 2008 we have a different pagination and rendering approach, which could make adding such a feature somewhat easier in a future release, but one underlying challenge here is that due to the CanGrow behavior on textboxes, the textbox in the body that is supposed to contain the actual current page number could grow and then no longer fit on the current page, ultimately requiring repagination steps with page number updates until things fit on the page. If you are interested in this, here is a document about fields in Page Header (2008) wrote by Robert Bruckner.

     

    Regards,

    Raymond

    Tuesday, March 31, 2009 7:21 AM
    Moderator
  • Okay. I think I understood the challenge now in the tool to achieve this feature.
    Regarding the challenge of textbox showing page number within a report body - it probably requires reporting services to have one pass where find out all the pages and contents in each page (and so it can find out which page the textbox belongs to) and split the textbox as two if it requires to be in two pages  (or something like "pagenumberbox" similar to textbox that you can drop onto report body). Report header different from page header is probably another awaited feature - if implemented, report header and body can work together better (?).
    Thanks again.
    ..hegde
    Thursday, April 2, 2009 2:07 PM
    Answerer
  • Hi Raymond,

    As you mentioned page header can reference textbox values, however I am getting some unexpected error and need help with global variables in the following thread, can you help?

    http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/b8583b79-08d5-4e2f-9295-65522636a23b

    Thanks.

    Tuesday, May 18, 2010 8:18 PM
  • Hi All,

    Is there any other way to access the globals in the body section. I mean any tweaks or any code that we can write this which will allow us to pass the globals in the body section?

    I have a report where I have two table and the second table is the replica of first one. I need to suppress/hide data in the second table based on the page number.

    Thursday, February 6, 2014 3:40 PM