Skip to Content

help in REGEX operation

Hi All,

I have a character field for which the validation needs to be don so that it will contain only numeric value with 2 decimal places.

Currently i am doing the validation by splitting and checking with the below REGEX operation.

CLEAR:l_int_str,l_dec_str.

SPLIT lwa_data-tax_charge_amt AT '.' INTO l_int_str l_dec_str.

CONDENSE: l_int_str, l_dec_str.

FIND ALL OCCURRENCES OF REGEX '\D' IN l_int_str

RESULTS lt_result_tab.

IF sy-subrc IS INITIAL.

CONTINUE.

ENDIF.

FIND ALL OCCURRENCES OF REGEX '\D' IN l_dec_str+0(2)

RESULTS lt_result_tab.

IF sy-subrc IS INITIAL.

CONTINUE.

ENDIF.

Please help if we can do this without splitting and ignoring the . or , decimal separator based on the user profile.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Dec 09, 2014 at 07:47 AM

    Hi Kumar,

    If its a field that you want to validate why not create the variable with a float type and give it a suitable decimal place. Then it will automatically trim it down.

    eg:

    DATA: lv_var TYPE p DECIMALS 2.


    lv_var = '222222.222222'.

    WRITE lv_var.


    Output


    222222.22


    if its a parameter that you want to specify then you can do the below as well, when the user enters the value and enter only two decimals will be displayed.


    START-OF-SELECTION.

    PARAMETERS prav TYPE p DECIMALS 2.



    This will only display the value with two decimals.


    is this what you want to accomplish ?


    Thanks

    Aabid

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      This is in webdynpro and the user don't want to see 0.00 as initial value,so we have used char type and also the requirement is different for region wise..so we had to use char field and do the validation.

      When the user enters on the webdynpro screen,we are doing this validating.

  • Posted on Dec 09, 2014 at 10:07 AM

    Hello,

    following regex should work for with the dot:

    ^[1-9]\d*(\.\d{2})?$

    Should be easy to check for the comma as well.

    Regards,

    Dominik

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.