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

E-mailing spool files the easy way

Here's a small program and associated files to handle those users who want their reports via e-mail.

Here's a small program and associated files to handle those users who want their reports via e-mail.


Header file EMAILH01 

R REMAILH 
 REPORT 10A TEXT('REPORT NAME') 
 DESCR 44A TEXT('REPORT DESCRIPTION') 
 MESSAG 256A TEXT('EMAIL MESSAGE') 
 DOCUM 12A TEXT('DOUMENT NAME') 
 FOLDER 12A TEXT('QLDS FOLDER NAME') 
K REPORT 

Detail (Recipient File) File EMAILD01 
  
R REMAILD 
 REPORT 10A TEXT('REPORT NAME') 
 EMAIL 50A TEXT('EMAIL ADDRESS') 
 ACTIVE 1A TEXT('ACTIVE RECIPIENT?') 
 NAME 50A TEXT('RECIPIENT NAME') 
K REPORT 
  
Embedded code in your report stream 

 /* EMAIL MANAGEMENT SUMMARY REPORT TO RECEPIENTS  */ 
CHGVAR &REPORT 'MANAGE_SUM' /* REPORT ID IN FILES */ 
CHGVAR &SPOOL 'QSYSPRT1' 
CALL EMAILC02 (&SPOOL &REPORT &RTN) 
IF (&RTN *EQ '1') DO 
SNDMSG     MSG('The daily management summary report emailing has failed') TOUSR(*SYSOPR)     
ENDDO                                   IF COND(&RTN *EQ '0')DO 
CALL EMAILR01 &REPORT 
ENDDO 

Program-EMAILC01 
/* THIS PROGRAM IS SUPPLIED WITH THE SPOOL FILE NAME */ 
/* AND THE REPORT NAME  COPIES THE SPOOL FILE TO THE */              
/* SHARED FOLDER */ 
                       
EMAILC02: PGM PARM(&SPOOL &REPORT &RTN) 
DCL &SPOOL *CHAR 10 
DCL &REPORT *CHAR 10 
DCL &DOCUM  *CHAR 12 
DCL &FOLDER *CHAR 10 
DCL &RTN *CHAR 1 
CALL PGM(EMAILR03) PARM(&REPORT &DOCUM &FOLDER) 
IF COND(&DOCUM *EQ '************')  THEN(GOTO NO) 
CRTPF QTEMP/TEMP RCDLEN (132) 
CPYSPLF FILE(&SPOOL) TOFILE(QTEMP/TEMP) SPLNBR(*LAST) 
MONMSG MSGID(CPF3309) /* No spooled file */ 
CPYTOPCD FROMFILE(QTEMP/TEMP) TOFLR(&FOLDER) TODOC(&DOCUM) REPLACE(*YES) 
DLTF QTEMP/TEMP      
CHGVAR &RTN '0' 
GOTO END 
NO: CHGVAR &RTN '1' 
END: ENDPGM 

Program-EMAILR01 
* This program reads the entries from the recipient file 
FEMAILH01IF  E  K DISK                
FEMAILD01IF  E  K DISK 
C *ENTRY PLIST 
C      PARM REPORT 10        
C SENDP PLIST                           
C      PARM  REPORT 10        
C      PARM  DESCR  44        
C      PARM  MESSAG256        
C      PARM  DOCUM  12        
C      PARM  FOLDER 12        
C      PARM  EMAIL  50        
C      REPORT CHAIN REMAILH  50    
C      *IN50 IFEQ '0' 
C      REPORT SETLL REMAILD 
C      *IN51 DOUEQ '1' 
C      REPORT READE REMAILD 51 
C      *IN51 IFEQ '0' 
C      ACTIVE ANDEQ 'Y' 
C      CALL 'EMAILC01' SENDP            
C      END 
C      END 
C      END 
C      SETON LR 

Program-EMAILC01 
/* Program to actually send email */ 
EMAILC01: PGM PARM(&REPORT &DESCR &MESSAG &DOCUM &FOLDER &EMAIL)   
DCL &REPORT *CHAR 10 
DCL &DESCR  *CHAR 44             
DCL &MESSAG *CHAR 256 
DCL &DOCUM  *CHAR 12 
DCL &FOLDER *CHAR 12             
DCL &EMAIL  *CHAR 50             
DCL &MSG    *CHAR 120 
SNDDST TYPE(*DOC) TOINTNET((&EMAIL))   DSTD(&DESCR) MSG(&MESSAG) DOC(&DOCUM) FLR(&FOLDER) 
CHGVAR &MSG (&REPORT || ' SENT TO ' || &EMAIL)     
SNDMSG MSG(&MSG) TOUSR(*SYSOPR)ENDPGM 

Here is the code I used for EMAILR03.

 Columns . . . :    1  80                                      Browse 
KEMPGM/QRPGSRC 
 SEU==> 
EMAILR03 
        *************** Beginning of data 
******************************************************* 
0001.00      FEMAILH01IF  E           K        DISK 
000517 
0002.00      C           *ENTRY    PLIST 
000517 
0003.00      C                     PARM           REPORT 10 
000517 
0003.01      C                     PARM           DOCUM  12 
000714 
0003.02      C                     PARM           FOLDER 12 
000714 
0011.00      C           REPORT    CHAINREMAILH              50 
000518 
0012.00      C           *IN50     IFEQ '1' 
000714 
0017.00      C                     MOVE *ALL'*'   DOCUM 
000714 
0019.00      C                     END 
000518 
0020.00      C                     SETON                     LR 
000518 
        ****************** End of data *********************************************************** 

Dig Deeper on RPG iSeries programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close