The INPUT PROCEDURE clause acts like a PERFORM, indicating
the logic to go to a different paragraph (i.e. procedure).
So the paragraph SELECT-PROD-CODE might be like this:
SELECT-PROD-CODE.
OPEN INPUT UNSORTED-DATA-FILE
PERFORM UNTIL END-OF-FILE
READ UNSORTED-DATA-FILE
AT END MOVE 'Y' TO EOF-FLAG
NOT AT END
IF 1ST-DIGIT-OF-CODE = 1 THEN
MOVE UNSORTED-RECORD TO WORK-REC
RELEASE WORK-REC
END-IF
END-READ
END-PERFORM
CLOSE UNSORTED-DATA-FILE
When the if condition is true, the record is moved to the
work-file (WORK-REC is the level 01 name) by the RELEASE verb, even though the
MOVE verb appears first (I dunno why..!). Unlike a simple SORT, you DO have to
OPEN the unsorted file prior to an input procedure.
OUTPUT PROCEDURE
If you just want to print specific sorted fields you would
use an OUTPUT PROCEDURE. Based on the above example:
PROCEDURE DIVISION.
PRINT-SORT-REC.
SORT WORK-FILE
ON DESCENDING KEY PRODUCT-NO
USING UNSORTED-RECORD
OUTPUT PROCEDURE PRINT-SELECT-PROD-CODE
STOP RUN.
The INPUT PROCEDURE clause acts like a PERFORM, indicating
the logic to go to a different paragraph (i.e. procedure).
So the paragraph SELECT-PROD-CODE might be like this:
SELECT-PROD-CODE.
OPEN OUTPUT PRINT-FILE
PERFORM UNTIL END-OF-FILE
RETURN UNSORTED-DATA-FILE
AT END MOVE 'Y' TO EOF-FLAG
NOT AT END
{move fields in SD sort group to print fields}...
WRITE PRINT-RECORD FROM {print group}
END-RETURN
END-PERFORM
CLOSE PRINT-FILE.
Instead of READ you use RETURN and then WRITE the record to the printer rather than RELEASE the record to a file.
You can combine INPUT and OUTPUT procedures into the same
sort statement by replacing both the USING and GIVING statements: