CVTOPT(*VARCHAR) および CVTOPT(*VARGRAPHIC)

ILE RPG コンパイラーは、外部記述ファイルまたはデータ構造からの可変長の文字フィールド、図形フィールド、または UCS-2 フィールドを、固定長の文字フィールドとして内部的に定義することができます。 可変長の文字フィールド、図形フィールド、および UCS-2 フィールドの固定長形式への変換は不要ですが、可変長フィールドがサポートされる前に作成されたプログラムをサポートするために、CVTOPT がこの言語に残されています。

可変長フィールドを変換するには、CVTOPT 制御仕様書 キーワードまたはコマンド・パラメーターで、*VARCHAR (可変長文字フィールド) または *VARGRAPHIC (可変長図形フィールドまたは UCS-2 フィールド) を指定します。*VARCHAR または *VARGRAPHIC を指定しないか、あるいは *NOVARCHAR または *NOVARGRAPHIC を指定した場合、可変長フィールドは固定長文字に変換されないので、ILE RPG プログラム内で可変長として使用することができます。

*VARCHAR または *VARGRAPHIC を指定 した場合には、次の条件が適用されます。
図 2. 可変長文字フィールドの変換
*..1....+....2....+....3....+....4....+....5....+....6....+....7....+..
A*
A*   File MASTER contains a variable-length field
A*
AAN01N02N03T.Name++++++Rlen++TDpBLinPosFunctions+++++++++++++++++++++
A*
A          R REC
A            FLDVAR       100          VARLEN
*..1....+....2....+....3....+....4....+....5....+....6....+....7....+.. *
 *
 *   Specify the CVTOPT(*VARCHAR) keyword on a control
 *   specification or compile the ILE RPG program with
 *   CVTOPT(*VARCHAR) on the command.
 *
HKeywords++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 *
H CVTOPT(*VARCHAR)
 *
 *   Externally described file name is MASTER.
 *
FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords++++++++++++++++++++++++++++
 *
FMASTER    UF   E             DISK
 *
 *   FLDVAR is a variable-length field defined in DDS with
 *   a DDS length of 100.  Notice that the RPG field length
 *   is 102.
 *
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++
 *
D                 DS
D FLDVAR                  1    102
D   FLDLEN                       5U 0 OVERLAY(FLDVAR:1)
D   FLDCHR                     100    OVERLAY(FLDVAR:3)
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq..
 *
 * A character value is moved to the field FLDCHR.
 * After the CHECKR operation, FLDLEN has a value of 5.
C                   READ      MASTER                                 LR
C                   MOVEL     'SALES'       FLDCHR
C     ' '           CHECKR    FLDCHR        FLDLEN
C  NLR              UPDATE    REC
変換済み可変長図形フィールドを使用したい場合には、2 バイトの符号なし 整数フィールドをコーディングして、長さを保留し、長さ N の図形サブフィールドを コーディングしてフィールドのデータ部分を保留することができます。
図 3. 可変長図形フィールドの変換
 *
 *   Specify the CVTOPT(*VARGRAPHIC) keyword on a control
 *   specification or compile the ILE RPG program with
 *   CVTOPT(*VARGRAPHIC) on the command.
 *
 *   The variable-length graphic field VGRAPH is declared in the
 *   DDS as length 3.  This means the maximum length of the field
 *   is 3 double bytes, or 6 bytes.  The total length of the field,
 *   counting the length portion, is 8 bytes.
 *
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++
 *
D                 DS
DVGRAPH                          8
D  VLEN                          4U 0 OVERLAY(VGRAPH:1)
D  VDATA                         3G   OVERLAY(VGRAPH:3)
 *
 *   Assume GRPH is a fixed-length graphic field of length 2
 *   double bytes.  Copy GRPH into VGRAPH and set the length of
 *   VGRAPH to 2.
 *
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq..
C*
C                   MOVEL     GRPH          VDATA
C                   Z-ADD     2             VLEN