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

passing parameter to subreport

Status
Not open for further replies.

atarrqis

IS-IT--Management
Nov 26, 2004
155
US
CR8.5 and Oracle
I want to pass a parameter (number) to a subreport but not link it to a paremeter in the subreport. I don't want to limit the records selected, I just want to use this parameter in formulas in the subreport. I've done Change Subreport Links but every time I go into the subreport to make a formula the ?Pm... is not there. When I go back to the main report and Change Subreport Links the link is not there. What am I doing wrong? Thanks.
 
Use a formula in the main report header with a shared variable, as in:

whileprintingrecord;
shared numbervar MainReportValue := {?MainReportParameter}

Then in the subreport you can reference it, as in:
whileprintingrecord;
shared numbervar MainReportValue;
"I have the value : " & MainReportValue & " from the main report"

-k

 
I tried that but my subreport has a cross-tab in it and I couldn't see the shared variable when I wanted to build a formula under the cross-tab. I thought there must be something about the cross-tab working on first pass and the variable working on second pass so I gave up and tried using a parameter - thinking that would be more straight forward. I'm sure I've done this before so can't figure out why I can't see it now.
 
Create a formula in the subreport that contains

// @MyVar
shared numbervar MainReportValue;

Now create another formula that contains:

@MyVar

It's a trick, the formula referencing the shared variable formula will now be available to your cross-tab.

-k
 
This isn't working for me.
In Main report I have a parameter {?Accounting Year}
and formula
@current_year
WhilePrintingRecords;
Shared NumberVar CurrYr := {?Accounting Year};

In subreport I have a formula
@current_year
WhilePrintingRecords;
Shared NumberVar CurrYr;

and @trick
{@current_year} and this is passing correctly to the subreport.

When I 'format cross-tab' on the subreport I cannot see either @current_year or @trick.
What I want to do here is make a formula @year that does:
If {acctg_yr} = @trick then totext({acctg_yr})
else if {acctg_yr} = @trick -1 then totext({acctg_yr} -1)
else if {acctg_yr} < @trick -1 then "Prior"
etc.
and use @year as my column.

What I really want to do is bring in the @current_year from another sub-report that determines this (yes, this probably should be a stored procedure but that is beyond me at this point) without using a parameter the user has to manage and pass this to the 2nd subreport but I think my problem is a lack of nderstanding of the cross-tab area.

(I also do not know how I will control the group ordering of @year as I want the end result to be, assuming @trick = 2006,
Prior 2005 2006 2007 Future)

 
You could create a manual crosstab using detail level formulas in the subreport like:

//{@CurrYr}:
shared numbervar curryr;
numbervar curramt;
if year({table.date}) = curryr then
curramt := curramt + {table.amt};

//{@LastYr}:
shared numbervar curryr;
numbervar lyamt;
if year({table.date}) = curryr-1 then
lyamt := lyamt + {table.amt};

Then in the subreport footer, use display formulas like:

//{@displcurramt}:
whileprintingrecords;
numbervar curramt;

//{@displlyamt}:
whileprintingrecords;
numbervar lyamt;

Then suppress the detail section. If you were able to use an inserted crosstab (although I think you can't), you would leave the year as a number to sort correctly and then in the crosstab expert go to group options (while the column field is highlighted)->customize column name->use a formula to customize name and then convert the value to text there.

-LB
 
OK, so are you saying that I cannot use shared variables in formulas within a cross-tab and that's why I should go to the manual crosstab using detail level formuals?

 
Yes, as far as I can determine, you can't do this in 8.5, although I might be wrong. Not sure about higher versions.

-LB
 
To pass a value from the main to the sub, you could try the following:
1.) Create a parameter in the sub that matches the data type of the field you wish to pass.
2.) Link your field from the main to this parameter in the sub. This will be in the drop-down list on the left(in v 8.5, the spinner arrows to view this list are VERY tiny) Don't use this parameter in the sub's record selection.
3.) Use this parameter in your formulas on the sub.



Bob Suruncle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top