Extra iteration in Loop Activity

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
chaks
Premium Member
Premium Member
Posts: 39
Joined: Wed Nov 22, 2006 9:21 pm
Location: MA

Extra iteration in Loop Activity

Post 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
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If that's not possible include a Nested Condition activity within the loop to test whether $Counter > ""
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chaks
Premium Member
Premium Member
Posts: 39
Joined: Wed Nov 22, 2006 9:21 pm
Location: MA

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Probably. Or, as Ray noted, include a stage to check the value and when empty bypass whatever is in the loop.
-craig

"You can never have too many knives" -- Logan Nine Fingers
filename.txt
Participant
Posts: 27
Joined: Thu Mar 20, 2008 11:55 am

Post 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
Thanks.

"Creativity is the ability to use your available resources to their fullest."
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chaks
Premium Member
Premium Member
Posts: 39
Joined: Wed Nov 22, 2006 9:21 pm
Location: MA

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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 )
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chaks
Premium Member
Premium Member
Posts: 39
Joined: Wed Nov 22, 2006 9:21 pm
Location: MA

Post 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!
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It probably failed because IsNull() is not really the test you wanted. It was IsNotNull(), as I posted.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
afriend2stay4ever
Participant
Posts: 1
Joined: Tue Feb 26, 2008 1:26 pm

Post 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
Post Reply