Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting with using/giving

Status
Not open for further replies.
May 3, 2002
6
US
Wondering if someone could help me with my program. What am I doing wrong? Is something wrong with my sort? Can't seem to get it to run and produce output.

IDENTIFICATION DIVISION.
PROGRAM-ID. PROG3.
AUTHOR. PRESTON AMUA-SEKYI.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALES-FILE ASSIGN TO 'A:\ASSIGN3A.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORT-FILE ASSIGN TO 'A:\SORTWORK.DAT'.
SELECT SORTED-FILE ASSIGN TO 'A:\SALES.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
*
DATA DIVISION.
FILE SECTION.
FD SALES-FILE.
01 SALES-RECORD-IN.
05 SR-ACCOUNT-NUMBER PIC 9(6).
05 PIC X.
05 SR-NAME-IN PIC X(15).
05 SR-SALES PIC S9(4).
05 PIC XX.
05 SR-COMMISSION-PERCENT PIC V99.
05 PIC XX.
05 SR-LOCATION-IN PIC X(15).
05 SR-REGION-IN PIC X(11).
SD SORT-FILE.
01 SORT-REC.
05 SR-NAME-OUT PIC X(15).
05 SR-LOCATION-OUT PIC X(15).
05 SR-REGION-OUT PIC X(11).
FD SORTED-FILE.
01 SORTED-REC PIC X(41).
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
PROCEDURE DIVISION.
100-MAIN-MODULE.
SORT SORT-FILE
ON ASCENDING KEY SR-REGION-OUT
WITH DUPLICATES IN ORDER
USING SALES-FILE
GIVING SORTED-FILE
OPEN INPUT SORTED-FILE
OUTPUT SALES-FILE
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO'
READ SORTED-FILE
AT END
MOVE 'NO' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 200-PROCESS-RTN
END-READ
END-PERFORM
CLOSE SALES-FILE
SORTED-FILE.
STOP RUN.
200-PROCESS-RTN.
MOVE SR-REGION-IN TO SR-REGION-OUT
MOVE SR-LOCATION-OUT TO SR-LOCATION-OUT
MOVE SR-NAME-IN TO SR-NAME-OUT
RELEASE SORT-REC.


 
The error message I receive is "attempt to execute more than 1 sort or merge simuletanously."
 
Hi RB,

I think you misunderstand the way sort w/using-giving works. The stmt after the Sort stmt is executed after the using file has been sorted and the giving file data has been created. If that's all you're trying to do, you don't need further code; you've got your sorted op in SALES.DAT.

Jack
 
The following is a generalized view. Things can be much more complex etc.

With the sort verb you can use either USING or an INPUT PROCEDURE to supply records to be sorted. If you use USING, you don't OPEN the input file or READ any records. All that is handled by the SORT verb. If you use INPUT PROCEDURE, you generally open your input file, read through the file, select any records you want, build the record to be sorted and RELEASE it to the SORT.

Similarly, wiht GIVING and OUTPUT PROCEDURE. With GIVING, you don't OPEN the output file or WRITE the records. With OUTPUT PROCEDURE, you OPEN the output file, RETURN the records from the SORT and WRITE the output records.

A typical use of INPUT/OUTPUT PROCEDURES would be to read a master file, selecting some records and only some fields in the record which you then sort and write to a nicely formatted report. If you want to report on every record in the input file and are comfortable sorting the entire input record, you might use a USING along with an OUTPUT PROCEDURE. Rarely, in my experience, do you see a USING/GIVING used together because those situations in most shops are handled by a standalone SORT utility rather than COBOL program.

Glenn Mitchell
Brainbench MVP for COBOL II
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top