次のコード例は、標準のファイル状態を拡張ファイル状態として使用できるように再定義する方法を示します。この例では、入力ファイルが存在しないことが想定されています。 OPEN INPUT 文を実行すると、9/013 ("ファイルが見つかりません") というファイル状態が返されます。
select in-file assign to "user.dat". file status is file-status. ... working-storage section. 01 file-status. 05 status-key-1 pic x. 05 status-key-2 pic x. 05 status-key-2-binary redefines status-key-2 pic 99 comp-x. ... procedure division. open input in-file if file-status not = "00" if status-key-1 = "9" if status-key-2-binary = 13 display "File not found" ...
拡張ファイル状態コードを表示する場合は、最大値 255 を格納できるだけの表示フィールドにファイル状態データ項目の 2 番目のバイトを移動する必要があります。
select in-file assign to "user.dat" file status is file-status. ... working-storage section. 01 ans74-file-status. 05 status-key-1 pic x. 05 status-key-2 pic x. 05 status-key-2-binary redefines status-key-2 pic 99 comp-x. 01 display-ext-status 05 filler pic xx value "9/" 05 display-key 2 pic 999 ... procedure division. open input in-file if file-status not = "00" display "Error. File status =" with no advancing if status-key-1 = "9" move status-key-2-binary to display-key-2 display display-ext-status else display file-status end-if ...