A copybook contains everything you need to use a module, f. e. prototypes, constants, template variables.
If a service program consists of multiple modules then I create a main copybook which just includes all the copybooks from the modules which are included in the service program.
I use the /if
, /define
, /eof
and /endif
compiler directives to make sure that a copybook only gets included once.
/if defined(STREAM_EMITTER)
/eof
/endif
/define STREAM_EMITTER
//
// here starts the code for the copybook
//
...
If a program consists of multiple modules the other modules need to know how to call the procedures provided by each module. I then create an extra copybook for internal use in the program only, internal.rpginc
. It contains the necessary prototypes, templates and constants needed by the other modules to use the exported procedures.
Example: A web service offers multiple resources/subdomains. I would split up the web service setup from the end points. Each resource would be in a separate module. So there would be
- application module
- resource module A
- resource module B
The procedures from the resource modules would be exported and the prototypes listed in the copybook internal.rpginc
.
Example: A service program consists of multiple modules and some procedures are only exporte inside the service program to be called internally by the other modules.
- module A with public procedures
- module B with public procedures
- module C with internal procedures
The copybook internal.rpginc
would contain the prototypes, templates and constants need for using the internal procedure.