Microsoft KB Archive/32952

Using SELECT for DOS File Assignment in COBOL Version 3.0

PSS ID Number: Q32952 Article last modified on 04-21-1993

3.00 | 3.00 MS-DOS | OS/2

Summary: A COBOL filename is associated with a DOS filename in one of the following three ways: 1. Literal Assignment SELECT (file-name) ASSIGN TO “DOS-FILE-NAME-LITERAL”. DOS-FILE-NAME-LITERAL can include a drive and path specification. To change the filename, you have to modify the source code and recompile the program, as follows: SELECT in-file ASSING TO “A:.DAT”. 2. Dynamic Assignment SELECT (file-name) ASSIGN TO DYNAMIC-FILE-NAME. DYNAMIC-FILE-NAME can be a user-defined name (in the DATA DIVISION) or if not defined, the compiler will create a data item that is 65 characters in length for you. The program must initialize the name with the DOS filename prior to the OPEN statement for the file. The DYNAMIC-FILE-NAME must be space terminated, as follows: SELECT in-file ASSIGN TO WS-IN-FILE. SELECT in-file ASSIGN TO DYNAMIC WS-OUT-FILE. WORKING-STORAGE SECTION. 01 WS-IN-FILE PIC x(30) VALUE “A:-DATA”. 01 WS-OUT-FILE PIC x(40) VALUE PROCEDURE DIVISION. MOVE “C:.DAT” TO WS-OUT-FILE. 3. External (DOS Set) Assignment SELECT (file-name) ASSIGN TO EXTERNAL DOS-SET-NAME. DOS-SET-NAME is a DOS environment-variable name. You must issue a DOS “SET” command prior to execution of the program. Please note that if DOS_SET_NAME contains hyphens (-), only those characters after the last hyphen are used to search for a DOS environment name, as follows: SELECT in-file ASSIGN TO EXTERNAL VAR1. Prior to executing the program, you must issue a DOS “SET VAR1=C:TEST.DAT” command, as follows: SELECT out-file ASSIGN TO EXTERNAL AB-CDEF. Because the “set name” contains hyphens, COBOL will search for the DOS environment variable “CDEF” at run time.

Additional reference words: 3.00 Copyright Microsoft Corporation 1993.