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

Numeric value check

Former Member
0 Likes
4,587

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?

9 REPLIES 9
Read only

Former Member
0 Likes
3,014

We want that system treat this value as Error if customer input "-"(Negative sign only) or "."(Period only).

Read only

matt
Active Contributor
3,014

Clearly the function module is not fit for purpose. So you'll have to write some custom code.

Read only

former_member226519
Active Contributor
3,014

an easy way to check is:

TRY.

MOVE 'check_value' TO 'numeric variable'.

CATCH CX_SY_CONVERSION_NO_NUMBER.

MESSAGE ... 'no number'.

ENDTRY.

Read only

Former Member
3,014

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.

Read only

Former Member
3,014

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.

Read only

NTeunckens
Active Contributor
3,014

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.
Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
3,014

Now this is just getting confusing. "Only"? So now if someone enters "-1" it's OK but "-" is not OK?

Read only

Former Member
0 Likes
3,014

>>Jelena.

You are corecct. "-1" it's OK but "-" is not OK.
We will try to add to code like as Mr.Volker.

Read only

Former Member
0 Likes
3,014

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.