AS400 – Sorting in COBOL

The ON ASCENDING KEY NAME clouse   has always been used by the COBOL to sort data from one or more data base file. It’s simple and easy to use and runs faster than any of other languages.

For example, we had to do this:

SORT File_Name

ON ASCENDING KEY NAME

If you wanted to be able to sort the data both ways in the same program (i.e., both ascending and descending), you had to do a bit of fooling around. For example :

PROCEDURE DIVISION.
SORT FILE_NAME.
ON ASCENDING KEY FIELD_NAME .
USING FILE_NAME .
GIVING OUTFILE_NAME.
And we can also perform Descending order use simple line. For example:
PROCEDURE DIVISION.
SORT FILE_NAME.
ON DESCENDING KEY FIELD_NAME .
USING WORK_FILE_NAME .
GIVING OUTFILE_NAME.

About the Author

pradeep

pradeep

Related Posts

X