Midrange News for the IBM i Community


Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Chicagoland
Name of this CL Program's Library?
has no ratings.
Published: 16 Dec 2011
Revised: 19 Feb 2014 - 3712 days ago
Last viewed on: 19 Apr 2024 (6750 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Name of this CL Program's Library? Published by: Bob Cozzi on 16 Dec 2011 view comments(6)

Are you kidding me? In 2011 I can't retrieve the name of the library from which "this" CL program is running? I know we can use the snd/rcv msg CL commands to find out the runtime CL program name, but I assumed the library name was in there too. Especially since they added a *SHORT/*LONG option to the RCVMSG command for the Sender data, but it is not.

Yikes!

What I want to be able to do is to avoid processing the library name of the library that the CL program is running from. Specifically I'm working on a migration routine and when I do a restore on the other system, I don't want to restore the migration tools library, as that would be bad. 

What I need to do is retrieve the runtime library from which the CL program is running, and avoid restoring that library. Sure I can restrict the user to running it out of the install library, but hey, why would I do that?

Darn! 

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: BrianR
Premium member *
Green Bay, WI
Comment on: Name of this CL Program's Library?
Posted: 12 years 4 months 5 days 9 hours 4 minutes ago
Edited: Fri, 16 Dec, 2011 at 11:27:29 (4508 days ago)

If the runtime library is in the library list, you could use RTVOBJD OBJ(*LIBL/pgmname) RTNLIB(&libname).

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Name of this CL Program's Library?
Posted: 12 years 4 months 5 days 8 hours 38 minutes ago
Edited: Fri, 16 Dec, 2011 at 11:57:40 (4508 days ago)

Hi Brian,

Thanks; I am doing that, but that does not guarantee that the library is for "this" program, only the one on the library list.

I've put in a request to add figurative constants to CL, so that we could do this:

DCL &LIB TYPE(*CHAR) LEN(10) VALUE(*LIB)

But IBM's response was "Great idea, but you probably won't live long enough to see it."

If IBM i shops would still be in the spend a few bucks mood, I'd probably spend time writing some of these missing commands. But except for Jim Sloan's TAA Tools, they don't seem to be willing to spend the bucks.

Posted by: DaleB
Premium member *
Reading, PA
Comment on: Name of this CL Program's Library?
Posted: 12 years 4 months 1 days 11 hours 45 minutes ago

More work, obviously, but there's the Retrieve Call Stack (QWVRCSTK) API...

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Name of this CL Program's Library?
Posted: 12 years 4 months 1 days 9 hours 46 minutes ago

I know Dale. That's what I was hoping to avoid.

I was thinking there might be a way to generate a message and then retrieve the sender/receiver information or even somehow get the "F9" information--but no. Yell

Posted by: jomocox
Premium member *
Comment on: Name of this CL Program's Library?
Posted: 10 years 2 months 1 days 4 hours 19 minutes ago

I found this to be very helpful.  It shows how to retrieve your CL program's name AND Library.

http://www.lisug.org/Tips/TIP6_Retrieve_PGM_Name.pdf

 

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Name of this CL Program's Library?
Posted: 10 years 2 months 1 days 2 hours 49 minutes ago

Very cool Joanne, thanks! I've updated the example for explicit declarations and it works. Only issue is this should be a built-in function in both RPG and CL.

 TESTGETNM:  PGM
             DCL        VAR(&MATPGNM_T) TYPE(*CHAR) LEN(100)
             DCL        VAR(&TEMPL_SIZE) TYPE(*INT) STG(*DEFINED) +
                          LEN(4) DEFVAR(&MATPGNM_T 1)
             DCL        VAR(&BYTES_USED) TYPE(*INT) STG(*DEFINED) +
                          LEN(4) DEFVAR(&MATPGNM_T 5)
             DCL        VAR(&FORMAT) TYPE(*INT) STG(*DEFINED) +
                          LEN(4) DEFVAR(&MATPGNM_T 9)
             DCL        VAR(&RESERVED) TYPE(*CHAR) STG(*DEFINED) +
                          LEN(4) DEFVAR(&MATPGNM_T 13)
             DCL        VAR(&LIBTYPE) TYPE(*UINT) STG(*DEFINED) +
                          LEN(2) DEFVAR(&MATPGNM_T 17)
             DCL        VAR(&LIBNAME) TYPE(*CHAR) STG(*DEFINED) +
                          LEN(30) DEFVAR(&MATPGNM_T 19)
             DCL        VAR(&PGMTYPE) TYPE(*UINT) STG(*DEFINED) +
                          LEN(2) DEFVAR(&MATPGNM_T 49)
             DCL        VAR(&PGMNAME) TYPE(*CHAR) STG(*DEFINED) +
                          LEN(30) DEFVAR(&MATPGNM_T 51)
             CLREPEAT   VAR(&MATPGNM_T) VALUE(X'00')
             CHGVAR     VAR(&TEMPL_SIZE) VALUE(80)
             CHGVAR     VAR(&BYTES_USED) VALUE(80)
             CHGVAR     VAR(&FORMAT) VALUE(0)

             CALLPRC    PRC('_MATPGMNM') PARM((&MATPGNM_T))
             SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) +
                          MSGDTA('Program' *BCAT %SST(&PGMNAME 1 +
                          10) *BCAT 'in library' *BCAT +
                          %SST(&LIBNAME 1 10))
 ENDPGM:     ENDPGM