Guidelines for Searching and Locating COPY Files
The COBOL-IT compiler can be directed to search for copy files in directories named by either the COBCPY, or COB_COPY_DIR environment variable, or with the use of the -I compiler flag. Copy file name resolution is refined with the use of the -ext compiler flag.
By default, the COBOL-IT compiler will search the current directory,and $COBOLITDIR\copy for named copy files, and if the copy files have no explicit file name extensions, the COBOL-IT compiler will search for default copy file extensions.
Default copy file extensions are:
- .CPY
- .COB
- .CBL
- .cpy
- .cob
- .cbl
- no extension
The COBOL-IT compiler will then check the environment variables COBCPY and COB_COPY_DIR for pathes to add to the default search pathes.
At the command line, you may add more directories to search with the -I <directory> compiler flag, and you may add more extensions to the default file extensions searched with the -ext <extension> compiler flag.
Example 1:
Consider a case where a program, myprog.cbl has a copy file declared as follows:
COPY "customer.cpy".
And where customer.cpy is contained in a subdirectory called copy.
>set COBCPY=.\copy
>cobc myprog.cbl
Example 2:
Consider a case where a program, myprog.cbl has a copyfile declared as follows:
COPY "customer".
And where customer.fd is contained in a subdirectory called copy. .fd is not a default extension, so both the directory and the extension need to be given to the compiler, to find the file.
>set COBCPY=.\copy
>cobc -ext=fd myprog.cbl
or
>cobc -I .\copy -ext=fd myprog.cbl
Locating COPY books
The COBOL-IT compiler will search for copy files in the following order:
- In the same folder as the source file
- In the folder named by the -I compiler option
- In the folder named by the COBCPY environment variable
- if there has been no other indication in the environment or through the
-Iflag, inthe folder$COBOLITDIR/copyon a Unix/Linux-based system and%COBOLITDIR%\copyon a Windows-based machine.
Note that the listing file will expand the copy file, and indicate which file was located:
SCREEN SECTION.
*#1 "../COPY/SAMPLE1X.CPY“
Resolving COPY book names
Resolving the statement:
COPY "MYFILE".
The file is located if the compiler locates myfile followed by any of the following extensions:
- .CPY
- .cpy
- .CBL
- .cbl
- .COB
- .cob
- any extension passed with
-extcompiler option or with no extension at all.
Resolving the statement:
COPY "MYFILE.CPY".
The file is located if the compiler locates the file myfile.cpy.
Note
The copy file should not have the same name as the object file.
The target of the COPY command is case-sensitive on UNIX systems.
The -I <directory> compiler flag causes <directory> to be searched for copy files.
Example: cobc -I .\copy program1.cbl
The -ext<extension> compiler flag causes <extension> to be included in search for copy files.
Example: cobc -I .\copy -ext ws program1.cbl
For systems where copy file searches are case sensitive:
-ffold-copy-lowerFold COPY subject to lower case (Default no transformation)-ffold-copy-upperFold COPY subject to upper case (Default no transformation)
Using compiler flags
-
Using -fcurdir-include compiler flag
The
-fcurdir-includecompiler flag causesCOPYfiles to first be searched for in the current directory. (before the-I <path>). TheCOPYsearch is performed for files with default extensions, and with extensions described with the-extcompiler compiler flag. This is the default behavior of the compiler.The
-fno-curdir-includecompiler flag causes the search for aCOPYfile to not search forCOPYfile in the current directory, unless that directory is named by an-Icompiler flag, or by aCOB_COPY_DIR, orCOBCPYenvironment variable. -
Using -I <path>[,ext1,ext2,.,extn][@<LibName>] | <command-file> compiler flag
The following rules apply to the treatment of file extensions
- If file extensions are specified, then the compiler will limit its
COPYfile search to files with these extensions inside the specified<path>. - If no file extensions are specified, then standard extensions and those specified with the
-extcompiler flag are used for theCOPYfile search. - File extensions must be named when the
COPY <path>is the current directory ("."). - To specify that files with no extension should be included in the
COPYfile search, use a single dot "." . For example, the following string would check for files with no extension, and with the.cpyextension:>cobc -I /opt/mycopys,.,.cpy
Note that if your file is declared with an extension, for example:
COPY test.cpyThen, for the purposes of the COPY file search, it is not necessary to apply any extensions. In this case, you would want to check for files with no extension, as follows:
>cobc -I /opt/mycopys,.That is you would follow
<path>by a comma, and then a single dot ".", indicating that files with no extension should be included in theCOPYfile search.The following rules apply to cases where a COPY <filename> IN/OF LibName statement is being interpreted:
Consider the case where source code contains the line:
COPY MyCpy IN/OF LIBA.Note that the default behavior of the compiler in this case is to look in the current directory for a subdirectory
LIBA, and to search that directory for files calledMyCpywith all of the standard file extensions. If not found, the compiler would continue the search in all<path>specified by the-Icompiler flag, and would ignore theLibraryName.- If no
@<LibName>is specified in the-Icompiler command, then the default behavior of the compiler is assumed. - If
@<LibName>is specified in the-Icompile command, then the default behavior of the compiler is not applied. Instead, the<path>named in the-Icompiler command is searched for theCOPYfile. - If the
COPYfile is not located in the<path>, then the search fails.
- If file extensions are specified, then the compiler will limit its
Examples:
>cobc -I /opt/copylooks forCOPYfiles with standard extensions in/opt/copy.>cobc -I /opt/copy,.cpylooks forCOPYfiles with the.cpyextension in/opt/copy.>cobc -I /opt/copy,.,.cpylooks forCOPYfiles with no extension or with the.cpyextension in/opt/copy.>cobc -I /opt/copy,.,.cpy@LIBAlooks forCOPYfiles with no extension or with the .cpy extension in/opt/copywhen resolving aCOPYfile described asIN/OF LIB, for example:COPY [filename] IN/OF LIBA>cobc -I <command-file>reads<command-file>and interprets each line as a command in the-Icommand string.