FLD
Can be used in FASTREXX condition expressions.
Fetches the value of a field from the current input record (INREC), starting at start_column, of length number of bytes, interpreted according to the specified type.
- Returns
- The value of the field from the current input record.
- start_column
- Position, in bytes, in the input record at which to start reading
the field value. Can be specified as:
- Absolute position
- Must be a positive integer. Default value is 1. If start is greater than the current length of the input record, the function has no effect.
- Relative to current INPOS
- Can be specified as IPx or INx, or as Px or Nx. If this resolves to a value of less than or equal to zero, the function results in an error. If this resolves to a value that is greater than the current length of the input record, the function has no effect.
- Relative to current OUTPOS
- Must be specified as OPx or ONx. If this resolves to a value of less than or equal to zero, the function results in an error. If this resolves to a value that is greater than the current length of the input record, the function has no effect.
- length
- The length of the field in bytes.
For binary fields, you must specify the length. It can be 2, 4, or 8.
For character fields, if you omit the length, FLD returns the remainder of the record.
For packed decimal fields, if you specify the length, it must be in the range 1–16. If you omit the length, FLD attempts to determine the packed field length from the record data and returns only that field.
For zoned decimal fields, if you specify the length, it must be in the range 1–31 or, if the field contains a separate sign character, in the range 1–32. If you omit the length, FLD returns the remainder of the record.
- type
- The data type of the field. Valid values are:
- B
- Binary. FLD interprets binary fields as being signed.
- C
- Character. This is the default.
- P
- Packed decimal.
- U
- Interprets the field as Character, but converts it to uppercase before returning the string.
- Z
- Zoned decimal. Interprets all of the COBOL external decimal variants as numeric data.
If you specify a value for length that would cause the record length to be exceeded:
- For character fields (type C, U), FLD returns the remainder of the record.
- For numeric fields (types B, P, Z), FLD returns a null string.
If you specify a numeric type (types B, P, Z), and the specified field contains invalid data for that type, then FLD returns a null string. Numeric data is always returned in integer form; that is, FLD does not perform scaling of numeric data.
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 FLD(8,P) > 100 Then Return 'DROP'
Example 2
If FLD(42,2,Z) > 60 Then
outrec = FLD(1,41)||'19'||FLD(42)
Else
outrec = FLD(1,41)||'20'||FLD(42)
Example 3
If FLD(11,4,p) = '' Then Return 'DROP'
Example 4
If FLD(P8,P) > 100 Then Return 'DROP'