Page 1 of 1

Extra iteration in Loop Activity

Posted: Wed Sep 10, 2008 3:13 pm
by chaks
Hi,
I am creating a text file using comma as record delimiter,values in the file look like this

Code: Select all

000TX,000TZ,000WG,
I am reading this file with Execute command and passing it to Loop Activity,now loop finds another comma at the end and iterates again with null value. now I need your help to remove the very last comma to avoid the extra iteration.

Thanks in Advance
shiva

Posted: Wed Sep 10, 2008 3:19 pm
by chulett
How are you creating the text file? The loop is doing the right thing as the trailing comma denotes a null or empty field at the end. Best to not generate one there in the first place.

Posted: Wed Sep 10, 2008 3:28 pm
by ray.wurlod
If that's not possible include a Nested Condition activity within the loop to test whether $Counter > ""

Posted: Wed Sep 10, 2008 3:29 pm
by chaks
Thanks Craig,
I am generating that file in another parallel job and using a sequential stage for that. I know every thing is working as they are supposed to. As i am using Execute command to read the file,Can we use any Unix command to strip off the last comma.

Posted: Wed Sep 10, 2008 3:34 pm
by chulett
Probably. Or, as Ray noted, include a stage to check the value and when empty bypass whatever is in the loop.

Posted: Wed Sep 10, 2008 4:26 pm
by filename.txt
Hi chaks,

you could also change the file (deleting the comma in unix) before Loop using execute command stage.

execute command---->Startloop<====>endloop

Posted: Wed Sep 10, 2008 5:13 pm
by ray.wurlod
... only if you know that the final comma is always there. Otherwise the command becomes a tad more complex. Still do-able, but caution is advised.

Posted: Thu Sep 11, 2008 11:12 am
by chaks
Thanks Filename.txt :-) & Ray

I thought Nested condition will solve the issue but It is not working, I used the below derivation in Nested Condition

Code: Select all

StartLoop_BusUnits_List.$Counter <>'' Or StartLoop_BusUnits_List.$Counter<>' ' Or StartLoop_BusUnits_List.$Counter<>',' Or StartLoop_BusUnits_List.$Counter <> @NULL
And the job is like this

Code: Select all

 <Execute Command> --> <Loop Begin> --> <Nested Cond> --> <JOB> --> <Loop End>
As Comma is a record delimiter, it will be always there at the end, Can you give me the Unix command please.

Posted: Thu Sep 11, 2008 11:22 am
by chulett
AND not OR. And you can't check if something is equal to or not equal to NULL as that value is unknown. Use IsNull() instead.

Posted: Thu Sep 11, 2008 4:02 pm
by ray.wurlod
Assuming that the real names have more than one character:

Code: Select all

Len(StartLoop_BusUnits_List.$Counter) <= 1 And IsNotNull(StartLoop_BusUnits_List.$Counter )

Posted: Thu Sep 11, 2008 4:02 pm
by chaks
Hi Craig
I tried to check with IsNull but that failed, I don't know why, Finally I Used Len($Counter) > 2 in the Nested condition, Which resolved my issue.


Thanks Every one for your Support!

Posted: Thu Sep 11, 2008 5:40 pm
by ray.wurlod
It probably failed because IsNull() is not really the test you wanted. It was IsNotNull(), as I posted.

Posted: Thu Sep 11, 2008 9:16 pm
by chulett
My 'IsNull' advice was generic, strictly meant as an example of how to test for null and not meant to be applied directly to this problem. It seemed pretty obvious to me that one would need to 'not' it in this context. Ah, well... c'est la guerre.

Posted: Thu Mar 19, 2009 2:35 am
by afriend2stay4ever
chulett wrote:How are you creating the text file? The loop is doing the right thing as the trailing comma denotes a null or empty field at the end. Best to not generate one there in the first place. ...
run fillowing command to put the out put in a single line and remove the last comma

ls *FILE_PATTERN| awk '{ ORS=","; print; }'|sed '$s/,$//g'

sri