identification division.

       program-id.  sort-program.

      ***************************************************

*  This program takes an input file called lab3.dat and sorts it.

*  lab3sortwork.dat is the file used by the system to store temporary information for when sorting takes place. Notice that this is the file with the SD declaration.

*  lab3sorted.dat is the file where the sorted information is stored

*  Thus, lab3.dat remains in its original format with lab3sorted.dat being the result file i.e. the sorted file

      *************************************************** 

       environment division.

       configuration section.

       input-output section.

           select input-file assign to 'lab3.dat'

               organization is line sequential.

           select input-sortwork-file assign to 'lab3sortwork.dat'.

           select sorted-file assign to 'lab3sorted.dat'

               organization is line sequential.

              

       data division.

      

       file section.

 

      * lab3.dat

       fd  input-file.

       01  input-rec                   pic x(10).

      

      * lab3sortwork.dat

       sd  input-sortwork-file.

       01  input-sortwork-rec.

           05  sort-store-num          pic 9.

           05  filler                  pic x.

           05  sort-charge-code        pic x.

           05  filler                  pic x.

           05  sort-charge-amount      pic S9(4)v99.

 

      * lab3sorted.dat

       fd  sorted-file.

       01  sorted-rec                  pic x(10).

   

       procedure division.

 

* This particular file has 3 different fields that the data is being sorted by.  We could have * used two keys using hospital number and patient number as two different keys instead of  * combining them into one key field. Notice the SD is on the sort line, the input file is on   * the using line and the result file is on the giving line.

 

           sort input-sortwork-file

               ascending key sort-store-num

               ascending key sort-charge-code

               descending key sort-charge-amount

               using input-file

               giving sorted-file.

           stop run.