Problem solve Get help with specific problems with your technologies, process and projects.

Receiving operator messages by e-mail

This tip shows you how you can receive operator messages by e-mail.

With this tip you can handle operator messages and e-mail it depending on the message attributes (ID, severity...

and sender.)

Step 1: Build a CL program to handle the messages.

0001.00              PGM        PARM(&MSGQ &MSGLIB &MRK)                       
0002.00              DCL        VAR(&MSGQ) TYPE(*CHAR) LEN(10)                 
0003.00              DCL        VAR(&MSGLIB) TYPE(*CHAR) LEN(10)               
0003.01              DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)                 
0004.00              DCL        VAR(&MRK) TYPE(*CHAR) LEN(4)                   
0005.00              DCL        VAR(&MSG) TYPE(*CHAR) LEN(75)                  
0005.01              DCL        VAR(&MSG2) TYPE(*CHAR) LEN(3000)               
0005.02              DCL        VAR(&MSGX) TYPE(*CHAR) LEN(5000)               
0005.03              DCL        VAR(&SEV) TYPE(*DEC) LEN(2)                    
0005.04              DCL        VAR(&SENDER) TYPE(*CHAR) LEN(80)               
0005.05              DCL        VAR(&SEVA) TYPE(*CHAR) LEN(2)                  
0006.00              RCVMSG     MSGQ(&MSGLIB/&MSGQ) MSGKEY(&MRK) RMV(*NO) +    
0007.00                           MSG(&MSG) SECLVL(&MSG2) MSGID(&MSGID) +      
0007.01                           SEV(&SEV) SENDER(&SENDER)                    
0007.02              CHGVAR     VAR(&SEVA) VALUE(&SEV)            
     --- prepares the message to send by email             
0007.03              CHGVAR     VAR(&MSGX) VALUE('Message:' *BCAT &MSG *BCAT + 
0007.04                           ':/N' *BCAT &MSG2 *TCAT ':/N ID:' *BCAT +    
0007.05                           &MSGID *TCAT ':/N Severity:' *BCAT &SEVA +   
0007.06                           *TCAT ':/N Sender:' *BCAT &SENDER)           
     --- send message only if severity is greater than 40 
0007.07              IF         COND(&SEV > 40) THEN(DO)
     --- handle a specific message (Device xxx needs to be cleaned.) and send it
         to operator cell phone                        
0007.08              IF         COND(&MSGID = 'CPF6792') THEN(DO)              
0008.00              SNDDST     TYPE(*LMSG) TOINTNET(( +    
0008.01                           DSTD(MENSAGEM) LONGMSG(&MSGX) +              
0008.02                           SUBJECT('Clean the tape')
0008.03              ENDDO                                               
0008.04              SNDDST     TYPE(*LMSG) TOINTNET(( + 
0008.05                           DSTD(MENSAGEM) LONGMSG(&MSGX) +        
0008.06                           SUBJECT('AS400 QSYSOPR message')
0008.10              ENDDO                                               
0011.00              ENDPGM  

In this example, the program was compiled as MSG_GET in library MSGLIB

Step 2: Build a CL Program to allocate QSYSOPR message queue

     --- *ALWRPY = allow other jobs to reply messages
0003.00              CHGMSGQ    MSGQ(QSYSOPR) DLVRY(*BREAK) +
0003.01                           PGM(MSGLIB/MSG_GET *ALWRPY)
     --- it is just a way to make the program don't finish and maintain
         message queue allocated
0004.00  LOOP:       DLYJOB     DLY(600)                     
0005.00              GOTO       CMDLBL(LOOP) 

In this example, the program was compiled as MSG_MAIL in library MSGLIB

Step 3: Execute the program


You can use this command to submit the program and test it. To have this solution always running you can put it on QSTRUPPGM program or create a auto start job for a subsystem.

Make sure that QSYSOPR user is able to send messages (WRKDIRE) or use another user in USER parameter.


The Best Web Links: tips, tutorials and more.

Ask your systems management questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our systems management gurus are waiting to answer your technical questions.

Dig Deeper on Implementation