5 pts.
 delete records from a directory with IFS root using CL
How to delete records from a directory with IFS root using CL based on the timestamp of the records.

Software/Hardware used:
ASKED: July 24, 2008  6:55 AM
UPDATED: May 6, 2010  7:31 AM

Answer Wiki:
Hi, Do you mean delete <b>files</b> from the IFS based on timestamp? Or do you mean delete records from a file in the IFS? Regards, Martin Gilbert.
Last Wiki Answer Submitted:  July 24, 2008  2:27 pm  by  Gilly400   23,625 pts.
All Answer Wiki Contributors:  Gilly400   23,625 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


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


 

Next question is are you familiar with UNIX commands?
You can manipulate files in the IFS using QSHELL commands – which are basically UNIX. (or UNIX-like)
For example you can get a directory listing and redirect it to a file in QSYS using a command like

ls - l ifspath > qsyspath

where ifspath is formatted like dirname/dirname
and qsyspath is formatted like qsys.lib/libname.lib/filename.fil/mbrname.mbr
Put the whole thing in a variable like &SHELCMD and then you execute it in CL using

QSC CMD(&SHELCMD) 

Of course, then you have to parse the resulting file and determine what IFS files you need to change.

If it’s individual records you are looking at, it gets more complicated. You can use the CPYFRMSTMF command to copy an IFS file to a QSYS file, modify the file as needed and then use CPYTOSTMF to put it back.

Regards
Mike

 2,725 pts.

 

Oh.. that should be
QSH CMD(&SHELCMD)

not QSC..

(too many fingers….)

Regards
Mike

 2,725 pts.

 

I do not have the idea of UNIX. Can we do this using CL commands??

 15 pts.

 

You could create an RPG program which uses some of the C runtime library functions (lstat, opendir, readdir, and closedir) to get a list of the files in the specified IFS directory, which could direct its output to a file. You could then create a command for that program that could be initiated from your CL.

(I downloaded a utility for this a while back, IFS Tools, that was created by Peter Connell. I don’t have the link anymore of where I got it, but I bet you could search and find it or something similar.)

Then you could read that output file in your CL program, determine which files you want to delete, and use the DEL command to delete the specific files.

 4,275 pts.

 

Can we do this using CL commands??

If you are running V5R4 or later, yes.

Then you just write your CL like it was a C program or ILE RPG or COBOL. Of course, if you’re going to try to do that, the programming will be much easier in C or RPG, so why do it in CL?

Tom

 110,095 pts.