Page 1 of 1

Extract the line number to a variable

PostPosted: Thu Nov 14, 2019 6:46 pm
by RalphEagle
Hi all,

When we have a CICS abend, we sometimes log customized information in a DB2 table. A colleague suggested that we add the line number where the error happened to the log information.

I found it a very useful suggestion, as it's ubiquitous for some other langages when it reaches an error...

Now, is there a way one could extract the current line number of a program to a variable in a Cobol program ? Some LE magic, maybe ?

Thank you for your help,

Re: Extract the line number to a variable

PostPosted: Thu Nov 14, 2019 11:21 pm
by Robert Sample
Generally speaking, it is not possible for an executing COBOL program to extract its own source line numbers. This is because the load module does not have any place for the source line number. Furthermore, depending upon the optimization level you compile with, the code that gets executed may be in a very different spot than the source line(s).
I found it a very useful suggestion, as it's ubiquitous for some other langages when it reaches an error...
But those other languages were not developed in the 1950's, were they?

Re: Extract the line number to a variable

PostPosted: Fri Nov 15, 2019 7:36 am
by steve-myers
Languages that are basically interpreted languages - Rexx, for example, and I can think of a popular facility in the *nix world, though I cannot recall its name - can readily produce a line number in the event the interpreter detects a problem. Compiled languages, such as Cobol, especially at higher optimization levels, have a much more difficult time producing a line number as the compiler moves elements of the program around to improve the code's run time.

Re: Extract the line number to a variable

PostPosted: Fri Nov 15, 2019 12:03 pm
by RalphEagle
Thank you Robert, Steve, I now understand that by its core implementation, it's not really feasible.