Page 1 of 1

How to loop through input file

Posted: Fri Jun 10, 2016 8:20 am
by llovelace
Hiya - I'm using a database task to select all records in a file. Each record contains two fields. I'd like to read one record at a time, and use the two fields in later steps. How do I control the reading and know when I'm at the end of file?

Thanks!

Re: How to loop through input file

Posted: Wed Jun 15, 2016 5:24 pm
by Support_Rick
llovelace,

When you retrieve data from a database, you are creating a "rowset" variable as output. (Example MyData)

You can use a "ForEach" loop (Across ${MyData}) to loop through that rowset and address each record (MyRec for example).

During that looping, you can address each field of that record by it's index value -- ${MyRec[1]} ... ${MyRec[2]} -- to associate with the 1st field, 2nd field, etc...

The loop will automatically end at the end of the Rowset (${MyData}).

You could also save the values into local variables for use later if needed. (setvariable MyVar = ${MyRec[1]}.

Hope this helps!