Link to home
Start Free TrialLog in
Avatar of peteie
peteie

asked on

How to retrieve record count of .csv file in IFS?

Is there a way to retrieve the record count of a .csv file in the IFS from RPG, CL, or SQL?  We are at V5R2.
Avatar of Member_2_2484401
Member_2_2484401
Flag of United States of America image

Ok, I realize this may be overly obvious (and most likely not what you're looking for), but you could always us the CpyFrmImpF command to put the data into a datbase table. Then, a simple "Select Count(*) From MyTable" would give you the record-count.

HTH,
DaveSlash
Avatar of peteie
peteie

ASKER

Your right, that is overly obvious.  Which is probably why it never occurred to me, I have a habit of making things harder than they need to be.  However, I don't think that is what I'm looking for.   This is going to be part of an automated ftp system where once a week we ftp all the files in certain directories to our clients ftp site.  After the FTP is complete for each client we create a log report of the files transfered, the status of the ftp transfer, and how many records were transfered for each file.  We have several clients who could be using this.  With each of these clients having anywhere from 1 to a couple of hundred files, and each file could have from a couple of hundred records to several thousand.  So, using the CpyFrmImpF command would probably not be a good way to implement this.

Although, I've been searching google & IBM for a couple of hours and not found anything yet.... If I don't find a better way, I'll probably use your suggestion.

Peteie
Hi
Read the csv into a  user space,  load the user space into a host variable with offsets and count the number of carriage returns.
(if the length of file is < 64K then you can read it into a host variable direct).

I am on holiday till 18th so can not supply any code.

Dave
ASKER CERTIFIED SOLUTION
Avatar of chriswalton777
chriswalton777
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peteie

ASKER

Oops!  I clicked the wrong one as the accepted answer.  I wanted ChrisWalton777 to have the accepted answer and RQnone to have the assisted.  Thank you all for the help.

peteie
Avatar of peteie

ASKER

When using the QSH command is it possible to place the results of the command directly into a CL variable?  I know if I go with RQnone's example I could read it from the file, but I was hoping to be able to load the CL variable directly from the QSH command.
peteie:

I'm not sure of a way to put a QSH value directly into a CL variable, but it's (fairly) easy to make a value _available_ to a CL program.

One potential way...

QShell output can be redirected to a streamfile. Further, for the purposes of this question, there is no difference between a streamfile and a user space. CL can create and retrieve values from a user space.

So, create a user space. Run the QSH commands redirecting the value to the space. Then, the CL calls the Retrieve User Space (QUSRTVUS) API to retrieve the value.

Tom