CL Copy stream files

CL can be used to copy ASCII stream files to EBCIDIC files.

Copying from stream files

The Copy From Stream File (CPYFRMSTMF) command copies the data in a stream file to either a database file member or a save file. Optional conversion of the data and reformatting is performed when copying a database file member. The command in the program below copies the data in stream file in named in the variable &FILEPATH, to a work file. The target database file member is /QSYS.LIB/QTEMP.LIB/CSGADRWF.FILE/CSGADRWF.MBR. The character LF is recognized as the end of a stream file line. Any embedded tabs are not expanded with blanks. The only line-formatting character that will be recognized is LF pairing as identified by CCSID (specified by the STMFCCSID parameter).

/*********************************************************************/
/* Program Name -CSG300CL                                            */
/*                                                                   */
/* Function     - This program was designed to read the CSG import   */
/*                directory and manage any certificate mailing data. */
/*                                                                   */
/* Programmer   - Steve Croy                       99/99/9999        */
/*********************************************************************/
/*********************************************************************/
/*                   Modification log                                */
/*                                                                   */
/*   Date    Programmer      Description                             */
/*********************************************************************/

             PGM

             DCLPRCOPT  DFTACTGRP(*NO) ACTGRP(CSGRCV) BNDSRVPGM((ISI000SV))

             DCL        VAR(&IMPFOLDER) TYPE(*CHAR) LEN(200)
             DCL        VAR(&ARCFOLDER) TYPE(*CHAR) LEN(200)
             DCL        VAR(&MSGKEY)    TYPE(*CHAR) LEN(4)
             DCL        VAR(&PGMNAME)   TYPE(*CHAR) LEN(10)
             DCL        VAR(&FUNCTION)  TYPE(*CHAR) LEN(25)
             DCL        VAR(&PROGRAM)   TYPE(*CHAR) LEN(15)
             DCL        VAR(&SENDER)    TYPE(*CHAR) LEN(80)
             DCL        VAR(&FILEPATH)  TYPE(*CHAR) LEN(200)
             DCL        VAR(&RTNVALUE)  TYPE(*CHAR) LEN(200)
             DCL        VAR(&ARCFLAG )  TYPE(*CHAR) LEN(4)
             DCL        VAR(&DATATYP) TYPE(*CHAR) LEN(10)
             DCL        VAR(&jobNAME) TYPE(*CHAR) LEN(25)
             DCL        VAR(&JOBTYPE)   TYPE(*CHAR) LEN(1)
             DCL        VAR(&POS) TYPE(*UINT) LEN(2)
             DCL        VAR(&ERROR) TYPE(*LGL) LEN(1)

             RTVJOBA    TYPE(&JOBTYPE)

/*-------------------------------------------------------------------*/
/* Get the program name                                              */
/*-------------------------------------------------------------------*/

             SNDPGMMSG  MSG(' ') TOPGMQ(*SAME) MSGTYPE(*INFO) +
                          KEYVAR(&MSGKEY)
             RCVMSG     PGMQ(*SAME) MSGTYPE(*INFO) RMV(*YES) +
                          SENDER(&SENDER)
             CHGVAR     VAR(&PGMNAME) VALUE(%SST(&SENDER 56 10))

/*-------------------------------------------------------------------*/
/* Get the CSG inbound folder.                                       */
/*-------------------------------------------------------------------*/

             CHGVAR     VAR(&PROGRAM) VALUE(&PGMNAME)
             CHGVAR     VAR(&FUNCTION) VALUE('IMPFOLDER')
             CALL       PGM(ISI005RP) PARM(&PROGRAM &FUNCTION &IMPFOLDER)
             CHGVAR     VAR(&FUNCTION) VALUE('ARCFOLDER')
             CALL       PGM(ISI005RP) PARM(&PROGRAM &FUNCTION &ARCFOLDER)

