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

Shared Variable

Status
Not open for further replies.

fischerc

Technical User
Jul 26, 2010
4
US
I have a main report with transaction detail and a subreport that pulls from another table for custom fields that is located in a group footer section of the main report and links are working great. However I have a formula in the main report that pulls from several main report fields and also a field in the subreport is part of the calculation. I think I need to use a shared number variable, but am not sure how to set that up. The field name in the subreport is Pending_Amount.

Any help would be great! Thanks.
 
You would need to set up a formula in the subreport something like the following.

shared numbervar pend_amount := {Pending_Amount}

Also in the main report you will need to set up the shared variable in your formula

shared numbervar pend_amount;

Just a reminder, this value will not be available until the subreport runs in the group footer.
 
Thanks for the quick response. This is what I had done but still something isn’t right.

Main Report
Formula Name: Pend_Amount (blank formula)

Formula Name: SetSharedVar (I placed randomly in Report Header)
Shared NumberVar Pend_Amount;

Subreport
Formula Name: SharedNumberVar (I placed in Report Header [suppressed] of the report)
Shared NumberVar Pend_Amount:=
{JCM_MASTER__COST_CODE_CUSTOM_FIELDS.Pending_Amount}

I placed Pend_Amount in the detail and also tried the GF1 of the main report and it’s blank. Also the Pend_Amount shows as a string type yet SetSharedVar is number type. The SetSharedVar appears as 0.00 in report header.

Thanks,
Corine
 
Formual s that contain shared variables returned from a sub report can only be used in sections after(below) the section containing the subreport. Inyour case if the subreport is in GF1 then any formuals that then refernec that same shared variable can only be used in subsequesnt sections.

If you place your formual SetSharedVar does thsi show teh correct valeu ?

HTH

Gary Parker
MIS Data Analyst
Manchester, England
 
If the pend amount value changes per group in the main report, then you need a reset formula in the group header. You ONLY need the following three formulas:

//{@reset} in the main report group header:
whileprintingrecords;
shared numbervar pend_amount;
if not inrepeatedgroupheader then
pend_amount := 0;

//{@shared} to be placed in the report footer of the subreport, assuming there is only one amount per execution of the subreport:
whileprintingrecords;
shared numbervar pend_amount :={JCM_MASTER__COST_CODE_CUSTOM_FIELDS.Pending_Amount};

//{@calc} in main report. If sub is in GF_a, place this formula in GF_b:
whileprintingrecords;
shared numbervar pend_amount;
sum({table.amt},{table.groupfield}) - pend_amount //sample calc only

Note that you cannot suppress the subreport itself or the section it is in for the shared variable to work.

-LB
 
LB,
I a little confused on the calc formula:
sum({table.amt},{table.groupfield}) - pend_amount

The pend_amount formula is blank and available on the main report, but where do the other fields come from?

Thanks,
Corine
 
As I said, that was just an example calculation. If you just put the following in the GF_b, you should see the value from the subreport:

//{@calc} in main report. If sub is in GF_a, place this formula in GF_b:
whileprintingrecords;
shared numbervar pend_amount;
pend_amount

If you are not seeing the correct value here, you have implemented this incorrectly.

-LB
 
LB,
Everything's looking better, but the calc formula in GF1b only pulls the last record and not the sum from the subreport...does this have something to do with your note "assuming there is only one amount per execution of the subreport" ???

//(CALC) If sub is in GF_a, place this formula in gf_b
whileprintingrecords;
shared numbervar pend_amount;
pend_amount

//(RESET) in the main report group header
whileprintingrecords;
shared numbervar pend_amount;
if not inrepeatedgroupheader then
pend_amount:=0

//(SHARED)to be placed in the report footer of the subreport, assuming there is only one amount per execution of the subreport:
whileprintingrecords;
shared numbervar pend_amount:={JCM_MASTER__COST_CODE_CUSTOM_FIELDS.Pending_Amount}


Thanks for all your help!!!!

-Corine
 
If you are trying to share a sum, then use:

//(SHARED)to be placed in the report footer of the subreport:

whileprintingrecords;
shared numbervar pend_amount:=sum({JCM_MASTER__COST_CODE_CUSTOM_FIELDS.Pending_Amount});

This assumes the sub is linked to the main report on the group field so that the summary would be for the group--even without adding the group condition.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top