Help me on this to solve it

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

Post Reply
shiv_nm
Participant
Posts: 13
Joined: Thu Sep 09, 2004 11:23 pm
Location: Bangalore
Contact:

Help me on this to solve it

Post by shiv_nm »

Hi,
How can i handle this condition in DS?

If (DSLink47.FACode = "11" OR DSLink47.FACode = "12" OR (DSLink47.FACode="13" AND DSLink47.SM_Code !="24" AND DSLink47.SM_Code !=@NULL)
"A"
Case (DSLink47.FACode = "14" OR (DSLink47.FACode="13" AND DSLink47.SM_Code ="24"))
"C"
End Case

Regards
Shiv
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

You can use a CASE statement if you move the statement into a routine and call that routine from your transformer. FACode and SM_Code would be inputs to the routine and "A" and "C" would be the return code. Use the Test button to test your code.

You need to have a CASE @TRUE statement that captures all combinations that are not "A" or "C".

Code: Select all

BEING CASE
CASE (FACode = "11" OR FACode = "12" OR (FACode="13" AND SMCode !="24" AND SMCode !=@NULL)
    Ans = "A" 
Case (FACode = "14" OR (FACode="13" AND SMCode ="24")) THEN
    Ans = "C" 
CASE @TRUE
    Ans = "?"
END CASE
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I don't believe that != is a valid operator in server job expressions. The only valid operators in DataStage BASIC for "not equal to" are
<>
><
NE
#

You are not permitted to test against @NULL. You must use the IsNull function.

Expressions do not support the CASE construct; in an expression you'll need nested If..Then..Else to achieve your aim. Or you can move the logic to a routine, as Vince suggested (though it's BEGIN CASE rather than BEING CASE!).

So, what you're left with is:

Code: Select all

If (DSLink47.FACode = "11" OR DSLink47.FACode = "12" OR (DSLink47.FACode="13" AND DSLink47.SM_Code <>"24" AND Not(IsNull(DSLink47.SM_Code)) Then "A" Else If (DSLink47.FACode = "14" OR (DSLink47.FACode="13" AND DSLink47.SM_Code ="24")) Then "C" Else "" 
(you must cover all possibilities)
Logic is evaluated purely left to right except where other precedence is specified by parentheses. That is, AND and OR have the same precedence.
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 »

ray.wurlod wrote:That is, AND and OR have the same precedence.
Are you sure about that, Ray? I was under the impression that it followed more 'standard' precedence rules in that AND had precedence over OR. :? Maybe I've been fooling myself all these years...
-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 »

Yes I'm sure (in DataStage BASIC and UniVerse BASIC expressions). Which is why I made the point - it's different from some other languages in this behaviour. :D
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

I sure am glad this wasn't a question in a DataStage certification test. I think I scored about 15%! I'd certainly put something like this in a routine so I could test it and add some code comments. You might find yourself using it in other jobs.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I've heard it argued that it helps to be certifiable to be a DataStage consultant! :lol:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply