cancel
Showing results for 
Search instead for 
Did you mean: 

Doubt on mapping

Former Member
0 Kudos

Hi Experts,

We have below requirement,

Source structure:

<A>one</A>

Target Structure:

<Name>

<Id>

If A=one, hard code 'Roof' to Name, '123' to Id else if A=two, hard code 'Moon' to Name, '456' to Id else pass Null to Name and Id.

I need one UDF to achieve this, so that in single map window i can map name and Id.

We can achieve this using graphical mapping, but we want to try UDF since we need same logic in more than 5 mappings.

Appreciate your help on this. Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor
0 Kudos

Hi Mohan,

If you really want to use UDF then use below.


public void mapNameAndID(String source, ResultList name, ResultList id, Container container)

            throws StreamTransformationException {

        if (source.equals("one")) {

            name.addValue("Roof");

            id.addValue("123");

        } else if (source.equals("two")) {

            name.addValue("Moon");

            id.addValue("456");

        } else {

            name.addValue("null");

            id.addValue("null");

        }

    }

Regards,

Praveen.

Former Member
0 Kudos

Praveen,

Thanks for your reply.

By using this UDF, if source is "one" or "two" it is passing result as null, not getting exact output.

is there any changes do i need to do?

former_member184720
Active Contributor
0 Kudos

You need to wrap the inside a for loop.

Execution type : All values of context

Signature :

Argument      :     source

result            :     name

result            :     id    

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

{

if (source[i].equals("one")) { 

            name.addValue("Roof"); 

            id.addValue("123"); 

        }

else if (source[i].equals("two")) { 

            name.addValue("Moon"); 

            id.addValue("456"); 

        }

else { 

            name.addValue("null"); 

            id.addValue("null"); 

        } 

}

former_member182412
Active Contributor
0 Kudos

Hi Mohan,

Can you paste your input xml? and required output then it will be easy to understand the problem (the problem may be you are passing capital letters to the UDF, if yes then you need to use equalsIgnoreCase instead of equals method.

Regards,

Praveen.

former_member184720
Active Contributor
0 Kudos

I believe that the problem is within the UDF itself -

>>>  if (source.equals("one"))  -> Here source is an array right?

former_member182412
Active Contributor
0 Kudos

Thanks Hareesh, you are right it should be an array, it was a mistake because i only tested in eclipse.

former_member182412
Active Contributor
0 Kudos

Hi Mohan,

In addition to Hareesh reply above. Remember this UDF is using two ResultLists so you will have two outputs, make sure first output map to name field and second output map to id field like below.

Regards,

Praveen.

Answers (1)

Answers (1)

iaki_vila
Active Contributor
0 Kudos

Hi Mohan,

Have you thought to use mapping templates http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/50171256-1ee2-2a10-3f84-ddecf098f...?

Your logic can be done easily with SAP standard functions, to do an UDF is not the best choice.

Regards.