Skip to Content
avatar image
Former Member

Compare string in UDF

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

  }

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Jan 12, 2015 at 12:11 PM

    Hi Stefan,

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

    regards,

    Harish

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 12, 2015 at 12:20 PM

    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-expression)

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 12, 2015 at 12:35 PM

    hi Stefan,

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

    thanks and regards,

    Praveen T

    Add comment
    10|10000 characters needed characters exceeded