if then else problem

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
seshikumar
Participant
Posts: 44
Joined: Fri Mar 16, 2007 5:51 am

if then else problem

Post by seshikumar »

hi guys,
i have code like this aruments i dec arg1,a1,a2

if arg1= '+' then
res=a1+a2
else
if arg1='-' then
res=a1+a2
else
if arg1='*' then
res=a1*a2
end
end
end


when i was compiling the code iam getting error
seshu
srinath
Participant
Posts: 9
Joined: Wed Nov 09, 2005 7:18 am

Re: if then else problem

Post by srinath »

seshikumar wrote:hi guys,
i have code like this aruments i dec arg1,a1,a2

if arg1= '+' then
res=a1+a2
else
if arg1='-' then
res=a1+a2
else
if arg1='*' then
res=a1*a2
end
end
end


when i was compiling the code iam getting error
if Arg1= '+' or Arg1='-' then
res=a1+a2
end
else if Arg1='*' then
res=a1*a2
end
God Gave Me Nothing I Wanted
He Gave Me Everything I Needed -- Swami Vivekananda
JKenklies
Premium Member
Premium Member
Posts: 30
Joined: Mon Mar 05, 2007 3:02 am
Location: Hamburg, Germany

Post by JKenklies »

I think you need an else clause at the end because the compiler needs to be sure, that in every situation you'll get some result.

What if arg1="crap"?

Saying your variable is called "someValue", the following example should work (delete the comments):

Code: Select all

if arg1= '+' then
  res=a1+a2
else
  if arg1='-' then
    res=a1-a2        // I bet this was a typo?
  else
    if arg1='*' then
      res=a1*a2
    else
      someValue   // this will be returned if arg1 not in (+,-,*)
JeroenDmt
Premium Member
Premium Member
Posts: 107
Joined: Wed Oct 26, 2005 7:36 am

Re: if then else problem

Post by JeroenDmt »

you need to add two extra 'end' statements before the 'else'
So it will be

Code: Select all

if arg1= '+' then 
res=a1+a2 
end
else 
if arg1='-' then 
res=a1+a2 
end
else 
if arg1='*' then 
res=a1*a2 
end 
end 
end
Then it compiles correctly.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Is this in a routine or in a derivation expression? Your answer to that will affect what is the correct answer to your question.

Please delete duplicate post.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Re: if then else problem

Post by JoshGeorge »

res = a1 arg1 a2

If my assumption below is right.
seshikumar wrote:hi guys,
i have code like this aruments i dec arg1,a1,a2

if arg1= '+' then
res=a1+a2
else
if arg1='-' then
<b> res=a1-a2 </b> **** Assuming this is a typo --> res=a1+a2
else
if arg1='*' then
res=a1*a2
end
end
end
when i was compiling the code iam getting error
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
seshikumar
Participant
Posts: 44
Joined: Fri Mar 16, 2007 5:51 am

THis is routine

Post by seshikumar »

ray.wurlod wrote:Is this in a routine or in a derivation expression? Your answer to that will affect what is the correct answer to your question.

Please delete duplicate post.
seshu
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Is this in a routine or in a derivation expression? Your answer to that will affect what is the correct answer to your question.
:roll:
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