cancel
Showing results for 
Search instead for 
Did you mean: 

Java udf

Former Member
0 Kudos

hey folks

I am looking for a java udf for :

Source:

TEXT

msg : aaaaaccccc

TEXT

msg : bbbbb

TEXT

msg : dddddeeeeeggggg

Here TEXT is a repeating segment in a file.Basically there is no limit on the length of msg which can come in msg field.

Target tructure is an IDOC : E1EDPL35 segment repeats but needs to be formed multiple times if msg has more than 5 chars.Since target GBL can only hav 5 chars as maximum length.So basically we need to create multiple E1EDPL35 if it exceeds the 5 chars limit.

E1EDPL35

GBL: aaaaa

E1EPL35

GBL:ccccc

E1EDPL35

GBL :bbbbb

E1EDPL35

GBL : ddddd

E1EDPL35

GBL : eeeee

E1EDPL35

GBL : ggggg

So basically in target structure : E1EDPL35 repeats ,and it needs to be split up after 5 chars. So a new E1EDPL35 will be formed after 5 chars in GBL .

The java udf should be like a context function to whom we pass an arrray of values and i am not sure whether 2 or one udf will be good for this functionality as segment needs to be created after 5 chars and the field should also be formed in new segment

Thnx

Edited by: xi project on Oct 2, 2008 4:33 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Is it possible or is it going to be a big challenge via XI . I am not really sure of the cpaabilities of XI.

Thnx

Former Member
0 Kudos

Hi,

try to use this context UDF (with input a 😞

>int startIndex = 0;

>while (startIndex < a[0].length()) {

> if (startIndex < a[0].length() -5)

> result.addValue(a[0].substring(startIndex, startIndex + 5));

> else

> result.addValue(a[0].substring(startIndex, a[0].length()));

> startIndex += 5;

>}

Your mapping should look like this:

Source -> UDF -> E1EDPL35

Source -> UDF -> splitByValue -> GBL

Regards

Patrick

Former Member
0 Kudos

Hey

I am not able to get the desired result with this function.

Maybe I am doing something incorrectly since the logic looks clear.

any suggestions?

Former Member
0 Kudos

Hi,

what do you get instead?

Regards

Patrick

Former Member
0 Kudos

It is not splitting.

I am raising the context to highest level too.

Secondly in your function : I see only a[0] being taken into account,so only first value in the array will be split?

Thnx

Former Member
0 Kudos

give us your mapping...and how is your output generated...

Former Member
0 Kudos

Hi,

sorry you are right (I tested it only for one source field)...

This should work now:

>int startIndex;

>for (int index = 0; index < a.length; index++) {

>startIndex = 0;

>while (startIndex < a\[index].length()) {

> if (startIndex < a\[index].length() -5)

> result.addValue(a\[index].substring(startIndex, startIndex + 5));

> else

> result.addValue(a\[index].substring(startIndex, a\[index].length()));

> startIndex += 5;

>}

>}

Use the same mapping as mentioned above and set the context to at least Text level.

Regards

Patrick

Former Member
0 Kudos

Thanks Patrick.

IT works.

Awarding the points and closing thread.

I guess we can achieve a lot within XI/PI.

Answers (0)