Q: If you have messages defined with multiple parameters-like FILE, LIB and MEMBER parameters-how do you actually pass the variable data into those parameters from a CL program? Those parameters aren't really defined variables within your CL program. I can see how having just the &1 variable would work with the MSGDTA parameter, but how would it handle multiple variables?
A: Every time you have predefined substitution variables in a message description, the message description knows the format and length of each variable. Suppose you want to create a message description in MYLIB/MYMSGF which goes like this:
Program &1 in &2 not found.
This message description is to have an ID of PGM0001. This is the command you use to create the message description:
ADDMSGD MSGID(PGM0001) + MSGF(MYLIB/MYMSGF) + MSG('Program &1 in &2 not + found.') + FMT((*CHAR 10) (*CHAR 10))
This means that, when you send PGM0001 with the Send Program Message
(SNDPGMMSG) command, the MSGDTA parameter's value will be assigned as follows:
the first 10 characters to &1, the next 10 characters to &2. Therefore:
SNDPGMMSG MSGID(PGM0001) + MSGF(MYLIB/MYMSGF) + MSGDTA('PGM1 PRODLIB') + MSGTYPE(*DIAG)
...sends PGM0001 as a diagnostic message, and will read: Program PGM1 in PRODLIB not found.
Optionally, you can use a CL variable in the MSGDTA parameter and set its value before running SNDPGMMSG. See 3. The &PGM and &LIB objects are both TYPE (*CHAR) LEN(10).
Optionally, you can use a CL variable in the MSGDTA parameter and set its value before running SNDPGMMSG. See Figure 3. The &PGM and &LIB objects are both TYPE (*CHAR) LEN(10).
TechTalk: Using Predefined Messages
Figure 3 Using Predefined Messages
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(80) /* LEN(80) as example */ : CHKOBJ OBJ(&LIB/&PGM) OBJTYPE(*PGM) MONMSG MSGID(CPF9801) EXEC(DO) CHGVAR VAR(&MSGDTA) VALUE(&PGM *CAT &LIB) SNDPGMMSG MSGID(PGM0001) MSGF(MYLIB/MYMSGF) MSGDTA(&MSGDTA) + MSGTYPE(*ESCAPE) RETURN ENDDO
LATEST COMMENTS
MC Press Online