open(open file for processing)

OPEN commmand is used for what purpose in rpgiv.pls also give me the short program of this command.

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.


Discuss This Question: 1  Reply

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Yorkshireman
    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..
    6,085 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: