KB Article 16120
2019/06/04

Close
X
Contact Tech Support

 Email Tech Support
 (250) 655-1766
 [7:30 - 5:00 PST]
Your Meeting ID will be Provided by a Rep.
Tech Support
Tech Support Home
Software Updates
Knowledge Base Search
Recent KB Articles
Product FAQs
Code Samples
Documentation
Tech Blog
System Requirements
Installation Instructions
Support Testimonials
Contact us to...
Create a Ticket
Request a Free Demo
Suggest a New Feature
Submit Feedback
Upload a Large File
Other Services
Software Training
Professional Services

How can I Catapult data directly from a Physical File or Table and email it as a CSV file?

Product: Catapult Type: How to

We had a client who wanted grab data directly from a table or physical file and dump it into a CSV file to be emailed.  The emailing part was relatively easy using a basic Catapult rule, but we had to first create the file.  To do this we created a CL and used the CPYTOIMPF command.  At the bottom of the CL after the file is created we ran the ZRUNNETRUL Catapult command to take care of the emailing.  Below is an example CL program that accepts 3 parameters:

Parm 1: LIbrary name
Parm 2: Data file name
Parm 3: Name of CSV file to create on the IFS (do not include the extension csv in the name)

An example of the call to our program, we'll call it CATADATA:  CALL PGM(CATADATA) PARM('XL_WEBDEMO' 'MU_ORDHF' 'MYCSVFILE')

This command can be scheduled in the jobscheduler (WRKJOBSCDE), called from another program or from called from a command line and will drop a CSV file into a folder on your IFS. The folder in question is hard coded in this CL, but you can modify it to be more or less flexible:

*************** Beginning of data *********************************************************

/* THIS CL IS MEANT TO COPY DATA FROM A PHYSICAL FILE AND DUMP IT */
/* TO A CSV FILE IN THE IFS AND THEN CATAPULT IT WITH ZRUNRULE. */
/* ACCEPTS 3 PARMS - LIBRARY, FILE AND IFS FILE TO CREATE */

PGM PARM(&LIB &FILE &IFSFILE)

DCL        VAR(&LIB) TYPE(*CHAR) LEN(10)
DCL        VAR(&FILE) TYPE(*CHAR) LEN(10)
DCL        VAR(&IFSFILE) TYPE(*CHAR) LEN(24)
DCL        VAR(&IFSPATH) TYPE(*CHAR) LEN(200)
DCL        VAR(&UNCPATH) TYPE(*CHAR) LEN(200)
DCL        VAR(&CMD) TYPE(*CHAR) LEN(400)


CHGVAR     &IFSPATH ('\ZZTEMP\KIM\' *CAT &IFSFILE *TCAT '.CSV')
CHGVAR     &UNCPATH ('\\PROD.EXCELSYSTEMS.COM\PROD' *CAT &IFSPATH)

CHGVAR     &CMD ('CPYTOIMPF FROMFILE(' *TCAT &LIB +

                           *TCAT '/' *TCAT &FILE *TCAT ') +
                           TOSTMF(''' *CAT &IFSPATH *TCAT ''') +
                           RCDDLM(*CRLF) ADDCOLNAM(*SYS)')

CALL          PGM(QCMDEXC) PARM(&CMD 400)
MONMSG MSGID(CPF0000) EXEC(GOTO WHOOPS)

/*FOR DEBUG: SNDMSG MSG(&CMD) TOUSR(KIM) */
/* ***** EXAMPLE COMMAND TO COPY PHYSICAL FILE TO IFS>CSV FILE             */
/*                                                                                                                    */
/*CPYTOIMPF FROMFILE(KIM/MU_ITMF) TOSTMF('/ZZTEMP/KIM/MU_ITMF.CSV')+ */
/*RCDDLM(*CRLF) ADDCOLNAM(*SYS)                                                              */

CHGVAR      &CMD ('ZRUNNETRUL PATH(''' *TCAT &UNCPATH *TCAT ''') +
                            RULENBR(191)')
ADDLIBLE TS_CAT820
CALL        PGM(QCMDEXC) PARM(&CMD 400)
RMVLIBLE TS_CAT820
SNDMSG MSG('IFS FILE WAS CATAPULTED') TOUSR(KIM)
RETURN

WHOOPS:SNDMSG MSG('CATADATA FAILED') TOUSR(KIM)  

ENDPGM

****************** End of data ************************************************************

 

 

 

 

 

 

 

 

 

Rate This Article

Did this example help you to achieve your goal?
 Yes  No  Don't Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

Email Address:
Comments:
Please enable JavaScript in order to rate this page.