Page 1 of 1

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

Posted: Mon Sep 14, 2015 12:13 pm
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.

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

Posted: Mon Sep 14, 2015 1:06 pm
by enrico-sorichetti
what is the business need for it ?
please ... do not answer "that' s the requirement"

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

Posted: Mon Sep 14, 2015 3:58 pm
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.

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

Posted: Tue Sep 15, 2015 1:52 pm
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.

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

Posted: Tue Sep 15, 2015 2:20 pm
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.

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

Posted: Wed Sep 16, 2015 2:58 pm
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.

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

Posted: Wed Sep 16, 2015 4:19 pm
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?

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

Posted: Mon Sep 21, 2015 3:12 pm
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.

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

Posted: Mon Sep 21, 2015 3:20 pm
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.

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

Posted: Mon Sep 21, 2015 5:41 pm
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.

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

Posted: Tue Sep 22, 2015 2:12 pm
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.

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

Posted: Tue Sep 22, 2015 2:15 pm
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.