Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating off of subreports...

Status
Not open for further replies.

arachnoid

Programmer
Jun 14, 2002
108
US
Main Report

Sums total invoice amount from File A

Subreport

Sums total invoice amount from File B

I need to print records where the total invoice amount of File A and the total invoice amount of File B are not equal to zero.

Using Crystal Reports XI, can I calculate the difference of the two amounts using a subreport?

If so, how?

Any input will be greatly appreciated.

Regards,
 
A subreport value can be used in a formula in the main report, but it first has to be converted to a Shared Variable within the subreport. To do this, create a formula SV_Invc Amt File B (I typically prefix them with SV as an identifier):

Shared NumberVar xyz:={total invoice amt File B}

Now insert this into the subreport (and suppress the orginal {total invoice amt File B}). In the main report, create a similar SV formula with the statement:

Shared NumberVar xyz

This value (from the subreport) can now be used in the main report to compare to {invoice amt File A}.
 
I would add "whileprintingrecords;" in front of the shared variable in each formula that mocgp references. You must place the marin report formula in a section below the one in which the subreport is executing, and do your calculation there.

-LB
 
Thanks to both of you for your responses! [thumbsup]

I have the main report calculating from the total of the subreport, but now I have a new issue.

I am only wanting to print records where the difference between the two amounts does not equal zero.

I have tried multiple variations of formatting the sections with very strange results.

Is there a way for me to suppress the records I do not want to see without impacting the calculation of the variable? My report is currently over 400 pages, when it should be closer to 3 or 4.

Any additional info will be greatly appreciated!

 
From experience in XI, there is no feasible way to suppress or hide a subreport without stopping it from running in the background. The best way I've found to still run it is to put the subreport in its own section, make the subreport 1-2 pixels high (zoom in for this). Resize the section accordingly. Uncheck the 'Can Grow' option for the subreport. Within the subreport hide/suppress all sections.

If the subreport is in the details section, and is the only thing in the details section, you may consider formatting the details section with multiple columns (See section expert), and setting the column width to be 0.01 inches.

Just FYI lbass, putting a Shared variable in any formula forces the formula to be run whileprintingrecords. So the code is redundant, but still nice for displaying when the code is being run to the developer.

If anybody else has any ideas, I'd love to hear them.
 
HardJeans, yes, I guess you are right. I always use shared only when using subreports, and use whileprintingrecords to force a later pass on calculations that accumulate across sections in a main report. If I used a global variable to accumulate a shared variable and some other main report field, I would add whileprintingrecords so that I could reference the result in the report footer, instead of making the accumulation variable also shared. You could instead use shared variables throughout to get the same result, but then to me that confuses what is coming from sub and main.

Also, you should be able to suppress all sections within a subreport, format the subreport to "suppress blank subreport" and format the section it is in to "suppress blank section" and still have the subreport run.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top