This was published in a Club Tech iSeries Programming Tips Newsletter:
4. READING TWO FILES IN A REXX PROGRAM
Q: Is it possible to read more than one file in a REXX program? According to the documentation I have read so far, I can specify something such as LineIn(MyFile). I’m working on the iSeries, and overriding the StdIn works well for a single file, but I want to read two files to compare options.
A: You’ve discovered a limitation of REXX on the iSeries. A program can read only one database file when you override StdIn before the first Parse LineIn or Parse Pull instruction. To read two files, you can use the StrREXPrc (Start REXX Procedure) command from inside a REXX program to start a child invocation of the REXX interpreter, read a file there, and pass back records via the REXX external data queue. Both the parent and child invocations of the REXX interpreter will share the same external data queue, but each invocation can open a different file.
The Parse LineIn instruction reads a record from StdIn or its override. The Parse Pull instruction reads a record from the REXX external data queue. If the external data queue is empty, then Parse Pull behaves like Parse LineIn.
For example, program Compare works with two input files:
/* Program: Compare */
/* Language: REXX */
/* Purpose: Compare two database files */
“StrREXPrc QueueFile Parm(‘MYLIB2 MYFILE2 MYMBR2’)”
“OvrDbF StdIn MyLib1/MyFile1 MyMbr1”
Parse LineIn Record1 /* read MyLib1/MyFile1/MyMbr1 */
Parse Pull Record2 /* read MyLib2/MyFile2/MyMbr2 */
/* compare Record1 and Record2 here */
The Parse LineIn instruction reads records from MyLib1/MyFile1/MyMbr1, and the Parse Pull instruction reads copies of MyLib2/MyFile2/MyMbr2 records from the REXX external data queue. Program Compare calls the QueueFile program through the StrREXPrc command:
/* Program: QueueFile */
/* Language: REXX */
/* Purpose: Copy database file into REXX data queue */
Arg Library File Member
“OvrDbF StdIn” Library”/”File Member
Parse LineIn Record
If Record = ” Then Return
The QueueFile program copies records from MyLib2/MyFile2/MyMbr2 into the external data queue.
The above tip was from Gene Gaunt and was published in iSeries NEWS.