入出力手続きを使用したファイルの整列

SORT 文を使用して、ファイル内のレコードを整列できる。SORT 手続きは、同時に複数のスレッドから呼び出すことはできない。以下のプログラムは、入力ファイルおよび出力ファイルの名前をコマンド ラインから取得する。レコードの入力、整列、および整列したファイルの出力を行う入出力手続きでは、RELEASE 文および RETURN 文を使用する。

$SET ANS85
 select ifile assign to ipf
     organization is line sequential 
     file status is ipstat.

 select sfile assign to "temp.dat".

 select ofile assign to opf 
     organization is line sequential.

 fd ifile. 
 01 irec     pic x(80).
 fd ofile. 
 01 orec     pic x(80). 
 sd sfile. 
 01 srec     pic x(80).

 working-storage section.
 01 ipstat.
   03 iskey1 pic x. 
   03 iskey2 pic x. 
 01 ipf  pic x(20). 
 01 opf  pic x(20). 
 01 ext  pic x(20). 
 01 clin     pic x(132). 
 01 len  pic 9(2) comp-x. 
 01 a    pic 9(2) comp-x value 0. 
 procedure division. 
     accept clin from command-line 
     unstring clin delimited by space into ipf, opf, ext
     if ext not = space 
         display "too many arguments"
     end-if. 
     sort sfile on ascending srec 
      input procedure sortin 
      output procedure sortout

     stop run.

 sortin section. 
     open input ifile
     read ifile 
     perform until ipstat not = "00"
         move irec to srec 
         release srec 
         read ifile 
     end-perform
     close ifile.
 sortout section.
     return sfile at end go to sortout-exit
     display srec
     go to sortout.
 sortout-exit.
     display "Done".