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: 

check whether value in a field is odd or even

Former Member
0 Kudos

Hi folks,

I have some value in a field 'count'. I want to check if the value in that field is even or not. I need to put a IF loop saying that if the value in 'count' is even then execute the loop. How can I do this.

I appreciate the efficient method to check this. Thanks

Waiting.............

3 REPLIES 3

abdul_hakim
Active Contributor
0 Kudos

hi

try using the below logic..

data even type i.

even = count mod 2.

if even eq 0.

<execute your loop here>.

endif.

Cheers,

Abdul Hakim

abdul_hakim
Active Contributor
0 Kudos

hi

has your problem solved??

Cheers,

Abdul Hakim

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You can do something like this.



report zrich_0002 .


data: i type i value 48.
data: remainder type i.

remainder = i mod 2.
if remainder = 0.
  write:/ 'This is an even number'.
else.
  write:/ 'This is an odd number'.
endif.

Ooops, Abdul beat me to it.

Regards,

Rich Heilman

Message was edited by: Rich Heilman