Declare AS400 copybooks
This is how we declare copybook in ILE RPG (RPG IV) program.
Declaring a copybook means declaring its location in the program in the compilation environment.
To declare a copybook we use the compiler directive /COPY. After this we write the name of the copybook.
...+... 1 ...+... 2
*************** Beginning
/COPY QBC
****************** End of
The compiler directive begins at the 7th position. After this, we specify the name of the copybook. In the above example the compiler will look for the copybook in the source file QRPGLESRC. If we have put our copybook QBC in some other source file, generally QCPYLESRC, then we have to specify this as below.
...+... 1 ...+... 2
*************** Beginning
/COPY QCPYLESRC,QBC
****************** End of
Note:- If there are several copies of this copybook in the library list, the first occurrence of copybook will be picked. i.e. if we have copybooks named QBC in three libraries, QTEMP, TUTORIAL01 and TUTORIAL02 and the library lists these libraries in the same order then compiler will pick QBC from QTEMP.
Summary:
- Declaring a copybook means telling the compiler its location.
- On AS400 machine we require three things to uniquely identify a source code. Library, Source Physical File's Name and Member Name
- Library: The first occurrence in the library list.
- Source Physical File's Name: It's declared immediately after the compiler directive /COPY with a blank space.
- Member: This is the actual copybook we are interested in. It's declared after specifying the name of source PF with a comma. Refer the example above for clarification.
Next we will see an example which will further clarify the declaration and usage of Copybooks.
- 4088 reads
