Username:

Password:


Lost Password?

Register now!
Home
Music Services
Get Personal!
Contact
Flying Snowman Productions Forum Index
   AS/400 (iSeries)
     File Input and Output on iSeries using Rexx
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
The Flying Snowman
Posted on: 2005/10/18 15:23
Webmaster
Joined: 2004/10/31
From: BE
Posts: 2208
Online
File Input and Output on iSeries using Rexx
I you look at the Appendix I of the REXX/400 Programmer's Guide (http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/c4157280.pdf), you'll notice that it's not so easy to read or write a file, compared to Rexx running on other IBM operating systems like VM/CMS or MVS/TSO. Another interesting document about this can be found on http://www-912.ibm.com/s_dir/slkbase.NSF/0/f463a8aaf7dd36af8625689a00538de1?OpenDocument


There is of course a workaround. To read from a file in REXX/400, you have to use several CL commands (assume the inlib variable contains the library name, the infile variable contains the file name, and the inmbr variable contains the member name to read). The variable reccnt returns the number of records present in the file, you retrieve this number using the CL RTVMBRD (retrieve member description) command. You then use the CL OVRDBF (override database file) command to read from the file, instead of the terminal:

/* get the number of records in the file */
'RTVMBRD FILE('inlib'/'infile') MBR('inmbr') NBRCURRCD(&reccnt)'

/* read from the file instead of the keyboard */
'OVRDBF FILE(STDIN) TOFILE('inlib'/'infile') MBR('inmbr')'

do reccnt
parse pull recin
end

To write to several files, instead of printing to the terminal, do the following. Call another Rexx exec, invoke the Rexx interpreter (assume the outlib variable contains the name of the output library, outfile the name of the output file, outmbr the name of the output member, and recout contains the line of data you want to write to the file):

"STRREXPRC SRCMBR(WRITFIL2) PARM('outputlib("outlib")",
"outputfile("outfile")",
"outputmbr("outmbr")",
"outrec("recout")')"

In the Rexx WRITFIL2 you do the following. Override the STDOUT file to your output library/file/member. Then issue a say command, and it will be printed into that file. For each file, you call the WRITFIL2 rexx from within your calling rexx, using the strrexprc command like described above, otherwise the override will not work (works only once in a rexx interpreter session).

'OVRDBF FILE(STDOUT) TOFILE('outlib'/'outfile') MBR('outmbr')'
say recout

You might have to translate some things in order to prevent syntax errors, in case your data contains single quotes or parenthesis. In the calling Rexx, first do :

outrec = translate("[]´","()'")

In the called WRITFIL2 rexx, translate it back to the original value:

outrec = translate("()'","[]´")

To get the parameters passed in WRITFIL2, do the following in the beginning of the WRITFIL2 Rexx:

arg 'OUTPUTLIB('outlib')'
arg 'OUTPUTFILE('outfile')'
arg 'OUTPUTMBR('outmbr')'
arg 'OUTREC('outrec')'

Threaded | Newest First Previous Topic | Next Topic | Top

Register To Post
 

Copyright © 1999-2017 Flying Snowman Productions. All rights reserved.
Designed and developed by Flying Snowman Productions
Best viewed with settings 1024 x 768 pixels
You need to enable your cookies for excellent browsing experience