Concept of Copybook | How the compiler processes copybooks
On the first page itself you must have noticed "compiler" popping up in the article several times. This is because everything related to copybook happens at the compile time, and only at the compile time.
Copybook processing:-
This is how a copybook is processed.
- You create an RPGLE source for a copybook.
- You tell its location in main RPGLE source using compiler directive /COPY or /INCLUDE(We will learn later about it).
- When you compile the main source, the compiler will look for the copybook in the location specified.
- If compiler does not find it, it will list an error in the spool file.
- If it finds the copybook, it will copy its entire source code* at the place we specified the /COPY directive.
- Compiler will now compile the main source based on the new source.
- Once a program or module object is successfully created, The Compiler or the AS400 system does not require the copybook in the same way as they do not require the main source file.
- To make the point clear, there won't be any problem if you delete the copybook after creating a program or module object!
* - If we are using conditional copying of sources, then only that block of RPGLE source is copied which satisfies the copying condition. We will learn about this later.
So, on the basis of concept just learned you can
- Write several /copy directives.
- Copy several copybooks in a single source code.
- Use /copy directive anywhere in source code. Be it definition, initialization, procedure, subroutine... anywhere! Just make sure that the HFDC and PDCP rule does not break. i.e. the specifications are in proper order.
Now, in the next section we will learn
- 2060 reads
