Application Development and Automation 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: 
Read only

Nested IF statement: issue

Former Member
0 Likes
4,409

hello,

I have a code like below:

If <condition1>

if (variable) between value1 and Value 2.

if (variable2) between value3 and value 4.

---

---

--

endif.

endif.

else.

-


---

endif.

Now problem is even when all the three conditions are satisfying, the cursor always goes to else statement in the second half of the coding..

Any suggestions...

9 REPLIES 9
Read only

ThomasZloch
Active Contributor
0 Likes
1,932

> Any suggestions...

Yes, please use tags and post the actual code here, not just pseudo code.

Thomas

Read only

0 Likes
1,932

solved by selfl

Edited by: S Simran on Mar 29, 2010 9:46 AM

Read only

0 Likes
1,932

I got the same problem.. let me know that how you fixed it ?

Read only

0 Likes
1,932

Hi Karthik Mrvk ,

Just remove if statements and use Case statements. It is better to use case statements when you have more than one condition to satisfy. It will improve your program performance.

Regards,

Praveen

Read only

0 Likes
1,932

Thank you Sai praveen .. and one more help.. i'm very new to ABAP.. can you tell me how to use case statement instead of IF ELSE.

this is my source code.. to find the biggest number among three .. this is working perfectly but how to do it using Case statement.. also if the two number has same value how can i process it . which is the best logic to find it . ??

REPORT ZKARTHI_BIGGESTNUMBER.
WRITE 'fINDING THE bIGGEST NUMBER'.
NEW-LINE.

*DECLARING PARA METERSS*

PARAMETERS: NUMBER1 TYPE I,
             NUMBER2 TYPE I,
             NUMBER3 TYPE I.

*PARAMETER DECLARATION OVER HERE*

IF ( NUMBER1 = NUMBER2 AND NUMBER1 = NUMBER3 ).
WRITE 'ALL NUMBERS ARE EQUAL'.
ELSEIF ( NUMBER1 > NUMBER2 ).
   IF ( NUMBER1 > NUMBER3 ).
     WRITE:'bIGGEST NUMBER IS,NUMBER1',NUMBER1.
   ENDIF.
ELSEIF ( NUMBER2 > NUMBER3 ).
   WRITE:'BIGGEST NUMBER IS NUMBER2',NUMBER2.
ELSE.
   WRITE:'BIGGEST NUMBER IS NUMBER3',NUMBER3.
ENDIF.

Message was edited by: Karthi Mrvk

Read only

Former Member
0 Likes
1,932

Hi ,

give the logc below..

if <condition1>

if (variable) between value1 and Value 2.

if (variable2) between value3 and value 4.

---

---

--

else.

-


-


endif.

endif.

endif.

now ur problem will solve..let me know still if you have any issues..

Read only

0 Likes
1,932

This message was moderated.

Read only

Former Member
0 Likes
1,932

The cursor will indeed go to the ELSE statement in debug, but does it execute the code after the else, or does it then go directly to the outer ENDIF....

If I have:

IF .... <First stop.

IF.... <second stop

IF.... <third stop...

endif.

endif.

else.<eventually I get here and then I should immediately go to ENDIF, if the first IF statement is true.

....

endif...<next stop after ELSE.

Read only

Former Member
0 Likes
1,932

Hi Simran,

Instead of using nested if statements in my open it is better to go with CASE statement.I am sure it is better in performance prospective of the program.

Regards,

Venkat.