Source Copybooks
What are RPG COPYBOOKS anyway?
Copybooks are a very simple way of reproducing the same code into many programs: a copybook is a source member containing a section of code that can be inserted/copied into any other source member at compilation time. The main idea behind RPG Copybooks is reusability.
Think of a copybook as a source member that contains a common re-usable code component that that you dont want to compile but want to include in the actual programs that use it at compile time.
Copybooks were frequently used back in the day as a fast alternative to having a common program that every other program called. A classic example may be definition for a system wide *LDA structure. Just think, all your programs in a given application will be defining certain parts of the *LDA, or program status data structure, or *PSSR routine or just about anything - all with the same field names, in every program written within that application.
COPYBOOKS make it simple to write a bit of code in a source member and then have all the other programs referencing it and sucking in that code at compile time.
For example - Here is a copybook of a PSDS
0001.00 * sample copysrc member called QGPL/COPY(PSDS) - program status data structure 0002.00 D SDS 0003.00 DSx4PROG 1 10 Program Name 0004.00 DSx4STAT 11 15 status code 0005.00 DSx4SEQ# 21 28 rpg stat number 0006.00 DSx4RTN 29 36 rpg routine 0007.00 DSx4PARM 37 39 number of params 0008.00 DSx4CERR 40 46 cpf/mch error cod 0009.00 DSx4PLIB 81 90 program library
So this little code snippet is defining some areas of the program status data structure which could in turn be used by every other program on the system. Rather than reproduce this code everywhere it's simply coded into its own unique source member (generally called something like COPYBOOK for no other reason that to differentiate it from the normal QRPGSRC, QRPGLESRC, etc.. etc..) and can then be referenced from any RPG program on the system by inserting a line in the code that looks like this:
0094.00 * Fetch external description of PSDS 0095.00 /COPY QGPL/COPY,PSDS 0098.00 * ---------------------------------------------------
SImple huh?
When the program is compiled the compiler will suck the copybook source code into that point in the program and compile it as if you had typed it in yourself.
If you make a change to your copybook - you simply recompile all programs using it to update them.
Current weather
Roanoke, Virginia USA
- Overcast
- Temperature: 57.2 °F
- Wind: West, 4.6 mph
- Pressure: 996 hPa
- Rel. Humidity: 59 %
- Visibility: 10 mi
Sat, 03/13/2010 - 11:54
Bunch of Twits
- adds 'Thievery Corporation' to his list of groovey background music to play while programming :) — 1 day 2 hours ago
- is watching very serious blokes playing plastic darts.... wtf is that all about? — 1 day 16 hours ago
- has discovered that his mighty hammer Mjölnir is missing. — 4 days 4 hours ago
- grabs a coffee and settles down for a day of post implementation checks, project closure and user documentation... bah! — 5 days 4 hours ago
- is about to embark on an IHOP pancake eating frenzy with the sprogs... — 6 days 4 hours ago
- just watching tv, a female marine running up a beach, teagan says 'i hope shes not wearing heels because thats hard' ;) — 6 days 16 hours ago
- saturday morning, determined to do no work today just gonna hang out with the kids, walk the mutts, watch movies and vejjjjjj... hurrah! — 1 week 1 hour ago
- is al about rpg3, rpg4, php, asp, IBMi, html, xml, wsdl's and any other acronyms I can think of.... — 1 week 1 day ago
- is pretending to type something important to avoid listening to someone talking a load of codswallop. — 1 week 1 day ago
- see... DOTnetnuke.... Microsoft products make my brain shout 'Uncle!' — 1 week 3 days ago
- 1 of 8
- ››

Recent comments
1 week 2 days ago
4 weeks 10 hours ago
9 weeks 19 hours ago
9 weeks 3 days ago
9 weeks 3 days ago
22 weeks 4 days ago
36 weeks 4 days ago
38 weeks 3 days ago
39 weeks 3 days ago
39 weeks 3 days ago