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!

Subroutine Formula 1

Status
Not open for further replies.

MrFuzzwah

MIS
Mar 28, 2011
49
US
I want to pass an amount field from a subreport to a container report but the amount field was created with a Selection formula as well as a Running total. I need to reference the amount field for calculation in the container report. How can I refer to the calculated amount field in the subreport from the container report?
 
I need to add that my 'formula' is really just a set of filter criteria from Select expert (example below). I need to reference the result of this 'formula' in my container report.

{PAYROLLDB_TYPCD.PAYDEDCODE} = 3.00 and
{PAYROLLDB_EVENT.EMP_NO} = {?Pm-PAYROLLDB_EVENT.EMP_NO} and
{PAYROLLDB_EVENT.TRANDATE} = {?Pm-PAYROLLDB_EVENT.TRANDATE} and
({PAYROLLDB_TYPCD.TC_FED} <> "X" OR {PAYROLLDB_TYPCD.TCFICA} <> "X")
 
Use a shared variable

@Value//place this in subreport at same location as amount result you want to capture, it can be suppressed so is invisble

whileprintingrecords;
shared numbervar SRTotal;

SRTotal:= {your formula };

In main report in a location after the SR has executed

@displayVar
whileprintingrecords;
shared numbervar SRTotal;

If SR executed multiple times then Var will need to be reset, place this in SR header
@resetVar
whileprintingrecords;
shared numbervar SRTotal:=0;

Ian

 
I am trying to add the result of two subroutines but the formula is returning a value of zero.
In subroutine 1 (named Taxable) I have:
whileprintingrecords;
shared currencyvar SumSaved1;
SumSaved1:={#Taxable Wages};
SumSaved1

In subroutine 2 (names NonTaxDeds) I have:
whileprintingrecords;
shared currencyvar SumSaved2;
SumSaved2:={#NontaxDeds};
SumSaved2

In the main report I have:
{@Taxable} + {@NonTaxDeds}

Am I referring to the routines incorrectly? Or - is it a section problem - both the subroutines are in Group Header 1 and do return values corectly but the sum is in the next section which is returning zero incorrectly. I hope this makes sense?
 
You need to create in main report a new formula

@display Taxable + NonTaxDeds
whileprintingrecords;
shared currencyvar SumSaved1;
shared currencyvar SumSaved2;

SumSaved1 + SumSaved2;

Make sure {@Taxable} {@NonTaxDeds} are moved from main report as they may be causing the shared vars to evaluate again on main report returning zero

Ian

 
Thanks Ian -

This particular code creates the message:
'The remaining text does not appear to be part of the formula'

Also I should say I have subroutine 1 in GH1, subroutine 2 in GH2 and this code in GF1 - not sure if that could be causing the error message though.

 
Please paste your formula and show which text is highlighted in the error message

Ian
 
Thanks Ian - your help is appreciated

Here is the code - it is just as you suggested:

@Display Taxable + NonTaxDeds
whileprintingrecords;
shared currencyvar SumSaved1;
shared currencyvar SumSaved2;
SumSaved1 + SumSaved2

The entire statement becomes highlighted upon checking -
 
It appears you put the '@Display Taxable + NonTaxDeds' as part of the formula. I believe Ian was suggesting that would be the title of the formula.
 
I wonder if the problem could be in the sections. I have the data from each of the 2 subroutines displaying in the report - in GH1 and GH2 respectively. My total is in GF2 - this should work but it does not.
 
When I remove the adding of the 2 subroutines and just try to display the value of Sumsaved1 - nothing returns - therefore the variable is not shared. I can display the subroutine thru Crystal functionality - but the actual sharing of the variable does not occur as even a static value cannot be displayed .

Thanks
 
Note that you cannot suppress or hide the subreports themselves or that sections that contain them and still pass shared variables. There is a way to make the subs disappear though.

-LB
 
Hello -

I have a shared variable that returns a running total in the first subroutine. It returns the total in the subroutine and the container report returns the shared variable as well. In the container, the subreport is in GH1. In the subreport, the formula is in GF1.

The problem is - in the container I have a formula that needs to access the shared variable and it can't. It is in GF1. So my subroutine returns the values to the container (GH1) but the formula in the container (GF1) cannot see them.

My subroutine formula is:
whileprintingrecords;
shared currencyvar SumSaved1;
SumSaved1:={#Taxable Wages};
SumSaved1

My formula to read the shared variable is:
whileprintingrecords;
shared currencyvar SumSaved1;
SumSaved1

This should work!

 
Solved. The problem was with the Grouping of the variables. To resolve this - I placed a static value in each shared variable and passed them into the container report one at a time until I found the one that was not passing. Everything else was easily resolved afer that.
 
Hi MrFuzzwah, would you mind telling more on your solution to this case? As I am having this problem as well.
Thx..
 
Basically - the problem was that the variable was not truly being shared. I set the variable in the subreport to a static value meaning a literal value. Then I displayed it on the container to see that the variable was truly sharing and it was not. NOw - there is something strange about the way CR accesses these subreports - I found that if I edited the subreport outside of my main report - meaning I opened it and edited and saved it - it would not pass to the main report that way. I had to open the main report and open the subreport and to see my changes. This contributed to my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top