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: 

Numbers validation functions

Former Member
0 Kudos

Hi all.

I'm looking for a FM that checks if a number is a decimal format or an integer format.

If it's not possible, a FM that splits a number to its 2 different parts will do it also .. meaning input 523.12 will be splitted to 523 and 12.

Thanks in advance,

Rebeka

1 ACCEPTED SOLUTION

Former Member
0 Kudos

I am not 100% clear on your requirement, but does using the MOD function supply the right answer?

DATA:
  g_1(16)     TYPE p DECIMALS 9 VALUE '1500000.1',
  g_2(16)     TYPE p DECIMALS 9.


g_2 = g_1 MOD 1.

IF g_2 NE 0.
  WRITE 'decimal'.
ELSE.
  WRITE 'int'.
ENDIF.

Sorry, just noticed that Gunpreet had posted a similar solution.

Edited by: Jerry Coleman on Feb 15, 2009 7:23 AM

6 REPLIES 6

Former Member
0 Kudos

store ur number in a char string, then

use this check

if v_str cp '*.*'

if the condition is true then the number is in decimal format else its in integer format.

then for splitting use SPLIT keyword.

SPLIT v_str AT '.' into v_left v_right.

кu03B1ятu03B9к

Edited by: kartik tarla on Feb 15, 2009 2:04 PM

Edited by: kartik tarla on Feb 15, 2009 2:06 PM

0 Kudos

It's not correct cause in some of our international offices the decimals splitter is ',' (Germany, Switzerland and the like), meaning that 1,500,230.80 will be at these countries 1.500.230,80.

That's exactly the reason that I search for a std FM.

Thanks,

Rebeka

0 Kudos

Well i think fms must be there but i'm not sure if they would take care of currency specific settings and split accordingly.

Former Member
0 Kudos

Hi,

SPLIT will only work in case on character or string type

try these codes:

Parameters: P_Num type p decimals 2 default '502.53'.

data:w_num type i.

W_num = p_num mod 1.

If w_num is '0' entered number has no decimal part.

else w_num = 53.(decimal part)

regards,

Gurpreet

former_member182371
Active Contributor

Former Member
0 Kudos

I am not 100% clear on your requirement, but does using the MOD function supply the right answer?

DATA:
  g_1(16)     TYPE p DECIMALS 9 VALUE '1500000.1',
  g_2(16)     TYPE p DECIMALS 9.


g_2 = g_1 MOD 1.

IF g_2 NE 0.
  WRITE 'decimal'.
ELSE.
  WRITE 'int'.
ENDIF.

Sorry, just noticed that Gunpreet had posted a similar solution.

Edited by: Jerry Coleman on Feb 15, 2009 7:23 AM