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!

Shared variables and totals

Status
Not open for further replies.

pennyb01

Technical User
Jul 8, 2007
12
0
0
GB
Hi,

I am using CRXI with SQL server 2005 and am trying to create a Custom's invoice.

I have created a supreport in GH #1a to return product price. I pass the price from the subreport to the main report using a shared variable:

onlastrecord;
Shared numbervar x;
{SALES_PRICE_LINES.VALID_FROM_DATE}=maximum({SALES_PRICE_LINES.VALID_FROM_DATE});
if {SALES_PRICE_LINES.SALES_PRICE_1}=0 then
x:= {SALES_PRICE_LINES.SALES_PRICE} else
x:={SALES_PRICE_LINES.SALES_PRICE_1}

This formula was placed in the footer of the subreport.

I have another shared variable (y) which passes the pricing unit of measure to the main report. This is declared in the header of the subreport:

Shared stringvar y := {SALES_PRICE_LINES.UNIT_PRICE};

x and y are then used to calculate the line total in GH #1b in the main report:

Shared numbervar x;
shared stringvar y;
if y = 'KG' then
x*sum({DESPATCH_NOTES.WEIGHT},{DESPATCH_NOTES.PART_CODE}) else 0

I then use the following formula to calculate the running total (also placed in GH #1b):

whileprintingrecords;
shared numbervar z;
z := {@Line value};
numbervar v := v + z

And show the final total in the Report Footer:

whileprintingrecords;
numbervar v

My problem is that this works perfectly up until the last group header record, where the total just doesn't add up, the line total is correct, just not the running total. Why might this be? I have checked all background data, and this appears to be OK.

I would also like to ask how you would return only the last record if more than one record is returned by the selection criteris. I tried to do this with the following formula in the subreport, but to no avail:

onlastrecord;
Shared numbervar x;
{SALES_PRICE_LINES.VALID_FROM_DATE}=maximum({SALES_PRICE_LINES.VALID_FROM_DATE});
if {SALES_PRICE_LINES.SALES_PRICE_1}=0 then
x:= {SALES_PRICE_LINES.SALES_PRICE} else
x:={SALES_PRICE_LINES.SALES_PRICE_1}


Thanks for your help!

Penny
 
One other thing I meant to mention: The error in the totalling started when the data was pushed onto a new page - could this have had anything to do with it?

Thanks,

Penny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top