Solved

Passing Formula to Subreport

Posted on 2004-08-26
16
597 Views
Last Modified: 2012-08-13
Hi,

I have a problem.

I have a main report that has a Paramter Field "Year"

I have also two subreports which does a subreport link to the Parameter Field.

These subreports uses SQL Command and has parameter in the SQL query as "Reporting Year"

Now I want to modify the Parameter Field "Year" such that if I enter 2004, it will pass 2004 to the 1st subreport and 2003(Year-1) to the 2nd subreport.

I am able to use formula to do the subtraction but when I do a subreport link from this formula to the 2nd subreport, it does not show the 2nd subreport in the main report.

That is it is showhow hidden the whole 2nd subreport.

Is there a way to go about show both the subreports if I just enter 1 parameter field in the main report?

Thank you.
0
Comment
Question by:tansiakl
  • 7
  • 3
  • 3
  • +2
16 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 11901902
>>> when I do a subreport link from this formula to the 2nd subreport, it does not show the 2nd subreport in the main report

Sounds like there's something wrong with your linking.  Can you explain exactly what you've done?  You should be able to link your formula in the main report to your subreport and get the results you want.

>>> Is there a way to go about show both the subreports if I just enter 1 parameter field in the main report?

Of course - I have dozens of subreports based off a single parameter.  The problem is most likely in the linking but if you explain how you currently have the report laid out I can maybe help identify the issue.

frodoman
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11901952
you can do this with subreport linkig or shared variable

u already know the sub report linking so i wont explain more,

Shared variable solution
1. sharedvar yearvariable;
yearvariable  := field.{year};

put it in Mainreport  

2.Create second one
sharedvar yearvariable;
yearvariable;

Put this in subreport
It will have the valiue passed from the main report
0
 

Author Comment

by:tansiakl
ID: 11902048
Okie,

First of all, I have a main report without any database connection. It is just a empty shell to accept the "Year"

After the user enters the "Year" e.g. 2004, I have a formual {@Year-1} to calcalute and result 2003.

Then I have two subreports. Subreport 1 with SQL Command
Select
tblCal.Year, tblCal.Months, tblRevenue.Sales
From
tblCal, tblRevenue
Where
tblCal.key = tblRevenue.key AND
tblCal.Year = {?Reporting Year}

And the 2nd subreport with the same SQL Command.

I try to show some results from both subreport. No big deal here.

I do have my own reasons why I need to use 2 similar subreport. This is not a issue here.

Then I place the 2 subreports in the details section in the main report. And link the 1st report with the main report "Year" --> ?Reporting Year

And for the second subreport, I link formula "Year-1" --> ?Reporting Year.

I suppress all ther section in the main report.

I try to refesh the main report, the 1st subreport is okie but the second subreport is not show. However, if I put my mouse over where the 2nd subreport suppose to be, I can click on the space and it opens the 2nd subreport with any data.

If you want, you could do a simple test on Crystal without any tables and try to print some Special Fields to do some testing, the problem will appear.

If you want I can also send you a simple report on that.

Thanks
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11902067
are you sure that in the subreport change links you are selecting the correct parameetr field to use .
0
 

Author Comment

by:tansiakl
ID: 11902069
Hi ebolek,

THe problem is that I need to pass the parameter from the main report to the parameter in the subreport so that the subreport can run the SQL Command
Select ...
From...
Where Year = {?Reporting Year}

So a shared varible will not be useful in this case.

Correct me if I am wrong.
0
 

Author Comment

by:tansiakl
ID: 11902079
Hi ebolek,

I am sure I am selecting the right parameter field in the subreport bcos from my comment above, if I double-click on the subreport that is not show, it could display 2003.

Hope that helps.
0
 
LVL 10

Expert Comment

by:ebolek
ID: 11902217
You are right
0
 
LVL 19

Accepted Solution

by:
GJParker earned 75 total points
ID: 11902367
This is because the formula Year -1 will never be evaluated because your main report doesn't retrieve any data from the database.

There are 2 ways round this

1. Create a connection in your main report and return some data to the report (the field can be placed in a suppressed section) This will force the Year - 1 formula to evaluate in the main report.

2. Link the 2nd subreport to the Year paramater and then amend the command to

Select
tblCal.Year, tblCal.Months, tblRevenue.Sales
From
tblCal, tblRevenue
Where
tblCal.key = tblRevenue.key AND
tblCal.Year = {?Reporting Year} - 1

HTH

Gary

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:tansiakl
ID: 11902760
GJParker,

Your suggestion 1 is what I want.

It works now. Thanks.
0
 
LVL 19

Expert Comment

by:GJParker
ID: 11902794
Glad I could help

Gary
0
 
LVL 28

Expert Comment

by:bdreed35
ID: 11902813
I know your problem has been resolved, but out of curiosity, would you mind sharing why you developed you report the way you did?  I mean, just from reading through this post, I see several different ways that you could have condensed this report into one.  I know that you weren't looking for feedback on that, but I was wondering why that you did it this way.

~Brian
0
 

Author Comment

by:tansiakl
ID: 11902954
Becos in the data mart we do not historize our monthly Sales Revenue. So now there is a to calculate my previous 12 months using formula.

For example, if the user enters 08/2004, then CR have to create 12 formula and 12 subreports so that the subreports can pass the Sales figures back to the main report. The result will look like:

09/2003  10/2003  11/2003  12/2003 ............................... 08/2004
$123       $112       $145      $245                                      $124

In this case what I have thought of is using 12 subreports to return each individual monthly sales revenue. And also we are using CR connection to SAP BW, so we can't actually modify the Query to the suggestion number 2 you give.

So the easiest way is to do the query 12 X.

Please let me know if you have better suggestions or views that you may want to share.
0
 
LVL 28

Expert Comment

by:bdreed35
ID: 11903299
Is this a valid query for you to use:

Select
tblCal.Year, tblCal.Months, tblRevenue.Sales
From
tblCal, tblRevenue
Where
tblCal.key = tblRevenue.key AND
(tblCal.Year = {?Reporting Year} or tblCal.Year = {?Reporting Year} -1)


OR maybe a UNION would work:

Select
tblCal.Year, tblCal.Months, tblRevenue.Sales
From
tblCal, tblRevenue
Where
tblCal.key = tblRevenue.key AND
tblCal.Year = {?Reporting Year}
UNION ALL
Select
tblCal.Year, tblCal.Months, tblRevenue.Sales
From
tblCal, tblRevenue
Where
tblCal.key = tblRevenue.key AND
tblCal.Year = {?Reporting Year} - 1

If either of the two above work, you could condense it down to one report.

If either of thse work, than it might save you some work.  I am not sure what you mean about not keeping a history of the monthly Sales Revenue.  Where dio you get that information from for the report then?
0
 

Author Comment

by:tansiakl
ID: 11903439
Tis is a bit history so I will not go into why did we not have history tables.

Basically, the user needs to enter a month/year then the SAP BW will base on that value do some calcution and since everyday we will have differnet values, having a history tanles is not feasible.

And we cannot use UNION becos we are using SAP BW as the backend and it is not just some simple Oracle SQL as the SAP BW and ORacle is two different DB to start with.

Hope it helps.
0
 
LVL 28

Expert Comment

by:bdreed35
ID: 11903600
Ok, since I don't have experience with SAP, I will have to trust you.  Sounds like it is very constricting.

Well, at least you got your inital problem resolved.
0
 

Author Comment

by:tansiakl
ID: 11903737
Yeah,

Thanks for all your feedback and suggesiton though.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now