Skip to main content

$ZB (ObjectScript)

Contains status information for the current I/O device.

Synopsis

$ZB

Description

$ZB contains status information specific to the current I/O device following a READ operation.

  • When reading from a terminal, sequential file, or other character-based I/O device, $ZB contains the terminating character of the read operation. This can be a terminator character (such as <RETURN>), the final character of the input data if the read operation does not require a terminator character, or the null string if a terminator character is required but was not received (for example, if the read operation timed out).

  • When reading from a block-based I/O device $ZB contains the number of bytes remaining in the I/O buffer. $ZB also contains the number of bytes in the I/O buffer when writing to a block-based I/O device.

This special variable cannot be modified using the SET command. Attempting to do so results in a <SYNTAX> error.

$ZB and $KEY can both be used to return the READ termination character when reading from a character-based device or file. For character-based reads, these two special variables are very similar, but not identical. For block-based reads and writes use $ZB; $KEY does not provide support for block-based read and write operations. See $KEY for further details.

End-of-File Behavior

By default, InterSystems IRIS handles an end-of-file on a sequential file by issuing an <ENDOFFILE> error; it does not set $ZB. You can configure $ZB end-of-file behavior so that when an end-of-file is encountered, InterSystems IRIS does not issue an error, but sets $ZB to "" (the null string), and sets $ZEOF to -1.

To configure end-of-file handling, go to the Management Portal, select System Administration, Configuration, Additional Settings, Compatibility. View and edit the current setting of SetZEOF. When set to “true”, InterSystems IRIS sets $ZB to "" (the null string), and sets $ZEOF to -1. The default is “false”.

You can control end-of-file handling for the current process using the SetZEOF()Opens in a new tab method of the %SYSTEM.ProcessOpens in a new tab class. The system-wide default behavior can be established by setting the SetZEOFOpens in a new tab property of the Config.MiscellaneousOpens in a new tab class.

Reading from a Terminal or File

$ZB contains the terminating character (or character sequence) from a read operation involving a terminal, sequential file, or other character-based I/O device. $ZB can contain any of the following:

  • A termination character, such as a carriage return.

  • An escape sequence (up to 16 characters).

  • The nth character in a fixed-length READ x#n. (In this case, the $KEY special variable returns the null string.)

  • The single character of READ *x.

  • A null string ("") after a timed READ expires.

For example, consider the following variable-length read with a five-second timeout:

Zbread
  READ !,"Enter number:",num:5
  WRITE !, num
  WRITE !, $ASCII($ZB)
  QUIT

If the user types 123 at the READ prompt and presses <RETURN>, InterSystems IRIS stores 123 in the num variable and stores <RETURN> (ASCII decimal code 13, hexadecimal 0D) in $ZB. If the READ times out, $ZB contains the null string; $ASCII("") returns a value of –1.

$ZB on the Command Line

When issuing commands interactively from the Terminal command line, you press <RETURN> to issue each command line. The $ZB and $KEY special variables record this command line terminator character. Therefore, when using $ZB or $KEY to return the termination status of a read operation, you must set a variable as part of the same command line.

For example, if you issue the command:

>READ x:10

from the command line, then check $ZB it will not contain the results of the read operation; it will contain the <RETURN> character that executed the command line. To return the results of the read operation, set a local variable with $ZB in the same command line, as follows:

>READ x:10 SET rzb=$ZB

This preserves the value of $ZB set by the read operation. To display this read operation value, issue either of the following command line statements:

>WRITE $ASCII(rzb)
   ; returns -1 for null string (time out), 
   ; returns ASCII decimal value for terminator character
>ZZDUMP rkey
   ; returns blank line for null string (time out)
   ; returns hexadecimal value for terminator character

See Also

FeedbackOpens in a new tab