Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

parameters & nested ifs

Former Member
0 Kudos

Hi,

I have a problem with nested if conditions. I have to take in a field A as a parameter which has two values say 10 and 11 and value the should be selected depends on another field value say B which again has two values 1 and 2 and say this is how 10 and 11 are related to each other:

if A=10 & B=1 then write 10 else if A=11 and B-2 write 11.

the user can enter either 10 or 11 in the selection screen.

so right now the if condition that I have which is not working is as follows:

If A = 10.

If B = 1.

A = 10.

elseif B = 2.

A = 11.

else

A = 11.

endif.

endif.

WHat is happening is that it only writes out correct value for the first condition when a =10 but writes nothing when a = 11. So can somebody correct the condition and tell me what to do?

Thanks,

UU

2 REPLIES 2

Former Member
0 Kudos

Try this as a fix for your solution

if A = 10.

If B = 1.

A = 10.

elseif B = 2.

A = 11.

endif.

A = 11.

endif.

or

if A = 10 and B = 1.

A = 10.

elseif A = 11 and B = 2.

A = 11.

endif.

rishi

0 Kudos

This is a nutty one for a Saturday morning.

If this is exactly your requirement: <i>if A=10 & B=1 then write 10 else if A=11 and B-2 write 11</i> .

Then only Rishi's second attempt gets this result:


if A = 10 and B = 1.
  A = 10.
elseif A = 11 and B = 2.
  A = 11.
endif.

If you want to achieve this using nested ifs then you can do it:


if A = 10.
  if B = 1.
    A = 10.
  endif.
elseif A = 11.
  if B = 2.
    A = 11.
  endif.
endif.

But, setting A = 10, or A = 11 is meaningless in this context as if A = 10 then it will always be 10, regardless of the value of B, and the same if it is 11, it will always be 11.

So, better to set a third variable C, like this:


if A = 10 and B = 1.
  C = 10.
elseif A = 11 and B = 2.
  C = 11.
endif.
WRITE: / C.

I hope that makes sense.

Brad