|
7.5 INPUT and OUTPUT PROCEDURE
The SORT statement above sorted all the records in the file into a new file.
But if you wanted to produce a sorted file that only contained, for example,
product numbers which begin with a '1', you would use an INPUT PROCEDURE.
The record FD might be:
The description gives the minimum detail required. Now some procedure division: 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:
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: 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:
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:
| ||||