Report Concept Question
I need some direction on the best way to approach a report. I am going to
give a very simplified example.
Consider the following data in 2 tables:
Table #1 Employees
Fields: SSNumber
Name
Table #2 PayRecords
Fields: Date
Code
Amount
I need to generate a report that sorts by employee and displays the data in
3 columns as shown below.
Employee (Group Header) Code Date Period YTD
John Doe
xxx
xxx xxx
xxx
xxx xxx
xxx
xxx xxx
xxx
xxx xxx
---
--- ---
Empoyee Total xxx xxx
xxx
The code column is dynamic and is not something I can hard code as it may
change per employee. Howver, if a Code / Amount combination exist in the
Period it will exist in the YTD.
The problem I am having is getting the Period Data and the YTD data in the
same band. I have tried seperate queries and linking them to a master query
of just employees but when I link the numbers go all out of sorts. If I
unlink they seem fine. I have tried using regions with seperate sub
reports, etc. I am convinced I am overlooking something simple and you guys
can give me a tip. This is an important issue for me because I have
numerous reports that require this same type of logic.
Any thoughts?
give a very simplified example.
Consider the following data in 2 tables:
Table #1 Employees
Fields: SSNumber
Name
Table #2 PayRecords
Fields: Date
Code
Amount
I need to generate a report that sorts by employee and displays the data in
3 columns as shown below.
Employee (Group Header) Code Date Period YTD
John Doe
xxx
xxx xxx
xxx
xxx xxx
xxx
xxx xxx
xxx
xxx xxx
---
--- ---
Empoyee Total xxx xxx
xxx
The code column is dynamic and is not something I can hard code as it may
change per employee. Howver, if a Code / Amount combination exist in the
Period it will exist in the YTD.
The problem I am having is getting the Period Data and the YTD data in the
same band. I have tried seperate queries and linking them to a master query
of just employees but when I link the numbers go all out of sorts. If I
unlink they seem fine. I have tried using regions with seperate sub
reports, etc. I am convinced I am overlooking something simple and you guys
can give me a tip. This is an important issue for me because I have
numerous reports that require this same type of logic.
Any thoughts?
This discussion has been closed.
Comments
Your best bet in the case below would be to create a Master-Detail report
linking on a common field between the two datasets (such as SSNumber or
Name). You need to be sure the detail dataset is ordered on the linking
field.
Next, you will need to connect the main report to the master dataset and
create a subreport that is connected to the detail data. See the article
below for more information on how this is to be done.
------------------------------------------------
TECH TIP: Fundamentals of Report Data Traversal
------------------------------------------------
1. Single Table Listing Report
Assign the Report.DataPipeline property and leave the
DetailBand.Pipeline unassigned.
The report will traverse the data from start to end (based on the
datapipeline range settings and honoring any filters you've placed on
the datset etc.)
2. Master/Detail Report:
A. Assign the Report.DataPipeline property to the master. Create a
subreport in the detail band and assign the childreport.DataPipeline to
the detail datapipeline.
Use either the visual linking features available from the Report
Designer's Data tab, or Use standard Delphi dataset linking to define
the relationships between the datasets.
The Report will traverse the master records and for each, the subreport
will traverse the detail data related to the master.
3. Master with 2 Details
Configure as in 2 above. Add an additional subreport to the detailband.
Set subreport.ShiftRelativeTo property to the point to the first
subreport. Connect the ChildReport's DataPipeline to the detail data.
4. Report connected to no datapipelines.
When Report.AutoStop is set to True, the Report will print a single
detail band.
When Report.AutoStop is set to False, the Report will print detail bands
until instructed
to stop. You can control when the report stops by setting the
Report.PageLimit property or by calling Report.DataTraversalCompleted
method. Otherwise the report will never stop.
Additional Notes:
----------------
1. SubReports have a Report property that is of type TppChildReport.
Thus, programmatically you can code SubReport.Report.DataPipeline :=
myDataPipeline.
2. ChildReport's traverse data following the same rules as above. A
ChildReport prints in its entirety each time it gets a turn to print.
3. For a Child style SubReport use the Title/Summary band rather than
the Header/Footer (or use a GroupHeader/GroupFooter combo). A standard
Header/Footer will not work because these always print at the very
top/bottom of the page.
4. Do not filter the dataset of modify it any way once the report.Print
command is issued. If you need to do master/detail and cannot use
linked datasets, then use the master DataPipeline.OnRecordPositionChange
event to filter the detail dataset.
5. The reports and datapipelines use dataset bookmarking. Make sure
the dataset can support bi-directional navigation.
Check out the RBuilder\Demos\Reports\Demo.dpr project. Reports 0071,
0072, 0073 show examples of master w/mutliple detail style reports.
Number 0072 has two detail reports.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Some thoughts:
1) for your detail band, you may want to use multiple sub-reports, each
formatted correctly, and link them to different pipelines--maybe JIT
pipelines. I do this in complex reports and it allows for easily changing
the configuration of the report.
2) Don't link your datasets--order the detail dataset by the order of the
master id field.
Edward Dressel
Team DM
Bob