cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping multiple source field to one target

ganguly05p
Explorer
0 Kudos

Hi experts,

I have a SOAP to IDOC requirement where SourceStruc1 can occur multiple times in the source xml and have to create TargetStrucut1 in the target IDOC same number of time as SourceStruc1. Structure is provided as below.

  Source XML                                             Target IDOC

SourceStruc1(occurrence 1-999)           TargetStrucut1(occurrence 1-999)
   Source1                                                    Target1
   Source2
   Source3
   Source4
   Source5
   Source6

As per my requirement, value of Target1 have to determine based on values of Source1 to Source6 fields.

Value Source1 to Source6 fields                Value of Target1

("A",4,"S","I",1,"N")                          N01

("A",4,"S","M",1,"N")                         N02

("A",5,"S","M",1,"N")                         N03

("A",5,"S","M",1,"W")                        N04

("A",5,"S","M",10,"N")                       N05

("A",5,"S","M",10,"W")                      N06

So I have implemented the logic in one UDF to determine the velue of Target1. But now the SourceStruc1 can occur multiple times in the source xml and TargetStrucut1 will also occur in the target IDOC same number of time as SourceStruc1. Could you please provide a solution to create the field Target1 in TargetStrucut1 each time TargetStrucut1 appears in the target structure.

Thanks & Regards,

Pratyus Ganguly

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

>>>So I have implemented the logic in one UDF to determine the velue of Target1.

Change this UDF to advanced(all values of context)

if you have already created an advanced UDF and see the correct output after UDF(display queue) then add a split by value after the UDF.

Source field -> remove context -> UDF -> splitby value -> target field

ganguly05p
Explorer
0 Kudos

Hi Hareesh,

Thanks for the quick reply. Iam already using UDF with execution type as "all values of context". I tried the solution you have suggested but the target field is not getting created in the target structure. By displaying queue i am getting NULL in the target field. Below is the code I have written in the UDF. Could you please let me know if anything is wrong.

public void CheckSizeCode(String[] Source1, int[] Source2, String[] Source3, String[] Source4, String[] Source5, String[] Source6, ResultList result, Container container) throws StreamTransformationException{

StringBuffer sb = new StringBuffer();
String str1 = "";
   
if(Source1.equals("A"))
  {
     result.addValue("N09");  
  if(Source3.equals("S") || Source3.equals("s"))
    {
      if(Source4.equals("I") || Source4.equals("i"))
      {
if(Source2.equals(4))
{
    if(Source5.equals(1))
    {
       if(Source6.equals("N") || Source6.equals("n"))
       {
       result.addValue("N01");
        
                  }
          }
        }
if(Source2.equals(6))
{
    if(Source5.equals("1"))
    {

      if(Source6.equals("W") || Source6.equals("w"))
      {
         result.addValue("N09");
      }
    }
}
     
      }
    }
  }

}

Thanks & Regards,

Pratyus Ganguly

former_member184720
Active Contributor
0 Kudos

You have to loop through your input's as you are using the advanced UDF.

I see that you have used "Source2.equals" to verify but here Source2 is an array(input of values).

So you have to verify this by looping through the input.

for( int i=0;i<Source1.length;i++)

{

if(Source[i].equals("A"))

{

etc....

------------

If you always have just once occurrence of Source<n> fields under one Source Structure then even simple UDF should work.

(if you just have five fields, you can just do without UDF itself)

So change this to simple UDF and try ( Instead of result.AddValue, you'll use return)

You don't need too many if statements there just merge them into 1

public String calculate1(String Source1, String Source2, Container container) throws StreamTransformationException{

if(Source1.equals("A") && Source2.equals("4") && Source3.equals("I") && Source4.equals("1") && Source5.equals("N"))

{

return "N01";

}

else if(if(Source1.equals("A") && Source2.equals("4") && Source3.equals("M") && Source4.equals("1") && Source5.equals("N"))

{

return "N02";

}

else if(if(Source1.equals("A") && Source2.equals("5") && Source3.equals("M") && Source4.equals("1") && Source5.equals("N"))

{

return "N03";

}

else if(if(Source1.equals("A") && Source2.equals("4") && Source3.equals("M") && Source4.equals("10") && Source5.equals("N"))

{

return "N04";

}

else if(if(Source1.equals("A") && Source2.equals("4") && Source3.equals("M") && Source4.equals("10") && Source5.equals("W"))

{

return "N05";

}

else{

return "N06";

}

<<Please check for Syntax errors. It's just a reference>>

ganguly05p
Explorer
0 Kudos

Hi Hareesh,

Thanks for the help. Mapping is now working I am not using advanced UDF but got the result by using split by value after UDF and remove context for each source field before the UDF as you have suggested earlier.

Thansk & Regards,

Pratyus Ganguly

Answers (0)