COBOL debugger tip

14 Aug

OK, so you’ve written your COBOL program with a copious amount of code that you pulled off the top of your head.  And now you execute the program, but the results are not what you were expecting.    What to do?  Using a COBOL debugger, you can step through your program execution, one line at time, and actually see what is happening every step of the way.  It was at my current job that I was introduced to this wonderful tool.  Way back in the 80’s and 90’s I “debugged” my programs by adding multiple displays to my code.   That did work, but was not nearly as efficient as a functional debugger.

I work daily with data files containing more than a million variable length records, so here’s a great tip for setting a breakpoint when you’re looking for a particular record.  You certainly aren’t going to “step through” thousands of records looking for one problem child.  Let’s say, for example, that you know that somewhere in your huge data file is a record in which the first 17 characters contain the string “FIRST17CHARACTERS”. Here’s a trick to make your debugger stop when it finds that record, so you can start “stepping through” your code at that point.

            GO TO ALL-DONE.
           STOP "RIGHT HERE".

Adding the “IF” statement shown above immediately after your “READ” statement will cause your program to stop when it finds the record you’re looking for, allowing you to monitor program execution from that point forward.  This will save you a great deal of time and frustration, which will make you more productive, and your boss much happier.  (Remember to remove the “IF” statement and recompile the program before moving it to a production environment).

Since debugger execution and commands are native to the proprietary version of COBOL you’re using, you’ll need to consult the documentation of your particular compiler to learn the details of how to use your debugger.   Believe me, it will be time well spent.


Leave a Reply

Your email address will not be published. Required fields are marked *