cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to replace a string in a context

11-21-2021 2:44 PM
pi_consultant1 Participant
1206 views 1 comments
0 Likes
SAP Managed Tags
Subscribe

Hello experts

Ive the following requirement, please suggest how to achieve/solve this...

Ive this UDF where I replace 0 with other values in a context:

This is my UDF

int flag,count=0;
for(int i=0;i<POSNR.length;i++)
{
flag=0;
for(int j=0;j<POSNR1.length;j++)
{
if(POSNR[i].equals("0"))
{
result.addValue(POSNR1[count]);
count++;
flag=1;
break;
}
}
if(flag==0)
result.addValue(POSNR[i]);
}<br>

It works also fine these two inputs and the result is like this:

But when I have these two input (multiple 0's) then I get this Error:

Exception:[java.lang.ArrayIndexOutOfBoundsException: while trying to load from index 1 of an object array with length 1, loaded from the second parameter of the method]

In this case it also should continue and give the values through...

Can you tell me please how to achieve this?

Thank you in advance!

0 Likes

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member202642
Participant
0 Likes

Hi,

You are getting this error because the no.of zeros in first queue is not equal to no.of input in second queue.

In first case you have given 2 zeros in first queue and no.of input in second queue is also 2. This is why it is getting executed successfully.

Thanks,

Aamir