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

Subreport with null value causes shared variable to be wrong

Status
Not open for further replies.

Luvsql

Technical User
Apr 3, 2003
1,179
CA
I am reporting off of 2 separate datasource with different datatype that must be linked, so I had to resort to using a subreport. I have the links correctly now (after having to convert some of the datatypes in the other DS), have created the necessary formulas to share the values from the subreport into the main report, but the values it brings in are incorrect if the link between main and subreport yields a null value (ie the main report has Doc 1000, but subreport does not, so it is bringing in a value of Doc 999, which is the previous matched link record).

Also, when I put a conditional suppression on the section where the shared values appear (subreport in Details A, values of main report and formulas in Details B), it prints about 2 pages of blanks and then prints the record where the conditional suppression is false (ie I have a cond. suppress to suppress the entire Details B if Field=0.00). Is still prints blanks for the subreport where I have all the fields suppressed.

Subreports are gross, but I like how I can manually setup the links by using formulas.
 
State where your subreport is, version of CR, database, example data and expected output.

Your problem is that you need to reset the shared variable prior to executing the subreport, but you've given very little technical information here, rather some good insight into the business rules.

Why are the shared variables in a detail section that also has the subreport?

I suspect that some major architectural redesign is in order, but hopefully this will solve your temporary problem.

-k
 
I am using CR 8.5 which is reporting off of 2 separate sql 2000 servers. I have placed the subreport in a section above the shared formula (ie subreport in detail A and formula in detail B as that is what the knowledge base from Crystal Decisions says to do).

My data example is:

Main Report Values

Doc Amount
10 $100
11 $150
12 $25

Subreport Values
10 $100
11 $50


What I am trying to get is:
10 Mainreport $100 subreport value $100, diff=0, which I would like suppressed
11 Mainreport $150 subreport value $50, diff=50
12 Mainreport $25 subreport null or $0.00 diff=25

 
Create another detail section before the subreport and use something like:

whileprintingrecords;
numbervar MySharedvariable := 0;

This will ensure that with each iteration of the sunreport it is zero going in, so it won't erroneously return the previous subreport value.

-k
 
I'm not sure this works (just tried it). The key fields that are linked between the main and subreport are string ie Doc Number and Doc Type (linked on both but only showing Doc Number). I tried adding the formula StringVar='' The issue I am seeing in my report is

DocNumberMain DocAmountMain DocNumberSub DocAmtSub
10 $100 10 $100
11 $150 11 $150
12 $200 11 $150

If the subreport does not have a corresponding record, it repeats the previous one's value. If I create a formula using the $field, that's the key field.
 
Arggh, I'm just going to convert the datatypes in sql using CAST, then using a normal left outer join between 2 ODBC datasources in crystal. I hate subreports.
 
It does work, and this:

StringVar='' is wrong, it must be StringVar := '', and I said to use a number, not a string.

Anyway, your new approach is MUCH smarter, subreports suck, and really slow things down.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top