cancel
Showing results for 
Search instead for 
Did you mean: 

CR2011: Shared Variables

leon_laikan
Participant
0 Kudos

Hi everybody

I often use shared variables in Crystal Reports 2011, and never had any problems.

This time, I got stuck ... don't know why.

I have a Main report and 2 subreports S1, and S2

I want to pass a shared variable from S1 to S2

So, I create the shared variable (SeriousErrors_sv ) in each of Main, S1, and S2.

I copy and paste the formulas so that you see exactly what I typed, and spot my error

In S1:

SeriousErrors_sv

WhilePrintingRecords;

Shared NumberVar SeriousErrors_sv;

SeriousErrors_sv:= {usp_2014_101.Er5_TotalNoOfEr};

--------------------------------------

In S2

WhilePrintingRecords;

Shared NumberVar SeriousErrors_sv;

-------------------------------------------------

In Main:

SeriousErrors_sv

WhilePrintingRecords;

Shared NumberVar SeriousErrors_sv;

------------

I have placed each shared variable in the respective report.

S1 ---> Reads 9 (Correct)

S2 ---->Reads 0 (Bad)

Main ----> Reads 0 (Bad)

----------

It seems that S1 is not passing the SV to Main.

What could have gone wrong?

Thanks

Leon Lai

Accepted Solutions (1)

Accepted Solutions (1)

ido_millet
Active Contributor
0 Kudos

The main report formula must be in a section below the section where S1 was placed (NOT in the same section!).  S2 can be in the same section of the main report formula or in a section below that section.

leon_laikan
Participant
0 Kudos

Hi Ido,

Thanks for your reply.

I tried your suggestion, but unfortunately it does not work.

In S1, I placed the SV in the Report Header  (reads 9 = correct)

In Main, I placed the SV in the Page Header (reads 0 = incorrect)

Then I placed the SV in GH1, and also Page Footer (same error)

Hope this will help to pinpoint my error

Regards

Leon Lai

abhilash_kumar
Active Contributor
0 Kudos

Hi Leon,

Make sure you do not have another formula inside the Subreport S1 that resets the shared variable to zero.

Also make sure you do not have another formula on the Main Report, somewhere on the Page Header or Report header that resets this variable to zero.

There's no other reason the shared variable shouldn't work otherwise.

-Abhilash

leon_laikan
Participant
0 Kudos

Hi Abhilash

No, I have not reset the SV.

I tried putting a fixed value (= 1) in S1 instead of a field value

The 1 is not passed to the Main Report

I also tried to pass a SV from Main to S1

It works without problems.

So, I can pass a SV from Main to S1,

but not from S1 to Main.

I'll continue fighting the problem...

And thanks to all who have replied similarly. I did not expect to get so many replies

Best Regards

Leon

abhilash_kumar
Active Contributor
0 Kudos

Would you be able to attach the report with saved data please?

-Abhilash

leon_laikan
Participant
0 Kudos

Hi Abhilash

There is something which is worrying me...

My subreport is an ON-DEMAND subreport

When I run my report, SV for main  gives 0 (even though SV in S1 gives 😎

I find this very logical!

S1 has not yet run (because I have not yet clicked on the S1 hyperlink).

So, this is not the way to pass a SV from S1 to Main???

Could you reconsider my question in the light of this observation?

Best Regards

Leon Lai

abhilash_kumar
Active Contributor
0 Kudos

Ah, I see!

You're right, unless the Subreport runs, shared variables inside this Subreport are Not evaluated.

-Abhilash

leon_laikan
Participant
0 Kudos

Aha!

So how can I pass a SV from subreport to Main Report?

If this is impossible, why do all CR books (all forums, all internet articles , ...) have a recipe for it?

For which circumstances do these recipes work?

Any workaround?

Should I abandon my fight?

Thanks

Leon

abhilash_kumar
Active Contributor
0 Kudos

With an on-demand Subreport, shared variables will only evaluate when the subreport is clicked on.

Only other workaround is to place another copy of the same subreport that is only used to make the shared variables work.

-Abhilash

leon_laikan
Participant
0 Kudos

Hi Abhilash

I now understand clearly where is my problem.

Your workaround works, but is not very elegant.

So, I'll rather modify the SQL Stored procedures to avoid using shared variables.

Best Regards

Leon Lai

JWiseman
Active Contributor
0 Kudos

hi Leon,

your other option is to format the subreports in such a way so that they look and act like on demand subreports. have a look at the attached report...extract the contents and change the .txt extension to .rpt.

notes:

1) as you saw the subreport has to run in order to pass variables

2) in this example, the subreports are not On Demand subreports

3) in the Format Subreport > Common tab, Can Grow is not checked

4) the subreport has a fake url in the subreport report header A

5) subreport report header A is suppressed when opened

-jamie

leon_laikan
Participant
0 Kudos

Hi Jamie Wiseman

Thanks a lot for your reply.

I did not reply earlier because I had already found an alternative solution to my problem, and did not visit the forum until now.

I am keeping good note of your suggestion. I may need it someday.

Best Regards,

Leon Lai

Answers (3)

Answers (3)

former_member477249
Participant
0 Kudos

The formula used to show the shared variable value in main report should be placed below the section where S1 is executing, while same goes for the physical placement of S2 in the main report.

-Prathamesh

leon_laikan
Participant
0 Kudos

Hi Prathamesh

Thanks a lot for your reply.

As I use on-demand subreports, I will need a different approach.

Best Regards,

Leon Lai

raghavendra_hullur
Active Contributor
0 Kudos

Hi,

It depends on where you have placed your sub report1.

I mean, the value of shared variable declared in sub report1 will not be available in the main report in a section above where you have placed your sub report1.

If you need that, you may have to place the formula with declaration of shared variable in report header of main report.

Thanks,

Raghavendra

leon_laikan
Participant
0 Kudos

Hi Raghavendra

Thanks a lot for your reply.

As I use on-demand subreports, I will need a different approach.

Best Regards,

Leon Lai

abhilash_kumar
Active Contributor
0 Kudos

Hi Leon,

The Subreport S2 and the formula on the Main report should be in a section below the section that holds Subreport S1.

-Abhilash

leon_laikan
Participant
0 Kudos

Hi Abhilash

Thanks for your reply.

Your reply came in as I was replying to Ido Millet

Please see my reply.

Best Regards

Leon Lai