on 03-29-2012 5:59 PM
HI
Scenario is file to file:
Facing issues in mapping:
I have two fields at the source side and two fields at the target side:
Source Side Fields: Header: (Pallet_ID,Quantity)
Target Side Fields: Header: (Pallet_ID,Sum_Quantity)
ExampleData:
(Pallet ID: 1, Quantity:10) (Pallet ID: 2, Quantity:20) (Pallet ID: 1, Quantity:100) (Pallet ID: 2, Quantity:110)
Output should be: The sum of pallet id should be presnet
(Pallet ID: 1, Quantity:30) (Pallet ID: 2, Quantity:210) (Pallet ID: 1, Quantity:30) (Pallet ID: 2, Quantity:210)
I have thousands of records and thousands of pallets and the client needs in same sequence.
Could you please throw some idea on achieving this.
Thanks,
--Sai
Hi Sai,
Here is how I would personally do it:
1. UDF declaration:
2. UDF source code:
Dictionary dict = new Hashtable();
for (int i = 0; i < id.length; i++){
if (dict.get(id[i]) == null)
dict.put(id[i], qty[i]);
else {
float temp = Float.valueOf(dict.get(id[i]).toString()).floatValue() +
Float.valueOf(qty[i]);
dict.put(id[i], temp);
}
}
Enumeration e = dict.keys();
do {
String key = e.nextElement().toString();
out_id.addValue(key);
qty_out.addValue(dict.get(key));
}
while (e.hasMoreElements());
3. Mapping:
Hope this helps,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not able to paste/attach the screen shot but will try to explain you one of the possible solution:
you have to use a combination of standard functions and UDF...
RC--> Remove Context, SBK: Sort By Key, FBE: Format By Example, SBV: Split by value, CC: Collapse Context
UDF will have 3 inputs:
Id--RC----------------------------------------------------------\
Id----RC----Sort---SBV(value changed)---CC------UDF-----SBV(each value)------Sum_Quantity
3rd input--------------------------------------------------------/
3rd Input mapping shown below:
Id--RC--\
------------------SBK-------------------------------------\
Quantity--RC--/ \
-------------------------------------------------------------------FBE----SUM-----RC ----------- ( 3rd input)
Id-RC--Sort---SBV (value changed)------/
UDF:
Execution type: all values of a context
for(int j=0;j<a.length;j++)
{
for(int i=0;i<b.length;i++)
{
if(a[j].equals(b[i]))
{
result.addValue(c[i]);
break;
}
}
}
I know its looking horrible but i don't have any option left
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.
Hi Sai,
You can do easily with UDF.
Could you please provide occurrance of the following source fields and parents. if you can attach complete source structure that will be helpful.
Pallet ID
Quantity
Cheers,
Jag
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can set the context to the parent node of the quantity and use SUM function. Assign the variable to the target. You might be able to do with predefined function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sai,
Calculating this kind of "conditional" sum is not possible (or at least very difficult, in the best case) with graphical mapping. Your scenario looks like a typical use case for Java or ABAP mapping, where you should be able to perform the calculations with just a few lines of code. I would go for this kind of solution if I were you.
However, you should also be aware that application logic shouldn't ideally be executed by PI, but rather in the source and target system instead, as a principle.
Hope this helps,
Greg
Can it be done with existing predefined functions in mapping or it requires UDF..
Please suggest
Sai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.