While loop to read CSV file

While loop to read CSV file

I am working on reading in a variable with csv seperated data in it. I would like to loop through it and convert the data in elements but am strugling to see how I can do this. Normally A while loop would do the trick since I do not know the number of elements in the csv data. There probably is an easy solution for this but I am not seeing it. How would I best simulate a while loop to do this?

Regards Tony

Hello Tony,

There is a really simple way to deal with while loops in outsystems, here it is:

In your case I would suggest something like sequencially searching for the next "," and when there is no "," left its time to end the loop.

Hope it helps!

Hermínio Mira
Hi Tony!

Welcome to the forums - it's great to hear from you again!

About reading the CSV data, on top of my head, one way to do it is to use a While loop to iterate through the lines, and then use a text String Split function by the "," (comma) or whatever separator character the file is using. That would return all the items in that line.

The main problem is how do you end up manipulating the data in a normalized fashion, if you do not know how many columns does each row have.

You can use a file reader, reading a text line every time, and doing something like a

if (not end of file) ,
read next text line
do (split line at the separator character)
and then access the elements returned.

The extensions I recommend for that are FileSystem  and the Text extension, which if I recall correctly is included in the Enterprise Manager component.

Let me know if this helps somehow.

Best regards,

Paulo Tavares

[Edited a small error I had.]

Hi Tony,

There a CSV extension that reads CSV files pretty much like a "ExcelToRecordList" element.

Check it out here!


Hi Mário!

...that extension you suggested, I found it in search, but it says:

# RecordListToCsv
# : converts any record list to Csv. CsvToRecordList
: whish to have :) not developed yet, go on and contribute!

...is that function really implemented, or is it just for a future release? ;)

If it is, please update the description then - it might come in handy for more people! :)


Paulo Tavares

Correct me if I'm wrong, but I believe implementing a generic 'CsvToRecordList' functionality is not possible via extension.

You would have to have a way to dynamically pass the structure of the records to the extension (much like the 'Record Definition' parameter in the ExcelToRecordList widget) and that's not possible.

Or am I missing something?

I currently need to import some CSV's and have concluded the only way is to write a specific importer for each and every format.

- Stefan
CSV2RecordList – A mostly automated solution

Attached is a ZIP file of a mostly automated solution. As a newbie, I see the requirements as two different tasks.
  1. Convert a CSV file to a RecordList – This is easy and can be automated (assuming consistent delimiters)
  2. Map the converted RecordList to a structure, second RecordList, useful to the application
My ‘sample application’ is a vacation log. It was created ‘from scratch’ with CE. No tailoring was done to the espaces.
With some slight exceptions, the mapping step can be reduced to ONE action in the eSpace:

The contents of the ZIP file are
  • FileSystem.xif – The 4.1 version of the FileSystem extension found elsewhere on this forum and upgraded to 5.1. Actually Integration Studio did all the work, all I did was open and publish
  • CSV2RLTestData.csv – A sample CSV file with the delimiters as expected by the parser
  • CSV2RecordList.oml – This is the reader/parser that takes a CSV file and converts it to a RecordList where each attribute it ‘text’; this should really be included in the CSV extension but I don’t know how to do that kind of coding. ANY TAKERS?
  • CSV2RLTest.oml – This is THE application that ties everything together
Hope this is useful to someone.
Alex C.