20 pts.
 Renaming a file in the IFS directory
I am receiving a file daily in an IFS directory, I manually copy the file to a library using the CPYFRMSTMF command. I want to automate the process so that it will be done every day at a specific time. The challenge is that the file name in the IFS directory is different every day, for example it is ABC121206 today and ABC121306 tomorrow and the CPYFRMSTMF cannot take a generic value such as ABC*. Is there a process or API that would rename the file to a generic name in the IFS so that the CPYFRMSTMF command would use that name every days? Thanks

Software/Hardware used:
ASKED: December 14, 2006  3:53 PM
UPDATED: December 26, 2009  1:34 AM

Answer Wiki:
If the file name contains a date. Create a variable with the constant (i.e. ABCxxxxxx). You can do it one of two ways (chgvar &filename ('ABC' || &date)) or (chgvar substr(&filename,4,6) &date). Use the variable (&filename) in you copy statement. ============================================= If you have Qshell installed, try experimenting with something like this:<pre> crtdtaara MYLS *char 32 qsh cmd('ls | datarea -w -l MYLS') dspdtaara MYLS</pre>Note that the "pipe" character between the ls and datarea utilities will need to be the appropriate pipe character for your system. Right now, my emulator sessions require using "!". There are far better ways of doing this, but you need something simple for now. What I coded is simply to give you an example to see if it can be adapted. You ought to be able to copy/paste those commands onto a command line (watching the "pipe".) The code creates a basic *char(32) data area in the current library -- pick a library you prefer, set the size you need. The STRQSH commands then list (ls) the current directory to standard out, which is piped into the datarea utility, which writes (-w) lines to the MYLS data area found in the library list (-l). You can then display the data area to see what's there. In a CL program, you'd use RTVDTAARA rather than DSPDTAARA of course. If you try variations of ls, you can choose the path that you want to list and set a pattern to select which files to list. If there's only and always just a single file, then you probably won't have to worry much. It's not very sophisticated. I didn't think you needed anything but the basics. It should be easy enough to adapt for various purposes. Tom
Last Wiki Answer Submitted:  December 26, 2009  1:34 am  by  MDratwa   645 pts.
All Answer Wiki Contributors:  MDratwa   645 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

If you need the process to be more forgiving you can create a list of the file names in the IFS folder and populate a physical file with the results. Then run a program to use CPYFRMSTMF for each filename in your physical file. Here is some sample CL code to create the physical file with the list of filenames in the IFS the reason for filelist2 is this PF has the field name in it.

CLRPFM FILE(mylib/FILELIST) QSH CMD(‘(LS /IFSfoldername>/QSYS.LIB/mylib.LIB/FILELIST.FILE/FILELIST.MBR)’)
CPYF FROMFILE(mylib/FILELIST) TOFILE(mylib/FILELIST2) MBROPT(*REPLACE) FMTOPT(*NOCHK)

 0 pts.