cancel
Showing results for 
Search instead for 
Did you mean: 

Doubt in UDF

Former Member
0 Kudos

am mapping dummy to a segment E1MAKTM-MAKTX.

Dummy is a field which will contain the text this text needs to be split for every 4 character and populate it into multiple E1MAKTM.

This is the requirement.

If the input is

Thanks for answering my posts

the outpu should be

Than

ks fo

rans

weri

How can do an UDF where i pass a single value and getting a result as an array

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks it worked

Former Member
0 Kudos

Hi,

but I think that this code will not work for the last substring if the length is not a multiple of 4.

It's working in my code

Regards

Patrick

Former Member
0 Kudos

Hi Patrick,

It worked. Now i need only more functionality in the code that it shoud not split in the space.

If the length we are considering is 10.

for the input " Thanks for answering my posts".

then the ouput should be

Thanks for

anwering

my posts

Is it possible to include this functionality also in the code

Former Member
0 Kudos

Hi,

after the startIndex += 4;

expression you just have to insert this while loop:

while (startIndex < a[0].length() && a[0].charAt(startIndex) == ' ') {

startIndex++;

}

Regards

Patrick

Answers (3)

Answers (3)

Former Member
0 Kudos

I have tested the below code is working fine .Choose context while creating the UDF


String input1=input[0];
int cnt=4;
for(int i=0;i<input1.length();i++)
{
if(i+4<=input1.length()){
result.addValue(input1.substring(i,cnt));
 i=cnt-1;
 cnt=cnt+4;
}
}

Former Member
0 Kudos

Thanks guys..

i tried with Fathima's code. Am getting a runtime exeption when i clicked on Displyqueue of the udf i used

RuntimeException in Message-Mapping transformation: Exception:[java.lang.ArrayIndexOutOfBoundsException: 0] in class com.sap.xi.tf._Lennox_MDM_Material_create_2_MATMAS05_ method test$[com.sap.aii.mappingtool.tf3.CBufIter@20bed219]

what shall we do.

Former Member
0 Kudos

It worked Thanks1

Former Member
0 Kudos

Hi,

this (context) UDF should work:

int startIndex = 0;

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

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

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

else

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

startIndex += 4;

}

Regards

Patrick

Former Member
0 Kudos

Hi,

You can use the function substring to break the string . eg : for the first 4 characters substring(0,3) then next 4 characters substring(4,7) like that you break the string into small components.

Thanks

Arijit Guha.