2016 Oct 26 3:48 AM
Hi all,
I am using CATS_NUMERIC_INPUT_CHECK to check if the value is numeric or not.
But if I input a value "-"(Negative sign only) the system treats this value as Numeric.We find "." also.
How to solve this without creating original function module?
We want that system treat this value as Error if customer input "-"(Negative sign only) or "."(Period only).
2016 Oct 26 3:53 AM
We want that system treat this value as Error if customer input "-"(Negative sign only) or "."(Period only).
2016 Oct 26 6:07 AM
Clearly the function module is not fit for purpose. So you'll have to write some custom code.
2016 Oct 26 7:43 AM
an easy way to check is:
TRY.
MOVE 'check_value' TO 'numeric variable'.
CATCH CX_SY_CONVERSION_NO_NUMBER.
MESSAGE ... 'no number'.
ENDTRY.
2016 Oct 26 8:01 AM
Hi Takashi,
This may help you.
CONSTANTS: lc_sy_numbers TYPE string VALUE '0123456789'.
IF iv_string CN lc_sy_numbers.
"not numeric
ELSE.
"numeric
ENDIF.
with regards,
Pramod Kumar Mandal.
2016 Oct 26 8:10 AM
Dear Takashi Watanabe,
I don't think Function Module making mistake, maybe its your import/export parameter.
Let me know you are receiving import parameter?. FM module return parameter(for us its import parameter) if given data is numeric('-200' or 200.00 or 200.0).
Else it will not return value to return parameter. Then we decide that value is not numeric.
Ex:
REPORT ztest_test.
DATA: lv_output(10) TYPE c,
lv_input(10) TYPE c.
*lv_input = '1.000'.
*lv_input = '-1000'.
lv_input = 'abcd'.
CALL FUNCTION 'CATS_NUMERIC_INPUT_CHECK'
EXPORTING
input = lv_input
INTERNAL = 'X'
IMPORTING
OUTPUT = lv_output
EXCEPTIONS
NO_NUMERIC = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
WRITE: lv_output.
You can try this code.
1. uncomment lv_input ='1.000' then see output as 1.000
2.uncomment lv_input = '-1000' then see output as 1000-
3 uncomment lv_input = 'abcd' then you will not see any output, since lv_output has no value.
Hope you understand.
Thanks,
Sivaraj Sadasivam.
2016 Oct 26 9:02 AM
Hello Takashi
You could use a small Regex-check?
Something along the lines of :
DATA(lv_text) = '-'.
TRY.
DATA(lo_matcher) = cl_abap_matcher=>create(
pattern = `([0-9]*)`
text = lv_text ).
DATA(lv_matches_regex) = lo_matcher->match( ).
CATCH cx_sy_matcher INTO DATA(lo_excp).
DATA(lv_msg) = lo_excp->get_text( ).
ENDTRY.
2016 Oct 27 6:54 PM
Now this is just getting confusing. "Only"? So now if someone enters "-1" it's OK but "-" is not OK?
2016 Oct 31 5:15 AM
>>Jelena.
You are corecct. "-1" it's OK but "-" is not OK.
We will try to add to code like as Mr.Volker.
2016 Oct 31 5:17 AM
Dear All
Thank you for many response.
I understand that SAP have not other function module which match our require.
So, I will programing like as Mr.Volker.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |