Warnings from routines returning other than 0

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

RodBarnes
Charter Member
Charter Member
Posts: 182
Joined: Fri Mar 18, 2005 2:10 pm

Warnings from routines returning other than 0

Post by RodBarnes »

I have a sequence that uses a couple of routine stages that employ custom routines to retrieve values. These values are subsequently stored in sequence/job parameters for use by several of the stages in the sequence.

Unfortunately, when a routine returns anything other than zero, it causes a "did not finish OK" warning to be inserted into the log. The help confirms this but doesn't offer any alternatives. The result is a Status = 2 for the sequence. This is confusing because I have to go investigate to know whether the status reflects the "normal" warning from my routine return values or a "real" warning caused by something else.

I'd like to come up with a way that the routines can return the values I need without DS thinking it is an incorrect value. Any suggestions from those who've done something similar to this?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

We've had this conversation many times here, Rod. I don't have time to do it justice, but I'm sure a search would turn up several examples.

This is how the new 'Automatically handle activities that fail' option works in Sequence jobs. Check the docs / online help, it has two suggestions on handling routines so they don't cause issues like this.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

You can use the Conditional Triggers from the Routine Activities in the Job sequence. If you look at the Options, you will find that you can define the triggers based upon the "Return Value" of the routine and also "Custom" Options. So, get few of these from your routine activity stage and define your return values you expect to be(if you know what it is beforehand) and pass them through a sequencer with condition set to ANY and then have an "Otherwise Trigger" and send it to the "UtilityWarningToLog" Routine to capture any other exceptions.

HTH.
Kris

Where's the "Any" key?-Homer Simpson
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Make your routines always return 0, look at using @USER0 thru @USER4 as some alternative methods for returning values from a subroutine call. The are COMMON variables that exist out there without you knowing about them. Now you do, think about using them. :wink:
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
RodBarnes
Charter Member
Charter Member
Posts: 182
Joined: Fri Mar 18, 2005 2:10 pm

Post by RodBarnes »

Actually, I tried several searches. The challenge is knowing what to search for. :?

And I understand about the option "Automatically handle activities that fail". But you can't use this if you also have an exception handler in the sequence.
chulett wrote:We've had this conversation many times here, Rod. I don't have time to do it justice, but I'm sure a search would turn up several examples.

This is how the new 'Automatically handle activities that fail' option works in Sequence jobs. Check the docs / online help, it has two suggestions on handling routines so they don't cause issues like this.
RodBarnes
Charter Member
Charter Member
Posts: 182
Joined: Fri Mar 18, 2005 2:10 pm

Post by RodBarnes »

Thank you. This sounds promising. I'll look into it.
kcbland wrote:Make your routines always return 0, look at using @USER0 thru @USER4 as some alternative methods for returning values from a subroutine call. The are COMMON variables that exist out there without you knowing about them. Now you do, think about using them. :wink:
RodBarnes
Charter Member
Charter Member
Posts: 182
Joined: Fri Mar 18, 2005 2:10 pm

Post by RodBarnes »

Oh, so if I make the trigger catch the warning as well as the OK (and treating them as acceptable) then the warning won't be in the log?

This sounds worth checking out. Thanks.
kris007 wrote:You can use the Conditional Triggers from the Routine Activities in the Job sequence. If you look at the Options, you will find that you can define the triggers based upon the "Return Value" of the routine and also "Custom" Options. So, get few of these from your routine activity stage and define your return values you expect to be(if you know what it is beforehand) and pass them through a sequencer with condition set to ANY and then have an "Otherwise Trigger" and send it to the "UtilityWarningToLog" Routine to capture any other exceptions.

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

Post by chulett »

Yes, that's part of what is documented in the online help. It only 'automatically handles' failures it thinks that you are not explicitly handling yourself.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

They sort of switched it. You need to use routine arguments to return values in a sequence. Newer versions allow you to use argment values as parameter values in 7.5 and above.
Mamu Kim
RodBarnes
Charter Member
Charter Member
Posts: 182
Joined: Fri Mar 18, 2005 2:10 pm

Post by RodBarnes »

I can easily see how I could put something into these variables within my routine. But I haven't figured out a way to get the values out of them without using another routine. It won't accept them as an expression in the parameters passed to a job by the sequence.

