Search code examples
ibm-midrangerpgle

Reading Multiple Files from IFS


I have a IFS file location where I have multiple inbound files from external system. There are Item related files which has a naming of ITEM_DDMMYYHHMMSS and customer related files as CUST_DDMMYYHHMMSS. There would be multiple files and my Item program has to read the Item file one by one and my customer program has to read the customer files one by one. I dont think a Mere CPYFRMIMPF can achieve this. Is there a good way to achieve this?


Solution

  • I happen to have resolved pretty much this exact situation about a year ago. Scott's answer to use the C apis from RPG is a good answer. However if you happen to have TAATOOLS on your system, it has a command called CVTIFS that makes this even easier (http://www.taatool.com/document/L_cvtifs.html). It's a fairly common third party tool so hopefully its available. You solution then becomes something like the following:

       // CVTIFS OBJ(MyDirectory) OUTLIB(QTEMP) PROCSUBDIR(*NO) <-- Call this however you prefer
    
       Exec Sql Declare FileNames Cursor For
           Select IfDirE From QTemp.IfsDirP
           Where IfoTyp = '*STMF' And IfPDir = :MyDirectory;
    
       Exec Sql Open FileNames;
    
       Exec Sql Fetch FilesNames Into :FileName;
       DoW SqlState = '00000';
           // Run your SQL XMLTable command here using FileName
           Exec Sql Fetch FilesNames Into :FileName;
       EndDo;
    
       Exec Sql Close FileNames;
    

    Additional note: You could also combine all of this into one large SQL statement and avoid the cursor but this is probably easier to understand as an answer.