‎2009 Feb 26 9:21 PM
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
‎2009 Feb 26 9:24 PM
Look at this:
PARAMETER: p_cahr TYPE char10.
IF p_cahr CN '1234567890 '.
WRITE: 'invalid'.
ENDIF.
‎2009 Feb 26 9:24 PM
Look at this:
PARAMETER: p_cahr TYPE char10.
IF p_cahr CN '1234567890 '.
WRITE: 'invalid'.
ENDIF.
‎2009 Feb 27 3:26 PM
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.
‎2009 Feb 27 3:39 PM
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.
‎2015 May 21 1:35 AM
‎2009 Feb 26 10:02 PM
See some examples here, including function modules:
http://friendlyabaper.blogspot.com/2006/10/fun-with-numbers.html
‎2014 Apr 29 3:19 PM
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