USING

From CometWiki

Jump to: navigation, search

USING

Syntax:
USING link-name [(alternate-actual-file-name{,directory-name})] [;link-name][;link-name]
Placement:
Place the USING command after the REPORT command.
Discussion:
The USING command links the primary data file to secondary files so that you can extract additional, appropriate data from them.

Follow the USING command with the name of the link(s) you wish to include.
The Reporter must have been educated about the link in the data dictionary (#CFILES).

There are two types of relationships that exist between files:

  • one-to-one relationships and
  • one-to-many relationships.

The type of relationship affects how your report will look.

In a one-to-one relationship, there is exactly one record in the second file that corresponds to the primary file, and as such, the data for each line of the report is limited.
An example of a one-to-one relationship would be between the customer file and the customer history file.
For each customer record, there is one and only one history record.

In one-to-many relationships, there may be multiple records in the secondary file that correspond to the primary file, and thus the data to be reported is, in a sense, unlimited.
A typical example of a one-to-many relationship is between the customer file and the open order file.
For each customer, there may be many open order records.
In such a case, you many want to arrange your report such that static information such as the customer name and address appear only once, and the variable information (each open order) is listed separately below.
This is accomplished by strategically placing the non-repeating variables in a second print line.

Once the USING command appears in the report, all fields from all linked files are available for manipulation by The Reporter.

Note:
The USING command indents the field data specified in the next PRINT command by 5 spaces.
You can use the INDENT command to override the USING indentation.

The alternate-actual-file-name and directory-name parameters are optional, and are used to specify an alternate link file for the report.
For example, the data dictionary (#CFILES) may contain a link named CUST.TO.HIST that links to a file named C1B on directory DSK.
For the purposes of a specific report, an alternate link file name and directory name can be specified, as follows:

 USING CUST.TO.HIST(TEMPFILE,ABC)
 

In this case, the link will be made to a file named TEMPFILE on directory ABC.
Example:

 100   INPUT CUSTOMER
 200   TITLE PAST DUE ACCOUNTS
 210   TITLE
 220   TITLE CALIFORNIA CUSTOMERS
 300   DEFINE PAST.DUE = AR.OVER.60 + AR.OVER.90;8.2
 400   SELECTING IF PAST.DUE GT 0 AND STATE EQ "CA"
 500   SORT ON STATE;CUST.NAME
 600   REPORT
 700   USING CUST.TO.HIST
 800   PRINT CUST.NAME;CUST.NUMBER;STATE;PREVIOUS.YTD;PAST.DUE
 900   BREAK ON STATE
 1000  TOTAL PAST.DUE;PREVIOUS.YTD
 1100  END

The USING statement on line 700 establishes a link between the primary file (CUSTOMER) and a secondary file.
The link name is CUST.TO.HIST.
The data dictionary contains the definition of the link, including the name of the secondary file (which in this case is assumed to be a "customer history" file).
Once the link has been specified in the report, fields from the primary and secondary files may be used (as seen on lines 800 through 1000).

Personal tools