cancel
Showing results for 
Search instead for 
Did you mean: 

Help in Mapping: User defined function

Former Member
0 Kudos

Hi All, I need your help in doing the following mapping:

The source contains the below fields:

Source_MT -- Under this 1...1

LineItem 1...Unbounded

CompanyCode 1..1

Amount 1..1

SubTotal 1...Unbounded

CompanyCode 1...1

Amount 1...1

And the Target strunture should be:

Target_MT -- Under this

Target 1...unbounded

CompanyCode 1...1

AmountMatched 1...1

There will be multiple line items in the source for each compony code which I need to loop through and add the amounts. For a company code, The sum of the amounts in the line items should match with the amount in the Subtotal/Amount.

For each company code, a target should be created with the result whther the amounts were matched or not.

Below is the data example:

Source:

Line Item :

CompanyCode Amount

-


ABC 5

ABC 5

XYZ 10

ABC 7

XYZ 6

Sub Total :

CompanyCode Amount

-


ABC 17

XYZ 5

Target should be:

-


CompanyCOde Amount

-


ABC Matched

XYZ Not Matched

Hope I am clear with my requirement. Please let me know if you need more clarity.

I was able to create mapping, if the line items contains single company code. Need help with multiple company codes.

Any help would be appreciated.

Edited by: GP on Jan 29, 2008 5:55 PM

Edited by: GP on Jan 29, 2008 5:57 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

This you could achive through useing Advanced UDFs

I am assuming that you are aware with creating the UDF

or refer below link for it,

Create Advanced UDF,

Use below logic to imply it in java coding.

In UDF take Company code (as A) & Amount (as B)

Then Cache parameter = queue

use below code

Integer amt = new Integer(0);

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

{

for(int j =0; j<A.length; j++)

{

If(A[j]==A<i>)

{

amt = amt + Integer.parseInt(B<i>);

flag = 'X';

}

}

if(flag== 'X')

{

result.addValue(Integer.toString(amt));

result.addContextChange();

flag = ' ';

}

}

This will resolve your purpose for the Field Amount, now for Field Company code create another UDF and copy the same code just instead of result.addValue(Integer.toString(amt)); use

result.addValue(A<i>);

Thanks

Swarup

Edited by: Swarup Sawant on Jan 29, 2008 6:30 PM

Former Member
0 Kudos

Thanks Swarup.

I already achieved the results for the line items with only one company code.

But I am having trouble grouping the line items by company code for summing up the totals. Actually there may be multiple company codes like in the example I have shown.

Also, after that I need to compare the sum of line items with SUB TOTALS to spit out the target.

Please let me know if I am not clear.

Edited by: GP on Jan 29, 2008 8:14 PM

justin_santhanam
Active Contributor
0 Kudos

GP,

There is no need for UDF. You can achieve it in Standard function itself.

If the below logic doesn't suits your reqmt, please let me know. I'll try to re-design it.

Mapping Logic

http://www.flickr.com/photo_zoom.gne?id=2228470917&size=o

http://www.flickr.com/photo_zoom.gne?id=2228470921&size=o

http://www.flickr.com/photo_zoom.gne?id=2228470923&size=o

Results

http://www.flickr.com/photo_zoom.gne?id=2228470925&size=o

Please refer the below link for more details on logic 3

http://www.flickr.com/photo_zoom.gne?id=2229287904&size=o

Note: GP I was in assumption that all the CompanyCode which is present in LineItem Level must repeat in the SubTotal Level.

raj.

Edited by: Raj on Jan 29, 2008 1:57 PM

Former Member
0 Kudos

Hi,

This will be also possible by just modifying the above given UDF

Here along with company code and sub-total pass the total amt also.

In the UDF you could verify that if the value of amt field is equal to Toatal amt passed to UDF.

If either matched pass company code and value as matched or notmatched.

Let me know if you get this solution.

I don't see any way to avoid UDF here

Raj ,

If possible suggest the sloution to avoid UDF here, that would also alternative help for GP.

Thanks

Swarup

justin_santhanam
Active Contributor
0 Kudos

Swarup,

>

> Raj ,

> If possible suggest the sloution to avoid UDF here, that would also alternative help for GP.

Did you saw those images? I think it's possible. I did anything wrong? Or I missed something over ther? Please correct me if I'm wrong...

raj.

Former Member
0 Kudos

Raj/Swaroop,

Thanks for your replies.

Raj, Your solution worked like a charm.

Answers (2)

Answers (2)

Jitendra_Jeswan
Contributor
0 Kudos

I would like you to elobarate more on the Mapping requirement with exact source and Target structure with what all you want to achieve..

Regards.

Jeet.

Former Member
0 Kudos

Raj,

I would like throw an error if the amounts are not matched. For this, I created UDF and wrote the code:

throw new RuntimeException("Validation Error Occurred: ");

But when the totals are not matched, it is not throwing the exception. It is showing "Resultlist.Supress" in the target in blue color (When I do "Display Queue".

Also, I do not want to create the target node when the totals match. I just want to raise exceptionw hen the totals do not match.

Could you please help?

justin_santhanam
Active Contributor
0 Kudos

GP,

I'm sorry, I couldn't able to understand ur reqmt. Could you please reframe it?

raj.

Former Member
0 Kudos

I am still working on the same map (please refer above) for which you gave th3e solution. The solution almost worked.

I need to validate the line items with the subtotals. If the validation fails, I should throw an custom exception. If the validation is successful, then do nothing (do not create the target element).

Hope I am clear. Please let me know if I am not clear.

LineItem1: 10

LineItem2: 20

SubTotal1: 30

LineItem3: 5

LineItem4: 5

SubTotal2: 15

In the above example, eventhough LineItem1 and LineItem2 sum up to Subtotal1, LineItem3 and LineItem4 doesn't sum up to SubTotal2. So it should throw an exception because second validation failed.

Also, it should not create target element because first validation was successful.

I used the logic int he below link :

[http://www.flickr.com/photo_zoom.gne?id=2229287904&size=o]

In the "else" part of "If else" statement, I have a user defined function which throws exception.

If the output is "true", I am avoiding creating the target element using "Createif" statement.

But strangely, when the vaildation of first set fails (LineItem1, LineItem2 and Subtotal1), then it is throwing the exception.

But when the validation of second set fails, then it is not throwing the exception.

My current map looks like below:

[http://www.flickr.com/photos/23389577@N02/2234471441/sizes/l/]

Edited by: GP on Feb 1, 2008 6:46 PM

Edited by: GP on Feb 1, 2008 6:50 PM

Edited by: GP on Feb 1, 2008 7:01 PM

justin_santhanam
Active Contributor
0 Kudos

>

>If the validation is successful, then do nothing (do not create the target element).

>

> Also, it should not create target element because first validation was successful.

GP, I'm extremely sorry. What u r trying to do? See the above statements! In which case u want to create the target node?

Let me clear something.

If the total matches then don't create the target -- Fine

If the total doesn't matches then throw exception -- Fine.(See if you throw RuntimeException none of the nodes will be created - Your mapping will fail)

raj.

Former Member
0 Kudos

Raj,

I have to map line items to the Idoc after the totals have been validated. I am okay with the runtime exception, because if the totals doesn't match, I should not post the Idoc.

I am posting the message structure. In the target i created temporary nodes like "SubTotalValidation", but I do not want to create them.

[http://www.flickr.com/photos/23389577@N02/2234505025/sizes/l/]