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.
Tom
Last Wiki Answer Submitted: February 21, 2010 11:35 am by TomLiotta107,715 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.
Opening a file is fundamental to any program. RPG makes it easy for the programmer by doing the work for you.
However, you may not want to incur the performance overhead of opening all files at initialisation – or at all.
Consider a program which is general purpose, and could access/update one or two of say a hundred files.
You may want to work out which files to open before having to open them all. then only open the ones required.
Consider if you want to do some work before opening the file – like issuing an override. or checking other stuff and deciding if that file is needed.
Big performance gains can be made in some situations by the programmer manually handling open and close. – equally, big degradations can happen too.
- any textbook should cover the topic. Oh, and the RPG manuals of course..
Opening a file is fundamental to any program. RPG makes it easy for the programmer by doing the work for you.
However, you may not want to incur the performance overhead of opening all files at initialisation – or at all.
Consider a program which is general purpose, and could access/update one or two of say a hundred files.
You may want to work out which files to open before having to open them all. then only open the ones required.
Consider if you want to do some work before opening the file – like issuing an override. or checking other stuff and deciding if that file is needed.
Big performance gains can be made in some situations by the programmer manually handling open and close. – equally, big degradations can happen too.
- any textbook should cover the topic. Oh, and the RPG manuals of course..