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: 

Numeric value check

Former Member
0 Kudos

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

Former Member
0 Kudos

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

matt
Active Contributor

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

former_member226519
Active Contributor

an easy way to check is:

TRY.

MOVE 'check_value' TO 'numeric variable'.

CATCH CX_SY_CONVERSION_NO_NUMBER.

MESSAGE ... 'no number'.

ENDTRY.

Former Member

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.

Former Member

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.

NTeunckens
Active Contributor

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.

Jelena
Active Contributor
0 Kudos

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

Former Member
0 Kudos

>>Jelena.

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

Former Member
0 Kudos

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.