Looping in DataStage

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

srai
Participant
Posts: 101
Joined: Wed Feb 09, 2005 10:50 pm

Looping in DataStage

Post by srai »

Hi All,

I have to develop a datastage job which internally calling a web service and updating saleforce.com portal and returning indicator as True or False.
Based on this indicator we have to run the job in loop.
Means if web service return indicator as "False" then againg same job we have to run. Once web service return indicator as "True" means all the records got updated successfully and job should come out of loop and stop the job.

My approach is run the job and store the return of web service in a text file and the using execute command stage read the file and if it retun "False" run the job again. But I am not able to implement this requirement using Start loop and end loop stage.

Please help me if some has any idea or approach to implement this logic.

Thanks in advance.
Santosh
Pagadrai
Participant
Posts: 111
Joined: Fri Dec 31, 2004 1:16 am
Location: Chennai

Re: Looping in DataStage

Post by Pagadrai »

Hi Santosh,

If i were you, i would have implemented this logic using a basic routine for the looping logic instead of opting for a sequence job.

In the sequence job we can specify the count of loops to be executed or for an 'in list' for the counter. But i dont think we have the option to break from the loop based on custom condition.

Good luck.
srai
Participant
Posts: 101
Joined: Wed Feb 09, 2005 10:50 pm

Re: Looping in DataStage

Post by srai »

Pagadrai wrote:Hi Santosh,

If i were you, i would have implemented this logic using a basic routine for the looping logic instead of opting for a sequence job.

In the sequence job we can specify the count of loops to be executed or for an 'in list' for the counter. But i dont think we have the option to break from the loop based on custom condition.

Good luck.
Hi,

Thanks. Same thing I was also thinking.
But I am not verymuch comfortable with the routine writing.
Could you provide some small tips how to write routine in DataStage for this particular requirement?

Thanks a lot.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

'Breaking from the loop' is easily done - it's just a matter of branching out of the loop to a point after the End Loop stage based on your 'custom condition'.
-craig

"You can never have too many knives" -- Logan Nine Fingers
srai
Participant
Posts: 101
Joined: Wed Feb 09, 2005 10:50 pm

Post by srai »

chulett wrote:'Breaking from the loop' is easily done - it's just a matter of branching out of the loop to a point after the End Loop stage based on your 'custom condition'. ...

Hi Craig,

But I did not understand how to do it using sequencer job...because when I am using start loop activity stage there are two types of loop.
In this case we cant use numeric loop because we dont know how many time we have to run the loop.
The second one is List loop there if I pass run it for "false " its running only once. We need to run this job jon in loop untill we get "true".
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What I've done is set it to run X number of times and set X to a sufficiently high number such that it (hopefully) won't end before your custom condition is met.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

To help with this and to cut down on the 'loop speed' add an Execute Command (or Routine Activity) stage inside the loop that does a 'sleep' for a user-configurable period of time.
-craig

"You can never have too many knives" -- Logan Nine Fingers
srai
Participant
Posts: 101
Joined: Wed Feb 09, 2005 10:50 pm

Post by srai »

chulett wrote:To help with this and to cut down on the 'loop speed' add an Execute Command (or Routine Activity) stage inside the loop that does a 'sleep' for a user-configurable period of time. ...

Hi Craig,

I am facing one problem. I am reading the return value from a seq file using execute command and in trigger I am using custom that if return is "false" then job should enter to loop, but its not going to the loop.
But when I put unconditional trigger, job is entering to the loop.

My job design is something like this->
1) Server Job - Calling the web service and storing return to Seq file.--This job is working fine and I am able to get returin seq file.
2) Main Sequence job-

Job Activity stage (calling the server job)-->execute command stage(reading the seq file for true/false, and in Trigger(custom) check the return of the execute command stage and if false go to loop and again call the server job )-->start loop(for 10 times only for testing purpose)--->serverjob---> end loop activity.

But job is getting executed for only one time even though web service returns as false. If I remove the custom trigger, job is entering into the the loop and executing for 10 time.

Please help me if any body has any idea how to implement this.

Thanks
Santosh
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

I believe you are using cat command to get True/False. Are you removing FIELD MARKS before comparision. I think its related to wrong comparision in custom trigger not the logic.

Code: Select all

use $returnvalue<1>="true".

Match case too.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

This is indeed probably the case. Either use the <1> syntax noted or use Convert() to remove the @FM characters.
-craig

"You can never have too many knives" -- Logan Nine Fingers
srai
Participant
Posts: 101
Joined: Wed Feb 09, 2005 10:50 pm

Post by srai »

priyadarshikunal wrote:I believe you are using cat command to get True/False. Are you removing FIELD MARKS before comparision. I think its related to wrong comparision in custom trigger not the logic.

Code: Select all

use $returnvalue<1>="true".

Match case too.
Hi Kunal,

I am using following syntax Execute_Command_3.$CommandOutput<1>="true" in custom trigger where Execute_Command_3 is execute command stage but its not working.

Please let me know if I am using the wrong syntax.

Thanks
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

First try to get what is the command output from the sequence log.
are you getting "true"?

Please let us know the command output from the logs.

Then try following codes 1 by 1

Code: Select all

Convert(@FM,'',Execute_Command_3.$CommandOutput)="true"

Trim(Convert(@FM,'',Execute_Command_3.$CommandOutput))="true"

UpCase(Trim(Convert(@FM,'',Execute_Command_3.$CommandOutput)))="TRUE"
And then let us know which one worked (if any).
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Try Convert() instead and see if that helps. If not, post the log entry that shows the Execute Command results and the returned value.
-craig

"You can never have too many knives" -- Logan Nine Fingers
srai
Participant
Posts: 101
Joined: Wed Feb 09, 2005 10:50 pm

Post by srai »

priyadarshikunal wrote:First try to get what is the command output from the sequence log.
are you getting "true"?

Please let us know the command output from the logs.

Then try following codes 1 by 1

Code: Select all

Convert(@FM,'',Execute_Command_3.$CommandOutput)="true"

Trim(Convert(@FM,'',Execute_Command_3.$CommandOutput))="true"

UpCase(Trim(Convert(@FM,'',Execute_Command_3.$CommandOutput)))="TRUE"
And then let us know which one worked (if any).

Hi Kunal,

Following are the output of Command output

Mainseq..JobControl (@Execute_Command_3): Executed: cat /Data/Project/input/echo_tg.txt
Reply=0
Output from command ====>
"true"

and I used all three options mentioned by you but its not working for me.

Thanks
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

yes it won't work because you are comparing
"true"=true

here quotes are making the difference

Use one of the codes below

Code: Select all

Trim(Convert('"','',Convert(@FM,'',Execute_Command_3.$CommandOutput)))="true"


Trim(Convert(@FM,'',Execute_Command_3.$CommandOutput),'"',"A"))="true"

Convert(@FM,'',Execute_Command_3.$CommandOutput)='"true"'
And let us know if it works.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Post Reply