Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-03-08
9
Medium Priority
?
1,374 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
8 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
[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 

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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

If you try to migrate from Elastix to Issabel, you will face a lot of issues. These problems are inevitable but fortunately, you can fix them. In the guide below, I will explain how I performed the migration while keeping all data and successfully t…
If you need to complete a Physical to Virtual (P2V), Virtual to Virtual (V2V) conversion to a VMware product (VMware Workstation, Player or VMware vSphere (ESXi) ) for FREE, then there is some good news...
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

571 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