Skip to Content
avatar image
Former Member

UDF

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 16, 2009 at 10:12 AM

    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>);
    }
    

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • Oct 16, 2009 at 08:50 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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();

  • avatar image
    Former Member
    Oct 16, 2009 at 08:52 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • avatar image
    Former Member
    Oct 16, 2009 at 09:18 AM

    yes change it to Queue.

    use this UDF

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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

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