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

ABAP function module to check data is a valid number

Former Member
0 Likes
3,890

Hi Guys,

I am parsing a long string from a R3 table to load into BW, and need to verify the incoming data is valid number instead of having some or all charactors so I can load into a quantity field, in BW, it is a Key figure infoObject. The string length is 14.

For example, if data is 123.34, then the number is valid. If data is 1A23, then it is not valid number.

Thanks in advance.

JA

1 ACCEPTED SOLUTION
Read only

former_member156446
Active Contributor
0 Likes
1,562

Look at this:

PARAMETER: p_cahr TYPE char10.

IF p_cahr CN '1234567890 '.
  WRITE: 'invalid'.
ENDIF.

6 REPLIES 6
Read only

former_member156446
Active Contributor
0 Likes
1,563

Look at this:

PARAMETER: p_cahr TYPE char10.

IF p_cahr CN '1234567890 '.
  WRITE: 'invalid'.
ENDIF.

Read only

0 Likes
1,562

Thank you J@Y, you solution works. I added check for "." decimal point to make sure only one ".". My code is below.

Thank you everyone!

DATA: count type i.

PARAMETER: p_input TYPE char14.

FIND ALL OCCURRENCES OF '.' IN p_input MATCH COUNT count.

Write: ' occurance of the . = ', count.

IF p_input CO '1234567890. ' and count <= 1.

WRITE: /'Yes, valid', p_input.

Else.

WRITE: /'invalid', p_input.

ENDIF.

Read only

0 Likes
1,562

Just to point out: in J@Y solution,

There is a space in the number "123456789. ", that is very important. Otherwise it would not work.

Read only

0 Likes
1,562

Thanks Jun

Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
1,562

See some examples here, including function modules:

http://friendlyabaper.blogspot.com/2006/10/fun-with-numbers.html

Read only

Former Member
0 Likes
1,562

Hi,

SAP provides the function BUS_NUMBERFIELD_PAI,

You pass in a table/field reference that matches the number you want to match to say GLT0-TSLVT (len 15 dec 2) and the string.

It tells you if the number is valid and will even return a reformatted string.

I.E.

123456,78 is valid and formatted as 123,456.99

123,,456.78 raises AMOUNT_NOT_ALLOWED

123.456 raises INTERNAL_ERROR as there are too many decimals

Hope that helps.

FUNCTION BUS_NUMBERFIELD_PAI .
*"  IMPORTING
*"     VALUE(I_TABNAME) LIKE  DD03L-TABNAME (Ex
*"     VALUE(I_FIELDNAME) LIKE  DD03L-FIELDNAME
*"     VALUE(I_CURRENCY) LIKE  TCURC-WAERS OPTIONAL
*"  EXPORTING
*"     VALUE(E_VALUE_DB)
*"  CHANGING
*"     VALUE(C_VALUE_DYNP)
*"  EXCEPTIONS
*"      NUMBER_NOT_ALLOWED
*"      AMOUNT_NOT_ALLOWED
*"      INTERNAL_ERROR