Midrange News for the IBM i Community

Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Reading CSV files in RPG
has no ratings.
Published: 02 Nov 2011
Revised: 20 Oct 2013 - 1459 days ago
Last viewed on: 18 Oct 2017 (4896 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Reading CSV files in RPG Published by: Bob Cozzi on 02 Nov 2011 view comments(4)

RPG xTools has always had CSV Generation APIs, but now I've built a CSV reader API for RPG. Question is, is this something lots of people need?  I know I'm using CPYFRMIMPF all the time (coming from Excel) so the ability to read and parse the CSV file directly is very helpful to me. 

Any comments?

Return to midrangenews.com home page.
Sort Ascend | Descend


(Sign in to Post a Comment)
Posted by: Viking
Premium member *
Comment on: Reading CSV files in RPG
Posted: 5 years 11 months 15 days 17 hours 11 minutes ago

That would be useful.  Post it as your next RPG Report newsletter!

Posted by: bobcozzi
Site Admin ****
Comment on: Reading CSV files in RPG
Posted: 5 years 11 months 15 days 15 hours 9 minutes ago

What I've got working is the parser itself.

RPG xTools has the "read IFS file" thing in it.

But right now, the parse accepts a "row" of data, parses it and returns the results to an array.

So each CSV value is stored in an individual array element which the programmer would then use EVAL along with %DEC or straight assignment to move the elements into the corresponding fields.

Like my Write To CSV API, I would probably include an API in xTools that provides an Open, read record, close thing.

Posted by: paul.raulerson
Premium member *
Comment on: Reading CSV files in RPG
Posted: 4 years 3 days 5 hours 40 minutes ago

Wish I had not lost track of you guys when the old system shut down, this post would have been very useful to me tonight.


I just had to spend a hour writing an import module for a CSV file. :)  It wasn't tough of course, not with %SUBST and %SCAN. And wasn't generic either, it was for one single format - but it amazes me how much I forget if I am not using it each day. ;)



Posted by: clbirk
Premium member *
Comment on: Reading CSV files in RPG
Posted: 3 years 11 months 28 days 11 hours 38 minutes ago

I recently watched a video of Jon Paris, talking about rpg open access which contrary to the opinion of some, it is more than just for web enablement. He did examples of using OA to write csv files and so reading is also something and unlike passing the results back in an array, etc. one could get them loaded right into the fields.

anyone using OA to do webservices, read/write csv files, etc.?