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

Even number routine

Former Member
0 Likes
1,497

I have to test if a value is even. The value can be from 0 - 560. What is the simpliest (and most efficient) way of writing this routine

thanks

I have to test if a value is even. The value can be from 0 - 560. What is the simpliest (and most efficient) way of writing this routine

thanks

6 REPLIES 6
Read only

Former Member
0 Likes
1,076

hi,

The best and easiest method..

Do 560 times.

lval = sy-index mod 2.

if lval EQ '0'.

  • EVEN

ELSE.

*ODD

ENDIF.

ENDIF.

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
1,076

hi,

DATA : num TYPE i,
       rem TYPE i.

DO 560 TIMES.
  rem = sy-index MOD 2.
  IF rem = 0.
    WRITE : / sy-index,  '-even'.
  ELSE.
    WRITE : / sy-index, '-odd'.
  ENDIF.
ENDDO.

Thanks & Regards

Read only

Former Member
0 Likes
1,076

The mod function is what you need.

DATA: mod_value TYPE i.

mod_value = 21 MOD 2 .

IF mod_value EQ '0'.
  WRITE / 'even'.
ELSE.
  WRITE / 'odd'.
ENDIF.

Read only

Former Member
0 Likes
1,076

Hi Dominic ,

the efficient way is :

parameter : number .

DATA: mod TYPE i.

mod = number MOD 2 .

IF mod EQ '0'.

WRITE / 'Number is even'.

ELSE.

WRITE / ''Number is odd'.

ENDIF.

It will work most efficiently .

Regards ,

Nilesh Jain .

Read only

Former Member
0 Likes
1,076

Hi,

the most efficient way to do this is

data : n type i.

do 280 times.

n = 2 * sy-index.

write 😕 'even', n.

enddo.

this is the shortest code and will do fast.

hope this will help you.

regards,

anand

Read only

0 Likes
1,076

REPORT Z_N_EVEN_NO.

DATA: V_NO TYPE I,

       RESULT TYPE I.

PARAMETERS: P_NO TYPE I.

IF RESULT = P_NO MOD 2.

   RESULT = 0.

   WRITE:/ ' THE NO  IS EVEN NO'.

   ELSE.

     WRITE:/ ' THE NO IS AN ODD NO'.

ENDIF.