Tim,
Perhaps the following sources may help you. You can retrieve the
commands later udsing F9 on the command line as well.
Regards,
Carel Teijgeler
/*
**************************************************************************
*/
/* To compile: */
/*
*/
/* CRTCMD CMD(QGPL/EXCCMD) PGM(QGPL/EXCCMD)
*/
/*
*/
/*
**************************************************************************
*/
CMD PROMPT('Execute a command')
PARM KWD(CMD) TYPE(*CHAR) LEN(3000) MIN(1) +
EXPR(*YES) VARY(*YES) PROMPT('Source +
command string')
PARM KWD(PROCES) TYPE(*DEC) LEN(4 0) RSTD(*YES) +
DFT(*RUN) SPCVAL((*RUN 0) (*CHECK 1) +
(*LINERUN 2) (*LINECHECK 3) (*CLSTM 4) +
(*CLINPUT 5) (*CMDSTM 6) (*BINDER 7) +
(*USRDFN 8) (*ILECL 9)) CHOICE('F4 voor +
lijst') PROMPT('Type of command processing')
PARM KWD(PROMPT) TYPE(*CHAR) LEN(1) RSTD(*YES) +
DFT(*SELECT) SPCVAL((*ALWAYS 1) (*NEVER +
0) (*SELECT 2) (*HELP 3)) CHOICE('F4 voor +
lijst') PROMPT('Prompter action')
PARM KWD(LOG) TYPE(*LGL) RSTD(*YES) DFT(*NO) +
SPCVAL((*YES '1') (*NO '0')) +
PROMPT('Log command')
PARM KWD(OPTION) TYPE(*CHAR) LEN(7) RSTD(*YES) +
DFT(*NEVER) VALUES(*AFTER *BEFORE *NEVER) +
PMTCTL(LOGGING) PROMPT('When to log')
LOGGING: PMTCTL CTL(LOG) COND((*EQ '1'))
EXCCMD-CMD2.txt
/*
**************************************************************************
*/
/* To compile: */
/*
*/
/* CRTCMD CMD(QGPL/EXCCMDSTR) PGM(QGPL/EXCCMD)
*/
/*
*/
/*
**************************************************************************
*/
CMD PROMPT('Execute a command')
PARM KWD(CMD) TYPE(*CMDSTR) LEN(3000) MIN(1) +
VARY(*YES) PROMPT('Source command string')
PARM KWD(PROCES) TYPE(*DEC) LEN(4 0) RSTD(*YES) +
DFT(*RUN) SPCVAL((*RUN 0) (*CHECK 1) +
(*LINERUN 2) (*LINECHECK 3) (*CLSTM 4) +
(*CLINPUT 5) (*CMDSTM 6) (*BINDER 7) +
(*USRDFN 8) (*ILECL 9)) CHOICE('F4 voor +
lijst') PROMPT('Type of command processing')
PARM KWD(PROMPT) TYPE(*CHAR) LEN(1) RSTD(*YES) +
DFT(*NEVER) SPCVAL((*ALWAYS 1) (*NEVER 0) +
(*SELECT 2) (*HELP 3)) CHOICE('F4 voor +
lijst') PROMPT('Prompter action')
PARM KWD(LOG) TYPE(*LGL) RSTD(*YES) DFT(*NO) +
SPCVAL((*YES '1') (*NO '0')) +
PROMPT('Log command')
PARM KWD(OPTION) TYPE(*CHAR) LEN(7) RSTD(*YES) +
DFT(*NEVER) VALUES(*AFTER *BEFORE *NEVER) +
PMTCTL(LOGGING) PROMPT('When to log')
LOGGING: PMTCTL CTL(LOG) COND((*EQ '1'))
EXCCMD-CLP.txt
/*
**************************************************************************
*/
/* To compile: */
/*
*/
/* CRTCLPGM PGM(QGPL/EXCCMD)
*/
/*
*/
/*
**************************************************************************
*/
PGM PARM(&CMD &PROCES &PROMPT &LOG &OPTION)
INPUT: DCL VAR(&CMD) TYPE(*CHAR) LEN(3002)
DCL VAR(&PROCES) TYPE(*DEC) LEN(4 0)
DCL VAR(&PROMPT) TYPE(*CHAR) LEN(1)
DCL VAR(&LOG) TYPE(*LGL)
DCL VAR(&OPTION) TYPE(*CHAR) LEN(7)
JOB: DCL VAR(&SRCCMD) TYPE(*CHAR) LEN(3000)
DCL VAR(&SRCCMDLEN) TYPE(*CHAR) LEN(4)
DCL VAR(&OPTCTL) TYPE(*CHAR) LEN(20)
DCL VAR(&OPTCTLLEN) TYPE(*CHAR) LEN(4)
DCL VAR(&OPTCTLFMT) TYPE(*CHAR) LEN(8) +
VALUE('CPOP0100')
DCL VAR(&RTNCMD) TYPE(*CHAR) LEN(6000)
DCL VAR(&RTNCMDAVL) TYPE(*CHAR) LEN(4)
DCL VAR(&RTNCMDLEN) TYPE(*CHAR) LEN(4)
DCL VAR(&APIERR) TYPE(*CHAR) LEN(4) +
VALUE(X'00000000')
DCL VAR(&SRCLEN) TYPE(*DEC) LEN(4 0)
DCL VAR(&TYPE) TYPE(*CHAR) LEN(4)
DCL VAR(&DBCS) TYPE(*CHAR) LEN(1) VALUE('0')
DCL VAR(&SYNTAX) TYPE(*CHAR) LEN(1) VALUE('0')
DCL VAR(&MSGKEY) TYPE(*CHAR) LEN(4)
DCL VAR(&RESERVE) TYPE(*CHAR) LEN(9) +
VALUE(X'000000000000000000')
FOUTJE: DCL VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(128)
DCL VAR(&MSGF) TYPE(*CHAR) LEN(10)
DCL VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&KEYVAR) TYPE(*CHAR) LEN(4)
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))
CHGVAR VAR(&SRCCMD) VALUE(%SST(&CMD 3 3000))
CHGVAR VAR(&SRCLEN) VALUE(%BIN(&CMD 1 2))
IF COND(&LOG *EQ '1' *AND &OPTION = '*BEFORE') +
THEN(DO)
SNDPGMMSG MSG(&SRCCMD) TOPGMQ(*EXT) MSGTYPE(*RQS) +
KEYVAR(&MSGKEY)
RCVMSG PGMQ(*EXT) MSGKEY(&MSGKEY) RMV(*NO)
ENDDO
CHGVAR VAR(%BIN(&SRCCMDLEN)) VALUE(&SRCLEN)
CHGVAR VAR(%BIN(&TYPE)) VALUE(&PROCES)
CHGVAR VAR(%BIN(&OPTCTLLEN)) VALUE(20)
CHGVAR VAR(%BIN(&RTNCMDAVL)) VALUE(6000)
CHGVAR VAR(&OPTCTL) VALUE(&TYPE *CAT &DBCS *CAT +
&PROMPT *CAT &SYNTAX *CAT &MSGKEY *CAT +
&RESERVE)
CALL PGM(QCAPCMD) PARM(&SRCCMD &SRCCMDLEN &OPTCTL +
&OPTCTLLEN &OPTCTLFMT &RTNCMD &RTNCMDAVL +
&RTNCMDLEN &APIERR)
/*
************************************************************************* */
/* ERROR HANDLING
*/
/*
************************************************************************* */
ERROR: RCVMSG MSGTYPE(*DIAG) KEYVAR(&KEYVAR) +
MSGDTA(&MSGDTA) MSGID(&MSGID) MSGF(&MSGF) +
MSGFLIB(&MSGFLIB)
IF COND(&MSGID *NE ' ') THEN(DO)
SNDPGMMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +
MSGDTA(&MSGDTA) MSGTYPE(*ESCAPE) +
KEYVAR(&KEYVAR)
MONMSG MSGID(CPF0000)
ENDDO
ELSE CMD(DO)
IF COND(&LOG *EQ '1' *AND &OPTION = '*AFTER') +
THEN(DO)
SNDPGMMSG MSG(&RTNCMD) TOPGMQ(*EXT) MSGTYPE(*RQS) +
KEYVAR(&MSGKEY)
RCVMSG PGMQ(*EXT) MSGKEY(&MSGKEY) RMV(*NO)
ENDDO
ENDDO
ENDPGM
On 28-2-2013 12:00, Tim Bronski wrote:
Thanks for the info Chuck. I'll take it as a confirmation that there
isn't an easy way to do this - or that the easy way is to rebuild the
command string from the parameters I'm passed.
I was hoping for
On 2/27/2013 10:00 PM, CRPence wrote:
On 27 Feb 2013 01:40, Tim Bronski wrote:
I'm trying to retrieve the actual command string of the the command
that was used to invoke my program - the CPP. Using QMHRCVPM or
RCVMSG I can retrieve the request message with the command string in
the message data but ONLY if the command is entered on a command
line.
The /command line/ is a request processor. The MSGTYPE(*LAST)
received from the request processor will locate the /request message/
that invoked your program. No mention is made if that is how "I can
retrieve" currently;;; Hmmm... just checked, and a later message in the
thread seems to imply that the following request is being used:
rcvmsg pgmq(*prv) msgq(*pgmq) msgtype(*last) rtntype(&rt) msg(&msg)
If the command was invoked from a CLP there's nothing there.
If using MSGTYPE(*LAST) for the CL program that invoked your program,
then that is correct. The invoking CLP did not send a message to effect
the request, nor is there officially a request message in its program
message queue, because the program is not a request processor.
I've looked up and down the stack. It's obviously around somewhere and
I could have sworn I've done this before.
If logging CLP is off [i.e. LOGCLPGM(*NO)], then no message is
logged. If the logging for CLP is active, then the request message
appears to be logged to the program message queue of the CLP; i.e. in
DSPJOBLOG, the request will be visible with an /apparent/ program
message queue of the CLP as invoker, sent from QCLCLCPR, as seen by
F9=Message Details.
I do not think I ever learned how to receive that message from the
*PGMQ of that CLP, thus why I say "apparent" in the above. But I do
know that the logged request message can be obtained by a [decremented]
key value, using the same technique used to obtain messages from
programs no longer on the stack. Of course if CL logging was off for
that request, then the request message eventually found using that
technique, may not be the one actually being sought, and that could
waste lots of resources having tried to learn that. I could code up and
post an example if you want.
Anyone know what the difference is between the way a command is
processed in these two scenarios and where I might find my command?
I recall dealing with a similar question, soon after I first started
learning CL. I do not recall exactly what I had been trying to do at
the time; why I thought I needed that information. But IIRC, I ended up
[learning how to, and then] coding a request processing program to deal
with my issue.... because as alluded above, the difference is that in
one case the prior invoker is the Request Processing Program, and in the
other case the prior invoker is the CL run-time for the compiled CLP.
Several years later, when I learned about getting messages from
inactive program message queues, I noticed that the request messages
were being processed. Thus how I learned\know that they are available
by message key, even if seemingly irretrievable by naming the CLP in the
PGMQ() parameter.
As an Amazon Associate we earn from qualifying purchases.