Q
Manage Learn to apply best practices and optimize your operations.

Sending a message to an output file after backup completion

On AS/400, it may be easier to create a special message queue for backup processes and send completion and/or error messages there instead of trying to write them to spool or to a physical file.

How can you send a message to an output file from scheduled back-up -- after being successfully completed or otherwise?
I suggest that you create a special message queue for backup processes and send completion and/or error messages there instead of trying to write them to spool or to a physical file. It is much easier and just as functional

Use the CRTMSGQ command to create your Message Queue. For example, to create a message queue in library QGPL:

CRTMSGQ MSGQ(QGPL/BACKUPMSGS) 
      TEXT('Messages from Backup Processes') 
      SIZE(5 1 10) 
      MSGQFULL(*WRAP)                                                        
 

Use the SNDPGMMSG command to send messages to it.

Here is some example CLP code showing how to capture and resend error messages and a completion message, to a particular message queue:

             PGM                                                       
/* ************************************************************** */   
/*                                                                */   
/* DECLARE PROGRAM VARIABLES                                      */   
/*                                                                */   
/* ************************************************************** */   
             DCL        &ERRORSW *LGL                     /* Std err */
             DCL        &MSGID *CHAR LEN(7)               /* Std err */
             DCL        &MSGDTA *CHAR LEN(100)            /* Std err */
             DCL        &MSGF *CHAR LEN(10)               /* Std err */
             DCL        &MSGFLIB *CHAR LEN(10)            /* Std err */
/* ************************************************************** */   
/*                                                                */   
 /* GLOBAL MESSAGE MONITOR                                         */   
 /*                                                                */   
 /* ************************************************************** */   
              MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(STDERR1))      
 /* ************************************************************** */   
 /*                                                                */   
 /* PROGRAM LOGIC                                                  */ 
 /*                                                                */   
 /* ************************************************************** */ 
                                                                  
            /* your backup code would go here */

SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) +           
MSGDTA('Backups have completed normally) + 
          TOMSGQ(QGPL/BACKUPMSGS) +    
          MSGTYPE(*COMP)                               
 /* ************************************************************** */ 
 /*                                                                */ 
 /* NORMAL END OF PROGRAM                                          */ 
 /*                                                                */ 
 /* ************************************************************** */ 
  END:        RETURN                                                  
 /* ************************************************************** */ 
 /*                                                                */ 
 /* STANDARD ERROR PROCESSING                                      */ 
 /*                                                                */ 
 /* ************************************************************** */ 
  STDERR1:               /* Standard error handling routine */        
    IF         &ERRORSW SNDPGMMSG MSGID(CPF9999) +          
    IF         &ERRORSW SNDPGMMSG MSGID(CPF9999) +            
                 MSGF(QCPFMSG) MSGTYPE(*ESCAPE) /* Func chk */
             CHGVAR     &ERRORSW '1' /* Set to fail ir error occurs */ 
 STDERR2:    RCVMSG     MSGTYPE(*DIAG) MSGDTA(&MSGDTA) MSGID(&MSGID) + 
                  MSGF(&MSGF) MSGFLIB(&MSGFLIB)                
   IF         (&MSGID *EQ '       ') GOTO STDERR3            
      SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +           
                   MSGDTA(&MSGDTA) TOMSGQ(QGPL/BACKUPMSGS) +    
                   MSGTYPE(*INFO)                               
      SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +           
                   MSGDTA(&MSGDTA) MSGTYPE(*DIAG)               
      GOTO       STDERR2 /* Loop back for addl diagnostics */   
 STDERR3:    RCVMSG     MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) + 
                   MSGF(&MSGF) MSGFLIB(&MSGFLIB)                
        SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +           
                   MSGDTA(&MSGDTA) TOMSGQ(QGPL/BACKUPMSGS) +    
                   MSGTYPE(*INFO)                               
        SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +           
                   MSGDTA(&MSGDTA) MSGTYPE(*ESCAPE)             
     ENDPGM                                                    

To view these messages you would use the command: DSPMSG MSGQ(QGPL/BACKUPMSGS)

This was last published in June 2008

Dig Deeper on Data backup, storage and retrieval on iSeries

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close