Skip to Content
0

SAP PO UDF help

May 17, 2017 at 09:20 AM

128

avatar image

InputField is - TEXT1|TEXT2|TEXT3|TEXT4

Please provide UDF to get output in 4 fields. | is the separator here.


Output should be -
Segment A value should come TEXT1
Segment B value should come TEXT2
Segment C value should come TEXT3
Segment D value should come TEXT4

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Vadim Klimov May 21, 2017 at 10:11 PM
0

Hi Vijay,

If I understood requirement correctly, fields in the target structure to which values are assigned, shall have different names, correct? If so, as one of solutions in achieving the requirement, you can use custom function to make splitting of the input value (from the source message) into array of substrings based on the given delimiter symbol, and then assign individual array entries to corresponding fields (of the target message). Here is example how this can be implemented...

UDF - note that it is possible to specify any arbitrary separator symbol (for example, if it will be not a pipe symbol next time), and it is required to specify which delimited chunk of the the input value needs to be assigned to the target field:

String[] values = value.split("[" + separator + "]");

if (position > values.length) {

throw new StreamTransformationException("Position of requested field exceeds available fields found in input value");

}

return values[position - 1];

Mapping rule for the first of target fields:

Mapping rule for the second of target fields, etc.:

Sample test of the mapping:

Regards,

Vadim


Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member May 17, 2017 at 12:23 PM
0

I don't have a PI or PO system at my disposal at the moment but you would use a StringTokenizer to split your string by the pipe delimiter and then assign the first token to Segment A, the second to Segment B etc. You will probably want to create a generic UDF that accepts the input string and an integer denoting the exact token you want returned) and use the same UDF with different token number on all four segments.

If you need to dynamically create segments according to the number of elements in your source string, you can create a UDF that loops through your StringTokenizer and adds a new result to the function for every available token (with the value of that token).

Share
10 |10000 characters needed characters left characters exceeded
Evgeniy Kolmakov May 17, 2017 at 01:44 PM
0

Hi Vijay!

I can't check it right now but UDF should look like this:

String[] parts = in.split("[|]");

for (int i = 0; i < parts.length; i++)

result.add(parts[i].trim());

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded