Home > AS/400 Tips > iSeries programmer tips > Selective SPOOLFILE copy to CSV files and e-mail
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Selective SPOOLFILE copy to CSV files and e-mail


Benito Abraham, Contributor
01.28.2008
Rating: -4.49- (out of 5)


iSeries news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


The XCPYSPLF command lets iSeries programmers send reports in CSV file format to e-mail accounts. In order to properly explain how it works we are going to develop an example. I've included the source code for this command at the bottom of the page.

Let's say that we want to work with the AMARTINEZ'S $SYSLIST file:
iSeries XCPYSPLF example screenshot

We go to the selected record and type 5 > Enter.
iSeries XCPYSPLF example screenshot

Since we only want the records and not the headlines, we must create a selection criteria. Generally speaking, we have to choose a character that is repeated in the same position in the records we want to include in our file. Iit could be a decimal point, a dash, etc. In this example we'll choose a '/' located in position 19.

We go back to our spool (enter) and hit F11 twice:
iSeries XCPYSPLF example screenshot

Next, write down the marked values for the selected spool: File: $SYSLIST
Spool Number: 4
Job: QPADEV0003
User: AMARTINEZ
Job Number: 193490

Finally, we invoke the XCPYSPLF command and load the parameters along with the e-mail target:
iSeries XCPYSPLF example screenshot

The receiver will see something like this:
iSeries XCPYSPLF example screenshot

And the received file will look like this without headlines and in CSV format:
iSeries XCPYSPLF example screenshot In order to work properly you should create the folder download with public authority *all and the users must be created in the distribution directory. If for some reason you can't or don't want to send a e-mail, you can find your converted report without headings in the DOWNLOAD folder were you can get it with iSeries Navigator or any other tool that you like.

Below is the source code you'll need:

Source Code XCPYSPLF Cmd


             CMD        PROMPT('XCopy spool file to csv')            
                                                                     
             PARM       KWD(SPOOL) TYPE(*CHAR) LEN(10) MIN(1) +      
                          PROMPT('Spool file to convert')            
                                                                     
             PARM       KWD(JOB) TYPE(*CHAR) LEN(10) MIN(1) +        
                          PROMPT('Job Name')                         
                                                                     
             PARM       KWD(USER) TYPE(*CHAR) LEN(10) MIN(1) +       
                          PROMPT('Spool file User')                  
                                                                     
             PARM       KWD(JOBNBR) TYPE(*CHAR) LEN(6) MIN(1) +      
                          PROMPT('Job Number')                       
                                                                     
             PARM       KWD(SPOOLNBR) TYPE(*CHAR) LEN(11) MIN(1) +   
                          PROMPT('Spool Number')                     
                                                                     
             PARM       KWD(POS) TYPE(*CHAR) LEN(10) MIN(1) +        
                          PROMPT('Choosen character position')       
                                                                     
             PARM       KWD(SEL) TYPE(*CHAR) LEN(3) MIN(1) +           
                          CHOICE('*EQ *NE *GT *LT, etc') +             
                          PROMPT('Selection Criteria')                 
                                                                       
             PARM       KWD(VALOR) TYPE(*CHAR) LEN(1) MIN(1) +         
                          PROMPT('Character to select/omit')           
                                                                       
             PARM       KWD(MAIL) TYPE(*CHAR) LEN(64) MIN(1) +         
                          PROMPT('Mail address')                       

Source Code XCPYSPLF CLP (XCPYSPLF Cpp program)


             PGM        PARM(&SPOOL &JOB &USER &JOBNBR &SPOOLNBR +     
                          &POS &SEL &VALOR &MAIL)                      
             DCL        VAR(&SPOOL) TYPE(*CHAR) LEN(10) /* Spool +     
                          File */                                      
             DCL        VAR(&FILE) TYPE(*CHAR) LEN(10) VALUE(XSPOOL) + 
                          /* Temporal File */                          
             DCL        VAR(&FIL1) TYPE(*CHAR) LEN(10) VALUE(XSPOO1) + 
                          /* Temporal File */                          
             DCL        VAR(&LIB) TYPE(*CHAR) LEN(10) VALUE(QTEMP) +   
                          /* Temporal Library */                       
             DCL        VAR(&JOB) TYPE(*CHAR) LEN(10) /* Spool File +  
                          Job Name */                                  
             DCL        VAR(&USER) TYPE(*CHAR) LEN(10) /* Spool File + 
                          User */                                      
             DCL        VAR(&JOBNBR) TYPE(*CHAR) LEN(6) /* Spool +     
                          File Job Number */                           
             DCL        VAR(&SPOOLNBR) TYPE(*CHAR) LEN(11) /* Spool +  
                          Number */                                    
             DCL        VAR(&POS) TYPE(*CHAR) LEN(10) /* Position +    
                          selected character */                        
             DCL        VAR(&SEL) TYPE(*CHAR) LEN(3) /* Criteria */    
             DCL        VAR(&VALOR) TYPE(*CHAR) LEN(1) /* Character */ 
             DCL        VAR(&MAIL) TYPE(*CHAR) LEN(64) /* Target +     
                          mail address */                              
                                                                       
