Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COPY and INCLUDE in COBOL Program 1

Status
Not open for further replies.

hormise

Programmer
Oct 11, 2001
4
What is the difference between COPY and INCLUDE in COBOL Program?

which among this is efficent and less cpu time consuming during compilation or run time
 
COPY is a method of including code from multiple files in a single compile unit. It is documented in the COBOL Standard and supported on most, if not all, COBOL platforms. INCLUDE is platform/vendor specific and does not work with all COBOLs. While I can't speak from actual experience, the performance difference of COPY versus INCLUDE should be negligible.

Regards.

Glenn
 
COPY is now the COBOL standard. Very early versions of COBOL used INCLUDE in some Divisions, COPY in others. Some mainframe source-code systems such as PANVALET and LIBRARIAN do their own expansion and have "verbs" such as ++INCLUDE or -INC. This occurs before the compiler sees the code. Most PC based COBOL compilers can handle copybooks in one or more separate subdirectories.
 
With IBM mainframe systems INCLUDE is used to include DCLGEN host variables in COBOL pgms and functions as a COPY stmt. They can appear in a pgm along with COPY stmts.

 
Slade,

isn't the include you talk about, in there for the DB2 pre-compiler and looks as follows.

EXEC SQL
INCLUDE T0S0611
END-EXEC.

I think that is subtly different.

Cheers
Greg
 
Hi Greg,

It's different, but my mentioning it is still germain to the topic. It's use by DB2 is the only use of INCLUDE (without the ++) I've seen in a COBOL pgm.

Though, it's helpful that you provided the EXACT usage of the feature (something I should have done).

Regards, Jack.
 
That should be "germane" not "germain". :~/
 
Again, this INCLUDE is not seen by the compiler. It is not a COBOL verb. The precompiler is run as a separate step before the compiler. The compiler itself does not "see" any DB2, DL/1, or CICS commands.
 
Nobody said it was. It's one thing, among many, that appears in COBOL code.
 
Even a COPY works for the DB2 DCLGEN include, but the best use of an INCLUDE I have come across is if your copy book has EXEC CICS code(copy is expanded only in the COBOL Compile step).
 
Hi everybody

I never come across INCLUDE statement on OS/390 to include a plain COBOL source code. (As discussed above we use it for CICS and DB2 pre-compilers).

But i remember when I used to work on UNISYS A-series machines, we had there COBOL-74 and COBOL-85 versions and this $INCLUDE statement was a standard in my shop. Whenever we need to copy a source from another file we always used $INCLUDE and never COPY. But again this was a precompiler directive for UNISYS COBOL.

The biggest adavntage of INCLUDE in UNISYS COBOL over COPY is you can include a source code which itself has another INCLUDE or COPY statement inside (nested INCLUDE).

As far the performance I remeber INCLUDE was more efficient. Sadly I cannot confirm this statement but if I am correct then in case of INCLUDE the compiler includes the objectcode and not Sourse code. We need to check this on UNISYS site.

After working with almost 2 years on IBM I found that UNISYS has many features which IBM may not support. (At least batch processing mode.)

I dont know or I never tried to include a part of source code (not the entire course code file) on OS/390 cobol. I always used the staement COPY <dataset name>. IS it possible to copy a range (i.e. from say line 200 to 500) of this data set ?? I know this is possible on PC COBOL.

This was a standard feature of UNISYS COBOL. but what was more exciting in UNISYS was one can control which part of the data set to be copied by using condition variables. You can set those condition variables (PRe-compiler directivities) right in your COBOL program and the pre-compiler will include only that part of the copy file which satisfy the conditions. Here is an example

main program...
000300 WORKING-STORAGE SECTION.
000350 77 CTR PIC 9(5) BINARY.
000400$SET INCLSET1
000500$RESET INCLSET2
000600$INCLUDE FILE1
000700...

=====
copy (FILE) FILE1

000100$OMIT NOT INCLSET1
000200 77 SET1_VAR PIC X(03).
000300$POP OMIT
000350 77 CHECK_FLAG PIC X(01).
000400$OMIT NOT INCLSET2
000500 77 SET2_VAR PIC X(03).
000600$POP OMIT

In this case when the precompiler try to include content from FILE1 it will evaluate the PRE-compiler variables.
In main program INCLSET1 is set to TRUE and INCLSET2 is false.

When it reach first line of the FILE it will evaluate the statement $OMIT NOT INCLSET1. Since INCLSET1 is true NOT INCLSET1 will be false so OMIT will be false. So it will include 000200 77 SET1_VAR PIC X(03) statement. When it encouter the statement $POP OMIT it will stop conditional processing and resume normal processing so it will include
000350 77 CHECK_FLAG PIC X(01). Again when it reaches to
000400$OMIT NOT INCLSET2 it will evaluate it. Since INCLSET2 is FALSE this statement will be $OMIT FALSE FALSE or $OMIT TRUE so it will omit everything untill it encouters $POP OMIT. This was a powerful feature. In fact UNISYS has many such precompile directivities which help a lot to simlify your code. That COBOL has a support to DMS2 (UNIsys platform database). And you dont need to include something like a EXEC<->END-EXEC BLOCK for precompiler to identify any DMS2 related statment. There is a built in support for Database and online stuff in UNISYS COBOL compiler.

Looks like I am diverting ....

I hope this information may be useful.

Devesh
 
deveshjogal -

Microfocus COBOL has features similar to the ones you describe. I have used Microfocus COBOL on PCs only, but I know it runs on many other platforms. I believe they have both OS/390 and Unisys versions.

All source code is passed through the integrated pre-compiler before being presented to the compiler. The pre-compiler that comes standard expands copybooks and does conditional processing. You can write your own pre-compiler. Any number of pre-compilers can be invoked for a single compilation.
 
Concerning the earlier reply that stated,

&quot;Again, this INCLUDE is not seen by the compiler. It is not a COBOL verb. The precompiler is run as a separate step before the compiler. The compiler itself does not &quot;see&quot; any DB2, DL/1, or CICS commands.&quot;

Used to be true - not any more. With IBM COBOL for OS/390 & VM (last release) and the latest IBM Enterprise COBOL, it is now possible (not required) to hve the compiler handle (via &quot;invisible to the programmer&quot; access to DB2 and/or CICS) all EXEC statements.

For additional information on this facility (and its advantages over the older preprocesor and translator) see:


and

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top