Open Streams Using Data Definition Names (C)

Data definition names (ddnames) provide the means to connect logical files within an application to physical files.

You can use ddnames to specify the files that are accessed by your application. You must specify the /Sh+ compiler option to use ddnames.

The maximum number of files that can be open at any time changes with the amount of memory available.

Set a ddname in one of the following ways:

For example, to open the file sample.txt, you could include the following statements in your source code:

FILE *stream;
stream=fopen("DD:DATAFILE", "r"); 

Before you run your application, use the set command:

      SET DD:DATAFILE=c:\sample.txt 

When the application runs, it will open the file c:\sample.txt. If you want the same program to use the file c:\test.txt the next time it runs, use the following set command:

   SET DD:DATAFILE=c:\test.txt 

Precedence of File Characteristics
You can describe your data within the program with fopen, and outside it with ddname, but you do not always need to do so. There are advantages to describing the characteristics of your data in only one place.

Opening a file with ddname may require the merging of information that is internal and external to the program. In the case of a conflict, the characteristics described by using fopen override those described using a ddname. For example, given the following ddname statement and fopen command:

   SET DD:ROGER=danny.c, memory(n)
   stream = fopen("DD:ROGER", "w, type=memory")

the file danny.c will be opened as a memory file.



Stream Processing
Standard Streams


File Options Used with Data Definition Names