SORT Parameters

SORT parameters specify a sequence for extracted data and establish control breaks when sort-key fields change. As many as 20 unique sort-keys fields can be specified for each report. Each sort-key field has its own ascending or descending sequence indicator.
idmscu19
SORT parameters specify a sequence for extracted data and establish control breaks when sort-key fields change. As many as 20 unique sort-keys fields can be specified for each report. Each sort-key field has its own ascending or descending sequence indicator.
A control break code can be specified on each sort-key field. This code calls for a control break when the value of the sort-key field changes. Usually, subtotals print when a control break executes. The value of the control break code determines report spacing that is associated with total lines.
The number of control break codes determines the maximum value of
LEVL
for the report. LEVL, a CA Culprit reserved word, is used in type 8 procedure logic.
The SORT parameter can be omitted if sorting is not required and control breaks are not needed.
This article describes the following information:
2
2
Syntax
      Col       2       ▼       ┌────────────────────────────────────────────────────┐ ►►─── 
nn
SORT ─▼─ 
field-name-expression
 ─┬──────────────┬─┬───────┬─┴──────────►                                         └─ 
break-code
 ─┘ ├─ A ◄──┤                                                          └─ D ───┘  ►─┬──────────┬───────────────────────────────────────────────────────────────►◄    └─ NOSORT ─┘
Expansion of Field-name-expression
►►──── 
field-name
 ──┬─────────────────────────┬───────────────────────────────►◄                     ├─ .
subscript-value
 ──────┤                     └─ .
subscript-field-name
 ─┘
Syntax Rules
  • nn
    Identifies the report that is associated with the SORT parameter.
    This value must be a 2-digit number in the range 00 through 99 and must be coded starting in column 2.
  • SORT
    Specifies the parameter type. This value must be coded starting in column 4.
  • field-name-expression
    Specifies a field to be sorted. This value can be coded in any column following SORT.
    Expanded
    field-name-expression
    syntax follows:
    • field-name
      Specifies the name of a singly or multiply occurring input field that is defined on a REC parameter or work field that is defined on a work field definition parameter.
    • subscript-value/subscript-field-name
      Specifies a subscript value for a multiply occurring field.
      If a subscript value is provided, the value must be separated from the name of the multiply occurring field by a period (.). The value of the subscript should be an integer in the range 1 through
      n
      , where
      n
      is the number of repetitions of the multiply occurring field. For example, if EMPLOYEE occurs ten times, the value of the subscript should not exceed 10. The value of the subscript can be tested in procedure logic.
    • subscript-value
      Specifies a numeric literal that identifies a specific occurrence of a multiply occurring field; for example, EMPLOYEE.4 identifies the fourth occurrence of EMPLOYEE.
    • subscript-field-name
      Specifies the name of a singly occurring numeric input or work field whose value identifies a specific occurrence of a multiply occurring field; for example, if INDX has a value of 2, then EMPLOYEE.INDX identifies the second occurrence of EMPLOYEE. The subscript field definition must not specify a decimal point.
  • break-code
    Specifies a control break when the value of the sort-key field changes. This value is a 1-character code whose value specifies output spacing after the control break executes;
    The
    table
    lists valid control break codes and their effect on report spacing.
    When a control break is immediately followed by a higher level control break, all lower level control breaks execute, beginning with the lowest level. The control break code that is associated with the highest level control break determines output spacing.
    Subtotals are automatically accumulated each time a control break executes. These lines are passed to the output file unless total lines are suppressed in procedure logic or by a details-only specification on the OUTPUT parameter. If total lines are suppressed, spacing indicated by the control break code is still performed.
    Each control break specified on the SORT statement has a corresponding level number, referenced by the CA Culprit reserved keyword
    LEVL
    . LEVL is used in type 8 procedure logic to identify the control break that is currently active.
  • A/D
    Specifies the sequence in which values are sorted. A (default) designates an ascending order (from lowest to highest); D designates a descending order (from highest to lowest).
  • NOSORT
    Eliminates sorting of extract data, while allowing sort-key fields and associated sort breaks to be defined. Sort-key fields can be used to make detail information available to header and totals processing.
    NOSORT can appear only once on a SORT parameter. Generally it is coded after the sort-key fields.
Usage
Sort Key Considerations
A maximum of 20 field names can be specified as sort keys. The sort hierarchy is established by the order of the sort keys from left to right. The leftmost key is the primary sort key; the rightmost key establishes the most minor sort sequence of extract data. Each sort key can be followed by its own control break code and A/D designation.
The total length of all sort-key values must not exceed 240 bytes. 
For output file type IS, the primary sort key is used to load the output file. The primary sort key must also appear on a type 5 edit parameter.
The following table lists the number of bytes allocated to each type of sort key, as well as the lengths allocated to each type of sort-key value in order to calculate the total length of all sort keys:
Field
Definition
A=Alphanumeric
N=Numeric
Length of Sort-key Value in Bytes
REC
N
Data types 1 and 5 (binary and bit fields): 5 bytes
 
N
Data types 2, 3, and 4: Half the maximum number of digits (rounded down) plus 2; for example, allow 10 bytes for a field that contains 17 digits
 
A
Field length plus 1
 
Work field
N
Field with a decimal position or initial value exceeding 15 digits: 17 bytes
 
N
Field with no decimal position and an initial value less than or equal to 15 digits: 9 bytes
 
A
Field length plus 1
Break Code Considerations
Break Code
Spacing
Comments
1
A new page is started after the control break
CA Culprit prints any title and header lines and associated spacing at the top of the new page. Do not use this break code for nonprinted output.
0
One blank line is printed after the control break
Do not use this break code for nonprinted output; it may cause blank records to appear in the output file.
-
Two blank lines follow the control break
Do not use this break code for nonprinted output; it may cause blank records to appear in the output file.
+
No blank lines follow the control break
This code is appropriate for printed and nonprinted output.
Examples
Sample SORT parameters follow.
Example 1
01SORT  CITY,1  ZIP  CUST-NAME
Customer names are sorted in alphabetical order according to zip code, zip codes in ascending order within city, and cities in alphabetical order. The break code that is associated with CITY specifies a new page of output when the value of CITY changes. Each page contains title and header lines (if they are specified), detail lines, and subtotal lines. The last page will also include the grand total lines for the report.
Example 2
10SORT  DIVISION,-  DEPT,0  EMPLOY-NO
The primary sort key for Report 10 is DIVISION. Within each division, extracted records are sorted by employee number within department. All fields are sorted in ascending order.
The value of LEVL associated with a control break on DEPT is 1. The value that is associated with a control break on DIVISION is 2. At grand totals time, the value of LEVL equals 3. These values can be used in type 8 procedure logic to test the currently active control break.
Detail lines within department are single spaced in the output file. When a control break executes on DEPT which is not immediately followed by a control break on DIVISION, one blank line follows the subtotal lines output for DEPT. When a control break executes on DEPT and is immediately followed by a control break on DIVISION, the break code that is associated with DIVISION outputs two blank lines following subtotals for DEPT and DIVISION.
Example 3
02SORT  BRNAME,0  NOSORT
Extracted records for Report 02 are not sorted; however, one blank line is output after each branch name. Also, CA Culprit maintains the current value of BRNAME for use on a type 4 header edit parameter.