Order of execution of sub reports(linked and non linked) and main report in Crystal - crystal-reports

I am new to crystal and want to understand the basics of subreports.Is it that main report is always executed before subreport?What if the subreport is placed in report/group header?If there are multiple subreports which are either linked or not linked to main report, what would be the order of execution in that case?Does it depend on positioning of report?
I have read many articles and got mixed responses. Please help me in understanding these concepts

Subreports are last to get processed in each section.
The key implication is that if you intend to pass a value from a subreport to the main report via a shared variable, you can't expect a formula in the same section to obtain that value. You must pass the value to a formula in a section below.

Related

How do I create a loop for subreports?

Adding a subreport into a report with Java and Jasper Reports was easy enough, but I am having trouble making that subreport into something loopable.
The code in Java was simple enough: create report and loop through the parameters to generate subreports. The report generated at the end is a XLS file.
The hassle starts with Jasper Reports since the second iteration complains about the subreport datasource ID already being in use, but then if I generate dynamically the names in the Java code, the Jasper Report won't compile since the subreport's database name is fixed in the XML.
I could, in theory, just create several of the reports with a single subreport and then attach all of them together, but that doesn't feel optimal. How can I create the looped reports then? Is it some sort of parameter to be given in the XML from Jasper Reports or is it impossible to be done and I must use the multiple reports strategy instead?

Collect all data from Crystal Report

I have a crystal report containing multiple subreports. I need to find the way to 'collect' all the data printed on the report/subreports in the following (or similar)
format:
Page1:FieldName1=Value1|FieldName2=Value2|...|Page2:FieldName1=Value1.1|FieldName2=Value2.1|.....
So, the important note is that there is a possibility to figure out on which page (in the PDF generated from report) the particular field value occured.
I tried to do some complex formulas which would 'remember' all the data in a cumulative string within formula(s) (WhilePrintingRecords) but the part I can't achieve is to associate each value to correct Page number of the main, top level, report (the page numbers are of crucial importance in this purpose).
The problem is even more complex because of the groupings and linking applied in main report and subreports, so the Page numbers is at the end of the printing kinda changed comparing to design time order.
Can anyone come up with any idea please?
Thank you Siva, your reply led me to another thing to investigate (I'm new to Crystal Reports) - the issue was actually not related to incorrect execution of the formula keeping the page counter, but rather the one more formula I thought was not executing, since I didn't know that if formula is in the section which is suppressed (and hidden) IS STILL EXECUTING. The counter always counted one more page which was sufficient. When I removed that formula that I didn't need - it worked just fine. So, it was my fault :(

How to show main report with empty linked subreports in Crystal Reports?

I have a Crystal Reports report which contains a main report and three subreports. The data tables used in subreports are linked with main report's data table. In subreports also I've given linking.
Now when I have data in subreports, all comes out fine. But if there is no data in subreports, the main report is also shown as blank.
How to make the main report show results despite (some) sub reports being empty?
Subreports only run after the main report has retrieved it's data. So unless you have set up some fairly complex suppression conditions using shared variables, there is no way that a linked subreport can 'blank' the main report. You can confirm this by running the same report criteria with all of the subreports deleted. You will likely still have the same blank main report. The cause is more likely to be an inner join in the main report.
And there is one final possibility that I hope no one finds insulting. Depending on how the subreports are arranged, it could be possible that adding the subreports causes the first page to be blank while the report starts on the second page. This is caused by the 'keep together' properties of sections and groups. I have had clients call me to troubleshoot blank reports when the data was on page 2.

How can I build a table of contents in iReport/JasperReports?

We use iReport to enable our customers to generate catalogs for print for their products. This process works GREAT. One of the things we've struggled with is how to create a table of contents for these product catalogs.
I decided to use the Scriptlet functionality to give this a shot. Note that our reports are all master-detail in nature, in that there is a master report and a subreport.
At first, I attached the scriptlet to the master report, and tried to find a way to collect all of the product numbers in the detail report, then pass that value back to the master report. I can't figure out how to get the detail information back to the master report, as it appears that you can only pass default variables from the subreport back to the master (eg PAGE_NUMBER, COLUMN_NUMBER, PAGE_COUNT, COLUMN_COUNT).
So then I tried attaching the Scriptlet to the detail report. Well, the detail report doesn't know what page the master is on, so I started passing the master's page_number into a variable in the detail report. That worked great, except that sometimes the detail can overflow to the point that page numbers from the master are skipped. In other words, if a subreport returns more than two pages worth of data, you are going to miss a page number when the subreport is called the next time.
So how to do this?
I found an approach that worked, similar to one of my ideas above. First of all, I could NOT get a subreport to return a value to the calling report, and then retrieve that value using getVariableValue from inside a scriptlet. I tried forever, and I just could not get that to work.
Instead, I went with the approach where I attached the same scriptlet to both the master and subreports. The scriptlet has a class variable where I can keep a running tally of all the product numbers I encounter in the detail, and this code goes inside the afterDetailEval() method of the scriptlet. Note that I only want this code to run for the subreport, so I do a check to see if a particular detail field, which will never be null, is present. If it's not, I don't run the code. So when that event is called by the master report, the code doesn't run.
Now for the part that I learned from the example. The admirable side-effect programming in the example is that there is a line of dimensions 1x1 that contains a call to a custom scriptlet method in the "Print When Expression" property. That's a great idea! So this custom method returns false no matter what, and the line never prints. I did the same thing in the Page Footer band, and this method collects the values from the class variable, determines the page, and stores the results in a hash. Then it resets the class variable.
In the Report Summary band, I have another line that will never print, that calls another custom method. All I do here is iterate through a map of product numbers and show all the pages each one appears on. Done!
There is an example of tables of contents (with subreport) in project folder jasperreports-x.x.x/demo/samples/tableofcontents.
And see the hyperlink example also.
Hyperlinks, Anchors and Bookmarks
JasperReports allows you to create drill-down reports, which introduce tables of contents
in your documents or redirect viewers to external documents using special report elements called hyperlinks.

Crytal Reports - Subreport

I have a main report and a group subreport the is driven off of a value in the mainreport. What I want to do is have the subreport printon a new page without the Headers showing from the main report. Is this possible?
Thanks.
There are several ways to do this, depending on how your report is structured and how it's being viewed (in it's native .rpt format, exported to PDF, etc.).
If you're looking for a "Do not print page header/footers if there is a subreport on this page" function, I've never seen one. Sure would be convenient though if it did exist. However, the InRepeatedGroupHeader boolean might help you in conditionally suppressing the header/footer sections. This will take a lot of trial & error, however.
If the subreports are that different from the main report, don't try to combine them. Keep these "subreports" in a completely separate file.
Are the page numbers of the subreports locked down? i.e. If you know for certain that these subreports are only 1 page long and appear only on even-numbered pages? In this case, you can 'suppress' page headers and footers only on even-numbered pages.