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
-I
flag, inthe folder$COBOLITDIR/copy
on a Unix/Linux-based system and%COBOLITDIR%\copy
on 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
-ext
compiler 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-lower
Fold COPY subject to lower case (Default no transformation)-ffold-copy-upper
Fold COPY subject to upper case (Default no transformation)
Using compiler flags
-
Using -fcurdir-include compiler flag
The
-fcurdir-include
compiler flag causesCOPY
files to first be searched for in the current directory. (before the-I <path>
). TheCOPY
search is performed for files with default extensions, and with extensions described with the-ext
compiler compiler flag. This is the default behavior of the compiler.The
-fno-curdir-include
compiler flag causes the search for aCOPY
file to not search forCOPY
file in the current directory, unless that directory is named by an-I
compiler flag, or by aCOB_COPY_DIR
, orCOBCPY
environment 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
COPY
file search to files with these extensions inside the specified<path>
. - If no file extensions are specified, then standard extensions and those specified with the
-ext
compiler flag are used for theCOPY
file 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
COPY
file search, use a single dot "." . For example, the following string would check for files with no extension, and with the.cpy
extension:>cobc -I /opt/mycopys,.,.cpy
Note that if your file is declared with an extension, for example:
COPY test.cpy
Then, 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 theCOPY
file 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 calledMyCpy
with all of the standard file extensions. If not found, the compiler would continue the search in all<path>
specified by the-I
compiler flag, and would ignore theLibraryName
.- If no
@<LibName>
is specified in the-I
compiler command, then the default behavior of the compiler is assumed. - If
@<LibName>
is specified in the-I
compile command, then the default behavior of the compiler is not applied. Instead, the<path>
named in the-I
compiler command is searched for theCOPY
file. - If the
COPY
file 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/copy
looks forCOPY
files with standard extensions in/opt/copy
.>cobc -I /opt/copy,.cpy
looks forCOPY
files with the.cpy
extension in/opt/copy
.>cobc -I /opt/copy,.,.cpy
looks forCOPY
files with no extension or with the.cpy
extension in/opt/copy
.>cobc -I /opt/copy,.,.cpy@LIBA
looks forCOPY
files with no extension or with the .cpy extension in/opt/copy
when resolving aCOPY
file 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-I
command string.