You can bring a variable-length field into your program if you specify *VARCHAR on the CVTOPT parameter of the CRTCBLMOD or CRTBNDCBL commands, or the VARCHAR option of the PROCESS statement. When *VARCHAR is specified, your ILE COBOL program will convert a variable-length field from an externally described file into an ILE COBOL group item.
An example of such a group item is:
06 ITEM1. 49 ITEM1-LENGTH PIC S9(4) COMP-4. 49 ITEM1-DATA PIC X(n).
where n represents the maximum length of the variable-length field. Within the program, the PIC S9(4) COMP-4 is treated like any other declaration of this type, and the PIC X(n) is treated as standard alphanumeric.
When *VARCHAR is not specified, variable-length fields are ignored and declared as FILLER fields in ILE COBOL programs. If *NOVARCHAR is specified, the item is declared as follows:
06 FILLER PIC x(n+2).
For syntax information, see the CVTOPT parameter under CVTOPT Parameter.
Your program can perform any valid character operations on the generated data portion; however, because of the structure of the field, the length portion must be valid binary data. This data is not valid if it is negative, or greater than the maximum field length.
If the first two bytes of the field do not contain a valid binary number, an error will occur if you try to WRITE or REWRITE a record containing the field, and file status 90 is returned.
The following conditions apply when you specify variable-length fields:
Figure 105. ILE COBOL Field Length of a Variable-Length Field
To see an example of a program using variable-length fields, refer to Examples of Using Variable-length DBCS-graphic Fields.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.