cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Issue

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (5)

Answers (5)

former_member184681
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Could you please elaborate the sequence of steps to UDF, its not working.

Thanks,

--Sai

Former Member
0 Kudos

seems strange..i have tested the above sequence and it was working fine....

anywayz paste your mapping here and take care of 3rd input mapping (i guess you are missing some of the functions while mapping)

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi,

Please check the below screen shot:

do remember to change the context of Id and Quantity (right click -> context-> choose MT* )to its parent node..

Mapping:

Output:

Thanks

Amit Srivastava

former_member214364
Active Contributor
0 Kudos

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

Former Member
0 Kudos

HI Jag,

Could you please find the attached snapshot for the structure.

Thanks,

--Sai

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

HI Baskar,

How do i check with pallet ID, can you post me the sequence of steps please.

Thanks,

-Sai

former_member184681
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Can it be done with existing predefined functions in mapping or it requires UDF..

Please suggest

Sai