Posted on May 03, 2010 at 10.17 AM - Kuala Lumpur, Malaysia
There is a myth that only Java based adapter can support multiple instances at the receiving end. It's not always true, at least with IDOC. How do we control number of IDOCs to be created at the SAP systems? We can use UDF. Here are some idea on how to do exactly just that.
First of all, you must make sure that the element IDOC supports multiplicity, meaning should have occurrence which support more than 1 instance.
1. Create exactly one instance of IDOC
This is the easiest one to do, just map a constant to the IDOC element.
2. Create as many IDOCs as number of incoming records
Over here, you can use SAP standard function like SplitByValue and CollapseContext. The latter function may not be required actually if you set the context of the incoming element at the root of the source XML :)
3. Create IDOCs for every 200 incoming records
There are several mapping functions which are actually required ONLY if the incoming records are actually created as elements instead of attributes.
employeeNumber UDF coding is as follows:
String b = "";
for (int i=0;i<employee.length;i++) {
if (i == 0) {
result.addValue(""+employee[i]+"");
b = "";
b = employee[i];
}
else {
if (b.equals(employee[i])) {
}
else {
result.addValue(""+employee[i]+"");
b = "";
b = employee[i];
}
}
}
splitIdocs UDF coding is as follows:
int j = 200;
int k = 0;
for(int i=0;i<employee.length;i++) {
if (k==0) {
result.addValue(""+employee[i]+"");
}
else {
}
k = k+1;
if (k==j) {
k=0;
}
}
Over here, instead of creating 2 UDF, which are employeeNumber and splitIdocs, we can actually combine them into one UDF.
Some of the codes in the UDFs are actually not necessary as well :)
Life is beautiful! Let's make it meaningful and colorful!