Page 1 of 1

Help me on this to solve it

Posted: Wed Sep 22, 2004 12:30 am
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

Posted: Wed Sep 22, 2004 12:51 am
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

Posted: Wed Sep 22, 2004 2:25 am
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.

Posted: Wed Sep 22, 2004 7:07 am
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...

Posted: Wed Sep 22, 2004 3:52 pm
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

Posted: Wed Sep 22, 2004 4:20 pm
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.

Posted: Wed Sep 22, 2004 4:25 pm
by ray.wurlod
I've heard it argued that it helps to be certifiable to be a DataStage consultant! :lol: