question regding if then else

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
srikie
Participant
Posts: 58
Joined: Thu Oct 14, 2004 4:19 pm

question regding if then else

Post by srikie »

Hi,
I have this question regding if then -else.
Can we acheive
if <condition>
then <expression1> <expression2>
else
<expression3><expression4>
end

i.e., performing multiple actions based on single condition checking.

Let me know if I am not clear.
Thanks
srikie
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Sure... more like this is how I do it:

Code: Select all

if <condition> then
  <expression1> 
  <expression2> 
else 
  <expression3>
  <expression4> 
end
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

chulett wrote:Sure... more like this is how I do it:

Code: Select all

if <condition> then
  <expression1> 
  <expression2> 
else 
  <expression3>
  <expression4> 
end
It's end else

Code: Select all

if <condition> then
  <expression1> 
  <expression2> 
end else 
  <expression3>
  <expression4> 
end
[/quote]
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
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:shock: Doh! You so right... too much in a hurry.
-craig

"You can never have too many knives" -- Logan Nine Fingers
srikie
Participant
Posts: 58
Joined: Thu Oct 14, 2004 4:19 pm

Post by srikie »

It's end else

Code: Select all

if <condition> then
  <expression1> 
  <expression2> 
end else 
  <expression3>
  <expression4> 
end
[/quote][/quote]

But I dont want to return any thing from <expression2> I mean based on that condition I want to increment the counter variable.
e.g., if var1=0 then
var2
count:=count+1
end
will that work I mean I dont know the assignment stmt for datastage.
Thanks
srikie
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

The assignment statement is confusing.

Code: Select all

x = 12
if x = 12 then
   y = 1
   z = 2
end else
   y = 2
   z = 3
end
You can also do C++ type assignments:

Code: Select all

x =1
x += 5
* x now equals 6
x -= 1 
* x now equals 5
x := 2
* x now equals 25 because it is the same as x = "2" : "5"
* : concatenates strings together
Assignment in BASIC is the same as a logical statement. Not like other langauges where x == 1 checks for equality and x = 1 is an assignment statement.
Mamu Kim
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

* is a comment line. Also BASIC if then else is different than one used in a transformation. In a transformation it is treated as a single line statement therefore there is no end like a multiple line if then else.

if x = 1 then 10 else 20

This will assign a 10 or 20 to column in a transform.
Mamu Kim
srikie
Participant
Posts: 58
Joined: Thu Oct 14, 2004 4:19 pm

Post by srikie »

kduke wrote:* is a comment line. Also BASIC if then else is different than one used in a transformation. In a transformation it is treated as a single line statement therefore there is no end like a multiple line if then else.

if x = 1 then 10 else 20

This will assign a 10 or 20 to column in a transform.
Yeh that what I wanted to know if we could use multiple stmts in derivation in transformer stage. And also I am talking abt Data Stage mvs so BASIC doesnt work in this case.

Srikie
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

You only get 1 expression in the THEN and 1 expression in the ELSE using an IF-THEN-ELSE in a mainframe job transformer. Use IF-THEN-ELSE in a business rule stage if you want more than 1 expression.

Mike
srikie
Participant
Posts: 58
Joined: Thu Oct 14, 2004 4:19 pm

Post by srikie »

Code: Select all

IF COND=1 THEN VAR+1 
ELSE IF COND=2 THEN VAR+2
END
I understand that if first if condition turns out to be true it doesnt check for the second condition. What if I want to check for all the conditons.
I mean instead of if then else. I want if then end, if then end.
Can I have more than two if stmts in one derivation.
Once again I am talking abt MVS edition of datastage.
Thanks
Srikie
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

In a mainframe job transformer derivation, the derivation is essentially a single statement. For IF-THEN-ELSE the format is:

Code: Select all

IF <BooleanExpression> THEN <Expression1> ELSE <Expression2> END
You need to use a business rule stage to utilize multiple IF-THEN-ELSE statements for a single output column derivation. For example:

Code: Select all

IF <Condition> THEN
   SET <Var>= <Expression>; 
END IF;
IF <Condition> THEN
   SET <Var>= <Expression>; 
END IF;
Mike
srikie
Participant
Posts: 58
Joined: Thu Oct 14, 2004 4:19 pm

Post by srikie »

I cant use business rule stage, coz all my transformation is done in transformer stage , I just want a way to keep track of the number of invalid i/ps if I use business stage I would lose that information or else I have to move all transofrmations into business rule stage.
Neway Thanks once again.
Srikie
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

I'm not sure why you think you can't split the transformations between a transformer and a business rule stage. Both stage types can keep track of error counts and error types with stage variables, and both stage types can write error records to the same output. One stage type can pass its stage variable contents to the other stage via output columns (to enable total counts across both stages).

Mike
Post Reply