cancel
Showing results for 
Search instead for 
Did you mean: 

IDOC to WSDL UDF - mapping unrequired data from context

Former Member
0 Kudos

Hi,

As per the subject i have an issue where my UDF maps all the data from the context even after being processed.

The purpose of the UDF is to map only unique occurences of each segment in the IDOC. Below is a sample of the IDOC

<Z1CONSUMPTION_VALUES SEGMENT="1">
<SAP_CCTR_GROUP>C320100</SAP_CCTR_GROUP>
<EC_TECNICAL_ID>1001180</EC_TECNICAL_ID>
<SAP_COST_CENTER>0032020620</SAP_COST_CENTER>
<SAP_COST_ELEMENT>0000510700</SAP_COST_ELEMENT>
<EC_MATERIAL_ID>0001000286</EC_MATERIAL_ID>
<MATERIAL_DESCRIPTION>STEAM CONSUMED</MATERIAL_DESCRIPTION>
<UNIT_OF_MEASURE>GJ</UNIT_OF_MEASURE>
<VALUE>            50</VALUE>
<PROCESSING_DATE>20110120</PROCESSING_DATE>
</Z1CONSUMPTION_VALUES>

The IDOC contains 0 to n segments, with duplicates possible. Each segment is identified by concatenating EC_TECNICAL_ID and EC_MATERIAL_ID to create a Tag ID. Once this ID is created the UDF compares the ID's and if it finds an equal ID it sums up the VALUE field so only one occurence of each ID exists. Below is the UDF code.


public void mapData(String[] tagID, float[] amount, ResultList resTagID, ResultList resAmount, Container container) throws StreamTransformationException{

HashMap hashMap = new HashMap();
                                
  for(int i=0;i<tagID.length;i++) 
  {
                                                
    if(hashMap.containsKey(tagID<i>)){
    Object v = hashMap.get(tagID<i>);
    float tmp = amount<i> + new Float(v.toString());
                                                                
    hashMap.put(tagID<i>, tmp);
    } 
    else{
      hashMap.put(tagID<i>, new Float(amount<i>));
    }
    }

    Iterator it2 = hashMap.entrySet().iterator();    
    while (it2.hasNext()) 
    {         
      Map.Entry<String, Float> pairs = (Map.Entry)it2.next();

      resTagID.addValue(pairs.getKey());
      resAmount.addValue(pairs.getValue());
    }
}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

No need of writing this UDF's

If you are able to handle via node functions you can achieve this requirement with the help of

SORT and SORT BY KEY functions.

a) First SORT the TECHNICAL ID by using SORT Node function and then also SORT the MATERIAL ID based on technical id in order to avoid swaping by using SORT BY KEY function. Once they both are sorted concatenate both results

b) Now SORT again based on Ascending ORder

c) now all will come in an Asecending Order

d) use SPLIT BY VALUE CHANGE so that all values will be Splitted based on Values changing.

Ex: -

10011800001000286

10011800001000286

10011800001000286

-


SPLITTED

10011800001000287

10011800001000286

-


SPITTED

10011800001000288

e) now use COLLAPSE CONTEXT and pass that ARRAY to node.

So finally you can able to create only UNIQUE RECORDS at target side.

Regards: -

Amar Srinivas Eli

NOW Once u create a node based on the same logic you can pass corresponding values to respective CHILD FIIELDS