cancel
Showing results for 
Search instead for 
Did you mean: 

Help on a UDF

Former Member
0 Kudos

Dear Xi Experts,

In my scenario i need to build a UDF for the next structure;

In my query I want to check, if on <b>message2</b> the <b><Key></b> value is <u>Businessday</u> then put the <b><text></b> into <b>Target</b> <Businessday>. If the Key value not exist then put the value from <b>Message1</b> the <u>Businessday</u> into Target <Businessday>.

Here is a graphic with the else-condition, but it doesn't work neither

http://photos1.blogger.com/blogger/3087/1595/1600/3.jpg

the problem is not that the if-condition wouldn't work. while sending a single key with value, it works. but when i have several keys, it only shows the first one.

http://photos1.blogger.com/blogger/3087/1595/1600/2.jpg

This is not possible with graphical mapping tool.

<b>Could anyone help me?</b>

Regards,

Fatih

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

Try following:

Key      
          equalS 
Constant /        ifWithoutElse 
            Text /               
                                  
        Key                       
                  equalS - exists - if - external
        Constant /                 /
                           external

This double checking is necessary as the queues of text and external are not in range.

Regards

Stefan

Former Member
0 Kudos

Hello Stefan,

Thank you for the answer. your solution seems to be right. it works if the values are set correctly. but if i use an incorrect value it doesn't work. the value needs to be checked on correctnes. if a key isn't set, then it should take the key of message1, but it doesn't.and if the key isn't set at all, it should take the key from message1.

thanks,

Fatih

stefan_grube
Active Contributor
0 Kudos

Hi Fatih,

I was too quick. The problem in this mapping is the different lenght of the queues. You have to remove entries from the key and text queues but the exists function does remove values. It is difficult to achieve this with standard functions. It might be easier with UDF.

You can use the function of Amit, but I think you need a 4th parameter to asign a constant with the value you want to compare the key.

Regards

Stefan

Former Member
0 Kudos

<b>Dear XI experts,</b>

The problem in my mapping is the compare. It doesn't work. Please see the following picture and code.

<b><a href="http://photos1.blogger.com/blogger/3087/1595/1600/wewewe.jpg">Screenshot</a></b>

public void UDF1(String[] key,String[] text,String[] constant,String[] msg,ResultList result,Container container){

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

if ( key.equals(constant[0])){

result.addValue (text[0]);

}

else

result.addValue(msg[0]);

}

}

Could anyone help me?

Regards,

Fatih

moorthy
Active Contributor
0 Kudos

Hi

i this udf, if any one of the value is false, it will populate false value right ?

so there is a problem.

I think,it is overwriting the latest values.

So can you try with Split By value after this function.

But one morething, can you store all these values in a Vector and then populate these vector in a loop. i.e

if success

store/append that text[0] value

else store/append msg[0].

So your Vector contains all the values true/false.

Atlast populate these.

Hopefully it works.

Regards,

Moorthy

stefan_grube
Active Contributor
0 Kudos

Hi Fatih,

you forgot the array index of key:

public void UDF1(String[] key,String[] text,String[] constant,String[] msg,ResultList result,Container container){
   for ( int k = 0; k < key.length; k++ )	{
     if ( key<b>[k]</b>.equals(constant[0])){
       result.addValue (text[0]);
       <b>return;</b> 
     }
   }
   result.addValue(msg[0]);
 }

Stefan

Former Member
0 Kudos

Hi,

In the code, you have mentioned

<b>if ( <i>key</i>.equals(constant[0])){</b>

You are not specifying an index for the key. So,we wouldnt be able to get the required output here.

Try using key [\i\].

Does constant[] array have only one element?

If no, change the code to make it key<i>.equals(constant[\i\])

Similarly, make sure you are using the right index for the arrays text[]and msg[].

Regards,

Smitha.

Former Member
0 Kudos

Hello Stefan, Krishan,Amit and Smitha

this is my solution ;

public void UDF1(String[] key,String[] text,String[] constant,String[] msg,ResultList result,Container container){

for ( int i = 0; i );

break;

}

}

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

if (!(key[j].equals(constant[0]))) {

result.addValue(msg[j]);

}

}

Thanks for the useful answers!

Fatih

Message was edited by: Fatih Kökce

Message was edited by: Fatih Kökce

Answers (1)

Answers (1)

former_member181955
Contributor
0 Kudos

Hi

You can do it by using node functions Createif(),removecontext(),splitByValue().

thanks

Prasad Babu

Former Member
0 Kudos

Hi,

Can u tell me how to do it exactly?

Can u give me an example?

Regards,

Fatih

moorthy
Active Contributor
0 Kudos

HI,

After your if-else Output before it maps with the target strcuture use the node functions RemoveContext and SplitByValue and test the mapping.

Hope this helps,

Regards,

Moorthy

Former Member
0 Kudos

Hi Fatih,

I guess the requirement is to check which key matches the Businessday and map its corresponding text, else the Businessday itself, right?

in that case apart from if-else.... use removeContext function for key and text nodes. Then pass key, text and Businessday respectively to the advanced UDF getText as below:

public void getText(String[] a, String[] b, String[] c,

ResultList result,

Container container)

{

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

{

if( a<i>.equals(c[0]))

result.addValue(b<i>);

}

if ( result.length == 0 )

result.addValue(c[0]);

}

Regards

Amit

Former Member
0 Kudos

Hello Krishna,

I have already have those steps;

http://photos1.blogger.com/blogger/3087/1595/1600/10.jpg

but it doesn't worked.

Regards,

Fatih

moorthy
Active Contributor
0 Kudos

Hi,

Check with changing the context to Root level for your input fields. hope this works

Regards,

Moorthy

Former Member
0 Kudos

Sorry Krishna,

I don't understand what you mean!

Regards,

Fatih

moorthy
Active Contributor
0 Kudos

right click on your input fields in the given mapping ( as in the diagram) then it will show different nodes/segments . Click on the Root level (Message Type level) there

More on

http://help.sap.com/saphelp_nw2004s/helpdata/en/ee/b88c4037fba62be10000000a1550b0/content.htm

Thanks

Former Member
0 Kudos

Hello Krishna,

I have tried , but it not worked !

Do you have another Idea?

Thanks,

Fatih

stefan_grube
Active Contributor
0 Kudos

Hi Amit,

could you replace the variable i in you rcode with k?

The i is not visible insides brackets, as [ + i + ] starts italic.

Regards

Stefan