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