Midrange News for the IBM i Community


Posted by: WestCoastGuy
Updating a source text (TXT) file
has no ratings.
Published: 27 Feb 2012
Revised: 23 Jan 2013 - 3964 days ago
Last viewed on: 28 Nov 2023 (5688 views) 

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.

Updating a source text (TXT) file Published by: WestCoastGuy on 27 Feb 2012 view comments(8)

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                                       

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: WestCoastGuy
Premium member *
Comment on: Updating a source text (TXT) file
Posted: 11 years 9 months 3 days 11 hours 7 minutes ago

In other words, changing the line from 'audjrnxxxxxx' to 'audjrn120227'

 

Posted by: neilrh
Premium member *
Jackson, MI
Comment on: Updating a source text (TXT) file
Posted: 11 years 9 months 3 days 9 hours 24 minutes ago

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.

Posted by: Viking
Premium member *
CA
Comment on: Updating a source text (TXT) file
Posted: 11 years 9 months 3 days 9 hours 7 minutes ago

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.

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Updating a source text (TXT) file
Posted: 11 years 9 months 3 days 8 hours 27 minutes ago

use the ftpfile command and be done with it.

Posted by: WestCoastGuy
Premium member *
Comment on: Updating a source text (TXT) file
Posted: 11 years 9 months 1 days 15 hours 44 minutes ago

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?

 

 

Posted by: WestCoastGuy
Premium member *
Comment on: Updating a source text (TXT) file
Posted: 11 years 9 months 1 days 12 hours 59 minutes ago

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'

Posted by: Viking
Premium member *
CA
Comment on: Updating a source text (TXT) file
Posted: 11 years 9 months 1 days 12 hours 46 minutes ago
Edited: Wed, 29 Feb, 2012 at 12:14:49 (4293 days ago)

>> 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)

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Updating a source text (TXT) file
Posted: 11 years 9 months 1 days 11 hours 51 minutes ago

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.