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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to have running total through main report + subreports. 2

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
0
0
GB
I have a report which contains two subreports.
Within each of these two subreports I have 'Quantity' fields (suppose we have ‘QTY1’ in the first subreport and ‘QTY2’ in the second).
Within the main report I have it grouped such that I output the details of the group and then within two separate detail bands I output subreports 1 and 2 respectively.
The two subreports are linked to a the main table report (the grouping field) such that I get a report layout as follows :

StockCode 1
SaleLine1 (StockCode1) - QTY1 = 3
SaleLine2 (StockCode1) - QTY1 = 8
SaleLine3 (StockCode1) - QTY1 = 6
QTY1 Sold = 17
BuyLine1 (StockCode1) - QTY2 = 12
BuyLine2 (StockCode1) - QTY2 = 32
QTY2 Bought = 44
Qty into Stock = (44 - 17) = 27 (StockCode1)

StockCode 2
SaleLine1 (StockCode2) - QTY1 = 200
SaleLine2 (StockCode2) - QTY1 = 120
QTY1 Sold = 320
BuyLine1 (StockCode2) - QTY2 = 150
BuyLine2 (StockCode2) - QTY2 = 66
BuyLine3 (StockCode2) - QTY2 = 14
QTY2 Bought = 230
Qty into Stock = (230 - 320) = -90 (StockCode2)

What I'm looking for is a means of starting the group with the total TOTAL1 (for the group) as being 0.
For each detail line in the first subreport I need to subtract the value of QTY1 from the value of TOTAL1, and for each detail line in the second subreport I need to add the value of QTY2 to the value of TOTAL1.
At the end of the grouping (after the two subreports) I need to output the value of TOTAL1 for the group.
On moving to the next grouping I then need to reset this TOTAL1 value back to zero.

How do I set about doing this ?
I'm assuming that I need to make use of Crystal variable(s) with the correct scoping - but am struggling to see where to start.
Where do I define the variable ?
What scoping do I need (shared / global) ?
How do I modify this value TOTAL1, either adding or subtracting from it ?

Any help would be greatly appreciated.

Thanks in advance
Steve

 
Quite an explanation, though I still may not understand...

I think you want: (subreport1.qty1 * -1) + (subreport2.qty2)

You didn't mention which part of the data is subreport 1 and 2, so I have to make the assumption that you demonstrated two sets of information, and that each represents the firing of both subreports.

In either case, the following should handle it, just use the appropriate field names from your tables:

In the Main Report Group Header before the firing of the subreports place a formula with the following (suppress the display):

whileprintingrecords;
shared numbervar Total1 :=0;

In Subreport 1 Details create a formula in the details containing:

whileprintingrecords;
shared numbervar Total1;
Total1 := Total1 - {MyTable.MyQty}

In Subreport 2 Details create a formula containing (suppress the display):

whileprintingrecords;
shared numbervar Total1;
Total1 := Total1 + {MyTable.MyQty}

In the Main Report Group Footer create a formula with the following;

whileprintingrecords;
shared numbervar Total1

This will display the results.

-k kai@informeddatadecisions.com
 
Fairly straight foreward using shared variables. Create these 4 variables:
1) In your main report section header (Where you have Section 1) declare/initialize
WhilePrintingRecords
shared numbervar QtyOH := 0
2) In your 1st sub report footer (wherever the total quantity is known)
WhilePrintingRecords
Shared numbervar QtyOH := QtyOH - QTY1
3) In your 2nd sub report footer (wherever the total quantity is known)
WhilePrintingRecords
Shared numbervar QtyOH := QtyOH + QTY2
4) In your main report section footer
WhilePrintingRecords
Shared QtyOH
 
Thanks to both synapsevampire and slupton1 for providing me with the help (and the idiot-proof walk-throughs) I needed on this matter.
I'm now able to generate the reports as required.
Thanks again.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top