Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
76
Добавлен:
11.05.2015
Размер:
8.74 Mб
Скачать

When you are considering whether to use a subreport or linked tables, you need to understand the ramifications of each. These issues are discussed fully in Performance considerations in one-to-many links, Page 515.

As a general rule, if you have:

indexed tables,

linked indexed fields, and

range limiting record selection criteria based on the indexed fields,

the program needs to read the same number of records whether you are linking tables in a single report or using subreports. Since each subreport is run as a separate report, linked tables may have a performance advantage. See Indexed tables, Page 511.

HANDS-ON (Subreports)

How to insert a subreport, Page 419, and How to link a subreport to the data in the primary report, Page 421, explain in detail how to perform the two basic subreporting tasks. You need to perform one or both of these tasks each time you set up a subreport. The other tutorials in this chapter will address more specific issues (i.e., how to create certain types of reports using subreports). In these later tutorials, instructions involving basic procedures will be conveyed in very general terms (i.e., "create a subreport," " link these two fields," etc.). To study these basic procedures in greater detail, refer back to the first two topics.

How to insert a subreport

1Click the SUBREPORT button on the supplementary toolbar. The Insert Subreport dialog box appears.

Subreports

419

2 To choose an existing subreport, click this option button and type the subreport name into the text box. If you do not know the name, click the Browse button and locate it in the dialog box that appears, or...

...to create a new subreport, click this option button and type a name into the text box. If you need assistance in creating the subreport, click the Report Expert button.

3 Click OK. The program displays an object frame.

4 Move this frame to the desired position in the report and click once to place it.

If you imported the subreport, the program creates a Subreport Design Tab, which is labeled with the subreport name.

¾If you do not want to edit the report, then you are finished.

¾To edit the report, click the Subreport Design Tab and then make your modifications.

If you are creating a new subreport, the program creates a Subreport Design Tab labeled with the subreport name.

¾To edit the subreport further, after exiting the Expert, click the Subreport Design Tab and finish modifying the subreport as you would with any other report.

¾If you do not want to edit the report, then you are finished.

420

Seagate Crystal Reports User’s Guide

For information about creating a custom caption for the Subreport

Preview Tab, see How to add captions to subreports, Page 430.

Click the Preview Tab to

 

Click the Example Subreport

see the parent report.

 

 

 

Preview Tab to see the subreport.

 

 

 

 

 

 

 

How to preview a subreport

There may be times when you want to preview a subreport on its own instead of previewing it as a part of the main report. For example, you may want to preview the subreport in order to view and analyze the data for a particular set of parameter values. While most Windows report designers do not allow you to preview subreports separately, Seagate Crystal Reports makes it easy.

1Click the Design Tab corresponding to the subreport of interest.

2Click the PRINT PREVIEW button on the standard toolbar.

The program displays a preview of the selected subreport.

How to link a subreport to the data in the primary report

Frequently, the data in a subreport supplements the data in the primary report. You might, for example, have customer data in a primary report and then use subreports to show the orders for each customer.

Subreports

421

 

 

 

Primary Report Data

 

Linked Subreport Data

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

In such cases, you will need to coordinate the data in the primary report with the data in the subreport so that the orders in each subreport match up with the correct customer.

To do this, you need to specify a field that is common to both the subreport and the primary report. With the Subreport Links dialog box, you create a link between the two common fields. Seagate Crystal Reports uses the link to match up records from the primary report to those in the subreport. The link makes certain that the "orders" data in the subreport sits on the same row as the corresponding "customer" data in the primary report. You can navigate to the Subreport Links dialog box in two ways:

1.Whether you are importing a report as a subreport or creating a subreport from scratch, click the Subreport Link button in the Insert Subreport dialog box. Then, you can build or import the subreport and link it to the primary report with one process.

2.If you have already placed a subreport in the primary report, but did not create a link at setup, you can navigate to the Subreport Links dialog box by choosing the SUBREPORT LINKS command on the Edit Menu.

From within the Subreport Links dialog box, follow these steps:

422

Seagate Crystal Reports User’s Guide

1 Choose the subreport that you want to link from this drop-down list (if it is not already selected).

2 Select the field you want used as a link field in the primary report from this list box.

3 Click the > (arrow) button.

The field is added to this list box, and is now selected as the link field.

4Repeat steps 2 and 3 for each additional link, as desired.

5Use the Field link section (which will only appear if you have selected a link field) to set up the link for each link field:

