?
Solved

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

Posted on 2005-03-08
9
Medium Priority
?
1,252 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:peteie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 18

Expert Comment

by:Dave Ford
ID: 13490796
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
0
 

Author Comment

by:peteie
ID: 13490944
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
0
 
LVL 14

Expert Comment

by:daveslater
ID: 13491543
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
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Accepted Solution

by:
chriswalton777 earned 800 total points
ID: 13494586
You might find it easier to use a couple of qshell commands, you could try something like qsh cmd('cat test.csv | wc -l')

Chris
0
 
LVL 3

Assisted Solution

by:RQnone
RQnone earned 200 total points
ID: 13495683
I would have never thought of doing it this way if Chris hadn't mentioned using QSH

CRTPF FILE(MYLIB/OUTPUT) RCDLEN(132)

STRQSH CMD('wc -l test.csv >/qsys.lib/mylib.lib/output.file/output.mbr')

You now have 1 record in file MYLIB/OUTPUT that shows the number of lines then the file name

   235   test.csv

Would be easy enough to create a CL program and a command.
Something like RTVNR IFS('/home/myhome/test.csv') RTNVAR( &RTN# )
0
 

Author Comment

by:peteie
ID: 13497144
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
0
 

Author Comment

by:peteie
ID: 13499699
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.
0
 
LVL 27

Expert Comment

by:tliotta
ID: 13511530
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
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Check out the latest tech news, community articles, and expert highlights in August's newsletter.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question