‎2007 Dec 12 8:44 AM
Guys help me..
this is a very simple logic.I have four variables it contains number.I need to know which one is the highest number.Help me with the codes.
example:
a-1
b-2
c-3
d-4
answer should be 4 w/c is d.
Thanks!!
‎2007 Dec 12 8:53 AM
biggest = a.
if a < b.
biggest = b.
elseif a < c.
biggest = c.
elseif a < d.
biggest = d.
endif.
‎2007 Dec 12 8:46 AM
if your itab contained
NUM
1
2
3
4
now sort the itab descending
data : l_grnum type I.
sort itab by NUM descending.
read table itab index 1.
if sy-subrc = 0.
l_grnum = itab-NUM.
endif.Regards
Gopi
‎2007 Dec 12 8:47 AM
Hi,
Take a variable in Max....Then compare each value with max.....If the value is greater than the variable , then store the value in max.....Do this for all values..
Loop.
If value in list > max.
Max = value currently in list.
Endif.
Endloop.
Thanks,
Aditya.
‎2007 Dec 12 8:50 AM
Four differently named variables... no-one said anything about internal tables.
If a gt b.
biggest = a.
ELSE.
biggest = b.
ENDIF.
IF biggest gt c.
biggest = c.
ENDIF.
IF biggest gt d.
biggest = d.
ENDIF.matt
‎2007 Dec 12 9:08 AM
‎2007 Dec 12 8:53 AM
biggest = a.
if a < b.
biggest = b.
elseif a < c.
biggest = c.
elseif a < d.
biggest = d.
endif.
‎2007 Dec 12 8:55 AM
>biggest = a.
>if a < b.
>biggest = b.
>elseif a < c.
>biggest = c.
>elseif a < d.
>biggest = d.
>endif.
oops. But mine was embedded in code tags, so easier to read
matt
should read more carefully to see that the answer is wrong. Thanks Eric!
Message was edited by:
Matthew Billingham
‎2007 Dec 12 9:00 AM
no, it is completely wrong...
biggest = a.
<b>if a < b.</b>
biggest = b.
elseif a < c.
biggest = c.
elseif a < d.
biggest = d.
endif.
if the bold part is true, the value of c and d won't even be considered!
ec
‎2007 Dec 12 9:35 AM
Thanks alot & Sorry Eric, Matt, Gopi....
I too realized now....
I will change my logic...
if a < b or a < c or a < d.
if b < c or b < d.
if c < d.
biggest = d.
else.
biggest = c.
endif.
else.
biggest = b.
endif.
else.
biggest = a.
endif.
-
biggest = a.
if biggest < b.
biggest = b.
endif.
if biggest < c.
biggest = c.
endif.
if biggest < d.
biggest = d.
endif.
‎2007 Dec 12 8:54 AM
Hi,
PARAMETERS : a TYPE n,
b TYPE n,
c TYPE n,
d TYPE n.
DATA : e TYPE n,
f TYPE n.
IF a > b.
e = a.
IF c > d.
f = c.
ELSE.
f = d.
ENDIF.
ELSE.
e = b.
IF c > d.
f = c.
ELSE.
f = d.
ENDIF.
ENDIF.
IF e > f.
WRITE : /1 e.
ELSE.
WRITE : /1 f.
ENDIF.
‎2007 Dec 12 9:31 AM
best part is to make a internal table
add all items to it
sort it
if not then usinf nested if endif will solve your purpose
i think both of the solutions have ben mentioned above in youir replies
if your query is answered please mark it answered
and do reward others
thank you
‎2007 Dec 12 9:45 AM
Hi salma,
1. This is one way.
2.
Data : max type i.
*----
Put first value
max = a.
*----
Then compare with other three varibles
if b > max.
max = b.
endif.
if c > max.
max = c.
endif.
if d > max.
max = d.
endif.
regards,
amit m.