cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Requirements

raviteja_satuluri
Contributor
0 Kudos

Dear Experts,

Requirement:

Table 1 : T_CHARDATA

Inline image 1

Table 2 : T_RETURN

Inline image 2

Input :

See the source xml for example it contains 2 tables in SAP BAPI

T_CHARDATA and T_RETURN

for each 'item' of T_RETURN,T_CHARDATA will have maximum of 35 rows.

in example I have given 3 items of  T_CHARDATA to one  'item' of T_RETURN

and observe that the MATNR of T_RETURN is equal to MATNR of T_CHARDATA for 3 items.

File struture:

Inline image 3

Output :

will contain all possible 35 items in target XSD.

in xml i have not mentioned all 35 for understanding purpose.

Mapping:

mapping needs to be done to all 35 fields in target side.

Logic:

step1: compare the MATNR of T_RETURN and MATNR of T_CHARDATA

step2: if both MATNR are equal, compare CHAR_NAME in T_CHARDATA with constant say 'LEGAL_DEMANDS'.

step3: if CHAR_NAME is equal to constant we maintain, then pass the CHAR_VALUE as output to LEGAL_DEMANDS field.

step4: we have to send 35 CHAR_NAME and  CHAR_VALUE combinations to 35 fields in target side

Note:1. for all 35 fields in target xsd we need to do mapping with constant .

2.contant is the name of target field.

3.CHAR_NAME of T_CHARDATA will get 35 target field names.

4. CHAR_VALUE of T_CHARDATA will get values corresponding to CHAR_NAME values.

5.Multiple materials will come as input.

Please let me know if you get any idea on this requirement.

Kindly help on this Requirement friends it is very urgent to me, Please help me.

Thanks and Regards,

T.S.

Accepted Solutions (0)

Answers (1)

Answers (1)

raviteja_satuluri
Contributor
0 Kudos

Dear friends,

I tried UDF, but getting some syntax errors.

Please find the below code and help me to sort it out the problem.

UDF Code:

int j;

AbstractTrace trace = container.getTrace();

trace.addInfo("Tracing");

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

for(j = 0; j < charMtrl.length; j++){

if(charMtrl[j] == returnMtrl[i]){

if(charName[j].equals(charField[0])){

result.addValue(charValue[j]);

result.addContextChange();

}

}

}

j = 0;

}

Kindly provide me if any other code suits the requirement.

Thanks and Regards,

T.S.

former_member182412
Active Contributor
0 Kudos

Hi Teja,

Your screens are not appearing but i created the structure like below and i have done the mapping.

Note: all fields the context should be root node which is my case it is SenderData or you can use removeContexts

UDF:


public void mapTarget(String[] materialReturn, String[] materialChar, String[] charName, String[] charValue,

  ResultList field1, ResultList field2, ResultList field3, Container container) throws StreamTransformationException {

  Map<String, String> map = new HashMap<String, String>();

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

  map.put(materialChar[i] + charName[i], charValue[i]);

  }

  for (String material : materialReturn) {

  field1.addValue(map.get(material + "FIELD1"));

  field2.addValue(map.get(material + "FIELD2"));

  field3.addValue(map.get(material + "FIELD3"));

  }

  }

Mapping Result:

Regards,

Praveen.

former_member186851
Active Contributor
0 Kudos

Very good Praveen.

Your screenshots are not loading TS.

raviteja_satuluri
Contributor
0 Kudos

Hi Praveen,

Thank you so much for your reply but am getting Syntax errors.

Please help on this as here i am attaching the errors.

I am getting these syntax errors. Kindly check and provide the code again. it is very helpful to me.

Thanks and Regards,

T.S.

former_member182412
Active Contributor
0 Kudos

Hi Teja,

Can you show me the screen shot of your udf under functions tab of message mapping? I think you put extra curly braces in your method like below.

Regards,

Praveen.

raviteja_satuluri
Contributor
0 Kudos

Hi Praveen,

Thank you for your reply. I will cross check again and let you know. Is there any other way with out using UDF ? I mean can we achieve this using Node functions.

If yes can you please share the screenshots.

it is very helpful to me.

Thanks and Regards,

T.S.