Send a message to every active member of a group profile at once.
If you've been on an AS/400 for any length of time, you have probably come to realize that messaging is the lifeblood of the AS/400. You might also have realized that, in certain situations, it's not immediately apparent which message command you should use. The Send Group Profile Message (SNDGRPMSG) command infuses yet another pint of blood into the messaging system of the AS/400 without adding to the confusion; instead, the command bridges a gap which other commands don't address, presenting a very clear choice in some of those ambiguous situations.
Consider how often you would like to send a message to a select group of active users. The commands you typically use might not adequately address this task. The SNDGRPMSG command (see 1) allows you to send the message to just one group or up to 20 groups. The only consideration in using this command is whether or not your users are assigned to meaningful group profiles. How you choose to group your users is, of course, up to you. ("Organizing Users with Group Profiles," MC, April 1993, supplies some relevant hints and strategies.) If the size of your user base does not necessitate the use of group profiles, or if you have simply chosen not to utilize the feature, this command may get dusty before you find a use for it.
Consider how often you would like to send a message to a select group of active users. The commands you typically use might not adequately address this task. The SNDGRPMSG command (see Figure 1) allows you to send the message to just one group or up to 20 groups. The only consideration in using this command is whether or not your users are assigned to meaningful group profiles. How you choose to group your users is, of course, up to you. ("Organizing Users with Group Profiles," MC, April 1993, supplies some relevant hints and strategies.) If the size of your user base does not necessitate the use of group profiles, or if you have simply chosen not to utilize the feature, this command may get dusty before you find a use for it.
If, however, you have grouped your users, you'll find plenty of uses for the SNDGRPMSG command. Maybe you'd like to send a message just to active users in the Payroll department. If you have users across the country, maybe you'd like to send a message only to those active users in Dallas, Texas. It's easy enough if you follow the steps outlined here.
The command provides three parameters:
o MSG-Receives the text for the message. Like all other message commands, SNGGRPMSG allows up to 512 characters. This parameter is required.
o GRPPRF-Receives a maximum of 20 group profile names. This parameter is also required.
o OPTION-Allows you to specify whether to send a break (*BREAK) message or a standard (*STD) message. The default value is *BREAK.
Here's an example of using SNDGRPMSG. We need to shut down interactive subsystem INTER3, which is used by Accounting and Customer Service. Since all users in Accounting belong to group profile GRP_ACG and all Customer Service users are covered by GRP_CSV, we can simply run:
SNDGRPMSG MSG('System will + go down in 15 minutes.') + GRPPRF(GRP_ACG GRP_CSV) + OPTION(*BREAK)
How It Works
The command processing program (CPP), GRP003CL (see 2), accepts a message, a list of group profiles to which a message is to be sent and the type of message delivery (*BREAK or *STD). The program's main task is to determine if any of the users who belong to a group profile in the list are signed onto the system. If so, it sends the message to them.
The command processing program (CPP), GRP003CL (see Figure 2), accepts a message, a list of group profiles to which a message is to be sent and the type of message delivery (*BREAK or *STD). The program's main task is to determine if any of the users who belong to a group profile in the list are signed onto the system. If so, it sends the message to them.
It starts by determining how many group profiles are in the list. As you probably know, command parameters defined as lists contain the number of elements in the list in the first two bytes of the parameter. This number is expressed in binary format; therefore, we use the %BIN function to convert it to decimal. (Notice that the %BIN function allows us to do two things at once: isolate the first two bytes of the &GROUPS parameter and convert it to decimal.)
Next, the CPP creates a file containing the active jobs on the system by using the Convert WRKACTJOB to Database File (WRKACTP) command from QUSRTOOL library. (This tool and the physical file that it creates must exist before you can compile GRP003CL, the SNDGRPMSG CPP.)
OPNQRYF is used to read the file in user profile order with the UNIQUEKEY parameter of *ALL. The OPNQRYF access path presents only the first record of a group where the key field (KEYFLD) is equal. When a user is signed onto the system more than once, this technique will prevent a duplicate message from being sent.
A primary loop (LOOP) is set up to read each record of the active jobs file and retrieve the group profile for the job's user. A secondary loop (LOOP2) is entered to process each group profile in the list, comparing it to the group profile of the current job record. If the two are equal, a message is sent to the user profile attached to the job.
One command does it all! You don't have to send the same message dozens of times (once for each user). Also, SNDGRPMSG relieves you from the responsibility of keeping lists of who belongs to the group profiles you have set up. SNDGRPMSG will be a valuable tool in your increasing bag of tricks.
Charley Shanks is a programmer/ analyst at Cummins Diesel ReCon in Memphis, Tennessee.
Broadcast Your Messages
Figure 1 The SNDGRPMSG Command
/* */ /* To compile: */ /* CRTCMD CMD(xxx/SNDGRPMSG) PGM(xxx/GRP003CL) + */ /* SRCFILE(xxx/QCMDSRC) */ /* */ SNDGRPMSG: CMD PROMPT('Send Group Profile Message') PARM KWD(MSG) TYPE(*CHAR) LEN(150) RSTD(*NO) + MIN(1) KEYPARM(*NO) PROMPT('Message text') PARM KWD(GRP) TYPE(*CHAR) LEN(10) RSTD(*NO) + MIN(1) MAX(10) PROMPT('Group profile')
Broadcast Your Messages
Figure 2 CL Program GRP003CL
/* */ /* To compile: */ /* */ /* 1. If the CVTWRKACT command from QUSRTOOL is not already on your */ /* system, create it. */ /* */ /* 2. Execute the CVTWRKACT command interactively: */ /* CVTWRKACT OUTLIB(QTEMP) */ /* */ /* 3. CRTCLPGM PGM(xxx/GRP003CL) SRCFILE(xxx/QCLSRC) */ /* */ SNDGRPMSGC: + PGM PARM(&MSG &GROUPS) DCL VAR(&MSG) TYPE(*CHAR) LEN(150) DCL VAR(&GROUPS) TYPE(*CHAR) LEN(102) DCL VAR(&GRP) TYPE(*CHAR) LEN(10) DCL VAR(&USRGRP) TYPE(*CHAR) LEN(10) DCL VAR(&TYPE) TYPE(*CHAR) LEN(1) DCL VAR(&BIN) TYPE(*CHAR) LEN(2) DCL VAR(&BATCH) TYPE(*LGL) DCL VAR(&ENTRIES) TYPE(*DEC) LEN(5 0) DCL VAR(&START) TYPE(*DEC) LEN(5 0) DCL VAR(&COUNT) TYPE(*DEC) LEN(5 0) DCLF FILE(WRKACTP) CHGVAR VAR(&BIN) VALUE(%SST(&GROUPS 1 2)) CVTBINDEC FROMBIN(&BIN) TODEC(&ENTRIES) IF COND(&ENTRIES *LT 1) THEN(DO) SNDPGMMSG MSG('At least one group profile must be + specified.') MSGTYPE(*COMP) GOTO CMDLBL(END) ENDDO RTVJOBA TYPE(&TYPE) IF COND(&TYPE *EQ '0') THEN(CHGVAR VAR(&BATCH) VALUE('1')) DLTF FILE(QTEMP/WRKACTP) MONMSG MSGID(CPF0000) CVTWRKACT OUTLIB(QTEMP) OVRDBF FILE(WRKACTP) TOFILE(QTEMP/WRKACTP) LOOP: + RCVF MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(END)) IF COND(&AJTYPE *NE 'I') THEN(GOTO CMDLBL(LOOP)) RTVUSRPRF USRPRF(&AJUSR) GRPPRF(&USRGRP) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(LOOP)) CHGVAR VAR(&START) VALUE(3) CHGVAR VAR(&COUNT) VALUE(1) LOOP2: + CHGVAR VAR(&GRP) VALUE(%SST(&GROUPS &START 10)) IF COND(&USRGRP *EQ &GRP) THEN(DO) SNDBRKMSG MSG(&MSG) TOMSGQ(&AJJOB) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(LOOP)) IF COND(&BATCH) THEN(GOTO CMDLBL(LOOP)) SNDPGMMSG MSG('Message sent to msgq' *BCAT &AJJOB *TCAT '. + User ID' *BCAT &AJUSR *TCAT '.') MSGTYPE(*COMP) ENDDO ELSE CMD(DO) IF COND(&COUNT *EQ &ENTRIES) THEN(GOTO CMDLBL(LOOP)) CHGVAR VAR(&START) VALUE(&START + 10) CHGVAR VAR(&COUNT) VALUE(&COUNT + 1) GOTO CMDLBL(LOOP2) ENDDO GOTO CMDLBL(LOOP) END: + DLTF FILE(QTEMP/WRKACTP) MONMSG MSGID(CPF0000) ENDPGM
LATEST COMMENTS
MC Press Online