if then elseif

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
qutesanju
Participant
Posts: 373
Joined: Tue Aug 26, 2008 4:52 am

if then elseif

Post by qutesanju »

how can i code--if then elseif
in a stage variable?

Code: Select all

if       lnk_xfmr.DIR = 'IN' then  lnk_xfmr.AC1 
else if  lnk_xfmr.DIR = 'OUT'then nk_xfmr.AC2
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

Just as you would in an output link derivation...the rules are the same.

Every "if" requires both a "then" and an "else" to be present. In your code, you have no else statement to describe what to do when lnk_xfmr.DIR is not equal to either 'IN' or 'OUT'.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Re: if then elseif

Post by rkashyap »

This works ...

if lnk_xfmr.DIR = 'IN' then lnk_xfmr.AC1 else
if lnk_xfmr.DIR = 'OUT' then lnk_xfmr.AC2 else ...

Note: If no default exists for "..." then use setNull().
qutesanju
Participant
Posts: 373
Joined: Tue Aug 26, 2008 4:52 am

Post by qutesanju »

do you mean like this?

Code: Select all


if       lnk_lkp_filter_table_xfmr.C_ACH_DIR = 'IN' then  lnk_lkp_filter_table_xfmr.N_AC2 

else  lnk_lkp_filter_table_xfmr.C_ACH_DIR = 'OUT' then lnk_lkp_filter_table_xfmr.N_AC1 

else setNULL()

jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

There ya go! The column itself may only ever have "IN" and "OUT" as values, but in your logic you need to account for the possibility. If you absolutely, positively know that "IN" and "OUT" are all you will ever see, then the following type of logic could be valid, but wouldn't catch situations where the data is invalid:

Code: Select all

if VALUE = 'IN' then 1 else 2
Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

qutesanju wrote:do you mean like this?

Code: Select all


if       lnk_lkp_filter_table_xfmr.C_ACH_DIR = 'IN' then  lnk_lkp_filter_table_xfmr.N_AC2 

else  lnk_lkp_filter_table_xfmr.C_ACH_DIR = 'OUT' then lnk_lkp_filter_table_xfmr.N_AC1 

else setNULL()

Yes.
Post Reply