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!

Sort using input/output procudure

Status
Not open for further replies.
May 3, 2002
6
US
Appreciat your help on the last prgram. Got it working ok. This is a the second part to this program using I/O proc. I think there's something wrong with the compute statement or the compute routine. I've moved the compute statement before the IF and get a strange error on MF cobol. The way I have it listed here I get a run time error: "Illegal character in numeric field." I don't see where or if I redefined a numeric char to anything else. They all look ok to me. Any help would be appreciated. Thanks
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG3B.
AUTHOR. .
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALES-FILE ASSIGN TO 'A:\ASSIGN3B.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SORT-FILE ASSIGN TO SORTWORK.
SELECT SORTED-FILE ASSIGN TO 'A:\SALESB.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 9(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 COMMISSION-OUT PIC S9(4).
05 SR-REGION-OUT PIC X(11).
05 SR-LOCATION-OUT PIC X(15).
05 SR-NAME-OUT PIC X(15).
FD SORTED-FILE.
01 SORTED-REC PIC X(80).
WORKING-STORAGE SECTION.
01 ARE-THERE-MORE-RECORDS PIC X(3) VALUE 'YES'.
*
PROCEDURE DIVISION.
100-MAIN-MODULE.
SORT SORT-FILE
ON DESCENDING KEY COMMISSION-OUT
INPUT PROCEDURE 200-PROCESS-RTN
OUTPUT PROCEDURE 300-COMMISSION-RTN
STOP RUN.
200-PROCESS-RTN.
OPEN INPUT SALES-FILE
PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO '
READ SALES-FILE
AT END
MOVE 'NO ' TO ARE-THERE-MORE-RECORDS
NOT AT END
PERFORM 300-COMMISSION-RTN
END-READ
END-PERFORM
CLOSE SALES-FILE.
300-COMMISSION-RTN.
OPEN OUTPUT SORTED-FILE
IF COMMISSION-OUT IS > 100
MOVE COMMISSION-OUT TO COMMISSION-OUT
COMPUTE COMMISSION-OUT = SR-SALES * SR-COMMISSION-PERCENT
ELSE
MOVE SR-REGION-IN TO SR-REGION-OUT
MOVE SR-LOCATION-IN TO SR-LOCATION-OUT
MOVE SR-NAME-IN TO SR-NAME-OUT
RELEASE SORT-REC
END-IF.
 
RB,

You are performing your OutputProc in your InputProc! I think you are still a bit confused as to how InputProc and OutputProc work. Somebody gave you a good overview in your previous query... suggest you go back and review it.

SORT with (USING/GIVING) should give you the simplest way of sorting a file in COBOL

SORT with (INPUT PROCEDURE) allows you more flexibility in selecting the records you want sorted

SORT with (OUTPUT PROCEDURE) allows you more flexibility in formatting your output records

Note that you can SORT (INPUT PROCEDURE... GIVING) meaning you choose to have more say on what records to sort BUT you simply want the sort to write out whatever is submitted to it... then

You can SORT (USING... OUTPUT PROCEDURE) meaning you want the sort to take in everything from your file, BUT you want to have more say on how the output file will look like

Digest these concepts first and hopefully your code will follow the 'right path'

Note also in your OutputProcedure you initialize a field with itself... this is probably the source of your message; nevertheless you still need to get things straight on Input Procedure/Output Procedure or Using/Giving

Hope this helps.
 
Hi RB,

The general flow of a SORT w/I-O Procedures:

open in & out files, init etc.

Sort stmt

In Proc.

loop thru - Read a rec, reformat it, drop recs, add recs, etc. Release it to the SORT.

Out Proc.

loop thru - Return a rec from the SORT, reformat it, drop recs, add recs etc. write it to your O/P.

Close files and wrap up.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top