IBM - VisualAge Cobol for Windows Programming Guide
634 pág.

IBM - VisualAge Cobol for Windows Programming Guide


DisciplinaCobol25 materiais168 seguidores
Pré-visualização50 páginas
You cannot perform any input or output operations on this file.
RELATED REFERENCES
\u201cFILE SECTION entries\u201d on page 12
Describing the input to sorting or merging
Describe the input file or files for sorting or merging by following this procedure:
1. Write one or more SELECT statements in the FILE-CONTROL paragraph of the
ENVIRONMENT DIVISION to name the input files. For example:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT Input-File ASSIGN TO InFile.
116 Programming Guide
Input-File is the name of the file in your program. Use this name to refer to
the file.
2. Describe the input file (or files when merging) in an FD entry in the FILE
SECTION of the DATA DIVISION. For example:
DATA DIVISION.
FILE SECTION.
FD Input-File
RECORD CONTAINS 100 CHARACTERS.
01 Input-Record PIC X(100).
RELATED TASKS
\u201cCoding the input procedure\u201d on page 118
\u201cRequesting the sort or merge\u201d on page 120
RELATED REFERENCES
\u201cFILE SECTION entries\u201d on page 12
Example: describing sort and input files for SORT
The following example shows the ENVIRONMENT DIVISION and DATA DIVISION entries
needed to describe sort files and an input file.
ID Division.
Program-ID. SmplSort.
Environment Division.
Input-Output Section.
File-Control.
*
* Assign name for a working file is
* treated as documentation.
*
Select Sort-Work-1 Assign To SortFile.
Select Sort-Work-2 Assign To SortFile.
Select Input-File Assign To InFile.
. . .
Data Division.
File Section.
SD Sort-Work-1
Record Contains 100 Characters.
01 Sort-Work-1-Area.
05 Sort-Key-1 Pic X(10).
05 Sort-Key-2 Pic X(10).
05 Filler Pic X(80).
SD Sort-Work-2
Record Contains 30 Characters.
01 Sort-Work-2-Area.
05 Sort-Key Pic X(5).
05 Filler Pic X(25).
FD Input-File
Record Contains 100 Characters.
01 Input-Record Pic X(100).
. . .
Working-Storage Section.
01 EOS-Sw Pic X.
01 Filler.
05 Table-Entry Occurs 100 Times
Indexed By X1 Pic X(30).
. . .
RELATED TASKS
\u201cRequesting the sort or merge\u201d on page 120
Chapter 8. Sorting and merging files 117
Coding the input procedure
If you want to process the records in an input file before they are released to the
sort program, use the INPUT PROCEDURE phrase of the SORT statement. You can use
an input procedure to do the following:
v Release data items to the sort file from WORKING-STORAGE.
v Release records that have already been read in elsewhere in the program.
v Read records from an input file, select or process them, and release them to the
sort file.
Each input procedure must be contained in either paragraphs or sections. For
example, to release records from a table in WORKING-STORAGE to the sort file
SORT-WORK-2, you could code as follows:
SORT SORT-WORK-2
ON ASCENDING KEY SORT-KEY
INPUT PROCEDURE 600-SORT3-INPUT-PROC
. . .
600-SORT3-INPUT-PROC SECTION.
PERFORM WITH TEST AFTER
VARYING X1 FROM 1 BY 1 UNTIL X1 = 100
RELEASE SORT-WORK-2-AREA FROM TABLE-ENTRY (X1)
END-PERFORM.
To transfer records to the sort program, all input procedures must contain at least
one RELEASE or RELEASE FROM statement. To release A from X, for example, you can
code:
MOVE X TO A.
RELEASE A.
Alternatively, you can code:
RELEASE A FROM X.
The following table compares the RELEASE and RELEASE FROM statements.
RELEASE RELEASE FROM
MOVE EXT-RECORD
TO SORT-EXT-RECORD
PERFORM RELEASE-SORT-RECORD
. . .
RELEASE-SORT-RECORD.
RELEASE SORT-RECORD
PERFORM RELEASE-SORT-RECORD
. . .
RELEASE-SORT-RECORD.
RELEASE SORT-RECORD
FROM SORT-EXT-RECORD
RELATED REFERENCES
\u201cRestrictions on input and output procedures\u201d on page 119
RELEASE statement (IBM COBOL Language Reference)
Describing the output from sorting or merging
If the output from sorting or merging is a file, describe the file by following this
procedure:
1. Write a SELECT statement in the FILE-CONTROL paragraph of the ENVIRONMENT
DIVISION to name the output file. For example:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT Output-File ASSIGN TO OutFile.
118 Programming Guide
Output-File is the name of the file in your program. Use this name to refer to
the file.
2. Describe the output file (or files when merging) in an FD entry in the FILE
SECTION of the DATA DIVISION. For example:
DATA DIVISION.
FILE SECTION.
FD Output-File
RECORD CONTAINS 100 CHARACTERS.
01 Output-Record PIC X(100).
RELATED TASKS
\u201cCoding the output procedure\u201d
\u201cRequesting the sort or merge\u201d on page 120
RELATED REFERENCES
\u201cFILE SECTION entries\u201d on page 12
Coding the output procedure
If you want to select, edit, or otherwise change sorted records before writing them
from the sort work file into another file, use the OUTPUT PROCEDURE phrase of the
SORT statement.
Each output procedure must be contained in either a section or a paragraph. An
output procedure must include both of the following elements:
v At least one RETURN or RETURN INTO statement
v Any statements necessary to process the records that are made available, one at
a time, by the RETURN statement
The RETURN statement makes each sorted record available to your output
procedure. (The RETURN statement for a sort file is similar to a READ statement for an
input file.)
You can use the AT END and END-RETURN phrases with the RETURN statement. The
imperative statements on the AT END phrase are performed after all the records
have been returned from the sort file. The END-RETURN explicit scope terminator
delimits the scope of the RETURN statement.
If you use the RETURN INTO statement instead of RETURN, your records will be
returned to WORKING-STORAGE or to an output area.
RELATED REFERENCES
\u201cRestrictions on input and output procedures\u201d
RETURN statement (IBM COBOL Language Reference)
Restrictions on input and output procedures
The following restrictions apply to each input or output procedure called by SORT
and to each output procedure called by MERGE:
v The procedure must not contain any SORT or MERGE statements.
v The procedure must not contain any STOP RUN, EXIT PROGRAM, or GOBACK
statements.
v You can use ALTER, GO TO, and PERFORM statements in the procedure to refer to
procedure names outside the input or output procedure. However, control must
return to the input or output procedure after a GO TO or PERFORM statement.
Chapter 8. Sorting and merging files 119
v The remainder of the PROCEDURE DIVISION must not contain any transfers of
control to points inside the input or output procedure (with the exception of the
return of control from a declarative section).
v In an input or output procedure, you can call a program. However, the called
program cannot issue a SORT or MERGE statement, and the called program must
return to the caller.
v During a SORT or MERGE operation, the SD data item is used. You must not use it
in the output procedure before the first RETURN executes. If you move data into
this record area before the first RETURN statement, the first record to be returned
will be overwritten.
RELATED TASKS
\u201cCoding the input procedure\u201d on page 118
\u201cCoding the output procedure\u201d on page 119
Requesting the sort or merge
To read records directly from an input file (files for MERGE) without any preliminary
processing, use SORT . . . USING or MERGE . . . USING and the name of the input
file (files) that you have declared in a SELECT statement. The compiler generates an
input procedure to open the input file (files), read the records, release the records
to the sort or merge program, and close the input file (files). The input file or files
must not be open when the SORT or MERGE statement begins execution.
To transfer sorted or merged records from the sort or merge program directly to
another file without any further processing, use SORT . . . GIVING or MERGE . . .
GIVING and the name of the output file that you have declared in a SELECT
statement.