/*-------------------------------------------------------------------*/
/* Read the inbound files. Check to see if any are POM, Bulk or      */
/* Certified data files. Add to data files.                          */
/*-------------------------------------------------------------------*/

             DLTF       FILE(QTEMP/CSGIMPWF) /* sac01 */
             MONMSG     MSGID(CPF0000) /* sac01 */

             CRTPF      FILE(QTEMP/CSGIMPWF) RCDLEN(307) TEXT('CSG: +
                          Work file for ascii imports') +
                          SIZE(*NOMAX) /* sac01 */

 LIST:       CALL       PGM(ISI010RP) PARM(&IMPFOLDER)

 READ:       DOUNTIL    COND(&FILEPATH *EQ '*****')
             CALL       PGM(ISI020RP) PARM(&FILEPATH)
             IF         COND(&FILEPATH *NE '*****') THEN(DO)
/*-------------------------------------------------------------------*/
/* Determine the file type from the file name.                       */
/* If the file contains Policy index data, execute the upload.       */
/*-------------------------------------------------------------------*/
             CHGVAR     VAR(&FILEPATH) VALUE(%UPPER(&FILEPATH)) /* +
                          sac01 */
             IF         COND(%SCAN('.PDF' &FILEPATH) *EQ 0) +
                          THEN(CALLSUBR SUBR(UPLOADDTA))

             ENDDO
 ENDREAD:    ENDDO

/*-------------------------------------------------------------------*/
/* Once the data index files have been built read the directory for  */
/* a list of the image files.                                        */
/*-------------------------------------------------------------------*/
 PDFLIST:    CALL       PGM(ISI010RP) PARM(&IMPFOLDER)

 STARTIMG:   DOUNTIL    COND(&FILEPATH *EQ '*****')
             CALL       PGM(ISI020RP) PARM(&FILEPATH)

/*-------------------------------------------------------------------*/
/* If the file contains Policy index data, execute the upload.       */
/*-------------------------------------------------------------------*/
             IF         COND(&FILEPATH *NE '*****') THEN(DO)

             CHGVAR     VAR(&FILEPATH) VALUE(%UPPER(&FILEPATH)) /* +
                          sac01 */
             IF         COND(%SCAN('.PDF' &FILEPATH) *NE 0) +
                          THEN(CALLSUBR SUBR(UPLOADPDF))
             ENDDO
 ENDLIST:    ENDDO

 TERMINATE:
             DLTF       FILE(QTEMP/CSGIMPWF) 
             MONMSG     MSGID(CPF0000) 

             RETURN

/*==================================================================*/
/* 1. Copy file to CSG data work file                               */
/* 2. Call program to populate the index data file                  */
/*==================================================================*/

 IDXDATA:    SUBR       SUBR(UPLOADDTA)

             CLRPFM     FILE(CSGDATPF)

             CPYFRMSTMF FROMSTMF(&FILEPATH) +
                          TOMBR('/QSYS.LIB/QTEMP.LIB/CSGIMPWF.FILE/CS+
                          GIMPWF.MBR') MBROPT(*REPLACE) +
                          STMFCCSID(*STMF) ENDLINFMT(*LF) 

             CPYFRMIMPF FROMFILE(CSGIMPWF) TOFILE(CSGDATPF) +
                          MBROPT(*ADD) RCDDLM(*LF) FLDDLM('|') +
                          RPLNULLVAL(*FLDDFT) 

             CALL       PGM(CSG300RP) PARM(&FILEPATH)

             CALLSUBR   SUBR(ARCHIVESR) 

             ENDSUBR
/*==================================================================*/
/* 1. Call program to push PDF to SolCom                            */
/*==================================================================*/

 IMAGES:     SUBR       SUBR(UPLOADPDF)

             CALL       PGM(CSG310RP) PARM(&FILEPATH &ARCFLAG)

             IF         COND(&ARCFLAG *EQ '*YES') THEN(CALLSUBR +
                          SUBR(ARCHIVESR)) 

             ENDSUBR

/*==================================================================*/
/* move file to archive                                             */
/*==================================================================*/

             SUBR       SUBR(ARCHIVESR)
 RETRY:
             CHGVAR     VAR(&ERROR) VALUE('0')
             MOV        OBJ(&FILEPATH) TODIR(&ARCFOLDER)
             MONMSG     MSGID(CPFA0A0) EXEC(DO)
             CHGVAR     VAR(&ERROR) VALUE('1')
             CALL       PGM(CSG305RP) PARM(&FILEPATH &ARCFOLDER)
             ENDDO
             IF         COND(&ERROR) THEN(GOTO CMDLBL(RETRY))

             ENDSUBR

             ENDPGM 

File not copied

The error message, CPFA095 will be issued if the copy fails. If a save operation is in progress the target file or stream file may not be accessed. The code below was created to monitor the error message and retry the copy command if the initial attempt to copy the stream file failed. It did solve the problem.


/*-------------------------------------------------------------------*/
/* Retry the copy from stream file. Occasionally, the file          */
/* ADMDTAPF will be unavailable (backups) and the copy will fail.    */
/* Delay the job, then try the copy file again.                      */
/*-------------------------------------------------------------------*/
COPY:
             CPYFRMSTMF FROMSTMF(&FILEPATH) TOMBR(&DB2FILE) +
                          MBROPT(*REPLACE)
             MONMSG     MSGID(CPFA095) EXEC(DO)
             DLYJOB     DLY(60)
             GOTO       CMDLBL(COPY)
             ENDDO