Get the name of load library in COBOL at run time.

OS/VS COBOL, COBOL II, Enterprise COBOL for z/OS. OpenCOBOL and OOCobol.
Post Reply
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Get the name of load library in COBOL at run time.

Post by Sandy »

Hello,

In a COBOL program how can we capture the name of the load library that the program was executed from at run time? Is there way outfor this.

Thanks.
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 826
Joined: Wed Sep 11, 2013 3:57 pm

Re: Get the name of load library in COBOL at run time.

Post by enrico-sorichetti »

what is the business need for it ?
please ... do not answer "that' s the requirement"
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Get the name of load library in COBOL at run time.

Post by William Collins »

I agree with enrico. We'd need to know why. Your audit and compliance people (in a financial site) would be very keen to know why as well.
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Re: Get the name of load library in COBOL at run time.

Post by Sandy »

Actually there is no business need as such but in a system integration testing we have a module available in different libraries. And the setup is like we can't control the execution library as it is outsourced to other vendor. Now the program is producing a wrong output (older) but the load module in the intended library is up to date... we thought if we can know which library the program was executed it will help us to solve the problem.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Get the name of load library in COBOL at run time.

Post by William Collins »

OK, so change the emphasis slightly.

Code: Select all

       WORKING-STORAGE SECTION. 
       01  W-WHEN-COMPILED                     PIC X(8)BX(8).

Code: Select all

       PROCEDURE DIVISION. 
           MOVE WHEN-COMPILED           TO W-WHEN-COMPILED
           DISPLAY "yourprogramname " W-WHEN-COMPILED 
Obviously you do the MOVE/DISPLAY only once in any given program.

This will show you the date/time that the program was compiled (same date/time that appears on compile listing).

If you're concerned about only having a two-digit year (in this case a silly concern) FUNCTION WHEN-COMPILED does it with four-digit years.
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Re: Get the name of load library in COBOL at run time.

Post by Sandy »

Thanks WHEN-COMPILED gives a "timestamp" but does not really tell about the load lib. We can have the code in QA and test with the same day compilation date.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Get the name of load library in COBOL at run time.

Post by William Collins »

If it has the same compilation date/time it does not matter where you run it from. It is the same program, it will produce the same results.

The point of using WHEN=COMPILED is that you know which, compiled, version executed. I thought your problem was one of thinking you were running one thing, but running another.

If you look at the JOBLIB/STEPLIB libraries in order, the first library with that module is the one it will have been loaded from.

How many many datasets do you have on JOBLIB or STEPLIB?
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Re: Get the name of load library in COBOL at run time.

Post by Sandy »

Three or more datasets we have on STEPLIB and similar is the number for JOBLIB. Actually, they have some versions of these libs. I think your indication should work but for knowledge is it possible to know the library name? Perhaps not.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Get the name of load library in COBOL at run time.

Post by William Collins »

You could programatically find the datasetnames from the Control Blocks, and then search them in order. The first dataset you find it on is the one it was loaded from.

The information may be "directly" available somewhere, but if it is I don't know about it.
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Get the name of load library in COBOL at run time.

Post by nicc »

Once you know whether your job-step is using the STEPLIB or the JOBLIB (read the manual) you can easily find which library is being used - tehy are searched in the order coded so start at the top and work down. The first one containing the load module is the one where that load module is loaded from.
Regards
Nic
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Re: Get the name of load library in COBOL at run time.

Post by Sandy »

William Collins wrote:You could programatically find the datasetnames from the Control Blocks, and then search them in order. The first dataset you find it on is the one it was loaded from.

The information may be "directly" available somewhere, but if it is I don't know about it.
Thanks William. I thought it would be easy to cpature the library name but it is not. Reading control block is a tough thing for me.

Thanks for all the help and guidance.
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Re: Get the name of load library in COBOL at run time.

Post by Sandy »

nicc wrote:Once you know whether your job-step is using the STEPLIB or the JOBLIB (read the manual) you can easily find which library is being used - tehy are searched in the order coded so start at the top and work down. The first one containing the load module is the one where that load module is loaded from.
That is right nicc but we have UAT, QA and Test library concatenated. Ideally they all should have the same code once in UAT but once it happened that code was not there and perhaps was in between the transistion from one library to other while the job executed or may be something else. This caused a confusion. To avoid this we thought of picking up the lib name at execution time.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM COBOL, GnuCOBOL (OpenCOBOL), OOCobol.”