入力ルーチンは、通常、データがソートされる前に、データに対して何らかの 処理を加えるのに使用されます。例えば、データを印刷したり (図 38 および 図 40 を参照)、ソート・フィールドを生成したり、操作したりして、正しい結果を得るのに使用されます。
入力処理ルーチンは、PLISRTB または PLISRTD を呼び出すときに ソート・プログラムが使用します。ソート・プログラムは、レコードを必要とする場合、文字ストリング・フォーマットのレコードを戻す入力ルーチン、および渡されたレコードが ソートに含まれることを意味する戻りコード 12 を呼び出します。ソート・プログラムは、戻りコード 8 が渡されるまでこのルーチン を呼び出し続けます。つまり、すべてのレコードがすでに 渡されており、ソート・プログラムは、ルーチンを再び呼び出さないことを意味します。戻りコードが 8 のときにレコードが戻された場合、そのレコードはソート・プログラムによって無視されます。
E15 ルーチンによって戻されるデータは、固定または可変の文字ストリングでなければなりません。可変の場合、PLISRTx への呼び出し内 の 2 番目の引数である RECORD ステートメント内のレコード・フォーマットとして、通常は、V を指定する必要があります。しかし、F を指定することも可能です。その場合は、ストリングが最大長になるようブランクが埋め込まれます。
レコードは RETURN ステートメントを使って戻されるため、PROCEDURE ステートメント 内で RETURNS 属性を指定しなければなりません。戻りコードは、PLIRETC の呼び出し内で設定されます。入力ルーチンの例は、図 38 および 図 40 に示してあります。
戻りコード 12 (ソートに現行レコードを組み込む) と 戻りコード 8 (すべてのレコードを送付済み) 以外に、ソート・プログラムでは戻りコード 16 を使うこともできます。これは、ソートを終了させ、ソート・プログラムの戻りコード 16 (ソート失敗) を PL/I プログラムに設定します。
PLIRETC を呼び出すと、PL/I プログラムから渡され、その後の任意のジョブ・ステップで使用できる戻りコードが 設定されることに注意してください。出力処理ルーチンを使用した後は、PLISRTx を呼び出してから PLIRETC を呼び出し、戻りコードをリセットして、ゼロ以外の完了コードが出ないようにすることをお勧めします。ソート・プログラムからの戻りコードを引数として 使用して PLIRETC を呼び出せば、PL/I 戻りコードにソートの成功または 失敗を反映させることができます。この方法は、図 39 に示してあります。
E15: proc returns (char(80));
/* Returns attribute must be used specifying
length of data to be sorted, maximum length
if varying strings are passed to sort. */
dcl string char(80); /* A character string variable is normally
required to return the data to sort */
if Last_Record_Sent then do;
/* A test must be made to see if all the
records have been sent, if they have, a
return code of 8 is set up and control
returned to sort */
call pliretc(8); /* Set return code of 8, meaning last record
already sent. */
end;
else do;
/* If another record is to be sent to sort,
do the necessary processing, set a return
code of 12 by calling PLIRETC, and return
the data as a character string to sort */
/* The code to do your processing goes here */
call pliretc (12);/* Set return code of 12, meaning this
record is to be included in the sort */
return (string); /* Return data with RETURN statement */
end;
end; /* End of the input procedure */さらに、入力ユーザー出口ルーチンをコーディングするには、E15 がプログラム単位にネストされていない場合、PLISRTx を呼び出すプログラム単位に E15 の 明示的属性を指定する必要があります。
plisort: proc options(main);
dcl e15 entry returns(char(2000) varying);
/* Code to do your processing goes here */
call plisrtb(' SORT FIELDS=(5,10,CH,A) '
' RECORD TYPE=V,LENGTH=(2000) ',
0,
retcode,
e15);
/* Code to do your processing goes here */
end plisort;
*PROCESS
E15: proc returns (char(2000) varying);
/* Returns option must be used specifying
length of data to be sorted, maximum length
if varying strings are passed to sort. */
dcl string char(2000) varying;
/* A character string variable is normally
required to return the data to sort */
if Last_Record_Sent then do;
/* A test must be made to see if all the
records have been sent, if they have, a
return code of 8 is set up and control
returned to sort */
call pliretc(8); /* Set return code of 8, meaning last record
already sent. */
end;
else do;
/* If another record is to be sent to sort,
do the necessary processing, set a return
code of 12 by calling PLIRETC, and return
the data as a character string to sort */
/* Code to do your processing goes here */
call pliretc (12);/* Set return code of 12, meaning this
record is to be included in the sort */
return (string); /* Return data with RETURN statement */
end;
end; /* End of the input procedure */