Skip to Content

Variable with different value in 2 subreports

Aug 09, 2017 at 09:58 PM


avatar image


I am editing a report consisting of 1 main report(A) and 2 subreports(B and C) by Crystal Reports 2008 (, and printing it on server with crystal-report-java-runtime-sdk-

(Report A)

Page Header (shared numberVar counter := 0;)

Details a (Report B)

Details b (Report C)

Report Footer

A shared variable Counter is initialized in A and for B and C calling it. Counter is for B and C calculating stuffs during printing, and the result of B is supposed to to be passed to C.

For example,

---Start of B---

step 1) counter := counter + 5; (now counter is 5)

step 2) counter := counter + 3; (now counter is 8)

step 3) counter := 0; (now counter is reset to 0)

step 4) counter := counter + 1; (now counter is 1)

New page

step 5) counter := counter + 10; (now counter is 11)

step 6) counter := counter + 8; (now counter is 19)

---End of B---

(on server) After printing B, the value of Counter is shown as 0, which is supposed to be 19, in C. I tried to rewrite the initialization from (shared numberVar counter := 0;) to (shared numberVar counter;), the value of Counter is then shown as 27.

But there is no above problem if I "Print Preview" in the report editing software, all I get is 19 in C.

I have no idea what is happening (why are there different outcomes of the editing software and java sdk?), please correct me.


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Ian Waterman Aug 10, 2017 at 07:31 AM

Try two things

1. Make sure all formula evaluating, resetting and displaying start with


2 Move reset to Report header, if report c is on page 2 then counter will be reset in page2 header

Failing that try using two variables one for each subreport and then add together in report footer


Show 5 Share
10 |10000 characters needed characters left characters exceeded

Thanks for your reply, but the attempts seem not working.

Here is more info to my report:

Parent report (Report A)

"shared numberVar counter;" is in Page Header a

Sub report (Report B is in Details a, all subreports are similar to it)

All calculations are within Group Header #2 (sub group) and Details c, Group Header #1 is repeated on each page, so I put the reset formula (if not in the same page, shared numberVar counter := 0;) in Group Header #1a

All I am going to do is to collect the cumulative result of each page of all subreports

For example, Report B takes 2.5 pages to print,

Page 1)

new page, so run reset formula

group 1

group 2


The result of counter is 50

End of Page 1

Page 2)
new page, so run reset formula

group 1

group 2


The result of counter is 39

End of Page 2

Page 3)

shared numberVar counter := 0; in Group Header #1a

group 1


End of Report B (the result of counter is 20)

Start of Report C

In the same page, so don't run reset formula

counter is supposed to be passed to here for continuing calculation, but what it gets is 109 (sum of all)

I found that it doesn't make changes(no matter accumulating it or reset it to 0) to counter if putting formula in Group Header #1 or Report Header, but do if putting in Group Header #2 or Details (not at the start of the page, so it's not what I want)

Eventually, there is no this problem in the "Print Preview" of the editing tool

Please advise if there is any mistake


cr0.png (3.6 kB)
cr1.png (6.8 kB)

Try turning off repeat group header on new page. I have known that to incorrectly reset variables.



But the reset formula has to be put in the group header repeated on each page, which makes "reset at the start of a page", while not working if putting in other places. Any alternatives to this?


Sorry my mistake.

Subreports do not respect page headers and main report will not pass or reset variables whilst Subreport is executing.

So if you are trying to place a count in the subreport page footer I think that might not be possible. I have never done it and I Do not how to achieve it.

Perhaps some one else knows how to do this.

The only way I can think of achieving what you want is to build a command or stored procedure which brings back all the data you need and eliminates the need for subreports.



Thanks for your replies anyway, I am resetting the count in the sub reports like,

Shared numberVar counter;

Global numberVar currentPage;

if (currentPage <> PageNumber) then (

counter := 0;

currentPage := currentPage + 1;


but the result of counter I get in the next sub report is likely never reset, but accumulated

I tried to log the "PageNumber", by something like adding it to an array, and it showed that the values were 1,2,3,4... in that report which is expected, but the values were all 1 in the next sub report by getting the same array. And again, it is normal and achieves what I want in the "Print Preview" of the editing tool, so I just wonder if there is any difference between shared library and the software itself, or is it a bug?