By default all files are opened when an RPG program starts. Add the USROPN keyword to the file specification and then open it when you want it open..
You can also close a file which was opened "automagically" and then open it again for additional use. This is one way to re-position a file to bof, but setll *loval would be more efficient.
I have used close/open on printer files to create individual spool files for documents sent to Optio.
OPEN is one of those things that is there for no specific reason. If it does you some good, use it.
The OPEN op-code opens a file if it isn't already open. A file that isn't open can't be used for anything. Here's a program that OPENs a file and reads a record from the file:<pre>
FSpoolFile if f 132 disk
ISpoolFile ns 10
I 1 132 Line
C close SpoolFile
C open SpoolFile
C read SpoolFile
C eval *InLR = *on</pre>
You can open any full-procedural (F) file. You can also CLOSE files, as shown in the example (which isn't really useful for anything.)
A file can be opened and closed as many times as you might need. It all depends on what procedure you're trying to create.
Last Wiki Answer Submitted: February 21, 2010 11:35 am by TomLiotta107,715 pts.