Product Site

Chapter 14. Input and Output Streams

14.1. The Input and Output Model
14.1.1. Input Streams
14.1.2. Output Streams
14.1.3. External Data Queue
14.1.4. Default Stream Names
14.1.5. Line versus Character Positioning
14.2. Implementation
14.3. Operating System Specifics
14.4. Examples of Input and Output
14.5. Errors during Input and Output
14.6. Summary of Rexx I/O Instructions and Methods

Rexx defines Stream class methods to handle input and output and maintains the I/O functions for input and output externals. Using a mixture of Rexx I/O methods and Rexx I/O functions can cause unpredictable results. For example, using the LINEOUT method and the LINEOUT function on the same persistent stream object can cause overlays.

When a Rexx I/O function creates a stream object, the language processor maintains the stream object. When a Rexx I/O method creates a stream object, it is returned to the program to be maintained. Because of this, when Rexx I/O methods and Rexx I/O functions referring to the same stream are in the same program, there are two separate stream objects with different read and write pointers. The program needs to synchronize the read and write pointers of both stream objects, or overlays occur.

To obtain a stream object (for example, MYFIL), you could use:
Example 14.1. Obtaining a stream object
MyStream = .stream~new("MYFIL")

You can manipulate stream objects with character or line methods:
Example 14.2. Performing input on a stream object
nextchar = MyStream~charin()
nextline = MyStream~linein()

In addition to stream objects, the language processor defines an external data queue object for interprogram communication. This queue object understands line functions only.

A stream object can have a variety of sources or destinations including files, serial interfaces, displays, or networks. It can be transient or dynamic, for example, data sent or received over a serial interface, or persistent in a static form, for example, a disk file.

Housekeeping for stream objects (opening and closing files, for example) is not explicitly part of the language definition. However, Rexx provides methods, such as CHARIN and LINEIN, that are independent of the operating system and include housekeeping. The COMMAND method provides the stream_command argument for those situations that require more granular access to operating system interfaces.