Page 1 of 1

What is difference between copy book and sub-program?

Posted: Sat Nov 14, 2015 1:23 pm
by ajinkya123
This question was strange for me. I have never thought that this can be a question...question was, What is difference between copy book and sub-program? When they can serve the nearly similar feature?

Re: What is difference between copy book and sub-program?

Posted: Sat Nov 14, 2015 8:01 pm
by Robert Sample
A copy book brings code into the program at COMPILE time. Hence, it is done once when the compile is done and that's it. A subprogram, on the other hand, is invoked at EXECUTION time and hence can be done many times (each time the program executes). Furthermore, a change to the copy book requires a recompile of the program (and possibly many other programs as well). If the subprogram is linked dynamically, it can be changed without causing a recompile of the calling program.

Code in a copy book (yes, copy books can contain code as well as data structures) could be placed in a subprogram. If the code can be executed at multiple points in a program, use a subprogram. If the code exists only once in the program (but will be used in several programs), use a copy book.