Microsoft KB Archive/47750

From BetaArchive Wiki

Definition of Dynamic File Assignment in COBOL 3.00/3.00a

PSS ID Number: Q47750 Article last modified on 08-30-1989

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: You do not have to define the file-identifier data item used in the SELECT statement in the DATA DIVISION. “Dynamic file assignment” is the term for not explicitly defining a file identifier in the DATA DIVISION of a program. You can choose to define the file-identifier data item explicitly in the DATA DIVISION. If you do, the contents of the data item are used for the filename when the file is opened. If you decide not to define the data name explicitly, the COBOL system supplies an implicit definition for the data item of PIC X(65). In this case, you must MOVE a filename into the data item before the OPEN statement is executed. This information applies to Microsoft COBOL Compiler Versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: Before the file is OPENed, you must move the MS-DOS filename to the file identifier specified by the ASSIGN phrase of the SELECT clause.

Code Example

   SELECT test-file ASSIGN TO file-name.
   .
   .
   .
   PROCEDURE DIVISION.
   .
   .
   .
   MOVE "C:\DATA\PAYROLL.DAT" TO file-name.
   OPEN OUTPUT test-file.
   .
   .
   .
   CLOSE test-file.
   STOP RUN.

In the above sample code, the data item “file-name” is not defined in the program’s DATA DIVISION. Thus, the COBOL system will use dynamic file assignment for the data item and will make an implicit definition of PIC X(65). If you do not MOVE a value to the data item, the program may appear to not perform as expected and, in most cases, produces a run-time error. For more information about dynamic file assignment, refer to Pages 7-4 through 7-5 of the “Microsoft COBOL Compiler 3.00: Operating Guide.”

Copyright Microsoft Corporation 1989.