Page 1 of 1

Reading a CSV file for comparing data

Posted: Thu Mar 16, 2017 10:27 am
by monahanks
Hi all, I have a project that involves reading a CSV file and comparing a column from the file to a data variable.
I am retrieving the name of the day of the week (Mon, Thu, etc) using the set variable function into variable TodayIs. I have a CSV file that has 7 rows corresponding to the days of the week. To mix things up a little, Sat is day 1, Sun is day 2, up through Fri is day 7.
I read the csv file and create a rowset named ReturnDay.
Then I want a for-each-loop to read the rowset and compare the first column to the TodayIs variable and return the second column if equal. the error I get says they are different types of variables.
how do I define these to be both character variables? My xml is below.
Code: Select all
<project name="Get Promotions files" mainModule="Main" version="2.0" logLevel="debug">
	<description>retrieve promotion files from crm7promo</description>
	<import file="D:\GoAnywhere\userdata\projects\VARIABLES\VAR_Common_AS400.xml" />
	<variable name="TodayIs" value="xxx" description="3 letter Name of Day" />
	<variable name="daynum" value="6" description="Day of week number  Saturday = 1, Sunday = 2, Friday = 7 " />

	<module name="Main" logLevel="debug">
		<!--comment-->

		<createWorkspace label="Create Workspace" version="1.0" />

		<callModule label="Call Module" module="VarAS400" version="1.0" />

		<setVariable name="TodayIs" value="${CurrentDate(&apos;E&apos;)}" version="2.0" />

		<readCSV inputFile="D:\GoAnywhere\userdata\Aptos\Daynumber.csv" outputRowSetVariable="ReturnDay" version="1.0">
			<data trim="both">
				<column index="1" name="dayname" size="3" type="VARCHAR" trim="right" />
				<column index="2" name="daynumber" size="1" type="INTEGER" />
			</data>
		</readCSV>

		<forEachLoop itemsVariable="${ReturnDay}" currentItemVariable="row">

			<print version="1.0" disabled="false">
				<![CDATA[Return Day = ${ReturnDay}

row = ${row}]]>
			</print>

			<if label="compare day name" condition="${dayname eq TodayIs}" disabled="true">

				<setVariable label="set day number" name="daynumb" value="${daynumber}" version="2.0" />

			</if>
			<exitLoop condition="${5 eq 1}" />
		</forEachLoop>

		<deleteWorkspace label="Delete Workspace" version="1.0" disabled="true" />

	</module>

</project>
TIA,
Kevin

Re: Reading a CSV file for comparing data

Posted: Mon Mar 20, 2017 11:41 am
by Support_Rick
Kevin,

Try putting a "String()" around each variable .. so, you end up comparing apples to apples.

${ string( dayname ) eq string( TodayIs ) }