File management on iSeries™ provides several levels of support for shared files. Files can be shared among many users, many jobs, or many programs within the same job.
The server automatically provides the first level of support. By default, the server lets multiple users and multiple jobs use one file at the same time. The server allocates the file and its associated resources for each use of the file in such a way that it can prevent conflicting uses. Within the same job, programs can share files if one program opens the same file more than once or if different programs open the same file. Even though the same file is being used, each open operation creates a new path from the program to the data or device, so that each open represents an independent use of the file.
In the original program model, the SHARE(*YES) parameter lets two or more programs that run in the same job share an open data path (ODP). It connects the program to a file. If not specified otherwise, every time a file is opened a new open data path is built. You can specify that if a file is opened more than once and an open data path is still active for it in the same job, the active ODP for the file can be used with the current open of the file; a new open data path does not need to be created. This reduces the amount of time that is required to open the file after the first opened to open the file after the first open, and the amount of main storage that is required by the job. You must specify SHARE(*YES) for the first open and other opens of the same file to share the open data path. A well-designed (for performance) application will normally do a shared open on database files that multiple programs will open in the same job. Specifying SHARE(*YES) for other files depends on the application.
In the ILE model, shared files are scoped either to the job level or to the activation group level. An activation group is a substructure of a run-time job. It consists of server resources (storage for program or procedure variables, commitment definitions, and open files) that are allocated to one or more programs. An activation group is like a miniature job within a job.
Any programs that run in any activation group can share shared files that are scoped to the job level. Only programs that run in the same activation group can share shared files that are scoped to the activation group level.
Sharing files allows you to have programs within a job interact in ways that would otherwise not be possible. However, you need to understand the effects of opening, performing read and write operations, and closing shared files.
You should also see the appropriate documentation for all of the file types to understand how this support works, and the rules your programs must follow to use it correctly.