• Aucun résultat trouvé

Defining Types of Key Fields

Dans le document SORT Language (Page 134-137)

S

*

Forced without condition: Forces a character into a key field before the records are sorted.

Forced with conditions: Forces a character into a key field only when a condition is met.

Force-all. Forces a character into a key field before the records are sorted if the key field does not contain one of several entries.

Indicates a data field. Use this entry for SORTR and SORTRS jobs only. If you use a 0 entry in a SORTA job, the specification is treated as a comment.

Indicates a field containing data that is to be totaled for all records with identical key fields. Use this entry for SORTRS sorts only. If you use an S entry in a SORTA sort, the statement is treated as a comment. If you specify an S in a SORTR sort, the field is treated as a normal data field.

Indicates a comment line; the comment is ignored by the program.

Defining Types of Key Fields

You can define the following types of key fields:

• N onnal key fields

• Opposite key fields

• Forced key fields

Any field, containing 1 to 256 oharacters, in the input reCord can be used as a key field to control the sorting of the records. You can use one or several key fields in a GSORT job.

When you sort the records using more than one key field, the major key field is always the first key field you define for a record type. It is used first in the sorting process.

Minor key fields are the other key fields you define for a record type. You determine the hierarchy of the key fields by the order in which you define them.

To include normal key fields and opposite key fields in the output file, you must describe the field twice: once as a key field and once as a data field.

Using GSORT to Code and Run Sort Programs

When the input file has more than one type of record, you can do one of the following:

• You can make the key fields the same or different for each type of record. However, be sure you 'specify the correct data type, such as numeric or character data, in the Field Selection specifications.

• You can make the length of the key field the same or different for each type of record. (See the explanation for the Key Field Lengths columns in the Header specification for more information.)

Normal Key Fields

A normal key field (N) is any field in the input records that the GSORT program uses to sort the records. The data in that particular field are sorted in ascending or descending order, whichever is specified in the Header record.

Opposite Key Fields

Use opposite key fields (0) to define a field sequence that is the opposite of the sequence specified for other fields in the Header record. For example, the field sequence will be in ascending order if you specified descending order in the Record-Sorting Order column of the Header specification.

Forced Key Fields

Use forced key fields (F) to force a record to take a particular position when it is sorted.

For example, if you were sorting by three criteria (last name, first name, and middle name), you could use a forced key field to determine how to sort records without middle names.

Each forced key field can be only I-character long, but you can specify more than one forced key field for a given field. To do so, you define a Field Selection specification for each single character constant you want forced into a key field.

You can specify three types of forced key fields:

• Unconditional

• Conditional

• Force-all Unconditional Forced Field

Use an unconditional forced field to automatically place a specified character constant into the first position of the GSORT key field work record.

Conditional Forced Field

E-34

Use a conditional forced field to test a character in the input records and then to force a character constant into the GSORT key field only if the test is successful. You can

1169794.380

Using GSORT to Code and Run Sort Programs

make the test on any character in the input record. You can compare the entire input character or just the zone or digit portion.

As you define a conditional forced field, you can specify that the GSORT program force the constant either into the previously defined key field position or into the next available key field position.

Force-All Field

Use a force-all field after a series of Field Selection specifications that contain conditional forced fields. This feature allows you to specify a character constant to be forced into the key field when you already have a forced condition but when none of the preceding conditional force test conditions are met.

At least one conditional force specification must come before the force-all specification.

Specifying Types of ~Data Fields

Data fields are not involved in the sorting process and are not changed by the GSORT program. You can specify one of three types of data fields:

• N onnal data fields

• Summary data fields (fields containing data to be totaled)

• Forced data fields

Normal Data Fields

Normal data fields apply to regular (SORTR) and summary (SORTRS) GSORT jobs only.

These fields are included in the sorted records, but are not used in the sorting process.

Data are written into the output records in the order in which you define the fields on the Field Selection specification. Always specify data fields after key fields.

When you give a file more than one type of record, you can

• Have different numbers of data fields.

• Have different total lengths of all data fields for all record types. GSORT places blanks t? the right of shorter records so that all records are the same length.

If you specify data fields for a SORTAjob, these specification statements are ignored.

Summary Data Fields

Summary data fields are used to hold accumulated totals. These fields can be specified only in summary (SORTRS) sort jobs.

Using GSORT to Code and Run Sort Programs

You define summary data fields like normal output data fields:

• Column 6 must be an F to indicate a Field Selection specification.

• Column 7 must be an S to indicate a summary field.

• Column 8 defines the data type of the field to be added.

You can accumulate totals for a maximum of 24 different output fields in SORTRS job.

The data types (selected in column 8) used for normal data fields are also used for summary data fields. The data type entry you use determines the method of adding the

Dans le document SORT Language (Page 134-137)

Documents relatifs