/*           Create Working File                                     */
                                                                       
             CRTPF      FILE(&LIB/&FILE) RCDLEN(198)                   
             MONMSG     MSGID(CPF0000)                                 
                                                                       
/*           Be sure it is clear                                     */
                                                                       
             CLRPFM     FILE(&LIB/&FILE)                               
             MONMSG     MSGID(CPF0000)                                 
                                                                       
/*           First copy from the spool file                          */
                                                                       
             CPYSPLF    FILE(&SPOOL) TOFILE(&LIB/&FILE) +              
                          JOB(&JOBNBR/&USER/&JOB) SPLNBR(&SPOOLNBR)    
                                                                       
/*           Create 2nd Working File                                 */
                                                                       
             CRTPF      FILE(&LIB/&FIL1) RCDLEN(198)                   
             MONMSG     MSGID(CPF0000)                                 
                                                                       
/*           Copy with selection criteria from 1st to 2nd file       */
                                                                       
             CPYF       FROMFILE(&LIB/&FILE) TOFILE(&LIB/&FIL1) +      
                          MBROPT(*REPLACE) CRTFILE(*NO) +              
                          INCCHAR(*RCD &POS &SEL &VALOR) FMTOPT(*NOCHK)
                                                                       
/*           Copy 2nd file to a stream file in DOWNLOAD folder       */
                                                                       
             CPYTOSTMF  +                                              
                          FROMMBR('/QSYS.LIB/QTEMP.LIB/XSPOO1.FILE/XS+ 
                          POO1.MBR') +                                 
                          TOSTMF('/QDLS/DOWNLOAD/XSPOOL.CSV') +        
                          STMFOPT(*REPLACE) STMFCODPAG(*PCASCII)       
                                                                       
/*           Grant authority to the stream file                      */
                                                                       
             CHGAUT     OBJ('/QDLS/DOWNLOAD/XSPOOL.CSV') +             
                          USER(*PUBLIC) DTAAUT(*RWX) OBJAUT(*ALL)      
                                                                       
/*           Send the file by mail                                   */
                                                                       
             SNDDST     TYPE(*DOC) TOINTNET((&MAIL)) DSTD('Requested + 
                          spool file') DOC(XSPOOL.CSV) FLR(DOWNLOAD)           

Back to top

ABOUT THE AUTHOR: Benito Abraham is an analyst programmer at Pride International. He has over 15 years experience on AS/400, including iSeries security and RPG.

Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
Imaging on iSeries
Controlling spool files with APIs
Word Search: iSeries printing
Fast guide to Redbooks and guides on printing/output
20 printing tips in 20 minutes
Use Excel, WebSphere to present live iSeries business data
Document Imaging
Fast guide to Redbooks and guides on printing/output
Quadrant Software's Formtastic Fusion5 delivers full PDF support, seamless document imaging software integration
Ten tips for printing from the iSeries
Premium printing advice
Imaging on iSeries Research

iSeries programmer tips
Using SQL on System i to create multicolored comment lines
Eight steps for creating program documentation using AS/400 utilities
DAYSPAST CLLE program for AS/400: Compares object creation date with today's date
Coloring source lines with COBOL and using a shortcut from within PDM
Date calculation commands for AS/400
There is very little RPG on System i can't do: From RPG nay to RPG yay!
Using SQL on System i to color source code and inline comments
Controlling spool files with APIs
System i document management tips
System i Resume Building 101

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts