If your application consists only of C and C++ modules, the preferred way to share a file is by opening the file in one program and passing the file pointer to the other programs. This eliminates the need to open the file more than once.
Sharing a file in the same job allows programs in that job to share the file's status, record position, and buffer. To allow an Open Data Path (ODP) to be shared between two or more programs running in the same job, use the SHARE(*YES) parameter on commands that create, change, or override files . An open data path is the path through which all I/O operations for a file are performed.
You can share open data paths for streams processed a record at a time. You can also share open data paths for record files. You should not share the open data path for streams processed a character at a time, because unpredictable results can occur when you perform I/O operations.
If you want to share a file between your C/C++ programs and programs that are written in other languages, you can do this by sharing an open data path.
The first open of a shared file determines the open mode for the file (for example, whether it is open for INPUT, OUTPUT, UPDATE, and DELETE). If a subsequent open specifies an open mode that was not specified by the first open, the file will be opened the second time but the open mode will be ignored. For example, if the first open specifies an open mode of IO and the second open specifies IOUD, the file will be opened the second time with a mode of IO.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.