The STRING option in GET and PUT statements transmits data between main storage locations rather than between the main and a data set. DBCS data items cannot be used with the STRING option.
The GET statement with the STRING option specifies that data values assigned to the data list items are obtained from the expression, after conversion to character string. Each GET operation using this option always begins at the leftmost character position of the string. If the number of characters in this string is less than the total number of characters specified by the data specification, the ERROR condition is raised.
The PUT statement with the STRING option specifies that values of the data-list items are to be assigned to the specified character variable or pseudovariable. The PUT operation begins assigning values at the leftmost character position of the string, after appropriate conversions are performed. Blanks and delimiters are inserted as in normal I/O operations. If the string is not long enough to accommodate the data, the ERROR condition is raised.
The NAME condition is not raised for a GET DATA statement with the STRING option. Instead, the ERROR condition is raised for situations that raise the NAME condition for a GET DATA statement with the FILE option.
The following restrictions apply to the STRING option:
The STRING option is most useful with edit-directed transmission. It allows data gathering or scattering operations performed with a single statement, and it allows stream-oriented processing of character strings that are transmitted by record-oriented statements.
For example:
read file (Inputr) into (Temp);
get string(Temp) edit (Code) (F(1));
If Code = 1 then
get string (Temp) Edit (X,Y,Z)
(X(1), 3 F(10,4));
The READ statement reads a record from the input file Inputr. The first GET statement uses the STRING option to extract the code from the first byte of the record and assigns it to Code. If the code is 1, the second GET statement uses the STRING option to assign the values in the record to X, Y, and Z. The second GET statement specifies that the first character in the string Temp is ignored (the X(1) format item in the format list). This ignored character is the same one assigned to Code by the first GET statement.
An example of the STRING option in a PUT statement is:
put string (Record) edit
(Name) (X(1), A(12))
(Pay#) (X(10), A(7))
(Hours*Rate) (X(10), P'$999V.99');
write file (Outprt) from (Record);
The PUT statement specifies, by the X(1) spacing format item, that the first character assigned to the character variable is a single blank, which is the ANS vertical carriage positioning character that specifies a single space before printing. Following that, the values of the variables Name and Pay# and of the expression Hours*Rate are assigned. The WRITE statement specifies that record transmission is used to write the record into the file Outprt.
The variable referenced in the STRING option should not be referenced by name or by alias in the data list. For example:
declare S char(8) init('YYMMDD');
put string (S) edit
(substr (S, 3, 2), '/',
substr (S, 5, 2), '/',
substr (S, 1, 2))
(A);
The value of S after the PUT statement is 'MM/bb/MM' and not 'MM/DD/YY' because S is blanked after the first data item is transmitted. The same effect is obtained if the data list contains a variable based or defined on the variable specified in the STRING option.