Some standard content:
1 Introduction
1.1 Function
National Standard of the People's Republic of China
Programming Language COBOL
Sort-merge module
GB/T 4092.7—92
Replaces GB 4092. 7—83
The sort-merge module provides the following functions: sorting records in one or more files or merging records in two or more files with the same order according to a set of keys included in each record proposed by the user. In addition, the user can choose to perform specific processing on the records by input or output procedures. This specific processing can be applied before or after the records are sorted by a SORT statement or after the records are merged by a MERGE statement.
1.2 Language Concepts
1.2.1 Sorting Definition
A sorted file is a set of records sorted by a SORT statement. Sorted files have no numbering process that the programmer can control, and the rules for block and internal storage allocation are specific to the SORT statement. RELEASE statements and RETURN statements have no meaning with respect to buffers, blocks, or volumes. However, a sorted file can be considered an internal file that is created from input files (RELEASE statement), processed (SORT statement), and then made available (RETURN statement) as an output file. Sorted files are named by file control clauses and described by sort-merge file description clauses. Sorted files are referenced by RELEASE, RETURN, and SORT statements.
1.2.2 Merged files
Merged files are sets of records that are merged by MERGE statements. Merged files have no numbering process that the programmer can control, and the rules for block and internal storage allocation are specific to the MERGE statement. RETURN statements have no meaning with respect to buffers, blocks, or volumes. However, a merge file can be considered an internal file that is built from input files and becomes available (RETURN statement) as an output file by merging them (MERGE statement). The merge file is named by the file control clause and described by the sort-merge file description clause. The merge file is referenced by RETURN and MERGE statements.
2 Environmental section of the sorting and merging module
2.1 Input-output section
For information on the input-output section, see 2.1 of the sequential IO module. 2.2 FILE-CONTROL section
For information on the FILE-CONTROL section, see 2.2 of the sequential IO module. 2.3 File control section
.2.3.1 Function
File control section describes the physical properties of sorting or merging files, approved by the State Administration of Technical Supervision on August 4, 1992 and implemented on May 1, 1993
2.3.2 General format
2.3.3 Syntax rules
GB/T 4992.7—92
SELECT file name 1ASSIGNTO
【Implementation name 1
Study if 1
(1) Each sort or merge file described in the data portion can be referred to only once in the FILE-CONTROI. section. Each sort or merge file referred to in the SELECT clause must have a sort-merge file description in the data portion of the same program. (2) Because file name 1 refers to a sort or merge file, only the ASSIGN clause is permitted to follow the file name in the FILE-CONTROL segment.
2.3.4 General Rules
(1) The ASSIGV clause indicates the association between the file referenced by file name 1 and the storage medium referenced by implementation name 1 or value 1. 2.4 1-O-CONTROL Segment
2.4.1 Function
The IO-CONTROL segment indicates the storage area common to the different files comprising the sort or merge file. 2.4.2 General Format
I O.CONTROL.
RECORD
2.4.3 Syntax Rules
SORT-MERGE,
AREA FOR File Name 14 File Name 21
<1) The availability of the RECORD option of the SAME clause depends on the level of the sequential IO module that implements the support. 2.4.4 General Rules
(1) The SAMERECORD/SORT/SORT-MERGEAREA clauses for the sort-merge module are introduced below. 2.5 SAMERECORD/SORT/SORT-MERGEAREA clauses) 2.5.1 Functionality
SAMERECORD/SORT/SORT-MERGEAREA clauses Specifies a storage area shared by different files (at least one of which is a sort or merge file).
General format
FRECORD
SAMESORT
SORT-MERGE
2.5.3 Syntax rules
AREAFOR file name 1 file name 2)
(1) Each file name specified in the SAMESORT/SORT/SORT-MERGEAREA clause must be specified in the FILE-CONTROL section of the same program.
(2 (3)SORT and SORT-MERGE are equivalent. (4)Unless the SORT, SORT-MERGE or RECORD phrase is used, the name of the file that sorts or merges cannot appear in the SAME clause.
(5)Multiple SAME clauses can appear in a program, however: .. A file name must not appear in two or more SAMERECOREA clauses. b. A file name that sorts or merges files cannot appear in more than one SAME clause.
C If a file name other than a sort or merge file appears in a SAME clause and one or more SAMESORTAREA or SAMESORT-MERGEAREA clauses, all file names named in the SAME clause must be named in that SAMESORTAREA or SAMESORT-MERGEAREA clause. (6) File names used in a SAMESORTAREA, SAME SORT-MERGEAREA, or SAME RECORDAREA clause are not required to have the same organization and access methods. 2.5.4 General Rules
(1) A SAMERECORDAREA clause specifies that two or more files referenced by filename1 and filename2 share the same storage area in the processing of the current remote record. All of these files may be in open mode at the same time. The logical records in the SAMESORTAREA are treated as if they were the logical records of each output file opened in the SAMESORTAREA clause and the logical records of the most recently read input file in the SAMESORDAREA clause. This is equivalent to an implicit redefinition of storage areas, i.e., the records are aligned to the leftmost character position. (2) If the SAMESORTAREA or SAMESORT-MERGEAREA clause is used, at least one of the file names denotes a sort or merge file. The clause indicates that storage areas are shared as follows: The SAMESORTAREA or SAMESORT-MERGEAREA clause specifies a storage area that is available for sorting or merging each named sort or merge file. Thus, storage areas allocated for sorting or merging a sort or merge file are available for reuse for sorting or merging any other sort or merge file. bIn addition, storage areas allocated to non-sort or merge files may also be allocated to sort or merge files named in the SA.MESORTAREA or SAMESORT-MERGEAREA clauses as needed for sorting or merging. The extent of such allocations is "up to the implementation.
.Non-sorted or merged files do not share a storage area with each other. However, if the user wants these files to share the same storage area with each other, the program must include the SAMEAREA or SAMERECORDAREA subclause to indicate the file names associated with these files.
d During the execution of a SORT or MERGE statement that references the sorted or merged files named in this clause, any non-sorted merged files named in this subclause cannot be opened. 3 Data Section of the Sort-Merge Module
3.1 File Section
The file section is located in the data section of the source program. The file section defines the structure of the sort and merge files. Each sorted or merged file is defined by a sort-merge file description clause and one or more record description clauses. The record description clause is written immediately after the sort-merge file description clause.
The general format of the file section of the sort-merge module is given below. FILESECTION
[Sort-Merge File Description Section
{Record Description Section
3.1.1 Sort-Merge File Description Section
In the COB)I. program, the Sort-Merge File Description Section SD represents the highest level of organization in a file section. The file section begins and ends with a Sort-Merge File Description Section consisting of a level indicator (SD), a file name, and a series of independent clauses. The following clauses of the Sort-Merge File Description Section (SD Section) specify the data records associated with a sort file or merge file. There is no user-controlled labeling process. Blocking rules and internal storage rules are only used by SORT and MERGE statements. The Sort-Merge File Description Section ends with a period. 3.1.2 Record Description Structure
A record description consists of a set of data description sections that describe the characteristics of a particular record. Each data description section consists of a level number followed by a data name or FILLER clause (if specified), followed by a series of independent clauses as needed. Record descriptions can have a hierarchical structure, so the clauses that use a particular clause may be different, depending on whether it is followed by subordinate clauses. The availability of specific clauses in a data description clause depends on the level of the core module supported by the implementation. :
3.1.3 Initial value
GB/T 4092.7—92
The initial value of a data item in a file section is undefined. 3.2 Sorting-merging file description clause
, 3.2.1 Function
The sorting-merging file description clause provides information about the physical structure and record names of a sorted or merged file. 3.2.2 General format
FD file name 1
(CONTAINS integer 1 CHARACTERS
RECORIK
IS VARYING IN SIZE [IFROM integer 2JTO integer 3]CHARACTERS][DEPENDING ON data name]
[CONTAINS integer 4 TO integer 5 CHARACTERS(data name 2)
RECORD[S
IRECORDS AREJ
3.2.3 Syntax Rules
(1) The level indicator SD indicates the start of a sort/merge file description and must precede file name 1. (2) The clauses following file name 1 are optional and the order of appearance is irrelevant. (3) A sort or merge file description clause may be followed by one or more record description clauses. However, input-output statements cannot be executed on such files.
(4) The availability of format 2 of the REC()RD clause depends on the level of sequential IO modules supported by the implementation. 3.2.4 General Rules| |tt||(1) The DATARECORDS clause of the sort-merge module is identical to the DATARECORDS clause of the sequential IO module. Therefore, the description of the DATARECORDS clause is given in 3.5 of the sequential IO. The DATARECORDS clause is considered obsolete in this version of Standard COBOL because it will be deleted in future revisions of Standard COBOL. (2) The DATARECORDS clause of the sort-merge module is identical to the RECORD clause of the sequential IO module. Therefore, the description of the RECORD clause is given in 3.5 of the sequential IO. 3.8.
4 Procedure of the Sort-Merge Module
4.1 MERGE Statement
4.1.1 Function
The MERGE statement merges two or more files with the same sequence together according to a key specified by the group. During this process, the MERGE statement makes the records available to the output process or output file in the merged order. 4.1.2 General Format
MERGE filename1
IASCENDING
KEY(dataname1)
IDESCENDING
[COLLATING SEQUENCE IS TABLENAME1]]USING filename2 (filename3) *
OUTPUT PROCEDURE IS Procedure name 1
[GIVING(document name..
4.1.3 Syntax rules
THROUGH
(1) The MERGE statement can appear anywhere in the procedure part except the declaration part. (2) Document name 1 must be described in the sort merge document description clause of the data part. Procedure name
3) If the document referenced by document name 1 contains variable-length records, the length of the records contained in the documents referenced by document name 2 and document name 3 cannot be less than the minimum record described by document name 1 nor greater than the maximum record described by document name 1. If the document referenced by document name 1 contains fixed-length records, the length of the records contained in the documents referenced by document name 2 and document name 3 cannot be greater than the maximum record described by document name 1. GB/T4092.7—92
(4) Data name 1 is a key data name and complies with the following rules: The data item identified by the key data name must be described in the record associated with document name 1. a.
b. The key data name can be restricted.
The data item identified by the key data name cannot be a group item containing variable-length data items. c
d. If the file name 1 has multiple record descriptions, the data item indicated by the key data name is required to be described in only one record description. The same character position referenced by the key data name in a record description is used as the key of all records in the file. e.
The data items indicated by the key data name cannot be described in a clause containing a CCURS clause or in a clause containing an OCCURS clause.
f. If file name 1 refers to an old file containing variable-length records, all data items identified by the key data name must be contained in the first X characters of the record, where X is equal to the minimum record length specified by the file referenced by file name 1. (5) File name 2, file name 3, and file name 4 must be described in the file description clause of the data section and not in the sort merge description clause. (6) At most one file name in a multi-file tape can appear in a MERGE statement. (7) The same file name cannot appear repeatedly in an MFRGE statement. (8) In a MERGE statement, no pair of file names can be specified in the same SAMEAREA, SAMESORTAREA, or SAME SORT-MERGE AREA clause. In a MERGE statement, two file names can be specified in the same SAMERECORD clause. The AREA subclause contains only those documents that are associated with the GIVING phrase (see 2.13 SAME clause and 2.5 SAMERECORD/SORT/SORT-MERGEAREA subclause in GB/T 4092.4). : (9) The words THRU and THROUGH are equivalent. (10) If document name 4 refers to an index document, the first description of data name 1 must be associated with the ASCENDING phrase, and the data item referenced by data name 1 must occupy the same character position in the record as the data item associated with the primary record key of that document. (II) If the GIVING phrase is specified and the document referenced by document name 4 contains variable-length records, the length of the record contained in the document referenced by document name 1 cannot be less than the minimum record described by document name 4, nor greater than the length of its maximum record. If the document referenced by document name 4 contains fixed-length records, the length of the record contained in the document referenced by document name 1 cannot be greater than the maximum record length described by document name 4. 4.1.4 General Rules
(1) The MERGE statement will merge all records contained in the files referenced by filename2 and filename3. (2) If the file referenced by filename1 contains only fixed-length records, then any record in the file referenced by filename2 or filename3 that is less than that fixed-length record will be filled with spaces after the last character of that record, starting from the first character position, when the record is sent to the file referenced by filename1. The number of spaces is the number of character positions less than the fixed-length. (3) The data names following the word KEY are arranged from left to right in the MERGE statement in descending order of importance, regardless of how they are divided into the KEY phrases. The leftmost data name is the primary key, the next data name is the next most important key, and so on.
When the ASCEVDING phrase is specified, the merge order is the order of the data items indicated by the key data names from the lowest value to the highest value, according to the rules for comparing the operands in the relational condition. b. When the DESCENDING phrase is specified, the merge order is the order of the contents of the data items indicated by the key data names from the highest value to the lowest value, according to the comparison rules of the operands in the relational condition. (4) According to the comparison rules of the operands in the relational condition, when the contents of all key data items of a data record are equal to the contents of the corresponding key data items of one or more other data records, the order in which these records are returned is: a. In the order of the related input files specified in the MERGE statement. b. All records related to one input file are sent before the records of another input file are returned. (5) The collation sequence used for comparison of non-numeric key data items is determined at the beginning of the MERGE statement execution in the following priority order: First, if the COLLATINGSEQUENCE phrase is specified in the MERGE statement, the collation sequence is established according to the CL.LATINGSEQUENCE phrase.
b. Second, the collation sequence is established that is the same as the program's collation sequence. GB/T 4092.7—92
(6) The result of the merge operation is predictable only if the records of the files referenced by filename2 and filename3 are ordered as specified by the ASCENDING or T)ESCENDINGKEY phrases in the MERGE statement. (7) All records in the files referenced by filename2 and filename3 are transferred to the file referenced by filename1. The files referenced by filename2 and filename3 must not be open at the start of the MERGE statement. For each file referenced by filename2 and filename3, the execution of the MERGE statement causes the following actions: a. Initialize file processing. Perform the initialization as if an OPEN statement with the INPIIT phrase had been executed. If an output procedure is specified, this initialization is performed before control is transferred to the output procedure. b. Logical records are retrieved and issued to the merge operation. Retrieve each record as if a READ statement with the NEXT and ATEND phrases had been executed.
Terminate file processing. Execution terminates as if a CLOSE statement without the optional phrase had been executed. If an output procedure is specified, C
then this termination is not executed until control passes through the last statement of the output procedure. These implicit functions are executed as if the associated USEAFTEREXCEPTION or ERROR procedure were executed. (8) An output procedure may consist of procedures necessary to select, modify, or copy records from the file referenced by filename1. RETURN statements make available one record at a time in the merge order. This includes: all statements within the scope of the output procedure that cause a transfer of control by the execution of CALL, EXIT, GOTO, and PERFORM statements; and all statements in a statement procedure that are caused to execute by the execution of statements within the scope of the output procedure. The scope of an output procedure cannot cause any MERGERELEASE or SORT statements to be executed. (9) If an output procedure is specified, it is transferred to during the execution of a MERGE statement. The compiler inserts a return mechanism at the end of the last statement of an output procedure. When control reaches the last statement in the output procedure, the return mechanism terminates the merge processing and transfers control to the next executable statement after the MERGE statement. Before entering the output procedure, the merge procedure reaches a point where the required records can be selected in the merge order. The RETURN statement is required to obtain the next record in the output procedure. (10) During the execution of the output procedure, statements that manage the files referenced by filename2 or filename3 or access their associated record areas cannot be executed. During the execution of any USEAFTEREXCEPTION procedure implicitly referenced during the execution of the MERGE statement, statements that manage the files referenced by filename2, filename3, or filename4 or access their associated record areas cannot be executed. (11) If the GIVING phrase is specified, all merged records are written to the file referenced by filename4, as in the output procedure implied by the MERGE statement. At the beginning of the execution of the MERGE statement, the file referenced by filename4 cannot be in the open state. For each file referenced by filename4, execution of the MERGE statement results in the following actions: a. File processing is initialized. Initialization is performed as if a WRITE statement with an OUTPUT phrase were executed. b. The merged logical records are returned and written to the file. Each record is written as if a WRITE statement without any optional phrases were executed.
For the relative file, the value of the relative key data item for the first record returned is "1"; the value of the second record returned is 2", and so on. After the MERGE statement is executed, the content of the relative link data item indicates the last record returned to the file.
Terminates file processing. Termination is performed as if a CIOSE statement without an optional phrase were executed. These implicit functions are executed as if the corresponding USEAFTEREXCEPTION or ERROR procedure were executed; however, execution of such a CIOSE procedure cannot cause the execution of statements that manage the file referenced by filename4 or access the record area associated with it. Before the first attempt to access the boundary of the file definition When a record is written out, any USEAFTERSTANDARDEXCEPTIN or ERROR procedure specified for the file is executed. When control returns from that USE procedure or if no such USE procedure is specified, the processing of the file is terminated as in paragraph 11C above.
(12) If the file referenced by file name 4 contains only fixed-length records, then for any record in the file referenced by file name 1 that is less than that fixed-length, when the record is returned to the file referenced by file name 4, after the last character of that record, the first character position on the right is filled with spaces, and the number of spaces is the number of character positions less than the fixed length. (13) Program segmentation can be applied to programs containing MERGE statements, however, the following restrictions apply: a. If the MERGE statement does not appear in an independent program segment, then any output procedures referenced by the MERGE statement must: GB/T 4092.7—92
1) All appear in a non-independent program segment, or 2) All be contained in an independent program segment. b. If the MERGE statement appears in an independent program segment, then any output procedures referenced by the MERGE statement must be: 1) entirely contained in dependent program segments, or 2) entirely contained in the same independent program segment as the MERGE statement. 4.2 RELEASE Statement
4.2.1 Function
The RELEASE statement transfers records to the initial stage of a SORT operation. 4.2.2 General Format
RELEASE recordname1 [FROM identifier1] 4.2.3 Syntax Rules
(1) Recordname1 must be a logical record name in the sort-merge file description and may be restricted. (2) The RELEASE statement can only be used within the scope of an input procedure associated with a SORT statement for a file whose sort-merge file description contains recordname1. (3) Recordname1 and identifier1 cannot reference the same storage area. 4.2.4-General Rules
(1) The execution of the RELEASE statement causes the record referred to by recordname1 to be released to the initial stage of the sort operation. (2) After the execution of the RELEASE statement, the logical records in the data area associated with recordname1 are no longer available, unless the sort merge file associated with recordname1 is specified in the SAMERECORD AREA clause. Records in other files associated with the output file referenced in the same SAMERECORD AREA clause, as well as the file associated with recordname1, remain available to the program. (3) The result of executing the RELEASE statement with the FROM phrase is equivalent to the result of executing the following statements in the specified order: a. Executed according to the rules specified for the MOVE statement: MOVE identifier1TO recordname1
b. The same RELEASE statement without the FROM phrase. (4) After the execution of the RELEASE statement, the contents of the data area associated with identifier1 are available. The information in the data area referenced by recordname1 is no longer available, except as specified by the SAMERECORD AREA clause. 4.3 RETURN Statement
4.3-1 Function
The RETURN statement retrieves the sorted records from the final stage of a SORT operation or retrieves the merged records during a MERGE operation.
General format
RETURN file name 1 RECORD [INTO identifier 1]ATEND command statement 1
[NCT AT END command statement 2._
TEND-RETURNJ
4.3.3 Syntax Rules
(1) The storage area associated with identifier 1 and the record area associated with file name 1 cannot be the same storage area. (2) File name 1 must be described in the sort merge file description clause of the data section. (3) The RETLRN statement can only be used for file name 1 within the scope of the output procedure associated with a SORT or MERGE statement. 4.3.4 General Rules
(1) When the logical records of a file are described by more than one record statement, these records automatically share the same storage area, which is equivalent to implicit area redefinition. The content of any data item that falls outside the range of the current data record is undefined after the execution of the RETURN statement.
GB/T 4092.7—92
(2) The execution of the RETURN statement makes the next existing record of file name 1 available in the record area associated with file name 1. This next record is determined according to the order indicated by the keys listed in the SORT or MERGE statement. If there is no next logical record for file name 1, the terminal condition occurs and control is transferred to command statement 1 of the ATEND phrase. Execution continues according to the rules for the statements indicated in command statement 1. If a procedure branch or conditional statement that explicitly causes a transfer of control is executed, the control transfer is negated according to the rules of that statement. After command statement 1 is executed, control is transferred to the end of the RETURN statement, ignoring the NOTATEND phrase (if specified). When the terminal condition occurs, execution of the RETURV statement is unsuccessful and the contents of the record area associated with file name 1 are undefined. After command statement 1 in the ATEMD phrase is executed, the RETURV statement can no longer be executed as part of the current output procedure.
(3) If during the execution of the RETURV statement, the terminal condition occurs, the record is available and the implicit MOVE operation is executed according to the presence of the [NTO phrase, and control is transferred to command statement 2 (noted): Otherwise. Control is transferred to the end of the RETURN statement
(4) The END-RETURN phrase defines the scope of the RETURN statement (see preparatory identification 6.6.4.3 Statement scope). (5) The INTO phrase may be specified in RETURN statements: a) only when a record description belongs to a sort-merge file description clause, or b) when all record names associated with file name 1 and the data items referenced by identifier 1 describe group or primary identifier items. (6) The result of executing a RETURN statement with a VTO phrase is equivalent to the following in sequence: b) executing the same RETURN statement without the INTO phrase. b) moving the current record from the record area to the area designated by identifier 1 according to the rules of a MOVE statement without the CORRESPONDING phrase. b) determining the length of the current record according to the rules specified by the RECORD clause. If the file description clause contains a RECORDISVARYING clause, the implicit move is a group move. When the RETURN statement fails to execute, no implicit MOVE statement appears. b) any subscripts associated with identifier 1 are calculated after the record is read and before being transferred to the data items. b) data in the record area and the data items referenced by identifier 1 are available. 4.4 SORT Statement
4.4.1 Function
The SORT statement sorts the records in a sorted file according to a specified set of keys by executing an input process or passing the records of another file to create a sorted file. Then, at the end of the sort operation, each record in the sorted file is made available in sorted order to some output process or output file. 4.4.2 General FormatbzxZ.net
SORT file name 1 {ON
JASCENDING
DESCENDING
KEY data name 1.
[WITH DUPLICATES IN ORDFR ]
[COLLATING SEQUENCE IS NULL ]
[COLLATING SEQUENCE IS NULL ]
[COLLATING SEQUENCE IS NULL ] Table name T(THROUGH
INPUTPROCEDUREISProcedure name 1
LITHRU
USING"Document name 2]
OUTPUTPROCEDUREISProcedure name 3
IGIVINGiDocument name 3]
4.4.3 Syntax rules:
Procedure name 2
THROUGH;
(1) The SORT statement can appear anywhere in the procedure part except the declaration part. (2) Document name 1 must be described in the sort and merge document description section of the data part. Procedure name 4
(3) If the IJSING phrase is specified and the document referenced by document name 1 contains variable-length records, the length of the records contained in the document referenced by document name 2 cannot be less than the minimum record described by document name 1, nor can it exceed the maximum record length. If the document referenced by document name 1 is GR/T 4092 7-92
Contains fixed-length records, then the length of the record contained in the document referenced by document name 2 cannot be greater than the maximum record length of the document description referenced by document name 1.
(4) Data item 1 is key data and must comply with the following rules: The data item identified by the key data name must be described in the record of the associated document name 1. a.
Key names can be restricted.
C. The data item identified by the key data name cannot be a group item containing variable-length data items. d. If document name 1 has multiple record descriptions, the data items identified by the key data name can only be described in Described in only one record description. In the individual record descriptions, the same character position referenced by the link data name is used as the key for all records of the file. e: The data item identified by the key data name cannot be described in a description that contains an OCCURS clause, or in a description that is subordinate to an OCCURS clause.
f. If the file referenced by file name 1 contains fixed-length records, then all data items identified by the key data name must be contained in the first X character positions of the record, where X is equal to the minimum record length specified by the file referenced by file name 1. (5) THRU character and THROUGII are equivalent. (6) File name 2 and file name 3 must be described in the file description clause of the data part, not in the sort-merge file description clause. (7) The files referenced by file name 2 and file name 3 can reside on the same multi-file volume. (8) If file name 3 references an index file, the first description of file name 1 must be associated with the ASCENDING phrase, and the character position occupied by the data item referenced by data name 1 in the record must be the same as the data item associated with the primary record key of that file. (9) In the same SORT statement, no pair of file names can be specified in the same SAMESORT-MERGEAREA or SAMESORT-MERGEAREA clause. File names associated with a GIVING phrase cannot be specified in the same SAME clause (see GB/T 4092.4 2.13 SAME- and 2.5 SAME RECORD/SORT/SORT-MERGE AREA clause). (10) If the GIVINC phrase is specified: and the file referenced by filename 3 contains variable-length records, the length of the record contained in the file referenced by filename 1 cannot be less than the length of the smallest record described by filename 3, nor greater than the length of its largest record. Or if the file referenced by filename 3 contains fixed-length records, the length of the record contained in the file referenced by filename 1 cannot be greater than the length of the largest record in the file referenced by filename 3. 4.4.4 General Rules
(1) If the file referenced by filename 1 contains only fixed-length records, then for any record in the file referenced by filename 2 that is less than that fixed-length record, when the record is sent to the file referenced by filename 1, the first character position after the last character of that record is filled with cells equal to the number of character positions less than the length. (2) In a SORT statement! The data names following the word KEY are listed from left to right in decreasing order of importance, regardless of how they are divided into the KFY phrases. The leftmost data name is the primary link, the next data name is the next most important key, and so on.
a. When the ASC:FVI>ING phrase is specified, the sorting order will be from the lowest value to the highest value of the contents of the data items specified by the link data names. This is done according to the operand comparison rules in the relational condition. h. When the PFSCENDING phrase is specified, the sorting order will be from the highest value to the lowest value of the contents of the data items specified by the key data names. This is done according to the operand comparison rules in the relational condition. (3) If the DIJP1.ICATES phrase is specified, and the contents of all key data items associated with a data record are equal to the contents of the corresponding data items associated with one or more other data records, the order in which the records are returned is:. According to the order of the related input files specified in the SCRRT statement. In a given input file, according to the desire to access the records in that file.
. (4) If the IJUIFI.IC'ATES phrase is not specified, and the contents of all key data items associated with a data record are equal to the contents of the corresponding key data items associated with one or more other data records, the order in which these requests are returned is undefined. (5) The collation sequence for comparisons of non-numeric key items is determined at the beginning of the execution of a SORT statement in the following order of precedence: First, if the COLLATINGSEQUENCE phrase is specified in the SORT statement, the collation sequence established by the COLLATINGSE-QUENCE phrase is used.
GB/T 4092.7-92
b, and second, the collation sequence established is the same as the program's collation sequence. (6) The execution of a SORT statement consists of the following three distinct phases: a. Make the file referenced by record pair volume name 1 available. To achieve this, the file referenced by filename2 must not be in open mode at the start of this phase, either by executing a RELEASE statement in the input procedure or by implicitly executing a READ statement for filename2. At the end of this phase, the file referenced by filename2 is not in open mode. b. The file referenced by filename1 is sequential. During this phase, the files referenced by filename2 and filename3 are not processed. c. The records of the file referenced by filename1 are available in sorted order. The sorted records are either written to the file referenced by filename3 or made available for processing by the output procedure by executing a RETURN statement. At the start of this phase, the file referenced by filename3 must not be in open mode. At the end of this phase, the file referenced by filename3 is not in open mode. (7) The input procedure may consist of procedures necessary to select, modify, or copy records from the file referenced by filename1, making such records available one at a time. The scope includes: all statements within the scope of the input procedure that cause control transfer by executing CALL, EXITGOTO, and PERFORM statements; and all statements in the declaration procedure that are caused by the execution of statements in the scope of the input procedure. The scope of the input procedure cannot cause any MERGE, RETURN, or SURT statements to be executed. (8) If the input procedure is specified, control is transferred to the input procedure before file name 1 is sequenced by the SRT statement. The compiler inserts a return mechanism at the end of the last statement in the input procedure. When control reaches the last statement in the input procedure, the records released to file name 1 have been sequenced.
(9) If the USING phrase is specified, all records of the files referenced by file name 2 are sent to the files referenced by file name 1. For each file referenced by filename2, execution of the SORT statement results in the following actions: File processing is initialized. Initialization is performed just like an OPEN statement with the INPUT phrase. Logical records are retrieved and sent to the sort operation. Each record is retrieved just like a READ statement with the NEXT and ATEND phrases.
For relative files, if filename2 is referenced in the GIVING clause, the contents of the relative key data items after the SORT statement is executed are undefined.
Terminate file processing. Termination is performed just like a CLOSE statement without the optional phrases. This termination is executed before the used file is sorted by the SORT statement. These implicit functions are executed as if the associated USEAFTEREXCEPTION or ERROR procedure were executed. However, execution of this UJSE procedure does not cause execution of statements that manage the file referenced by filename2 or access the record area associated with it. (10) The output process can consist of procedures that are necessary to select, modify, or copy records from the file referenced by filename1. The RLTURN statement makes one record available at a time. The scope includes, within the output process diagram, the execution of CAII., FXIT, GOTO, and PERF All statements that cause control transfer to the OM statement and all statements in the declaration procedure whose execution is caused by the execution of statements in the scope of the output procedure. The scope of the output procedure cannot cause the execution of any MERGE, REILEASE, or SORT statements. (11) If an output procedure is specified, the file referenced by file name 1 is sorted by the SORT statement and control is transferred to it. The compiler inserts a return mechanism at the end of the last statement of the output procedure. When control is transferred to the last statement of the output procedure, the return mechanism ends the sorting and then transfers control to the next executable statement after the SORT statement. Before entering the output procedure, the sorting process The process reaches a point at which the required records can be selected in sorted order. A RETURN statement is necessary to obtain the next record in the output process.
(12) If the IVING phrase is specified, all sorted records in filename 1 are automatically written to filename 3, just as the output process implied by the SORT statement. For each file referenced by filename 3, the execution of the SCRT statement results in the following actions: 1. File processing is initialized. The initialization is performed as if an OPEN statement with the OUTPUT phrase had been executed. This initialization is performed after any input process has been executed.
GB/T 4092.7—92
h, the sorted logical records are returned and written to the file. The records are written as if a WRITE statement without any optional phrases had been executed. For the relative file, the value of the relative key data item for the first record returned is "1"; the value of the second record returned is "2", and so on. After the SORT statement is executed, the contents of the relative key data item indicate the last record returned to the file. c. Terminate file processing. Execution terminates as if a CLOSE statement without an optional phrase had been executed. The implicit functions are performed as if the associated USEAFIEREXCEPTION or ERROR procedure had been executed, however - execution of such a USE procedure shall not cause execution of statements that manage the file referenced by file name 3 or access its associated record area. At the first attempt to write a record outside the boundaries of the file definition, any USE AFTER STANDARD EXCEPTION or ERROR procedure specified for the file is executed. When control returns from the USE procedure or if no such USE procedure is indicated, file processing is terminated as in paragraph 12C above.
(13) If the file referenced by file name 3 contains only fixed-length records,Then for any record in the file referenced by file name 1 that is less than that length, when the record is sent back to the file referenced by file name 3, after the last character of that record, the first character position on the right is filled with spaces, and the number of spaces is the number of character positions that are less than the fixed length. (I4) Program segmentation can be applied to programs containing SORT statements. However, there are the following restrictions: a. If the SORT statement appears in a section of a non-independent program segment. Then any input procedure or output procedure referenced by the SORT statement must:
1) All appear in the non-independent program segment , or 2) all contained in a separate program segment. b.
If the SORT statement appears in an independent program segment, then any input procedure or output procedure referenced by the SORT statement must:
1) be completely contained in a non-independent program segment, or 2) be completely contained in the same independent program segment as the SORT statement. Additional Notes:
This standard was proposed by the Ministry of Machinery and Electronics Industry of the People's Republic of China. This standard was drafted by the professor of Nanjing University.
The main drafters of this standard are Qian Shuren, Wang Jingying, Feng Hui, and Duan Xiang. This standard was issued in December 1983 and revised for the first time in August 1992.
Tip: This standard content only shows part of the intercepted content of the complete standard. If you need the complete standard, please go to the top to download the complete standard document for free.