cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping: Source( 0..N ) to Target (1..1)

former_member611341
Participant
0 Kudos

I'm  a SAP CRM developer new to PI. This might be a simple question, I tried to find this in forums but couldn't find it.

Question:

I have a source node with 0 to N occurrences and target node with 1 occurrence.

Target fields are mapped to same source field but with different mapping rules. See the screen shot below.

If the source has values A and Z , my target should give same values. but here my target is always taking first occurrence and giving values A and 0.

What should I do to get the target as A and Z.   i.e. read each occurrence of source node.

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

ambrish_mishra
Active Contributor
0 Kudos

Hi,

Please try this.

Context of src_fld1 should be test_source_msg.

right click on the node and traverse to context and choose test_source_msg.

Same for other field

And it should work....

Hope it answers your question

Ambrish

PS: this is assuming A and Z will come just once in the source nodes....

Message was edited by: Ambrish Mishra

ambrish_mishra
Active Contributor
0 Kudos

The graphical solution will work even if there are multiple As and Zs occurring in the source nodes...

Ignore my assumption above.

former_member611341
Participant
0 Kudos

This solution worked. Thank you very much.

But I didn't clearly understand what happened when we changed the CONTEXT ?? I tried to debug using DISPLAY QUEUE .

can you please explain?

Thank for you response once again.

ambrish_mishra
Active Contributor
0 Kudos

Hi,

PI graphical mapping is based on queues and contexts (grey portion between values).

Your requirement is to create the target node only once.

Earlier when the queue was set to context to node1, there was a context change with value in each context so it means both the queues will try to execute node1 number of times (twice in your test case). When you set it to higher context (message type level), both the values come under same queue and will execute once. If without else in case, returns true  gives corresponding source value(s) which get populated into the same target field. In case it returns false so an suppress (it is not a null but a empty context) is created which is handled by mapWithDefault which introduces a zero when it sees a suppress....

Hope I was able to explain it.

Ambrish

PS: there are multiple tutorials on SCN on this concept.

http://scn.sap.com/community/pi-and-soa-middleware/blog/2012/06/22/queues-contexts-concept-of-graphi...

Answers (2)

Answers (2)

Muniyappan
Active Contributor
0 Kudos

Hi,

did you try to debug the message mapping using display queue?

you may get some clue why you are getting 0 for z.

Regards,

Muniyappan.

Former Member
0 Kudos

Hello,

Check this UDF:

Input will be: var1 and var2

Execution type: All values of a context

int count=0;

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

{

if(var2[0].equals(var1[i]))

{

result.addValue(var1[i]);

count=count+1;

break;

}

}

if(count==0)

result.addValue(0);

Mapping:

src_fld1 ->

---------------->UDF ----tg_fld1

Constant(A)

src_fld1 ->

---------------->UDF ----tg_fld2

Constant(Z)

Note - do remember to change the context of "src_fld1" field and set it to MT name.

Thanks

Amit Srivastava