SAP PI/PO Library of User-Defined Functions (UDFs)

SAP PI/PO Library of User-Defined Functions (UDFs)

A good, comprehensive library of User Defined Functions (UDF) is a key component in any successful interface implementation in SAP PI/PO system. Without it, graphical mappings quickly become intricate, hard to read, understand and maintain. This library has been developed across several years and used in almost all SAP PI/PO projects we were involved in. It contains a set of functions covering the most common requirements (text transformations, date/time functions, boolean operations etc.)

Installation

The library is delivered as a Software Component Version (SWCV). Please unzip the downloaded file to any location on your local computer and import the included TPZ file into your Integration Repository.

Details

Language
JAVA

Tested with
SAP PI 7.31
SAP PO 7.50

License
MIT

Library Content

The SWCV is divided into several libraries. The functions are grouped in a similar way as the standard functions delivered by SAP (e.g. Text -> XText, Date ->XDate etc.).

Functions in Library XNode

getQualfValue

Returns a value from a segment having a specified qualifier
*This function is especially useful when working with IDocs, where qualified segments are quite commonly used (e.g. partner segment E1EDKA1, material identification segment E1EDP19 etc.)

Parameters:

qualfs (String[]) – a list of qualifiers from a message segment (the context should be set to match your requirements)
qualfValues (String[]) – a list of qualifiers values, or one constant qualifier value (if a list of values is provided then the qualfValues contexts should match qualfs contexts)
values (String[]) – a list of values from a message segment (leave the default, lowest context)

Sample usage

Let’s say we want to retrieve the description of an invoice item. The description is stored in field KTEXT of E1EDP19 segment with QUALF = 001.

The common pattern to accomplish this task is the following mapping (only standard functions are used):

With function getQualfValue we can do it much easier with this simple mapping:
*Please note that the context for QUALF field has been changed – as we want to produce one description element per item, we should set the context to E1EDP01 element:

Functions in LiBrary XText

condense

Replaces consecutive space characters with a single space

Parameters:

text (String) – a text to be condensed

getTextPart

Returns an n-th part of a delimited text

Parameters:

text (String) – a number to be condensed
delimiter (String) – a character or string delimiting text parts
n (int) – text part number to be retrieved

formatFloat

Returns a formatted float number using the specified format pattern

Parameters:

value (float) – a number to be formatted
format (String) – A format string

formatInteger

Returns a formatted integer number using the specified format pattern

Parameters:

value (int) – a number to be formatted
format (String) – A format string

formatString

Returns a formatted string using the specified format pattern

Parameters:

value (String) – a number to be formatted
format (String) – A format string

leftPad

Returns a new string of a specified length in which the beginning of the current string is padded with  specified character(s)

Parameters:

text (String) – a text to be padded
length (int) – total length of the text
padChar (String) – a character used to left-pad the text

leftPadZero

Returns a new string of a specified length in which the beginning of the current string is padded with 0 (zero)
*Useful for formatting document/customer/material number in SAP

Parameters:

text (String) – a text to be padded
length (int) – total length of the text

matches

Returns “true” if a given text matches a specified regular expression, otherwise returns “false”

Parameters:

text (String) – a text to search for a match
regex (String) – a regular expression (pattern)

removeLeadingZeros

Removes leading zeros from a text

Parameters:

value (String) – a text to be stripped of leading zeros

replaceRegex

Replaces all occurrences of a pattern (regular expression) in a given text with a replacement text

Parameters:

text (String) – an input text
regex (String) – a pattern/regular expression to be replaced
replacement (String) – a text to be substituted for each pattern match

substringSafe

Returns a substring of a given text
*Unlike standard substring function, substringSafe won’t raise an exception if length of the substring exceeds the input text’s length

Parameters:

text (String) – an input text
startPos (int) – starting position of the substring
length (int) – length of a substring

truncate

Returns the beginning of a given text

Parameters:

text (String) – an input text
length (int) – length of the truncated text

Functions in library XBOOL

in

Returns “true” if the given value exists in a specified values list, otherwise returns “false”

Parameters:

value (String) – a value to be checked against the list
list (String) – comma-separated list of values

isEmpty

Returns “true” if the given value is null or consists of blank characters only, otherwise returns “false”

Parameters:

value (String) – a value to be checked

Functions in LIbrary XArithmetic

toSAPNumber

Returns a specified number in SAP format (in case of negative values, the sign is displayed at the end)

Parameters:

number (String) – a number to be formatted

fromSAPNumber

Converts a number in SAP format (the sign is displayed at the end) to a Java-format number

Parameters:

number (String) – a number to be formatted

Functions in LIbrary XAsma

setAttribute

Sets a specified Adapter-Specific Message Attribute (ASMA)

Parameters:

ns (String) – a namespace of the attribute
name (String) – a name of the attribute
value (String[]) – a value of the attribute (the fist element of the table, value[0] is used)

getAttribute

Returns a value of a specified Adapter-Specific Message Attribute (ASMA)

Parameters:

ns (String) – a namespace of the attribute
name (String) – a name of the attribute

Functions in LIbrary XDate

addDays

Returns a date increased by a given number of days. The date is formatted according to a specified format.

Parameters:

date (String) – a starting date
dateFormat (String) – the format of the date
days (int) – the number of days to be added to the starting date

Leave a Reply

Your email address will not be published. Required fields are marked *