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

Find pattern in a string in ABAP

former_member383962
Participant
0 Likes
5,424

Hello Experts,

I get an i_date with the following value from the table

ex: i_date = 'MM/DD/YYYY'. note: it can be changed by the user.

And o_date = '01/01/2019'.

How to find the patterns are matched or not.

I tried the below code, but I didn' t get my output.


TABLES: map_rul.

data: i_date type string,
      o_date type string.


   o_date = '01/01/2019'.

select SINGLE low from map_rul into i_date where context = 'LOAD' and code = 'FORMAT'.

  write:/ 'Table date format:',i_date.
* Note: i_date value is 'MM/DD/YYYY'.

 if o_date cp i_date.
     WRITE: / 'Pattern matched'.
  else.
    write: / 'no pattern matched'.
ENDIF.

My code valuates the pattern and its value.

i just want to compare the pattern not a value.

any suggestions please...?

Thanks in advance

7 REPLIES 7
Read only

matt
Active Contributor
3,067

Have you read the ABAP help on CP? Does it anywhere say that you can use MM/DD/YY as a pattern? No - it doesn't. Always read the abap help if you don't know what a keyword does - don't guess and hope. You'll save time.

You could use the matches function with a suitable regex. Probably if you search on the net for a date matching regex, you'll find it.

Read only

Former Member
0 Likes
3,067

Or even Find with a regular expression.

Read only

BaerbelWinkler
SAP Champion
SAP Champion
3,067

To add to Matt's and Richard's mentions of regex (regular expression): check out program DEMO_REGEX_TOY in SE38 and play with the options. It comes with the documentation for what all - a lot! - is possible with regex. You can then use the demo-program and play with what you'd like to check.

Read only

monalisa_biswal
Contributor
3,067

You can refer code in FM DATE_CHECK_PLAUSIBILITY and write your own logic for checking date formats.

Read only

DoanManhQuynh
Active Contributor
0 Likes
3,067

A simple regex:

\d{1,2}/\d{1,2}/\d{4}
Read only

former_member596005
Participant
0 Likes
3,067

i think Irrespective of comparing you can get your desired pattern by using certain function modules so , when user enters in any format the code in your prog can convert into desired format so comparison may not required.

For format conversion there are lot of FM available u can check on google or go on this thread

https://archive.sap.com/discussions/thread/387802

Read only

former_member383962
Participant
0 Likes
3,067

Thanks for all...

Issue is solved...