Sharing Files

Open Data Paths. Each time you open a file, the system creates what is called an open data path (ODP). You can think of the ODP as a tunnel between your program and the file you are using. Each time you open a file, the system has to dig open a new tunnel.

If you have an application that consists of several programs that call one another, a good chance exists that more than one program will use the same file. In this case, the system digs open one tunnel (ODP) when it runs the first program. When it runs the second program that uses the same file, it digs another tunnel, even though the first one is already open and is not in use. All this digging is a lot of unnecessary work.

Sharing files means sharing the ODP. When you share files, the system creates a single ODP for each file, which can substantially improve performance. However, ODPs cannot be shared across different jobs. ODPs can only be shared among the programs that run in the same job. This limitation also means that your interactive job cannot share an ODP with a job you submit to batch because the interactive and the batch jobs are different.

Coding Files For Sharing. You can force the system to always share a file by using the SHARE(*YES) parameter in either the Create (CRTXXX F) or Change (CHGXXX F) commands. For example, if you have a physical file you suspect always will need to be shared, you can change the file to SHARE(*YES) using the Change Physical File (CHGPF) command, as follows:


More often than not, however, you need to control when a file is available for share and when it is not. Because of this, the SHARE parameter defaults to *NO in all commands.

If you create a file with SHARE(*NO) and want to be able to share its open data path, do not change it to SHARE(*YES) and back. Instead, use the appropriate override file command with SHARE(*YES) in the CL program that controls your job. As you will learn in the following section, file overrides provide a way to produce a localized change (as opposed to a permanent, system-wide change) in the characteristics of a file.

When you no longer want to share the ODP to the file, you can either override the file again to SHARE(*NO) or delete the override.

Disadvantages of Sharing. Sharing ODPs can cause problems. If programs A and B share the ODP of a database file, and program A calls program B, the following abnormal situation can occur:

Program A reads record 347 randomly by record number, then calls program B. Program B issues a read prior operation on the same file. The file pointer changes to 346; then program B returns control to A. Program A updates the record in the file. Because the file pointer changed position, the wrong record is updated.


Whenever you share ODPs, you must make sure you are processing the record you think you are processing. Read the record again if in doubt.

IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
IBM i5/iSeries Primer(c) Concepts and Techniques for Programmers, Administrators, and Sys[... ]ators
Year: 2004
Pages: 245 © 2008-2017.
If you may any questions please contact us: