Hi I want to store sub report fields per page into an array and print that array inside the report footer in main report. Any clue guys ?
If you're talking about only a few fields, then I'd recommend a shared variable taking the data back to the main report.
If it's alot of data, then you should make another subreport in the main report's footer and calculate all your data there.
Edit
Well, you asked, so here's how:
In your main report's footer, create a formula (call it FooMain) with this code:
whileprintingrecords;
shared stringvar MyLittleVar;
In your subreport, create a formula (call it FooSub) with this code:
whileprintingrecords;
Shared stringvar MyLittleVar:="This is from the subreport";
Preview your report. In the footer, the FooMain formula should display "This is from the subreport". Use FooMain in whatever calculations in the main report. Due to fundamental design aspects of Crystal, this will only work if FooMain (and any formulas that reference it) is below the subreport it is getting data from.
Related
I have a subreport with a field called Qty not FBA that is grouped by Customer. I have used the group sort expert to show me only the top customer (the one with the most qty).
I tried what I found in the post "Passing Subreport Value to Main Report" but am still getting zeros. I am guessing it is because the sort to see only the top customer needs to be included in my code but I don't know how to do that.
I would like to pass that through to the main report for use in a formula. From what I have read elsewhere, I have created a field in the subreport:
WhilePrintingRecords;
Shared NumberVar PctofTotal := PercentOfSum ({#Qty not FBA}, {CUSTOMERS.NAME})
and a field in the main report:
WhilePrintingRecords;
Shared NumberVar PctofTotal;
PctofTotal
It is returning zero. I am guessing it is because the sort to only show the top one doesn't work with "While printing records" but I don't know how to get around that. Any help is much appreciated!
I want to get sub report to main report value pass. How this possible?
this is my main report and My Need format
And sub report is-
this is my Sub report
AVGQty formula is - Sum ({Command.IssueQty})/Sum ({Command.WorkingDays})
I want to get every Item Wise average from sub report in main report using report link.
as like, Acetic Acid - AVG Qty: 128.91 (Item wise value come from sub report)
You need to use a shared numbervar in your formula.
In your case:
shared numbervar AVGQty:= Sum ({Command.IssueQty})/Sum ({Command.WorkingDays});
then in your main report you simply create a formula with:
shared numbervar AVGQty
From what i understand, you don't need callback value (shared variables) from subreport in your main report. Just include subreport dataset into your main report and link those 2 tables in database expert.
So for example you have table a which is in your main report and table b which is you subreport. You link them from itemname from table a to itemname to table b. To make this without any shared variables you should just add table b to main report, in database expert link both tables with itemname and then you can group by attribute itemname from table a to get summarizes which you want.
You can do it with shared variables or with this logic. Your choice
Hope it helps
I have a simple report that can display many detail rows.
I want to target a specific row and use it's values to populate aspects in the Report Header and Footer.
For example , I know what the minimum(primarykey) within the detail rows that I display.
A simply formula can capture that.
I want to pick up other attributes of the row with the minimum(primarykey) and display in the header or footer.
I therefore want to select a specific row select and use its data in the header and footer, something like:
Select NAME, DATE from DETAILSROWS where DETAIL.PRIMARYKEY = minimum(DETAIL.PRIMARYKEY)
I've thought about using a subreport here, and passing values back to the main report, but that doesn't see to the way to go... I've tried for example passing minimum(DETAIL.PRIMARYKEY) to the subreport so that the sub loads only the row I want, then passing the values back via shared variables. But I don't want to display the subreport, and if I suppress it, my shared variables don't seem to populate.
Displaying the values in the Report Footer would be easier than the Header. All you'd need to do is compare each row's primary key to the value of maximum({DETAIL.PRIMARY_KEY}) and save off the values. So something like:
stringvar saved_column1;
stringvar saved_column2;
if {DETAIL.PRIMARY_KEY}=maximum({DETAIL.PRIMARY_KEY}) then
(saved_column1 := {DETAIL.COLUMN1};
saved_column2 := {DETAIL.COLUMN2})
For the header, really the only way I can think of is to use the subreport like you're already doing. I'd just format the subreport to display itself, though, and not mess around with shared variables.
Okay so it turns out the SUBREPORT option is the way to go.
SUBREPORT is a bare minimum report that has passed to it, the lookup value you are after.
Long winded, I link to it using a formula that holds essentially: minimum(DETAIL.PRIMARYKEY).
In turn the subreport selects that single detail record.
Within the subreport, build a Formula and drop it the into its report header:
WhilePrintingRecords;
Shared DateTimeVar subCreationDate := {DETAIL.CREATIONDATE};
Shared StringVar subCreationName := {DETAIL.CREATIONNAME};
Finally, suppress all the the sections (delete what u don't need) on the SUBREPORT, and close.
On the main report... Not sure but it looks like the SUBREPORT can sit anywhere.
And because you've suppressed elements WITHIN the SUBREPORT, it won't display on the main report.
(So no need to suppress on the main report - and if you do suppress it there, it won't work anyway!)
Now create your formulas (in my case 2) on the main report and in each, repeat the variable declaration.
Shared DateTimeVar subCreationDate
Shared StringVar subCreationName
Again, each of the above sit in their individual formula declaration.
And from there, you now have "standard" formulas to work with on your main report.
They can be referenced just like any other!
Thx Ryan - your answer certainly helped me get where I need to go - u still get my +1!
Hi I am trying to have a master detail report. But the report always crashes as i hit the next page on the preview. Both the queries work fine in the query editor.
Main report query
select a.Name,a.ftid,a.instno from testschema.ViewA a where a.ftid={?ftid}
Shared variables declared in main report separately
shared numbervar instno;
instno:={Command.INSTNO}
shared stringVar gnpidesc;
gnpidesc:={Command.Name}
Sub report query
select a.TOTALAMT,b.Name from testschema.ViewB a CROSS JOIN testschema.View3 b where a.ftid={?ftid} AND b.ftid=a.ftid AND b.instno={?instno} AND a.Name='{?gnpidesc}' ORDER BY a.GENGNPIDESC
Shared variables declared inside subreport header separately
shared numbervar instno;
shared stringVar gnpidesc;
I have delcared 3 parameters fields also with the same name.Sub report only shows for first row in master, if I click next page the application crashes.
Edit
The Sub report contains a cross-tab report in the sub report head section.
Report Layout
Main Report
- Details Section (Main report query)
- Details Section2 (Sub report)
- Cross-tab (Sub report Footer- Query 2)
Main Report
I'm certain I've seen this before with my own reports. You probably have some data quality/consistency issues.
Do any of your joining fields have a null value? All it takes is 1 record ;)
Do you have a formulae that references a field with a null value?
I don't know what your data source is, but do any of those views have custom formulae that Crystal wouldn't recognize? For example, I often pull data from MS Access queries, but Crystal throws an error if I use the nz() function.
One way to find your culprit is to scroll through your preview until you find the page that can't display and crashes. See what data would have displayed on there.
You'll have to either fix the data before it gets to Crystal or rework a function. Good luck.
How can I retrieve the record count of a subreport from within the main report?
I think this is a dupe, but I'll answer anyway. :)
You can create a formula field on the subreport which contains a shared variable. In the formula you'll set the shared variable to the value of the rowcount field in the subreport.
Then in your main report you will need to create a formula with a shared variable that has the same name as the subreport and then return the value of the shared variable.
Here are some links that may help.
http://www.datamanagementgroup.com/Resources/TrainersTalk/trainerstalk_howto_share_subreport_data_with_main_report.asp
http://www.ozgrid.com/forum/showthread.php?t=19034
Put this formula in your subreport. You can suppress it from display if you like.
whileprintingrecords;
Shared numbervar SubRecordCount:=(however you want to count the records in the report);
Put this in your main report. Again, this can also be suppressed.
whileprintingrecords;
shared numbervar SubRecordCount;
SubRecordCount
Use the formula name for #2 for whatever calculations you need.
IMPORTANT: Due to the fundamental logic of Crystal, you can only use this field if it is BELOW it's subreport.
Also, as for counting the records in the subreport, I recommend a running total at the bottom of it.
here you can retrive sub report count from code side
===========================
CrystalDecisions.CrystalReports.Engine.ReportDocument RepDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
RepDoc.Load(ReportName);
int IntRepCount = RepDoc.Subreports.Count;
===========================
pass this count to your report