Former Member

# Function Module

hello friends,

i want to sepearte out even and odd digits from a given number and want to do addition of them.

Eg. suppose i have number 12345 now i want to seperate out even numbers and odd numbers which are 2,4 and 1,3,5 respectively.after that i want to do addition of these number which is 24 and 13+5 and final result is 6 and 9

is there is any function module available for this.

regards,

10|10000 characters needed characters exceeded

• Former Member
Posted on Aug 21, 2007 at 07:42 AM

no there isn't any fm of this kind, u have to create u'r own.

S@meer

10|10000 characters needed characters exceeded
• Former Member
Posted on Aug 21, 2007 at 07:43 AM

Hi Patil

i dont think there is a fm exist for u r req.

use this logic

find the string length

len = strlen (str) . len= 5.

do len times.

var1 = str + count(1). var1 = 1.

count = count + 1. count = 1.

if var1 % 2 eq 0.

even = even + var1.

else.

odd = odd+ var1.

endif.

enddo.

kiran.M

10|10000 characters needed characters exceeded
• Former Member
Posted on Aug 21, 2007 at 08:43 AM

Hello,

Just one question, I#m quite interested why you want to do it =)

10|10000 characters needed characters exceeded
• Former Member
Posted on Aug 21, 2007 at 10:37 AM

There are no function modules for your requirement in SAP so you need to create a function module...

Goto to<b> se37</b>,<b>Goto-> function groups->create group</b>then give the <b>function module name</b> and create it...

then a screen appears,goto <b>source code tab</b>...

in dat type the code

data : a type i,

b type i,

c type i.

selection-screen : begin of block blk1 with frame title text-001.

parameters : a type i,

b type i.

selection-screen : end of block blk1.

len = strlen (str) . len= 5.

do len times.

var1 = count + 1(str). var1 = 1.

count = count + 1. count = 1.

if var1 % 2 eq 0.

even = even + var1.

else.

odd = odd+ var1.

endif.

enddo.

in import n export parameters give a,b as export n c as import parameter.

reward if useful.............