cancel
Showing results for 
Search instead for 
Did you mean: 

ArrayIndexOutOfBoundsException in UDF in Multi-Mapping SAP PI

ramu_g4
Participant
0 Kudos

Hi Experts,

Our scenario is File to IDoc where the number of IDocs generated are based on the number of BusinessPartner [/ns0:Messages/ns0:Message1/ns1:SyncBusinessPartner/DataArea/BusinessPartner] nodeoccurences in the input XML. It is 1:n mapping. I have written UDF to capture values to target node as shown below.

public void multiaccountDetail(String[] adTyp, String[] Account, String[] isVenAcc, ResultList result, Container container) throws StreamTransformationException{ for(int i=0;i<addType.length;i++) { if(adTyp[i].equals("AB")) { for(int j=0;j<Account.length;j++) { if(isVenAcc[j].equals("true")) { result.addValue(Account[j]); } else { result.addValue(ResultList.SUPPRESS); } } } } }

This UDF is used here as highlighted in below snippet of graphical mapping.

Snippet of UDF input variables.

But in case of multiple BusinessPartner node occurrences UDF throws exception with below error code.

Runtime exception when processing target-field mapping /E1KNBKM/E1KNA1M/IDOC[2]/ZDEBMAS06/ns0:Message1/ns0:Messages/KOINH; root message: Exception:[java.lang.ArrayIndexOutOfBoundsException: while trying to load from index 0 of an object array with length 0, loaded from the third parameter of the method] in class com.sap.xi.tf._mm_yyyyy_to_customer_ method multiaccountDetail.

Kindly help me to modify UDF code here to resolve the issue.

Thanks,

Ramu.

Accepted Solutions (0)

Answers (6)

Answers (6)

PRAGSMATIC
Participant
0 Kudos
"Our scenario is File to IDoc where the number of IDocs generated are 
based on the number of BusinessPartner 
[/ns0:Messages/ns0:Message1/ns1:SyncBusinessPartner/DataArea/BusinessPartner]
 nodeoccurences in the input XML."

When you say the you have to generate IDOCs based on BusinessPartner occurrences , you should map the IDOC root, rite ?

I could have easily done it through XSL like below

<xsl:for-each select="ns1:SyncBusinessPartner/DataArea/BusinessPartner">

<IDOC Root>

.........

</IDOC Root>

former_member186851
Active Contributor
0 Kudos

Hello Ramu,

I executed the same UDF and I didn't get any errors.

with Value for Account.

With inputs same as you provided.

Let me know the exact requirement so that code can be modified accordingly.
ramu_g4
Participant
0 Kudos

Hi Raghu,

UDF works now, now my requirement is to remove the null value from queue.

Can you help me to modify the UDF code to suppress the NULL value.

Thanks,

Ramu.

former_member186851
Active Contributor
0 Kudos

Try using remove contexts.

Harish
Active Contributor
0 Kudos

Hi Ramu,

The third input is only having one context while the other is having two. you need to have same context for all the inputs.

regards,

Harish

ramu_g4
Participant
0 Kudos

Hi Harish/Evgeniy,

Please find the below screen shots of each input parameter values to UDF. I see there are unequal number of contexts occurring to each of the UDF. If I click on "Display Queue" of UDF then it throws array index bound of exception error.

Please let me know to modify the code or handle this exception.

1st Input parameter values:

2nd Input parameter values:

3rd Input parameter values:

Thanks,

Ramu.

former_member190293
Active Contributor
0 Kudos

Hi Ramu!

I guess, this error indicates that there is no element with given index exists in array while trying to check condition: if(isVenAcc[j].equals("true")).

As Harish has already mentioned you should provide the equal number of values in each of your inbound queues in order to make your UDF work as desired.

By the way, using MapWithDefault after switching queue's context has no meaning in most cases. As far as I understand you want to provide deault value for respective subitem of every BusinessPartner node. But in your case default value is added only in case output queue after switching is empty (no even single value in all of BusinessPartner nodes). You should use MapWithDefault on current context and after that add RemoveContext (and set context changes further if required, using FormatByExample).

Regards, Evgeniy.

Harish
Active Contributor
0 Kudos

Hi Ramu,

It seems like a context issue. Do you see the equal number of context when the three input fields passed to the UDF? Can you past the display queue screenshot from UDF?

regards,

Harish

ramu_g4
Participant
0 Kudos

Hi Harish,

I have pasted the screen shots of queue values of each input parameter, can you help me to resolve the issue.

Thanks,

Ramu.