Mainframes 360
The one stop destination for System Z professionals

Sunday, June 24, 2012

COBOL Copy-book Expansion tool XP in Rexx

Q. What is a copy-book in COBOL?
On Mainframe systems, a Copybook is a reusable code-snippet, that may be inserted into several different programs. Copybooks are separate files, generally containing COBOL variable declarations(record layouts) or procedural code(COBOL Statements like MOVE, ADD etc). For example, you may create a COBOL Copy-book A.


Now to insert this code in your program(s), you merely code the COPY statement in COBOL Program.


At compile-time, any references to these external copy-books are resolved. In other words, the COBOL compiler substitutes the copy-book code in your COBOL Program. What the COBOL compiler would do is expand this copybook inline.


If you took up the C programming course as one of your subjects, while you were in college, its easy to realise - COBOL copy-books work just like include <stdio.h> Header files statement in C.
Q. What does the copybook expansion utility XP do?
On analysing COBOL Programs, you often encounter variables in COBOL code, that aren't declared in the the program-source itself, rather in a separate external Cobol copy-book. At times, you may want to look at the definition of the variable – the PICTURE Clause, or the 88-Level values it can take. If the variable is a Group data-item, you might be interested to know its break-up, the 05- and 10- Level data-items under it.

Most COBOL Programs that run in the Production environment, typically refer to several external copy-books. Copybooks may reside in different libraries, based on your Mainframe shop standards. For large programs referring to several copy-books, an average programmer spends a good deal of time (i) navigating to the copy-book library, (ii)locating the desired copy-book, and then viewing it.

The XP Macro written by me, expands the COBOL copy-books in a program in-line, by searching them in user-specified libraries.
Q. Sounds interesting, but what are the features of this product? Does it have any limitations?
1. Currently, I have added support for upto 5 user-specified libraries.
2. The XP Macro properly ignores comment-lines. A commented COPY Statement will not be expanded.
3. Shows the copy-book expansion progress in real-time.
4. It has been tested with the version-management tool Changeman.

1. Does not support the REPLACING ALL option of the COPY Statement yet.
2. No checking in place, to ensure if the user-specified library is valid. I am working on this.
Q. How do I use the Cobol copybook expansion tool XP?

1. Open your COBOL Program in the ISPF Editor.


2. Type XP on the Command line in the ISPF Editor.


3. Enter the copy-book library, you would like to search in, for the copy-books.


4. Pause while all the copy-books are expanded, and wait for it to complete.


5. The expanded output appears like this -


Q. How do I install XP Utility at my Mainframe shop?
To install and use the XP utility, you need to copy over the Rexx Source-code and the panels to your SYSPROC and ISPPLIB Libraries.

Rexx Source
XPPAN01 Panel

XPPAN02 Panel

COBOL Code Tagger in Rexx

Q. What is the role of Modification Tags in a COBOL Program?

In a Mainframe environment, changes done to program source-code should be well-documented. This makes the source-code easier to understand.

Most COBOL Programs have a Modification Log. The Modification-Log is not executable source code, rather it is a block of comments. It is a the list of all changes(modifications) done to the program, in chronological order. A description of the change in about two-to-three lines, the date of the change and the author(programmer) is also mentioned. The Modification Log helps you track all changes done to program, right from its inception, to-date, its like the program’s diary(log).

Each entry in the Modification Log has a tag, to identify it. This tag forms its unique identity. The practise adopted by Mainframe programmers is to supply a tag for all the lines of source-code they modify, and then add an entry to Modification Log, under the same tag, thus providing a brief description of their change.

Here's a picture of the Modification log in one of my programs.


Have a look at the illustration below on, how the same modification tag QC3962 is used to highlight the modified lines of code.


Q. What does COBOL Code Tagger do?

Several people have asked for a way to automatically add a tag, and flag each changed line in an ISPF Edit Session.

The COBOL Code Tagger is an Edit Macro that runs SuperC against the original dataset and adds tags in a user-specified column. After the tagging is complete, you are shown the lines to which flags have been added. You’ll probably need to change it to meet your needs, but it should be a reasonable starting point.

Q. How do I use the COBOL Code Tagger?

It is very easy to use the COBOL Code Tagger. In the ISPF Editor, while editing a COBOL Program, merely type TAG <tag-name> <start-column> to add tags to all lines you have changed.

I type the command TAG QC0624 01 to tag all the lines I have modified, in this COBOL Program with QC0610, beginning from Column Position=01.


On pressing ENTER, the Macro tags the lines, you modified in this EDIT Session.


Q. How to install the TAG Macro at my Mainframe shop?
You can get the source code for the TAG Edit Macro here. You must copy the code to one of your SYSPROC or SYSEXEC Concatenations at your Mainframe shop.

In case you do not know about the SYSPROC or SYSEXEC concatenations at your site, just type TSO ISRDDN Command on ISPF.


The TSO ISRDDN command shows the active DDNames and the libraries allocated to them. At my shop, I put the TAG Rexx source code under the common //SYSPROC Library USER.CLIST. Like-wise, you must copy TAG's Rexx source code to one of the SYSPROC or SYSEXEC libraries.


To many people who are thrown to work at a mainframe computer on their first job, they feel lost. Mainframe people seem to speak a completely different language and that doesn't make life easy. What's more, the books and manuals are incredibly hard to comprehend.

"What on earth is a Mainframe?" is an absolute beginner's guide to mainframe computers. We'll introduce you to the hardware and peripherals. We'll talk about the operating system, the software installed on a mainframe. We'll also talk about the different people who work on a mainframe. In a nutshell, we'll de-mystify the mainframe.

Readers based in India, can buy the e-book for Rs. 50 only or the print book. International readers based in the US and other countries can click here to purchase the e-book.