+ Reply to Thread
Results 1 to 11 of 11

Thread: CPYFRMIMPF - multiple files

  1. #1
    Code400 Newbie gwilburn How long am I stuck at *ZEROS?
    Join Date
    Dec 2009
    Location
    Maryland
    Posts
    32
    Rep Power
    88

    CPYFRMIMPF - multiple files

    I have quite a few processes where I retrieve a text file from an FTP site, use CPYFRMIMPF to get the data into a native database file, then run RPG pgms over it.
    Until now, i have simply ensured that the file was a single file with the same filename.
    This is all done through a scheduled CLP and FTP script
    What i'm looking for is a way to do an MGET (get multiple files into a single folder on the IFS) and then copy what I get (one or more files) into my Physical file.
    Any ideas?

  2. #2
    Analyst GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400 Your starting to get annoying GLS400's Avatar
    Join Date
    May 2006
    Location
    connecticut
    Posts
    1,125
    Rep Power
    3103

    Re: CPYFRMIMPF - multiple files

    Hi gwilburn:

    After your mget......you can combine .txt and .csv files using a .bat

    pseudo .bat code:
    Code:
    del mycombinedfile.txt
    copy myfilea*.* + myfileb*.* + myfilec*.* mycombinedfile.txt
    del myfilea*.*
    del myfileb*.*
    del myfilec*.*
    
    alternative:
    
    del mycombinedfile.txt
    copy *.txt mycombinedfile.tmp
    del *.txt
    rnm mycombinedfile.tmp mycombinedfile.txt
    CL

    Code:
    strpco
    strpccmd pccmd('x:\path\mybat.bat') pause(*no)
    cpyfrmimpf  frmstmf('/path/mycombinedfile.txt blaha blah blah
    That assumes all the file you retrieve with the MGET are in the same format and start with the same prefix or end with the same file type.

    Best of Luck
    GLS
    The difference between stupidity and genius is that genius has its limits......Albert Einstien

  3. #3
    Code400 Newbie K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume
    Join Date
    May 2007
    Location
    France
    Posts
    213
    Rep Power
    2005

    Re: CPYFRMIMPF - multiple files

    Before the CPYFRMIMPF you can merge all file in once with qshell (with the QSH clp command)

    Code:
    find '/home/Myfolder/' -name 'myfil*.csv'  
    -exec sort -n {} >/home/Myfolder/myfileResult \;
    In this example, all the file named MYFIL*.CSV in the directory are merge into a new file

  4. #4
    Code400 Newbie gwilburn How long am I stuck at *ZEROS?
    Join Date
    Dec 2009
    Location
    Maryland
    Posts
    32
    Rep Power
    88

    Re: CPYFRMIMPF - multiple files

    Thanks... great ideas. I'll give them a try. I was thinking along the lines of using CFGHTTPSCH to create a Source member containing a listing the folder contents. Then read the source member (RPGLE) and do a copy for each of the files in the list... never thought of using those approaches.

  5. #5
    Code400 Newbie gwilburn How long am I stuck at *ZEROS?
    Join Date
    Dec 2009
    Location
    Maryland
    Posts
    32
    Rep Power
    88

    Re: CPYFRMIMPF - multiple files

    Quote Originally Posted by K2r400 View Post
    Before the CPYFRMIMPF you can merge all file in once with qshell (with the QSH clp command)

    Code:
    find '/home/Myfolder/' -name 'myfil*.csv'  
    -exec sort -n {} >/home/Myfolder/myfileResult \;
    In this example, all the file named MYFIL*.CSV in the directory are merge into a new file
    Ran this interactively with QSH command first... it created a file for me, but the file contained non-display characters when viewed with notepad.

    What am I doing wrong?

  6. #6
    Code400 Newbie K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume
    Join Date
    May 2007
    Location
    France
    Posts
    213
    Rep Power
    2005

    Re: CPYFRMIMPF - multiple files

    No problem.
    It's necessary to create the result file with the good CCSID (1252 for windows for example) before the operation (in the same statement with the touch operation) :

    Code:
    touch -C 1252 /home/Myfolder/myfileResult | find  
    '/home/Myfolder/' -name 'myfil*.csv'  
    -exec sort -n {} >/home/Myfolder/myfileResult \;
    Last edited by K2r400; December 8th, 2009 at 12:24 PM.

  7. #7
    Code400 Newbie K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume
    Join Date
    May 2007
    Location
    France
    Posts
    213
    Rep Power
    2005

    Re: CPYFRMIMPF - multiple files

    The same example from a command line or CLP :

    Code:
    QSH CMD('touch -C 1252 /home/Myfolder/myfileResult | find  
    ''/home/Myfolder/'' -name ''myfil*.csv''  
    -exec sort -n {} >/home/Myfolder/myfileResult \;')

  8. #8
    Code400 Newbie gwilburn How long am I stuck at *ZEROS?
    Join Date
    Dec 2009
    Location
    Maryland
    Posts
    32
    Rep Power
    88

    Re: CPYFRMIMPF - multiple files

    Quote Originally Posted by K2r400 View Post
    The same example from a command line or CLP :

    Code:
    QSH CMD('touch -C 1252 /home/Myfolder/myfileResult | find  
    ''/home/Myfolder/'' -name ''myfil*.csv''  
    -exec sort -n {} >/home/Myfolder/myfileResult \;')
    Ok--- two months later, i got around to using this again. I have tried this commend interactively with 3 files in "MyFolder"... File1 has 74 rows, File2 has 1 row and File3 has 1 row. The command creates a 4th file containing data from the first file it found, but duplicates some of that data... it also includes data from the second file, but nothing from the third file. The total number of rows in the result file is 298.

    what am i missing? here is the command i ran in qsh

    touch -C 819 /nyr/orders.csv | find '/nyr/' -name 'us*.csv' -exec sort -n {} >/nyr/orders.csv \;

  9. #9
    Analyst DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks If you were taller I'd think you were YODA. DeadManWalks's Avatar
    Join Date
    Mar 2006
    Location
    Springwater
    Posts
    933
    Rep Power
    2209

    Re: CPYFRMIMPF - multiple files

    Code:
    PGM                                                                                         
                                                                                                
         Dcl     &LSCommand     *Char       (200    )                                           
         Dcl     &ThisLib       *Char       ( 10    )                                           
                                                                                                
                                                                                                
      /* ************************************************************************+              
          Delcare Directory List receiver file                                   +              
       * *************************************************************************/             
         Dclf    MYP01                                                                       
                                                                                                
                                                                                                
      /* ************************************************************************+              
          Look for any files on the MY folder.                              +              
       * *************************************************************************/             
         RtvObjD   MYP01  ObjType(*File) RtnLib(&ThisLib)                                   
         ClrPfm     MYP01                                                                    
                                                                                                
         CHGVAR     VAR(&LSCommand) VALUE('LS /My/ > +                                     
                                          /QSYS.LIB/' *TCAT &ThisLIb *TCAT +                    
                                          '.LIB/MYP01.FILE/MYP01.MBR')                    
         QSH CMD(&LSCOMMAND)                                                                    
                                                                                                
      /* ************************************************************************+                  
          Look through the Directory List and copy and process each file         +                  
       * *************************************************************************/                 
    Loop:                                                                                           
         RcvF                                                                                       
           MonMsg   MsgId(CPF0864) Exec(Goto CmdLbl(Eoj))                                           
           CpyFrmStmf FromStmf('/My/' *Tcat &MYP01) +                                       
                      ToMbr('QSYS.LIB/' *TCAT &ThisLIb *TCAT '.LIB/MYP02.FILE/MYP02.MBR') +   
                      MbrOpt(*Replace)                                                              
                                                                                                    
           Call     MYR01      /* loads into MY  files */                                 
                                                                                                    
         GoTo       Loop                                                                            
                                                                                                    
    EOJ:                                                                                            
    ENDPGM
    /Free your self

  10. #10
    Code400 Newbie K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume K2r400 Now you can put ILE on your resume
    Join Date
    May 2007
    Location
    France
    Posts
    213
    Rep Power
    2005

    Re: CPYFRMIMPF - multiple files

    Quote Originally Posted by gwilburn View Post
    touch -C 819 /nyr/orders.csv | find '/nyr/' -name 'us*.csv' -exec sort -n {} >/nyr/orders.csv \;
    The find function search all us*.csv file in the /nyr/ folder and his sub-folder too.
    Verify how many files are find under qsh with :

    find '/nyr/' -name 'us*.csv'
    Patrick

  11. #11
    Code400 Newbie gwilburn How long am I stuck at *ZEROS?
    Join Date
    Dec 2009
    Location
    Maryland
    Posts
    32
    Rep Power
    88

    Re: CPYFRMIMPF - multiple files

    OK - after all this I decided to write a pgm that lists the contents of a folder and copies them one by one into a PF using CPYFRMIMPF, and then moves the files that were copied into a subfolder. I'm not completely finished, but it's basically working.
    Code:
     *                                                                                                  
     *  Parameters:  Folder  :  '/abc/123'                                                              
     *               File    :  'OUTPUTPF'                                                              
     *               Delimter:  '|' or 'x05'                                                            
     *                                                                                                  
     ********************************************************************                               
     *                                                                                                  
    Fifs_list  if   e             disk    rename(ifs_list:ifs_lstr) usropn                              
     *                                                                                                  
     * PARAMETER LIST                                                                                   
     *                                                                                                  
    D EntryParms      pr                  extpgm('IFS001')                                              
    D  pfldr                        80a   Const                                                         
    D  pfile                        10a   Const                                                         
    D  pdlm                         10a   Const                                                         
    D EntryParms      pi                                                                                
    D  pfldr                        80a   Const                                Folder                   
    D  pfile                        10a   Const                                Physical File            
    D  pdlm                         10a   Const                                Delimiter                
     *                                                                                                  
    D doclist         c                   const('/qsys.lib/asthhobj.lib/ifs_+                           
    D                                     list.file/ifs_list.mbr')                                      
     *                                                                                                  
    D q               s              1a   inz('''')                                                     
     *                                                                                                  
    D qcmdexc         pr                  extpgm('QCMDEXC')                                             
    D  cmd                        3000a   const options(*varsize)                                       
    D  cmdlen                       15p 5 const                                                         
     *                                                                                                  
    D cmdstring       s            512a                                                                 
     *                                                                                                  
     *---------------------------------------------                                                     
     **                 M A I N                                                                         
     *---------------------------------------------                                                     
                                                                                                        
     /free                                                                                              
                                                                                                        
      cmdstring = 'cfghttpsch option(*crtdocl) doclist(' + q +                                          
                   doclist + q +') ' + 'strdir(' + q +                                                  
                   %trim(pfldr) + q + ') subtree(*none) pattern(''*'')';                                
                                                                                                        
      qcmdexc(cmdstring:%len(cmdstring));                                                               
                                                                                                        
      open ifs_list;                                                                                    
      read ifs_lstr;                                                                                    
      dow not %eof(ifs_list);                                                                           
        cmdstring = 'cpyfrmimpf fromstmf(' + q + %trim(srcdta) + q + ') +                               
                     tofile(' + %trim(pfile) + ') rcddlm(*crlf) +                                       
                     flddlm(' + q + %trim(pdlm) + q +') +                                               
                     datfmt(*usa) rplnullval(*flddft)';                                                 
        monitor;                                                                                        
         qcmdexc(cmdstring:%len(cmdstring));                                                            
         on-error;                                                                                      
         leave;                                                                                         
        endmon;                                                                                         
                                                                                                        
        cmdstring = 'mov obj(' + q + %trim(srcdta) + q + ') +                                           
                     todir(' + q + %trim(pfldr) + '/ordhist' + q +')';                                  
        monitor;                                                                                        
         qcmdexc(cmdstring:%len(cmdstring));                                                            
         on-error;                                                                                      
         leave;                                                                                         
        endmon;                                                                                         
                                                                                                        
        read ifs_lstr;                                                                                  
      enddo;                                                                                            
                                                                                                        
      close ifs_list;                                                                                   
      *inlr = *on;                                                                                      
                                                                                                        
     /end-free                                                                                          
    ****************** End of data *********************************************************************

+ Reply to Thread

Similar Threads

  1. files in QSPL
    By mark_a_hall in forum Iseries System administration
    Replies: 4
    Last Post: July 30th, 2009, 03:44 PM
  2. Replies: 3
    Last Post: September 19th, 2007, 04:54 AM
  3. logical files with multiple formats
    By christinaf in forum DDS
    Replies: 5
    Last Post: January 21st, 2006, 08:18 AM
  4. Replies: 8
    Last Post: June 17th, 2005, 02:44 PM
  5. Replies: 7
    Last Post: May 25th, 2005, 09:25 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts