cancel
Showing results for 
Search instead for 
Did you mean: 

Compare string in UDF

Former Member
0 Kudos

Hi!

I want to compare a string with multiple values. Will .matches work in SAP PI? Or do I have to use equals?

if(Type.trim().matches("Z001|Z002|Z003|Z004|Z005|Z006"))

  {

  do something

  }

or .equals

if(Type.trim().equals("Z001") || Type.trim().equals("Z002")) // etc

  {

  do something

  }

Accepted Solutions (0)

Answers (3)

Answers (3)

praveen_sutra
Active Contributor
0 Kudos

hi Stefan,

PI(7.31) supports both the ways you have mentioned.

thanks and regards,

Praveen T

iaki_vila
Active Contributor
0 Kudos

Hi Stefan,

The matches method is the quicker way to compare strings that i know (http://stackoverflow.com/questions/10205437/compare-one-string-with-multiple-values-in-one-expressio...)

However, in PI world is better to use the standard functions, because you can have SAP assistance if something fails and you can avoid problems in future upgrades.

In your case , you can use the Constant, equalS, Or and If-then-else  functions:

Hope this helps

Regards.

Harish
Active Contributor
0 Kudos

Hi Stefan,

I did not try the matches but second one will definitely work.

regards,

Harish