Wednesday, February 13, 2008

The COBOL Compiler – The hidden benefits

As programmers, all of us have the responsibility of removing non-executable (“dead code”) from the COBOL programs. Even though non-executable code does not affect processing, it still takes up DASD space, and clutters the program with paragraphs that are never going to get executed. This also causes confusion to others who are trying to debug the program or make changes to the program. If you are wondering, how you can find out which paragraphs and lines are code are not getting executed in a program that runs into thousands of lines, then this article is for you.

As we all know every COBOL program, when compiled, produces a compile output. The compile output shows a list of the severe errors, warnings and informational messages in your program. Severe errors terminate the compilation and throw a Return Code RC=12. Warnings and Informational messages throw a Return Code RC=4, and proceeds to link-edit and generates a successfully compiled and executable code.

So, how can we identify non-executable code in a program?

The easiest way would be to look at the end of the COBOL compile listing for the IGYOP3091-W message. The message looks similar to the one shown below.

15147 IGYOP3091-W Code from "procedure name 01000-UPDATE-DATABASES" to "
to "EXIT (line 15299.01)" can never be executed and was
therefore discarded.


The message tells you the lines of code that are never going to be executed. As you can see, the code between the lines 15147 and 15299 (over 150 lines!) is never going to be executed, and you can safely delete these lines from your program. You can be proud of yourself for saving valuable DASD space.

Have you ever had to solve a production abend caused by an infinite execution of a paragraph? Have you wondered whether there is an easy way to find out if certain paragraphs could cause infinite looping?

If you answered yes, the answer is again in the COBOL compiler output. During compilation, the compiler detects paragraphs that can cause a potential repetitive looping. Look for the warning message IGYOP3094-W similar to the one below:

60707 IGYOP3094-W There may be a loop from the "PERFORM" statement at
"PERFORM (line 60707.01)" to itself. "PERFORM" statement
optimization was not attempted.

The compiler is attempting to warn you that you may be trying to execute the PERFORM statement (in line 60707) from within the same paragraph, thereby causing a potential looping situation. This requires a closer look at the lines in and around the lines mentioned in the compile listing to see if there is a looping situation.

I could go on and on about the beauty of the COBOL compiler. The above two cases are just a fraction of what the COBOL compiler can does for you.

So, the next time your COBOL compilation ends successfully with a RC=4, don’t just stop. Take a closer look at all the warnings generated by the compiler. You might save yourself a phone call in the middle of the night!

Happy compiling!
If you want additional information, or would like to see specific topics to be covered, please contact me via email at pkganapathi@yahoo.com.

No comments: