Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Java udf

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

replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question