on 2014 Nov 25 1:06 PM
Hi Experts,
My requirement is :
For each customer, there are 8 attributes and for each attribute there is some value. If any one of attribute is missing, PI will create that record with blank value.
If for one customer one attribute will come, PI will create another 7 records with all blank values with rest 7 attributes.
EX.
Input:
<Transaction>
<DETAIL>
<KUNNR>0001000007</KUNNR>
<ATTRIBUTE>A</ATTRIBUTE>
<VALUE>10</VALUE>
</DETAIL>
</Transaction>
Output:
<Transaction>
<DETAIL>
<KUNNR>0001000007</KUNNR>
<ATTRIBUTE>A</ATTRIBUTE>
<VALUE>10</VALUE>
</DETAIL>
<DETAIL>
<KUNNR>0001000007</KUNNR>
<ATTRIBUTE>B</ATTRIBUTE>
<VALUE></VALUE>
</DETAIL>
<DETAIL>
<KUNNR>0001000007</KUNNR>
<ATTRIBUTE>C</ATTRIBUTE>
<VALUE></VALUE>
</DETAIL>
<DETAIL>
<KUNNR>0001000007</KUNNR>
<ATTRIBUTE>D</ATTRIBUTE>
<VALUE></VALUE>
</DETAIL>
<DETAIL>
<KUNNR>0001000007</KUNNR>
<ATTRIBUTE>E</ATTRIBUTE>
<VALUE></VALUE>
</DETAIL>
<DETAIL>
<KUNNR>0001000007</KUNNR>
<ATTRIBUTE>F</ATTRIBUTE>
<VALUE></VALUE>
</DETAIL>
<DETAIL>
<KUNNR>0001000007</KUNNR>
<ATTRIBUTE>G</ATTRIBUTE>
<VALUE></VALUE>
</DETAIL>
<DETAIL>
<KUNNR>0001000007</KUNNR>
<ATTRIBUTE>H</ATTRIBUTE>
<VALUE></VALUE>
</DETAIL>
</Transaction>
Please help. Waiting for your early response.
Hello,
Where exacty u are stuck?
Just duplicate target "detail" node using duplicate subtree option and map constant values(a,b,c etc.) in the "attribute" target field.
Edited - I have deleted the mapping explained above, seems it will not create correct o/p. BTW, you will always have one source "Detail" node or you can have multiple source "Detail"
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Ur mapping is little bit tricky...so just to avoid lot of standard functions u can use 3 UDFs.. Count, Alphabets and Value
Do remember to change the context of each soure field and set it to +1 parent node.
1) Count - Input var1 and execution type all values of a context
int j = var1.length * 8;
int count = 0;
for(int i=0;i<j;i++)
{
result.addValue("");
count = count +1;
if(count==8 && i!=j-1)
{
count = 0;
result.addContextChange();
}
}
2) Aplhabets - input var1 and execution type all values of a context
for(int i=65;i<=72;i++) {
result.addValue((char)i);
}
3) Value - input var1 and execution type all values of a context
for(int k=0;k<var1.length;k++)
{
result.addValue(var1[k]);
}
if(8 - var1.length >0)
{
for( int i =0;i<8 - var1.length;i++)
{
result.addValue("");
}
}
Thanks
Amit Srivastava
Hi Amit,
For the alphabets I had given you example , but actually there are some values associated with those like, Attributes are Copyright, CSR, CustomerGroup etc.
The target csv file structure is:
customer attribute value
1000 CSR 10
1001 Copyright 11
There are 8 attributes with different names. But my requirement is to repeat based on customer. For each customer I will have to create 8 records , if any value is missing for any attribute, it will send space as value. in above example it should create 16 records and other than 10 and 11, it will send blank for all other attributes.
If structure is:
1000 | CSR 10 |
1000 | Copyright 11 PI should create rest 6 records with blank values . |
I had already used duplicate sub tree but issue is that it is repeating for all source nodes. I used UseOneAsMany in target node detail but it did not worked. I will try your above mentioned logic and let you know.
>>Can you please tell where I will use the context change.
I am asking you to change the context of source fields in ur mapping like this...
In the mapping editor (screeshot which u have shown above), right click on "KUNNR" Source field -> context -> and select Transaction.
Thanks
Amit Srivastava
Hello,
Mapping exception is coming for "DistinguishedName" target field becoz number of arguments in the first and second input of useoneasmany function is not matching...
Paste the mapping screenshot along with "display queue" (right click on the input functions i.e. "split by value" and "Count" UDF used just before "useoneasmany" and select display queue) for "Distinguished Name" target field.
Thanks
Amit Srivastava
Hi Amit,
Again I followed all the steps exactly mentioned above exactly. Now I am not getting that error but records are not coming as 8 or multiple of 8 .Please find all screen shots. My requirement is to get 8 records for each customer. I am pasting all 3 screen shots and test results. For test result , I am getting 8 entries but when executing only getting 1 record.
I have done the cache refresh but when testing the message mapping not getting 8 records. Please help.
User | Count |
---|---|
73 | |
10 | |
9 | |
8 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.