Can you provide any examples?
kcbland wrote:Make your routines always return 0, look at using @USER0 thru @USER4 as some alternative methods for returning values from a subroutine call. The are COMMON variables that exist out there without you knowing about them. Now you do, think about using them. :wink:
RodBarnes
Charter Member
Charter Member
Posts: 182
Joined: Fri Mar 18, 2005 2:10 pm

Post by RodBarnes »

I spent a while working along this line but haven't been completely successful. Even though I made the trigger a "Custom" and the expression "RUNOK Or RUNWARN", it triggers correctly but the warning still shows in the log and produces a Status = 2.

The only thing I found that affects the log output and status is to uncheck the "Log warnings..." option in the job properties dialog. Unfortunately, of course, this causes ALL warnings to not be logged. It does, however, influence the status so you get 1 instead of 2.
kris007 wrote:You can use the Conditional Triggers from the Routine Activities in the Job sequence. If you look at the Options, you will find that you can define the triggers based upon the "Return Value" of the routine and also "Custom" Options. So, get few of these from your routine activity stage and define your return values you expect to be(if you know what it is beforehand) and pass them through a sequencer with condition set to ANY and then have an "Otherwise Trigger" and send it to the "UtilityWarningToLog" Routine to capture any other exceptions.

HTH.
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Post by kris007 »

The answer to your question totally depends on how you want your Jobsequence to proceed based on the Routine's Return Values. Here are some suggestions which I think apply to your scenario:

Method1. You would need two triggers coming out of your Routine Activity Stage. One is ReturnValue(Condition) which you can set equal to zero or not equal to zero or any other fixed value you need and the other trigger needs to be "Otherwise" Trigger so that it handles all failures or otherwise conditions.Now pass the ReturnValue to downstream Jobs.

Method2. Now, if your routine always gives a different output based on some calculations with different inputs, you can simplify your job design by using a UserVariableStage. All you need is add a row to the UserVariableStage and then in the expression editor compute your routine. Now pass this uservariable value downstream to as many jobs as you can. It passes the ReturnValue of your routine to wherever you want, which I guess suits your requirement as much as it can.

I have used both methods mentioned above successfully in the past without any problems and have verified them again on my system today.So, I think you should be good to go with one of these methods. Else come back here and we can figure it out. :wink:
Kris

Where's the "Any" key?-Homer Simpson
RodBarnes
Charter Member
Charter Member
Posts: 182
Joined: Fri Mar 18, 2005 2:10 pm

Post by RodBarnes »

That was exactly what I needed. What have I learnt? 1) "routine" activities are more for doing some job and reporting back whether it succeeded or not, and 2) "user variable" activities are more for setting up variable values for use within the sequence by other stages.

You got me on track. Thanks.
kris007 wrote:Now, if your routine always gives a different output based on some calculations with different inputs, you can simplify your job design by using a UserVariableStage. All you need is add a row to the UserVariableStage and then in the expression editor compute your routine. Now pass this uservariable value downstream to as many jobs as you can. It passes the ReturnValue of your routine to wherever you want, which I guess suits your requirement as much as it can.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

If you are on DS 7.5 or above then any argument in a routine can be used as a parameter value. So your routine can return 0 or 1 and also return an argument with the real value you what passed back. You may need to add an argument to do this.

I think the same is true for variables within the sequence. I am not sure if they call these stage variables or not but whatever they call them you can use them to do calculations or whatever need them for. This is very different in earlier versions of DS. This is very powerful and with looping can do some very cool stuff. This makes upgrading very useful.
Mamu Kim
RodBarnes
Charter Member
Charter Member
Posts: 182
Joined: Fri Mar 18, 2005 2:10 pm

Post by RodBarnes »

If I undersand, you're saying that I can use a passed parameter to return a value as well. I'm not sure how you would do that in a routine activity since the only thing available is the <stage_name>.$ReturnValue. I see no way to access the passed in parameters from the stage. So maybe I'm not understanding your suggestion.
kduke wrote:If you are on DS 7.5 or above then any argument in a routine can be used as a parameter value. So your routine can return 0 or 1 and also return an argument with the real value you what passed back. You may need to add an argument to do this.
Post Reply