Copy from Folder

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

In last months's Tech Talk, I presented a utility called Copy to Folder (CPYTOFLR), which copies an AS/400 source member to a PC document in an AS/400 folder. The document is then available to the PC through PC Support's shared folder function. CPYTOFLR makes it easy to download files. This month, I am presenting this utility's counterpart, Copy from Folder (CPYFRMFLR), which makes it easy to upload files.

The CPYFRMFLR command is shown in 6 and the CPP, FLR004CL, is shown in 7. This utility uses the OS/400 Copy from PC Document (CPYFRMPCD) command to copy PC documents in an AS/400 folder to members in a source file. The problem with CPYFRMPCD is that it copies only one document at a time and you must specify the name of the document.

The CPYFRMFLR command is shown in Figure 6 and the CPP, FLR004CL, is shown in Figure 7. This utility uses the OS/400 Copy from PC Document (CPYFRMPCD) command to copy PC documents in an AS/400 folder to members in a source file. The problem with CPYFRMPCD is that it copies only one document at a time and you must specify the name of the document.

CPYFRMFLR solves this problem by copying all PC documents in a folder at once. It uses the Query Document Library (QRYDOCLIB) command to create an outfile containing the names of all documents in a folder. The file is then processed. For each record that is read, a document is copied. A typical use for this command would be if you have multiple PC files containing source code that you want transferred to members in an AS/400 source file.

To use this utility, you first need to activate PC Support shared folders and copy the files you want to upload from your PC to an AS/400 shared folder (usually drive I:). Make sure that the folder does not contain any files other than the ones you want to transfer. Next, run the CPYFRMFLR command on the AS/400. Specify the name of the folder where your PC files are located in the FROMFLR parameter and the name of the file and library that you want them copied to in the TOFILE parameter. The CPYFRMFLR utility copies all of the files which it finds in the folder to members in the specified AS/400 file.

The REPLACE parameter allows you to decide whether a member should be replaced if it already exists. The default of REPLACE(*NO) generates an error message for any members which already exist. However, the command continues copying any additional documents.


Copy from Folder

Figure 6 CPYFRMFLR Command

 /*===============================================================*/ /* To compile: */ /* */ /* CRTCMD CMD(XXX/CPYFRMFLR) PGM(XXX/FLR002CL) + */ /* SRCFILE(XXX/QCMDSRC) PRDLIB(QIWS) */ /* */ /*===============================================================*/ CMD PROMPT('Copy From Folder') PARM KWD(FROMFLR) TYPE(*NAME) LEN(80) MIN(1) + PROMPT('From folder') PARM KWD(TOFILE) TYPE(QUAL1) MIN(1) PROMPT('To + file') PARM KWD(REPLACE) TYPE(*CHAR) LEN(4) RSTD(*YES) + DFT(*NO) VALUES(*NO *YES) PROMPT('Replace + members') QUAL1: QUAL TYPE(*NAME) QUAL TYPE(*NAME) DFT(*LIBL) SPCVAL((*LIBL) + (*CURLIB)) PROMPT('Library') 
Copy from Folder

Figure 7 CL Program FLR004CL

 /*===============================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/FLR004CL) SRCFILE(XXX/QCLSRC) */ /* */ /*===============================================================*/ FLR004CL: PGM PARM(&FROMFLR &QFILE &REPLACE) DCL VAR(&FROMFLR) TYPE(*CHAR) LEN(80) DCL VAR(&QFILE) TYPE(*CHAR) LEN(20) DCL VAR(&REPLACE) TYPE(*CHAR) LEN(4) DCL VAR(&FILE) TYPE(*CHAR) LEN(10) DCL VAR(&LIB) TYPE(*CHAR) LEN(10) DCL VAR(&TOMBR) TYPE(*CHAR) LEN(10) DCL VAR(&CPYD) TYPE(*DEC) LEN(3 0) DCL VAR(&CPYA) TYPE(*CHAR) LEN(3) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) DCL VAR(&MSGF) TYPE(*CHAR) LEN(10) DCL VAR(&MSGFLIB) TYPE(*CHAR) LEN(10) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(80) DCLF FILE(QAOSIQDL) /* Send all errors to error handling routine */ MONMSG MSGID(CPF0000 IWS0000) EXEC(GOTO CMDLBL(ERROR)) /* Split out qualified file name */ CHGVAR VAR(&FILE) VALUE(%SST(&QFILE 1 10)) CHGVAR VAR(&LIB) VALUE(%SST(&QFILE 11 10)) /* Create file containing PC documents */ QRYDOCLIB FLR(&FROMFLR) OUTFILE(QTEMP/QAOSIQDL) OVRDBF FILE(QAOSIQDL) TOFILE(QTEMP/QAOSIQDL) /* Read through PC documents file */ RCVF: RCVF MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(EOF)) /* Retrieve member name */ CHGVAR VAR(&TOMBR) VALUE(%SST(&QDLDNM 1 8)) /* If REPLACE(*NO) specified skip duplicate members */ IF COND(&REPLACE *EQ '*NO ') THEN(DO) CHKOBJ OBJ(&LIB/&FILE) OBJTYPE(*FILE) MBR(&TOMBR) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(COPY)) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) + MSGDTA('Document' *BCAT &TOMBR *BCAT 'not + copied') GOTO CMDLBL(RCVF) ENDDO /* Copy PC document to source file */ COPY: RMVMSG CLEAR(*ALL) CPYFRMPCD FROMFLR(&FROMFLR) TOFILE(&LIB/&FILE) + FROMDOC(&QDLDNM) TOMBR(&TOMBR) CHGVAR VAR(&CPYD) VALUE(&CPYD + 1) /* Go get next record */ GOTO CMDLBL(RCVF) /* Send completion message */ EOF: CHGVAR VAR(&CPYA) VALUE(&CPYD) SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&CPYA + *BCAT 'documents copied from' *BCAT + &FROMFLR *BCAT 'to' *BCAT &FILE *BCAT + 'in' *BCAT &LIB) MSGTYPE(*COMP) /* Branch around error handling routine */ GOTO CMDLBL(ENDPGM) /* Error handling routine */ ERROR: RCVMSG MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) + MSGF(&MSGF) MSGFLIB(&MSGFLIB) SNDPGMMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) + MSGDTA(&MSGDTA) MSGTYPE(*ESCAPE) ENDPGM: ENDPGM 
BLOG COMMENTS POWERED BY DISQUS