### 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:

- To access the same file during each run of your application, use the _putenv function from within your program to set the ddname. For example:

      _putenv("DD:DATAFILE=sample.txt, writethru(y)");

- To change the files that are accessed during each run of your application without having to alter and recompile your source code, use the set command with ddnames. You can also use the set command to specify other file characteristics. For example,

      SET DD:DDNAME=filename[,option, option...]

  No white-space characters are allowed between the DD and the equal sign. DDNAME is the ddname as specified in the source code. The ddname must be in uppercase. filename is the name of the file that will be opened by fopen.

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