select the field you want linked to the primary report from the

Subreport parameter field to use drop-down list, and

toggle the Select data based on field check box on and select a field from the adjacent drop-down list if you want to organize the subreport data based on a specific field (this is the quick equivalent of using the Select Expert). If nothing is specified here, the subreport will adopt the organization of the primary report.

6Click OK.

When you run the report, the program will coordinate the data in the primary report with the data in the subreport.

NOTE: The field type of the Containing Report field determines which subreport fields are visible. Because Seagate Crystal Reports reads dates as either strings, Dates, or Date-Time fields, you must make sure your subreport parameter field type matches the field type set up in Report Options in the main report for the field you want linked.

Subreports

423

How to link a subreport to the main report without modifying the selection formula

At times, you may wish to use a linked parameter field in a subreport without using it as part of the selection formula for the subreport. For instance, you may want the main report to pass in a summary value that can be used in calculations by the subreport, or you may want the main report to pass in the title of the subreport.

You can accomplish these tasks using Seagate Crystal Reports, but first it is important to understand how the program handles subreport linking.

Seagate Crystal Reports uses a parameter field mechanism for linking subreports to main reports.

When linking a main report field that is not a parameter field to a subreport field, the program:

automatically creates a parameter field to complete the link, and

modifies the subreport record selection formula to select those records in which the subreport field is equal to the parameter field value.

The need for a parameter field is implied; it is called an “Implicit Link” situation.

When you link a field in the main report to a parameter field that you have created in the subreport, the Visual Linking Expert:

checks the link you have specified,

does not create any additional parameter fields, and

does not modify the subreport record selection formula. Specifying a link is called an “Explicit Link” situation.

For example, if you want to link a subreport to the main report but do not want to modify the selection formula, you must use an Explicit link. To do this:

1Create a parameter field in the subreport.

2Link a field in the main report to that parameter field using the Visual Linking Expert.

424

Seagate Crystal Reports User’s Guide

How to combine unrelated reports by using subreports

At times, you may wish to combine unrelated reports into a single report. For example, you may want to create a single report that presents:

sales grouped by sales representative, and

sales grouped by item.

While both reports deal with sales data, there is no real linear relationship between the reports.

NOTE: This sample report has been designed to illustrate concepts only, and not the actual look of your finished report.

Subreports can be used to combine unrelated reports into a single report like this. While the reports could be based on the same data set, they do not have to be. They could each be based on entirely different data sets.

Each of these reports is freestanding; the data in any of the reports is not linked in any way to data in another report. This is the easiest of the subreport options to work with.

FOR TWO UNRELATED REPORTS

To create a report that consists of two unrelated reports:

Subreports

425

1Create the report you want printed first as the primary report.

2Import an existing report for use as a subreport or create a new subreport.

3 Place the report you want printed first in the Details section.

4 Place the subreport into the Report Footer and it will print immediately after the primary report.

FOR THREE OR MORE UNRELATED REPORTS

To create a report that consists of three or more unrelated reports:

1Create the report you want printed first as the primary report.

2Import or create each of the other reports you want to use as subreports.

3Use the Section Expert to insert enough Report Footer sections to match the number of subreports that you are using. For example, if you want to use three subreports, insert two new Report Footer sections so that you have a total of three Report Footer sections.

4Place in Report Footer A the subreport you want printed immediately after the primary report, in Report Footer B the subreport you want printed next, and so forth. The primary report will print first and then the subreports in the order that you placed them in the report.

NOTE: Subreports can be placed side-by-side in the same Report Footer section. They will print next to each other at the end of the report.

426

Seagate Crystal Reports User’s Guide

5 Place the report you want to print first in the Details section.

6 Place the subreports into the Report Footer sections and they will print sequentially after the primary report.

Related Topics

Area printing characteristics, Page 59

How to add, delete, move, and merge sections, Page 79

How to use subreports with unlinkable data

Linking to/from a formula field

Tables can be linked in a report as long as the following criteria are met:

the link fields are both database fields,

the link fields contain similar data,

the link fields are the same length, and

the link field in the link to (lookup) table is indexed (PC databases only).

Linking tables is rarely a problem. However, there are some circumstances in which you can not coordinate data from different tables because the data does not meet the linking criteria.

For example:

linking to or from a formula field, or

linking two unindexed tables,

can not be done in a single report. Subreports must be used.

