cancel
Showing results for 
Search instead for 
Did you mean: 

UDF Help required

former_member183906
Active Contributor
0 Kudos

Hi,

In source there is field A - which has 3 values X,Y,Z

In target there is a field B

I need a UDF -

If A=X ,B=R

If A=Y, B=R1

If A=Z, C= R2

Can any one share UDF code or send screenshot for it. Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Muniyappan
Active Contributor
0 Kudos

Hi SAP,

you can achieve this using fix value function as mentioned by Ambrish Mishra.

no need to go for udf. any reason why do you want UDF?

do the mapping something like this.

FieldA-->fixvalues-->FieldB.

Regards,

Muniyappan..

former_member183906
Active Contributor
0 Kudos

I need a UDF -

If A=X ,B=R

If A=Y, B=R1

If A=Z, B= R2

the requirement is actually this, please advise on it :

actually under element A there is attribute M which will have dynamic value and that dynamic value will be passed to element B.. (R,R1,R2 are dynamic values which will come from attribute M values)

X,Y,Z are constant but conditions will be on attribute M dynamic values.

sorry i wasn't clear earlier...

Muniyappan
Active Contributor
0 Kudos

Hi,

say you have below values

A = X,Y,Z

M = R1,R2,R3

B= R1,R2,R3

you have to map m to b. you don't need any condition for this.

if possible can you share us the input and output xml. may be it can help us more.

Regards,

Muniyappan.


former_member183906
Active Contributor
0 Kudos

hi,

thanks 4 ur reply.

I am attaching word document giving input xml file and desired output. there r 3 cases in it of input data.

pls provide help for UDF in it.

rgds

Case 1 : When Firstvalue is
present (irrespective of firstvalue present or not).

                <Element1>

                          
<AllOne dom="Firstvalue">

                        <Id>FirstvalueValue</Id>

                    <AllOne dom="onefirstvalue">

                        <Id>xyz</Id>

                    </AllOne>

                    <AllOne dom="sap">

                        <Id>klm</Id>

                    </AllOne>

                    <AllOne dom="firstvalue">

                        <Id>xyz</Id>

                    </AllOne>

                    <AllOne dom="SID">

                        <Id>klm</Id>

                    </AllOne>

                </Element1>

Output

--------------------------------------------------

                <Element1>

                    <AllOne dom="Firstvalue">

                        <Id>FirstvalueValue</Id>

                    </AllOne>

                </Element1>

Case 2 : When Firstvalue is
not present and firstvalue is present.

                <Element1>

                  
<AllOne dom="onefirstvalue">

                      
<Id>xyz</Id>

                  
</AllOne>

                  
<AllOne dom="sap">

                      
<Id>klm</Id>

                  
</AllOne>

                  
<AllOne dom="firstvalue">

                      
<Id>smallfirstvalue</Id>

                  
</AllOne>

                  
<AllOne dom="SID">

                      
<Id>klm</Id>

                  
</AllOne>

                </Element1>

---------------------------------------------------------------------------

Output

--------------------------------------------------

                <Element1>

                  
<AllOne dom="Firstvalue">

                      
<Id> smallfirstvalue </Id>

                  
</AllOne>

                </Element1>

Case 3 : When Firstvalue
and firstvalue both are not present.

                <Element1>

                                   

                  
<AllOne dom="onefirstvalue">

                      
<Id>novalue</Id>

                  
</AllOne>

                  
<AllOne dom="sap">

                      
<Id>klm</Id>

                  
</AllOne>

                  
<AllOne dom="SID">

                      
<Id>klm</Id>

                  
</AllOne>

                </Element1>

---------------------------------------------------------------------------

Output

--------------------------------------------------

                <Element1>

                  
<AllOne dom="Firstvalue">

                        <Id> novalue </Id>

                  
</AllOne>

                </Element1>

---------------------------------------------------------------------------

Former Member
0 Kudos

Hello,

Check below UDF:

Execution type: all values of a context

Input: var1, var2

ResultList: result1, result2

int count1=0;

int count2=0;

String value1="";

String value2="";

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

{

if(var1[i].equals("Firstvalue"))

{

value1=var2[i];

count1=count1+1;

break;

}

if(var1[i].equals("firstvalue"))

{

value2=var2[i];

count2=count2+1;

continue;

}

}

if(count1>0)

{

result1.addValue("Firstvalue");

result2.addValue(value1);

}

else if(count2>0)

{

result1.addValue("firstvalue");

result2.addValue(value2);

}

else

{

result1.addValue("Firstvalue");

result2.addValue(var2[0]);

}

Mapping: Do remember to change the context of both id and dom and set it to "Element1" level

Thanks

Amit Srivastava

Former Member
0 Kudos

Test Results:

Case1: Firstvalue

Case2: firstvalue

Case3: No value

ambrish_mishra
Active Contributor
0 Kudos

Hi,

I would suggest a simple mapping for this requirement.

I have tested with your test cases and it works fine.

context of @dom and Id is root node (Element1 in your case)

I just used a simpler data type.

UDF code:

Parameters: DOM, ID

______________________________________

String temp = "";

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

    if(DOM[i].equals("FirstValue")){

        temp = ID[i];

        break;

    }

    else if(DOM[i].equals("firstvalue")){

        temp = ID[i];

        break;

    }

    else

        temp = ID[0];

result.addValue(temp);

______________________________________

Hope this works for you.

Ambrish

Your requirement is much clear after you explained your test cases well :) Message was edited by: Ambrish Mishra

Answers (2)

Answers (2)

former_member183906
Active Contributor
0 Kudos

Hi,

Thanks Amit & Ambrish. Both the solutions are working fine

Rgds

ambrish_mishra
Active Contributor
0 Kudos

Use standard -> Conversion FixValue function:

Input A and send the output to B

former_member183906
Active Contributor
0 Kudos

I need a UDF -

If A=X ,B=R

If A=Y, B=R1

If A=Z, B= R2

actually under element A there is attribute M which will have dynamic value and that dynamic value will be passed to element B.. (R,R1,R2 are dynamic values which will come from attribute M values)

X,Y,Z are constant but conditions will be on attribute M dynamic values.

sorry i wasn't clear earlier...

ambrish_mishra
Active Contributor
0 Kudos

Hi,

you just need to Map M to B. Why do you want to check A when M is dynamic.

Am I missing something ?

Ambrish

ambrish_mishra
Active Contributor
0 Kudos

use if then else.

If A to fix value

then M else pass null