Extract the line number to a variable



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Extract the line number to a variable

Postby RalphEagle » Thu Nov 14, 2019 6:46 pm

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,
RalphEagle
 
Posts: 24
Joined: Mon Apr 23, 2018 2:51 pm
Has thanked: 17 times
Been thanked: 0 time

Re: Extract the line number to a variable

Postby Robert Sample » Thu Nov 14, 2019 11:21 pm

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?

These users thanked the author Robert Sample for the post:
RalphEagle (Fri Nov 15, 2019 12:00 pm)
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Extract the line number to a variable

Postby steve-myers » Fri Nov 15, 2019 7:36 am

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.

These users thanked the author steve-myers for the post:
RalphEagle (Fri Nov 15, 2019 12:00 pm)
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Extract the line number to a variable

Postby RalphEagle » Fri Nov 15, 2019 12:03 pm

Thank you Robert, Steve, I now understand that by its core implementation, it's not really feasible.
RalphEagle
 
Posts: 24
Joined: Mon Apr 23, 2018 2:51 pm
Has thanked: 17 times
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post