FLD
Returns the value of a field from the current input record (INREC),
starting at start_column (in bytes), of length number
of bytes, interpreted according to the specified type:
- B
- if the field is binary. If you specify B for type, length must be 2, 4, or 8.
- C
- if the field contains characters.
- P
- if the field is packed decimal. If you specify P for type, length must be between 1 and 16.
- Z
- if the field is zoned decimal. If you specify Z for type, length must be between 1 and 32 or, if the field contains a separate sign character, between 1 and 33.
The default value for type is C.
If you omit length and specify type P (packed decimal), FLD attempts to determine the packed field length from the record data, and returns only that field. If you omit length for other field types, FLD returns the remainder of the record.
The FLD function is similar to the built-in REXX SUBSTR function,
except that FLD interprets the substring
according to the specified
data type, and returns the value formatted appropriately. (For a numeric
field, FLD returns the value with a sign, and without leading zeros.)
Example 1
If the value of the packed-decimal field that starts at byte 8
is greater than 100, do not process the current record.
if fld(8,P) > 100 then exit 'DROP'
Example 2
If the value of the 2-digit year field starting at byte 42 is greater
than 60, insert the literal
19before the year field. Otherwise, insert
20.
if fld(42,2,Z) > 60 then
outrec = fld(1,41)||'19'||fld(42)
else
outrec = fld(1,41)||'20'||fld(42)