Using a DDname
The DD statement enables you to write C or C++ source programs that are independent of the files and input/output devices they use. You can modify the parameters of a file or process different files without recompiling your program.
Use ddnames if you want to use non-DASD devices.
If you specify DISP=MOD
on
a DD statement and w
or wb
mode
on the fopen()
call, z/OS® XL
C/C++ treats the file as if you had opened it in append mode instead
of write mode.
- In batch (z/OS,
TSO, or IMS), you can write a JCL DD statement. For the
declaration shown above for the C or C++
file
PARTS.INSTOCK
, you write a JCL DD statement similar to the following://STOCK DD DSN=USERID.PARTS.INSTOCK,DISP=SHR
When defining DD, do not use
DD … FREE=CLOSE
for unallocating DD statements. The C library may close files to perform some file operations such asfreopen()
, and the DD statement will be unallocated.If you useSPACE=RLSE
on a DD statement, z/OS XL C/C++ releases space only if all of the following are true:- The file is open in
w, wb, a
, orab
mode - It is not simultaneously open for read
- No positioning functions (
fseek()
,ftell()
,rewind()
,fgetpos()
,fsetpos()
) have been performed.
For more information on writing DD statements, refer to the job control language (JCL) manuals listed in z/OS Information Roadmap.
- The file is open in
- Under TSO (interactive and batch), you can issue an
ALLOCATE
command. The DD definition shown above for the C fileSTOCK
has an equivalent TSOALLOCATE
command, as follows:ALLOCATE FILE(STOCK) DATASET(PARTS.INSTOCK) SHR
See z/OS Information Roadmap for manuals containing information on TSO
ALLOCATE
. - In the z/OS
environment, you can use the
svc99()
ordynalloc()
library functions to define ddnames. For information about these functions, refer to z/OS XL C/C++ Runtime Library Reference.