ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

How to read TXT file using RPG and change the string?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to read TXT file using RPG and change the string?

    Hi.
    We have an FTP function to upload a physical file from AS/400 onto an external host (window based server)

    The requirement is that the file to be uploaded should be named in YYYYMMDD format. eg : XX_20080521

    We have a CL which will perform the FTP upload function, together with a FTP script (which is in TXT file format in AS/400)

    Below is the content of the FTP script
    *****
    0001.00 xxxx_id xxxxx_pass
    0002.00 LOCSITE TRIM 0
    0004.00 PUT MPPDATAH/MU1EQTNSF PFMRE_YYYYMMDD.DAT
    0005.00 QUIT
    *****

    Do you know how we will be able to accomplish this ?
    My idea is that we need to create a RPG program, read the FTP scrip txt file, then change the "YYYYMMDD" string to current date string. Then proceed to perform the FTP upload operation.

    Can you please guide me how we can read a TXT file and update the string by using RPGLE ? (the TXT file is an TXT type member located in a library)

    Or if you have any other ideas that would be much appreciated.

    Thank you and regards.

  • #2
    Re: How to read TXT file using RPG and change the string?

    try something like this the Q is an initialized field of one char
    inz..ed to " '''' " which " ' "

    Code:
    c/exec sql                  
    c+ set option commit=*none     
    c/end-exec 
    
    
          *----------------------------------------------------------------
          * $Copy2Z - Copy from IFS to the Z: drive the new file
          *----------------------------------------------------------------
         CSR   $Copy2Z       begsr
          *
          * in case this is a repeat delete the overrides and
          * the input output file(s)
          *
         c                   eval      cmdstring = 'DLTOVR INPUT'
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   'QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength
          *
         c                   eval      cmdstring = 'DLTOVR OUTPUT'
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   'QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength
          *
         c                   eval      cmdstring = 'DLTF FILE(QTEMP/INPUT)'
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   'QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength
          *
         c                   eval      cmdstring = 'DLTF FILE(QTEMP/OUTPUT)'
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   'QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength
          *
          *  create the input and output files in QTEMP
          *
         c                   eval      cmdstring = 'CRTPF FILE(QTEMP/INPUT) ' +
         c                                         ' RCDLEN(256)'
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   'QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength
          *
         c                   eval      cmdstring = 'CRTPF FILE(QTEMP/OUTPUT) ' +
         c                                         ' RCDLEN(256)'
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   'QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength
          *
          * populate the input file
          *
          /free
    
             Exec SQL   INSERT INTO INPUT
                        values('@user  @password');
    
             Exec SQL   INSERT INTO INPUT
                        values('namefmt 1');
    
             Exec SQL   INSERT INTO INPUT
                        values('bin');
    
             Exec SQL   INSERT INTO INPUT
                        values('lcd /processes');
    
             Exec SQL   INSERT INTO INPUT
                        values('put Processes.csv  Processes.csv');
    
             Exec SQL   INSERT INTO INPUT
                        values('quit');
          /end-free
          *
         c                   eval      cmdstring =
         c                             'OVRDBF FILE(INPUT) TOFILE(QTEMP/INPUT)' +
         c                             ' OVRSCOPE(*JOB) '
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   'QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength
          *
         c                   eval      cmdstring =
         c                             'OVRDBF FILE(OUTPUT) TOFILE(QTEMP/OUTPUT)' +
         c                             ' OVRSCOPE(*JOB) '
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   'QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength
          *
         c                   eval      cmdstring =
         c                             'STRTCPFTP ' + Q + '10.10.10.10' + Q
         c                   eval      cmdlength = %len(%trim(cmdstring))
         c                   call(e)   'QCMDEXC'
         c                   parm                    cmdstring
         c                   parm                    cmdlength
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: How to read TXT file using RPG and change the string?

      Hi chongcs:

      I write out the entire script in an rpg program. The table below is the entire script. Line 5 (the put command) needs to be modified with date (dt) and other indicators.

      Code:
      C     CD(5)         CAT(P)    LLIMIT:1      COMAN  
      C     COMAN         CAT(P)    '-':0         COMAN  
      C     COMAN         CAT(P)    PPR:0         COMAN  
      C     COMAN         CAT(P)    '-':0         COMAN  
      C     COMAN         CAT(P)    TPTYPE:0      COMAN  
      C     COMAN         CAT(P)    '-':0         COMAN  
      C     COMAN         CAT(P)    DT:0          COMAN  
      C     COMAN         CAT(P)    '.RTF':0      COMAN  
      C                   EXCEPT    CMD1                 
      C                   CLEAR                   COMAN
      Code:
       **                       
       userid passwd            
       CD MYFTP               
       MKDIR ACCT               
       CD ACCT                  
       PUT QTEMP/RTFOUT.RTFOUT  
       QUIT
      Best of Luck
      GLS
      The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

      Comment

      Working...
      X