cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for splitting data in iDoc

Former Member
0 Kudos

Hi SAP Guru's

could you please write the code for me according to the requirement below.

I am struggling in regards to that.

I have write the code which only works for 1 "/" but not working for "//" , so can anybody please write the code for me ASAP.

Thanks,

From right hand side of the field E1IDKU3-INSTEXT1, all characters upto reaching of special character "/". This is because the filed may appear like "/ /MAIL" or simply "/ /". In the first case it is expected to take data MAIL and in second case blank.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

solve myself

Former Member
0 Kudos

Iqbal,

Don't worry about writing a UDF for something which you can easily do with provided functions.

You can do it using two of them;

1) Indexof

2) substring

So do something like this:

a) Use 'indexof' to find the first indexof '/'

b) then use 'substring' from (1, indexof value) and you are done

regards,

Former Member
0 Kudos

Hi there,

I am afraid it is not working.

I am using input --- indexOf --- output

Constant(/)

I can't used substring because I don't know the exact length of the input and also substring only accept integer value and can't write indexOf.

I believe the only way is to write a UDF.

Thanks,

Former Member
0 Kudos

Iqbal brother,

Just please give me an input example like this:

Iqbal// abcdd....

and what output you expect

I will do it for you now without UDF

Former Member
0 Kudos

hi brother,

these are the conditions and required outputs.

1. // output Blank

2. /mail output mail

3. /abc/xyz/efg output efg

4. Blank output blank.

5. aab/ output blank.

I hope this help you to generate the output.

Thanks,

Former Member
0 Kudos

Substring end value is not fix.

You have to determine this value.

cheers,

André

Former Member
0 Kudos

You Condition # 3 is slightly confusing in this case you are only taking the last '/' ?

Btw please paste your UDF code here too; might as well

Shabarish_Nair
Active Contributor
0 Kudos
public String Extract(String a, Container container) throws StreamTransformationException{
int index = 0;
int len = 0;
String out = "";
index = a.lastIndexOf("\\");
len = a.length();
if(index==len)
{
return out;
}
else
{
return a.substring(index+1,len);
}
}

try that

Former Member
0 Kudos

Iqbal,

I am still waiting; not sure if you are there anymore or not.

However even if you did it in a UDF you will still be using substring and index operations. But your requirement is slightly unclear to me on this condition;

/abc/def/ghi

you just want 'ghi' as output? what about the first two? (abc & def?)

In other words what you telling is take the whole string search for last occurance of '/' and take the value from there till the end of the string ?

Former Member
0 Kudos

IF you requirement is how I have understand above? then the code provided by Shabarish will work just make sure to change the backslash (\) to forward (/)

Former Member
0 Kudos

Hi there,

I managed to write the code which is working fine.

Here is the code

String str = input.toString();

String a[] = str.split("/");

int len = a.length;

if (input.equals("//"))

{

return "";

}

else

{

return a[len-1];

}

Thanks,

iqbal

Former Member
0 Kudos

Hi Vijay,

your udf is not working as per my requirement

I am getting output "/" instead of "".

Any ways thank you so much for all of you who replied and help me.

I managed to solve the problem myself.

Thanks,