Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
I have a need to change the name of the file being FTP'ed to a network folder. My idea is to read the source text member with a RCVF command and update the line in the source file if a condition is met. The code that I have so far changes the data read from the file, but I need that source line to be updated back to the text file. What do I do to make that happen?
Here is the code -
RTVJOBA DATE(&DATE)
OVRDBF FILE(QCLSRC) MBR(FTPAUDJRNL)
TAG1: RCVF
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDPGM1))
CHGVAR &CMD VALUE(%SST(&SRCDTA 1 3))
IF COND(&CMD *EQ 'put') THEN(DO)
CHGVAR (%SST(&SRCDTA 29 6)) VALUE(&DATE)
ENDDO
DMPCLPGM
GOTO TAG1
In other words, changing the line from 'audjrnxxxxxx' to 'audjrn120227'
Typically I'd go with a "master" source member, and a "runtime" source member. Clear the runtime source member at start then perform a line by line copy of the master to runtime using RPG. Use EXTFILE/EXTMBR on the F-Specs and use %scanrpl to look for the XXXXXXX and replace it with the character representation of the date.
If you're not running a version with %scanrpl, then google Bob's code equivalent.
We have an RPG program that changes a source member containing an FTP !--script--. It uses SQL to change the filename each time it runs:
// Load the filename into the FTP !--script--.
Exec Sql
Update MYLIB/MYSRCMBR
Set SRCDTA = Case
When SRCSEQ = :FTPSEQ
Then Substr(SRCDTA, 1, 4) || Trim(:FILENAME)
Else Substr(SRCDTA, 1, 7) || Trim(:FILENAME) || ' ' ||
:NEWFILENAME
End
Where SRCSEQ In(:FTPSEQ,
:FTPSEQ2);
FTPSEQ and FTPSEQ2 are line numbers to be changed in the !--script--, '16.00' and '19.00' in this case.
Line 16.00 is a get (with the filename starting in position 5) and line 19.00 is a rename (with the filename starting in position 8.) So after this SQL statement runs, the !--script-- contains the new filename we're working with on that get and that rename.
This only runs once every few hours on a schedule, but if you could have the situation where it could run multiple times at the same time, then you should do the copy first like Neil suggests.
use the ftpfile command and be done with it.
neilrh,
I like your approach. I have a question, if I use the EXTMBR keyword, do I have to use the EXTFILE with it as well?
Folks,
If one uses the Extmbr keyword, we need to put single quotes around the member name , ie
Extmbr('FTPAJWRK') works and Extmbr(FTPAJWRK) does not - it leaves you with a message of 'FTPAJWRK not defined'
>> I have a question, if I use the EXTMBR keyword, do I have to use the EXTFILE with it as well?
No, you can use EXTMBR and not use EXTFILE. Here's an example from a program I have that runs through all the source members in QCPYSRC:
FQCpySrc IF E Disk ExtMbr('*ALL')
F Usropn
F Infds(Infds)
F Rename(QRPGLESRC:COPYREC)
The EXTMBR and EXTFILE keywords only require Quoted names if the name is NOT in a field, that is it is a literal. The obviously you'd quote it.
I would use a field anyway and stuff the member name into it.