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: 

help in REGEX operation

former_member242255
Active Contributor
0 Kudos

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.

5 REPLIES 5

aabida_majeed
Participant
0 Kudos

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

0 Kudos

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.

DominikKraemer
Active Participant
0 Kudos

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

0 Kudos

Hi Dominick,


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


^[1-9]         - this says that it should start with a number and allowed values are 1-9

\d              - any single character

*                - any number of characters or no characters


could you please explain the below patterns.

(\.\d{2})

?

$


Regards,

Sravan

0 Kudos

Well actually we can simplify the pattern above: ^\d*([\.\,]\d{2})?$

^\d* - pattern needs to start with any number, which can occure multiple times

([\.\,] - above pattern ends in case either a dot or comma is found

\d{2})? - pattern needs to end with 2 digits

Regards,

Dominik