There are situations in which you may need to link to or from a formula (calculated) field. For example, an employee ID could be an 11 character value that consists of a two-character department code followed by the employee’s nine-character Social Security Number (for example,

Subreports

427

HR555347487). The formula language makes it easy to extract the Social Security Number from this field:

{employee.EMPLOYEE ID} [-9 to -1]

OR

{employee.EMPLOYEE ID} [3 to 12]

For the value HR555347487, either formula would return the value 555347487.

While the return value is a valid Social Security Number, the fact that it comes from a formula prevents you from using the field to link to a Social Security Number field in another table. You can report on and coordinate the values in the two tables, however, by using a subreport. Search for Subscript in Seagate Crystal Reports online Help.

LINKING TO A FORMULA FIELD

1Create the primary report using a table that includes the Social Security Number field (for this example, {file.SSN}).

2Create (or import) a subreport using the formula that extracts the Social Security Number from the Employee ID field (for this example, {@EXTRACT}). See How to insert a subreport, Page 419.

3Place the subreport where you want it to appear in the primary report.

4Link the subreport to the primary report by linking the Social Security Number field in the primary report ({file.SSN}) to the formula that extracts the number in the subreport ({@EXTRACT}). See How to link a subreport to the data in the primary report, Page 421.

LINKING FROM A FORMULA FIELD

1Create the primary report using the formula that extracts the Social Security Number from the Employee ID field (for this example, {@EXTRACT}).

2Create (or import) a subreport using a table that includes the Social Security Number field (for this example, {file.SSN}). See How to insert a subreport, Page 419.

3Place the subreport where you want it to appear in the primary report.

4Link the subreport to the primary report by linking the formula that extracts the Social Security Number in the primary report ({@EXTRACT}) to the Social Security Number field in the subreport ({file.SSN}). See How to link a subreport to the data in the primary report, Page 421.

428

Seagate Crystal Reports User’s Guide

Linking unindexed tables

When using PC databases (not SQL or ODBC), the link field in the lookup database needs to be indexed in order to create a valid link. You can not link the tables in a single report when two tables contain related data yet neither is indexed on the field which you want to use as a link field, or when the primary table is indexed but the lookup table is not. You must use subreports if you want to coordinate the data in both tables.

NOTE: It is important to note that linking unindexed tables or linking from an indexed primary table to an unindexed lookup table may cause inefficient reporting. If your data set is large, this kind of report will take considerable time to run. Use this technique only if you do not have other options.

1 Create the primary report.

2Create (or import) the subreport and insert it into the primary report. See How to insert a subreport, Page 419.

3Use the unindexed fields (or the indexed field in the primary table and the unindexed field in the lookup table) to link the subreport to the primary report. See How to link a subreport to the data in the primary report, Page 421.

How to create an on-demand subreport

Seagate Crystal Reports now allows you to create on-demand subreports. In the Preview Tab, an on-demand subreport is represented by an object frame, which is much easier to manage than the bulk of an entire subreport. Furthermore, the actual data is not read from the database until the user drills down on the frame. This way only data for ondemand subreports that are actually viewed will be retrieved from the database.

NOTE: Data for an on-demand subreport is not saved unless the subreport is actually open in a preview window.

On-demand subreports can be especially useful if you want to create a report that contains multiple subreports. In this case, you can choose to have these subreports appear only as object frames. This makes the subreports much more manageable.

Best of all, the process of creating an on-demand subreport is easy and fast. Simply place an ordinary subreport in your primary report, and then complete the following three steps:

1Click the OBJECT PROPERTIES button on the supplementary toolbar. The Format Editor appears.

Subreports

429

2With the Subreport Tab active, toggle the On-demand subreport check box on.

3Click OK.

The program does all the work for you.

For information about adding a caption to your on-demand subreport, see How to add captions to subreports, Page 430.

How to add captions to subreports

To further organize a report, captions can be created for the Subreport Preview Tab and for the placeholder frame of an on-demand subreport. This allows you to quickly organize reports in a concise and visually manageable form. Note that placeholder frame captions only apply to ondemand subreports, while tab text captions apply to both on-demand subreports and regular subreports. Since the data from a regular subreport is in place and visible on the Preview Tab, rather than ondemand and represented by a placeholder object frame, there is no need for a frame caption when you format a regular subreport.

NOTE: A tab text caption replaces the subreport file name caption on the

Subreport Preview Tab.

Captions are written by using formulas. Both placeholder frame captions and Subreport Preview Tab captions can include field names from the main report. To add a caption:

