2.13 What's the most common question about CI programming on HP3000-L? Answer: How can I read records from a file into a variable?

From Jeff Vance, architect of the CI:

The basic problem is that the CI's IO redirection opens the file and causes the record pointer to be set to the beginning. This is done each time the IO redirection is encountered by the CI. Thus, if you try to read from a file in a WHILE loop using the INPUT command, you will read only the first record each iteration. Below are some ways to overcome this restriction.

Method 1: using a MSG file.

PROS: simple, easy to maintain, and an easy way to read small files or make "quick and dirty" scripts.

CONS: slow, especially if the file is long.

Basic idea:

- use a file equation to create a MSG file

- redirect output to this MSG file

- use the INPUT command to read from the MSG file via IO redirection.

Example:

Method 2: using a flat file.

PROS: most efficient way in the CI to read files.

CONS: less intuitive and more effort to author.

Basic idea:

- create a file via IO redirection

- xeq the same script with the script's input redirected to the file created in step 1.

- use the INPUT command or input() function to read from the file (with no IO redirection since the input for the entire

script is redirected here).

Example:

Method 3: using PRINT to get an individual record.

PROS: I've seen this approach used many times so it must be intuitive.

CONS: inefficient, ok for small files.

Basic idea:

- create a file via IO redirection.

- use the PRINT;start=;end= to create another file with 1 record.

- use the INPUT command to read from the one record file via IO redirection.

Example: