Usage

The base.Channel class is a built-in class providing basic input/output functionality for:
  • text file reading/writing
  • subprocess communication (through pipes)
  • basic network communication (through TCP sockets)
Important: No character set conversion is done when reading or writing data with channel objects. The character set used in the data file must correspond to the locale of the runtime system, for both input and output.
Steps to use a channel object:
  • Define a variable with the base.Channel type.
  • Create a channel object with base.Channel.create() and assign it to the variable.
  • Open the channel for a file, piped process or socket (as a client).
  • Read or write data in formatted mode or in line mode.
  • Close the channel.

Channel methods may raise exceptions. Exceptions can be trapped with the WHENEVER ERROR or TRY/CATCH instructions.

When reading or writing strings, the escape character is the backslash (\).

The are three modes to read and write data with Channels:

  1. Reading/writing formatted data as a set of fields in a line (i.e. records), with the read() and write() methods, needing a value separator defined by setDelimiter(). This mode follows the same formatting rules as the LOAD/UNLOAD instructions, and can also be used to read/write CSV (Comma Separated Value) formatted data.
  2. Reading/writing complete lines with the readLine() and writeLine() methods. This mode is typically used to read/write simple data files.
  3. Handling raw character string data by reading/writing pieces of strings, with the readOctets() and writeNoNL() methods.