Skip to content

Commit a9377a5

Browse files
committed
Add chapter on copybooks
Signed-off-by: Hartanto Ario Widjaya <[email protected]>
1 parent ea72535 commit a9377a5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

COBOL Programming Course #1 - Getting Started/COBOL Programming Course #1 - Getting Started.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,8 @@ In this chapter we discuss the concept of structured programming and how it rela
26192619

26202620
- **Specifying the return value**
26212621

2622+
- **Using copybooks**
2623+
26222624
- **Summary**
26232625
- **Lab**
26242626

@@ -3094,6 +3096,42 @@ You might also see the phrase, BY VALUE, being used in a CALL sentence. BY VALU
30943096

30953097
Finally, the RETURNING phrase is used to specify the variable that should be used to store the return value. This can be any elementary data-item declared within the data-division. Note that this is optional. Some programs might not return anything, or you might have passed values BY REFERENCE to the target program in which case updates to those variables will be visible once the target program returns.
30963098

3099+
## Using copybooks
3100+
3101+
If your program contains frequently used code sequences, we can write the code sequence once and put them in a COBOL copy library. These code sequences are referred to as copybooks. Then, we can use the COPY statement to retrieve these code sequences and include them during compile time. Using copybooks in this manner will eliminate repetitive coding.
3102+
3103+
We would need to specify a copy library in the JCL we used. If you are using the provided procedure (IGYWC, IGYWCL or IGYWCLG), you can supply a DD statement to the SYSLIB parameter of the COBOL step inside the procedure. For example:
3104+
3105+
```
3106+
//COBOL.SYSLIB DD DISP=SHR,DSN=Z99998.COPYLIB
3107+
```
3108+
*Example 21. JCL SYSLIB statement*
3109+
3110+
This will tell the compiler to look for the copybooks on the supplied dataset.
3111+
3112+
Let us take a look at an example of how we can use the COPY statement in a program.
3113+
3114+
Assume that a copybook with the name of DOWORK is stored and contains the following statement:
3115+
```
3116+
COMPUTE SPACE-AVAILABLE = TOTAL-FREE-SPACE
3117+
MOVE SPACE-AVAILABLE TO PRINT-SPACE
3118+
```
3119+
*Example 22. Content of DOWORK copybook*
3120+
3121+
We can retrieve the copybook by utilizing the COPY statement:
3122+
```
3123+
PROCEDURE DIVISION.
3124+
...
3125+
DISPLAY "RETRIEVE COPYBOOK".
3126+
COPY DOWORK.
3127+
```
3128+
*Example 23. Basic COPY*
3129+
3130+
The statements inside the DOWORK procedure will then follows the DISPLAY statement.
3131+
3132+
Unlike subprograms, using copybooks does not transfer control over to another program. But the code written inside the copybooks will only be transferred once during compilation. So further changes to the copybooks will require a recompilation of the program.
3133+
3134+
On the other hand, the code inside a subprogram will only be invoked during the execution of the program. Therefore, assuming that the subprogram is linked dynamically, we can change it without needing to recompile the calling program.
30973135

30983136
## Summary
30993137

0 commit comments

Comments
 (0)