Skip to Content
Author's profile photo Shen Peng

PI 7.0 Mapping: UDF vs. Standard functions

Once I need to convert ‘20081120’ to ‘2008-11-20’.

I can use SAP standard function TransformDate.

And I have to check whether the string is null or empty, to avoid runtime error.

At last, I design the following mapping. It looks like a little complex, isn’t it?

 

 

I can’t reuse the UDF for another mapping in PI 7.0. It takes time to do it again and again.

 Then I tried to do some coding. It only has several lines of codes.

 

 

 

Maybe I can save time by this way. Do you think so?

 Regarding PI 7.1, please refer to http://help.sap.com/saphelp_nwpi711/helpdata/en/43/991c1f7ee225b3e10000000a1553f7/content.htm

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      My opinion would also be to prevent graphical mapping for this kind of functionality. Your code will only work on a 8 character long string and otherwise it will crash (eg. when the date string will be 2010528 = 2010-05-28).

      Some hint: Alternatively you could use SimpleDateFormat with pattern logic to convert different date representations to a desired outcome. Parameter could be the desired outcome format pattern.

      Author's profile photo Shen Peng
      Shen Peng
      Blog Post Author
      Thanks.
      No matter which function we use, we have to check the format. Here I assume that it is legal, eight date numbers or 00000000.
      Author's profile photo Stefan Grube
      Stefan Grube
      - Inside a UDF, a string variable never can be null.

      - you cannot compare Strings with "==", you have to use method equals() for it.
      But more elegant would be checking the length of the String to avoid the method substring() to fail: if (a.length()<8) 

      I often use UDF instead of standard function, as standard function fail when source value is not accurate.

      Author's profile photo Shen Peng
      Shen Peng
      Blog Post Author
      Good to konw. Thanks a lot.
      Author's profile photo Former Member
      Former Member

      Mustafa

      Author's profile photo Stefan Grube
      Stefan Grube
      You cannot reuse a UDF from one mapping in another mapping.

      In PI 7.1 you can create a "Function Library". Here you can create UDF that you can use in different mappings of the same SWVC.

      Author's profile photo Mayur Patel
      Mayur Patel
      to avoide null pointer runtime error ... you dont need code. You can use of the our of box Node funtions. In you Graphical message mapping go to Funtions: -> Node Funtions -> Map with Default (2nd from right).