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.
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!
If the runtime library is in the library list, you could use RTVOBJD OBJ(*LIBL/pgmname) RTNLIB(&libname).
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.
More work, obviously, but there's the Retrieve Call Stack (QWVRCSTK) API...
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.
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
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