Skip to Content
0

ArrayIndexOutOfBoundsException in UDF in Multi-Mapping SAP PI

Oct 19, 2017 at 12:20 PM

151

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

6 Answers

Harish Mistri Oct 19, 2017 at 11:10 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

0
Evgeniy Kolmakov Oct 20, 2017 at 08:27 AM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Harish Mistri Oct 24, 2017 at 12:51 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Raghuraman S Oct 24, 2017 at 08:34 AM
0

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.

capture1.png (76.1 kB)
capture2.png (71.6 kB)
Show 2 Share
10 |10000 characters needed characters left characters exceeded

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.

removenull.jpg (71.6 kB)
0

Try using remove contexts.

0
Anurag Gupta Oct 24, 2017 at 10:41 AM
0
"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>

Share
10 |10000 characters needed characters left characters exceeded
Ramu G Oct 23, 2017 at 06:57 AM
0

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.


1stinput.jpg (36.5 kB)
2ndinput.jpg (56.9 kB)
3rdinput.jpg (47.1 kB)
Share
10 |10000 characters needed characters left characters exceeded