1Select the subreport and click the OBJECT PROPERTIES button on the supplementary toolbar. The Format Editor appears.

2Click the Subreport Tab.

3You can enter either an on-demand subreport caption or a tab text caption by clicking the appropriate Formula button and opening the Format Formula Editor.

4Enter your formula in the Formula text box. For example:

"More Information About " + {Customer.Customer Name}

Using the xtreme.mdb sample database, this formula would give you a caption like "More Information About Pathfinders" or "More Information About Rockshocks for Jocks".

5Click CHECK to check the formula for errors. If the program finds an error, it will prompt you with a message box detailing the nature of the error.

430

Seagate Crystal Reports User’s Guide

6After fixing any errors, click the SAVE AND CLOSE button. The program returns you to the Format Editor.

7Click OK to return to the report.

NOTE: A tab text formula is only evaluated when you drill-down on a subreport. If you preview a subreport separately from the primary report, the formula will not be evaluated.

NOTE: Again, frame captions apply only to on-demand subreports, while tab captions apply to both on-demand subreports and regular subreports. For more information about on-demand subreports, see How to create an on-demand subreport, Page 429.

How to show different views of the same data in one report

Subreports can be used to provide a different view of the data in the primary report. For example, assume you want to show summary values at the top of a report and details at the bottom, like this:

NOTE: This sample report has been designed to illustrate concepts only and not the actual look of your finished report.

This can be done in a variety of ways. The two easiest methods are:

Subreports

431

1.By creating the summary report as the primary report and the details report as the subreport. In this method, the details subreport would be placed in the Report Footer section.

2.By creating the details report as the primary report and the summary report as the subreport. In this method, the summary report would be placed in the Report Header section.

Use the appropriate link fields to link the report and coordinate the data.

How to save a subreport as a primary report

You may find it advantageous to save a subreport as a primary report for the sake of distributing the information to a variety of audiences. For example, the primary report containing the subreport may be relevant for a stockholders meeting at the end of the fiscal year; however, the data contained in the subreport may be relevant for everyday use by your managers. In such cases, it is easy to save a subreport as a primary report.

1In the Design Tab, right-click the subreport and choose Save Subreport As from the shortcut menu. The Save As dialog box appears.

2Choose the appropriate directory from the list box.

3Type a new name for the subreport.

4Click Save.

The program saves the subreport as a primary report so that you can open it separately when necessary.

432

Seagate Crystal Reports User’s Guide

21

Document Import Tool

What You Will Find...

How to use the Document Import Tool, Page 435 How to set report font size, Page 441

How to define custom colors, Page 441 How to specify a custom formula, Page 442

Document Import Tool

433

The Document Import Tool

Why use this Tool?

Using the

Document

Import Tool

Seagate Crystal Reports offers a powerful reporting functionality in the Document Import Tool. With this specialized reporting tool, you can easily convert a plain ASCII text report to Seagate Crystal Reports.

This new tool lets you:

convert old text reports,

remap the fields to the original database, and then

generate the text report whenever you want, from within Seagate Crystal Reports.

The Document Import Tool extends your reporting capabilities by allowing you to use Seagate Crystal Reports functionality in all your reports.

NOTE: The Document Import Tool does not convert cross-tabs.

To give you an example of the uses of this tool, suppose that you created a plain text report in Microsoft Word, and now you want to modify the report using Seagate Crystal Reports functionality. If you save the Word document as an ASCII text file, you can open that file in the Document Import Tool and generate a Seagate Crystal Reports based on that file. You can then use all the familiar formatting abilities of Seagate Crystal Reports to modify the report, adapting it to better suit your needs.

To convert an ASCII text report to a Seagate Crystal Reports, you must specify the correlations between the sections and objects in the ASCII report and the sections and objects in Seagate Crystal Reports. You can accomplish this by highlighting various sections and objects in the ASCII report with a colored, resizable frame. These frames represent report headers and footers, page headers and footers, details sections, etc. Highlight only:

the first instance of each header,

the last instance of each footer, and

the first instance of the Details section.

You can highlight sections by using the Sections Menu or by using the button toolbar displayed to the right of the ASCII text report. A set of text boxes are displayed below the toolbar, allowing you to set the properties for each highlighted section.

NOTE: When highlighting fields, make certain your highlighting frames are at least as large as the maximum size of the field. That way, values

434

Seagate Crystal Reports User’s Guide

Соседние файлы в папке crystal