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

Simple Logic

Former Member
0 Likes
1,273

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!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,226

biggest = a.

if a < b.

biggest = b.

elseif a < c.

biggest = c.

elseif a < d.

biggest = d.

endif.

11 REPLIES 11
Read only

gopi_narendra
Active Contributor
0 Likes
1,226

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

Read only

Former Member
0 Likes
1,226

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.

Read only

matt
Active Contributor
0 Likes
1,226

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

Read only

gopi_narendra
Active Contributor
0 Likes
1,226

Hi Matt, Yes, you are correct, I over looked it

Regards

Gopi

Read only

Former Member
0 Likes
1,227

biggest = a.

if a < b.

biggest = b.

elseif a < c.

biggest = c.

elseif a < d.

biggest = d.

endif.

Read only

matt
Active Contributor
0 Likes
1,226

>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

Read only

0 Likes
1,226

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

Read only

0 Likes
1,226

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.

Read only

Former Member
0 Likes
1,226

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.

Read only

Former Member
0 Likes
1,226

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

Read only

Former Member
0 Likes
1,226

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.