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"
Do Queued()
Parse LineIn Record1 /* read MyLib1/MyFile1/MyMbr1 */
Parse Pull Record2 /* read MyLib2/MyFile2/MyMbr2 */
/* compare Record1 and Record2 here */
End
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
Do Forever
Parse LineIn Record
If Record = '' Then Return
Queue Record
End
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.
Last Wiki Answer Submitted: January 6, 2005 9:34 am by Qpgmrs0 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
I’ve found a way to access and manipulate as many tables/files as you’d like in a REXX program on the iSeries. You use SQL. If interested, let me know and I’ll provide examples of how.
REXX and SQL get along very well on all AS/400s and later systems, without requiring the SQL Dev Kit product. Anyone familiar with REXX can pick up the concepts easily. I can also post various samples if needed. I’m pretty sure we can cover most scenarios.
thanks for reply !
Works very nice.
thanks again
I’ve found a way to access and manipulate as many tables/files as you’d like in a REXX program on the iSeries. You use SQL. If interested, let me know and I’ll provide examples of how.
You use SQL.
REXX and SQL get along very well on all AS/400s and later systems, without requiring the SQL Dev Kit product. Anyone familiar with REXX can pick up the concepts easily. I can also post various samples if needed. I’m pretty sure we can cover most scenarios.
Tom