cancel
Showing results for 
Search instead for 
Did you mean: 

UDF

Former Member
0 Kudos

Hi,

I have an UDF where I create Idoc depending on the source message. But if the right input isn't entered I don't want to create any Idoc. but since I have an "else" with return in the end of the code it automatically creates an Idoc even if the wanted value is not entered.

Do you know what should be in the return statement in order to not create any Idoc?

if(a.equals("X"))

{

return Idoc;

}

else if(a.equals("Y"))

{

return Idoc;

}

else {

return "";

}

thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sonny

use this code .for or operator we have to use "||" as shown below in the code


for(int i=0;i<a.length();i++)
{
 
 if(a<i>.equals("X")||a<i>.equals("Y")) 
result.addValue(Idoc<i>);
}

Former Member
0 Kudos

Hi,

the or operator didn't work

if (a[0].equals("X") I I a[0].equals("Y"))

{

result.addValue(b[0]);

}

else {

result.addSuppress();

}

former_member187339
Active Contributor
0 Kudos

Hi Sonny,

"||" is not double I, it is other key in keyboard (below backspace)

Regards

Suraj

Former Member
0 Kudos

Ok thanks, it works now but I still get only one structure in the output message.

"X" should create 1 idoc and "Y" should create another Idoc.

I've got both X and Y in the source message but I only get 1 Idoc in the target.

could you assist?

former_member187339
Active Contributor
0 Kudos

Hi Sonny,

If this is your code


for(int i=0;i<a.length();i++)
{ 
 if(a<i>.equals("X")||a<i>.equals("Y")) 
result.addValue(Idoc<i>);
}

Then tell me what are you giving in "a" and "Idoc" input fields Also can you paste what you see in the display queue (right click udf-> display queue)?

Regards

Suraj

Edited by: S.R.Suraj on Oct 16, 2009 8:54 AM

Former Member
0 Kudos

I'll get this: t_.java:1743: cannot resolve symbol symbol : method length () location: class java.lang.String[] for(int i=0;i<a.length();i++)

Header

Item

a = "X"

Item

a = "Y"

former_member187339
Active Contributor
0 Kudos

Hi

Change the code to


for(int i=0;i<a.length;i++)
{ 
 if(a<i>.equals("X")||a<i>.equals("Y")) 
result.addValue(Idoc<i>);
}

also what is the value of input field "Idoc"???

Regards

Suraj

Former Member
0 Kudos

the field Idoc does not have any value. that is the parameter that pushes out the Idoc. in the graphip mapping that is the Item. that means for each "X" or "Y" a new Item should be created.

i ran your last suggestion and got:

Cannot produce target element /MBGMCR03/IDOC. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd

which means that it's something with me mapping but I only have 2 inputs so I don't see what could be wrong

former_member187339
Active Contributor
0 Kudos

Hi Sonny,

>>the field Idoc does not have any value. that is the parameter that pushes out the Idoc. in the graphip mapping that is the Item. that means for each "X" or "Y" a new Item should be created.

For each "X" and "Y" you want one IDOC (in output) to be created right? The in your code replace result.addValue(Idoc<i>) with result.addValue("")

>>Cannot produce target element /MBGMCR03/IDOC. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd

please don't simply execute mapping. First check the display queue of this udf and see whether you got the desired number in output. That is say to have input X, X, Z,Y then you should have 3 idocs created in output. Check if it is getting created

If it is done then this thread is answered. Because what follows next is the mapping logic correctness which should be done on a field by field basis. And for that you need to see which fiedl is not getting generated and need to find out why (remember X,X,Z,Y shoudl generate IDco for 1,2 and 4th value. how to make sure that the third value is not there in output.) These things need to be adjusted.

Hope you will be able to do so

Regards

Suraj

Answers (3)

Answers (3)

Former Member
0 Kudos

yes change it to Queue.

use this UDF



if(a[0].equals("X")||a[0].equals("Y")) 
{
result.addValue("Idoc");
}

Former Member
0 Kudos

But should Idoc be in "Idoc"? because it is an input parameter in the UDF it should not be between " " ?

Former Member
0 Kudos

You have to convert it to Advanced UDF and there you will not require to define any else part in your UDF, which will solve your problem.

Regards,

Sarvesh

Former Member
0 Kudos

Hi,

How do I convert to Advanced mode?

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

Use this code:

Use Queue type UDF for this.

if(a.equals("X"))

{

result.addValue("Idoc");

}

else if(a.equals("Y"))

{

result.addValue("Idoc");

}

else {

result.addSuppress();

}

Hope this helps,

Former Member
0 Kudos

thank you for replying,

I used your code and get:

cannot return a value from method whose result type is void return Idoc;

former_member187339
Active Contributor
0 Kudos

Hi Sonny,

>>How do I convert to Advanced mode?

Click on the pencil sign (display/edit mode) and change the signature

Regards

Suraj

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Sonny,

That is because you should use result.addValue(String). Execution type should be set to All values of a Queue if you are using PI7.1 otherwise. For SAP XI 3.0 use Queue type UDF

Regards,

Former Member
0 Kudos

Do you mean that I change it to Context or Queue?

Former Member
0 Kudos

my setting and code looks like this:

Queue:

Argument: a

Argument: Idoc

Result: result

else if(a.equals("X"))

{

result.addValue(Idoc);

}

else if(a.equals("Y"))

{

result.addValue(Idoc);

}

else {

result.addSuppress();

}

error: ResultList cannot be applied to (java.lang.String[]) result.addValue(Idoc);

former_member187339
Active Contributor
0 Kudos

Hi Sonny,

code should be



else if(a.equals("X"))
{
result.addValue(Idoc[0]);
}
else if(a.equals("Y"))
{
result.addValue(Idoc[0]);
}

else {
result.addSuppress();
}

Regards

suraj

Former Member
0 Kudos

Hi, ok this was very helpful thank you.

but I want to populate several Idocs if the source message includes both "X" and "Y".

in this code that I have now it only types out either one of them even if both are in the source message.

do you know how I can put "or" between the rules instead of "else if"?

if (a[0].equals("X"))

{

result.addValue(Idoc[0]);

}

else if(a[0].equals("Y"))

{

result.addValue(Idoc[0]);

}

former_member181962
Active Contributor
0 Kudos

Hi Sonny,

Is your IDOC a single value or a queue of values?

If it is a queue of values, then you should modify your code like this.

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

else if(a[0].equals("X")) 
{
result.addValue(Idoc<i>);
}
else if(a[0].equals("Y")) 
{
result.addValue(Idoc<i>);
}

else { 
result.addSuppress();
}
}

Regards,

Ravi Kanth Talagana

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

Use Queue type UDF for this.

In your else statement use

result.addSuppress(); instead of "".

Hope this helps,

Edited by: Mark Dihiansan on Oct 16, 2009 10:51 AM

Former Member
0 Kudos

Hi, Do I put result.addSuppress(); after Return or do I remove Return aswell?

I get :

1815: cannot resolve symbol symbol : variable result location: class com.sap.xi.tf._MMS_test_ result.addSuppress();