%STATUS (ファイルまたはプログラム状況の戻し)
%STATUS{(file_name)}
%STATUS は、プログラムまたはファイル状況に関して設定された最新の値を戻します。%STATUS は、プログラム状況またはいずれかのファイルの状況が変更された 場合 (通常はエラーが発生した場合) に設定されます。
任意指定のファイル名パラメーターを指定しないで %STATUS を使用した場合、この 関数は、最後に変更されたプログラムまたはファイルの状況を戻します。 ファイルを 指定した場合、指定したファイルに関する INFDS *STATUS フィールド に入っている値が戻されます。 このファイルに関して INFDS を指定する 必要はありません。
%STATUS は戻り値 00000 で開始し、'E' 拡張の指定がある命令が開始される 前に 00000 にリセットされます。
%STATUS の検査に最適な時期は、'E' 拡張またはエラー標識が指定されている命令の 直後あるいは INFSR また は *PSSR サブルーチンの先頭です。
詳細については、ファイル命令、結果命令、 または 組み込み関数を参照してください。
%STATUS を設定する命令を以下に示します。
- ACQ (獲得)
- ADDDUR (期間の加算)
- ALLOC (記憶域の割り振り)
- CALL (プログラムの呼び出し)
- CALLB (バインド・プロシージャーの呼び出し)
- CALLP (プロトタイプ・プロシージャーまたはプログラムの呼び出し)
- CHAIN (ファイルからのランダム検索)
- CHECK (文字の検査)
- CHECKR (逆向きの検査)
- CLOSE (ファイルのクローズ)
- COMMIT (コミット)
- DEALLOC (記憶域の解放)
- DELETE (レコードの削除)
- DSPLY (メッセージ表示)
- EXFMT (形式の書き出し、その後読み取り)
- EXTRCT (日付/時刻/タイム・スタンプの抽出)
- FEOD (データの強制終了)
- IN (データ域の検索)
- NEXT (次の入力の取り出し)
- OCCUR (データ構造のオカレンスの設定/取り出し)
- OPEN (処理のためのファイルのオープン)
- OUT (データ域の書き出し)
- POST (転記)
- READ (レコードの読み取り)
- READC (次の変更レコードの読み取り)
- READE (等しいキーのレコードの読み取り)
- READP (前のレコードの読み取り)
- READPE (等しいキーの前のレコードの読み取り)
- REALLOC (新しい長さでの記憶域の再割り振り)
- REL (解放)
- RESET (リセット)
- ROLBK (ロールバック)
- SCAN (ストリングの走査)
- SETGT (より大きい設定)
- SETLL (下限の設定)
- SUBDUR (期間減算)
- SUBST (サブストリング)
- TEST (日付/時刻/タイム・スタンプのテスト)
- UNLOCK (データ域のアンロックまたはレコードの解放)
- UPDATE (既存のレコードの変更)
- WRITE (新しいレコードの作成)
- XLATE (変換)
図 1. 'E' 拡張を使用する場合の %STATUS と %ERROR
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
* The 'E' extender indicates that if an error occurs, the error
* is to be handled as though an error indicator were coded.
* The success of the operation can then be checked using the
* %ERROR built-in function. The status associated with the error
* can be checked using the %STATUS built-in function.
/FREE
exfmt(e) InFile;
if %error;
exsr CheckError;
endif;
//-------------------------------------------------------------------
// CheckError: Subroutine to process a file I/O error
//-------------------------------------------------------------------
begsr CheckError;
select;
when %status < 01000;
// No error occurred
when %status = 01211;
// Attempted to read a file that was not open
exsr InternalError;
when %status = 01331;
// The wait time was exceeded for a READ operation
exsr TimeOut;
when %status = 01261;
// Operation to unacquired device
exsr DeviceError;
when %status = 01251;
// Permanent I/O error
exsr PermError;
other;
// Some other error occurred
exsr FileError;
endsl;
endsr;
/END-FREE
図 2. 'E' 拡張、エラー標識および *PSSR を使用する場合
の %STATUS と %ERROR
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++++++++
D Zero S 5P 0 INZ(0)
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....
* %STATUS starts with a value of 0
*
* The following SCAN operation will cause a branch to the *PSSR
* because the start position has a value of 0.
C 'A' SCAN 'ABC':Zero Pos
C BAD_SCAN TAG
* The following EXFMT operation has an 'E' extender, so %STATUS will
* be set to 0 before the operation begins. Therefore, it is
* valid to check %STATUS after the operation.
* Since the 'E' extender was coded, %ERROR can also be used to
* check if an error occurred.
C EXFMT(E) REC1
C IF %ERROR
C SELECT
C WHEN %STATUS = 01255
C ...
C WHEN %STATUS = 01299
C ...
* The following scan operation has an error indicator. %STATUS will
* not be set to 0 before the operation begins, but %STATUS can be
* reasonably checked if the error indicator is on.
C 'A' SCAN 'ABC':Zero Pos 10
C IF *IN10 AND %STATUS = 00100
C ...
* The following scan operation does not produce an error.
* Since there is no 'E' extender %STATUS will not be set to 0,
* so it would return a value of 00100 from the previous error.
* Therefore, it is unwise to use %STATUS after an operation that
* does not have an error indicator or the 'E' extender coded since
* you cannot be sure that the value pertains to the previous
* operation.
C 'A' SCAN 'ABC' Pos
C ...
C *PSSR BEGSR
* %STATUS can be used in the *PSSR since an error must have occurred.
C IF %STATUS = 00100
C GOTO BAD_SCAN
C ...