ONKEY

ONKEY returns a character string whose value is the key of the record that raised an input/output condition.

For indexed files, if the key is GRAPHIC, the string is returned as a mixed character string. ONKEY is in context for the following:
  • An ON-unit, or any of its dynamic descendants
  • Any input/output condition, except ENDFILE
  • The ERROR or FINISH condition raised as implicit action for an input/output condition.
ONKEY is always set for operations on a KEYED file, even if the statement that raised the condition does not specified the KEY, KEYTO, or KEYFROM options.

Read syntax diagramSkip visual syntax diagramONKEY()
The result of specifying ONKEY is:
  • For any input/output condition (other than ENDFILE), or for the ERROR or FINISH condition raised as implicit action for these conditions, the result is the value of the recorded key from the I/O statement causing the error.
  • For relative data sets, the result is a character string representation of the relative record number. If the key was incorrectly specified, the result is the last 8 characters of the source key. If the source key is less than 8 characters, it is padded on the right with blanks to make it 8 characters. If the key was correctly specified, the character string consists of the relative record number in character form padded on the left with blanks, if necessary.
  • For a REWRITE statement that attempts to write an updated record on to an indexed data set when the key of the updated record differs from that of the input record, the result is the value of the embedded key of the input record.

If ONKEY is used out of context, a null string is returned.