Skip to Content
author's profile photo Former Member
Former Member

Calling RFC using UDF

Hi,

I have a small doubt.

In file to IDOC mapping, I am mapping two fields using a UDF.

That UDF in turn calls a RFC.

But that RFC is not moved to quality server.

If now I try to test that in quality environment, the mapping works fine and IDOC is posted because the error handling is done in ABAP.

My doubt is why did the messge did not failed in XI, saying the RFC not available??

I tried to search in sdn, by did not get anything related to this.

Please try to clarify my doubt.

Regards,

Sachi

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Nov 13, 2009 at 02:57 PM

    Hi

    My doubt is why did the messge did not failed in XI, saying the RFC not available??

    Though you have not transported the RFC to Quality. But the UDF might be returning some default value. Due to which the target element might be getting generated.

    And though the RFC is not there, it will not raise any error because not having RFC will be equivalent to RFC returning no values.

    If you want to raise error in your UDF check what is output of RFC call and if is empty then raise error through UDF.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 13, 2009 at 02:45 PM

    Hi Sachi,

    Can you share the UDF code here?

    May be the connection parameters are hard coded and there is a RFC connection already existing between your XI quality system and your SAP DEV system and it is able to get some values from your sap r/3 dev system into your XI quality system.

    Regards,

    Ravi kanth Talagana

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Ravi,

      Below is the UDF code:

      MappingTrace importantTrace = container.getTrace();

      String query = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:Z_RFC_UOM xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\">";

      String restQuery = "</ns0:Z_RFC_UOM>";

      String Lookup_Key_Tag = "I_MATNR";

      String Lookup_Key_Tag1 = "I_VKORG";

      String Lookup_Key_Tag2="I_VTWEG";

      String Lookup_Value_Tag = "E_MENEE";

      String Lookup_key_StartTag = "<" + Lookup_Key_Tag + ">";

      String Lookup_key_EndTag = "</" +Lookup_Key_Tag + ">";

      String Lookup_key_StartTag1 = "<" + Lookup_Key_Tag1 + ">";

      String Lookup_key_EndTag1 = "</" +Lookup_Key_Tag1 + ">";

      String Lookup_key_StartTag2 = "<" + Lookup_Key_Tag2 + ">";

      String Lookup_key_EndTag2 = "</" +Lookup_Key_Tag2 + ">";

      String Lookup_Value_StartTag = "<" + Lookup_Value_Tag + ">";

      String Lookup_Value_EndTag = "</" +Lookup_Value_Tag + ">";

      String comm_channel = "";

      String content = "";

      String items = "";

      String item1 = "";

      String item2 = "";

      String item3 = "";

      String ItemsTag = "";

      String Lookup_Value = "";

      int j =0;

      String Rec = Service[0];

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

      {

      ItemsTag = Lookup_key_StartTag material<i> Lookup_key_EndTag;

      item1 = item1 + ItemsTag;

      }

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

      {

      ItemsTag = Lookup_key_StartTag1 sales_org<i> Lookup_key_EndTag1;

      item2 = item2 + ItemsTag;

      }

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

      {

      ItemsTag = Lookup_key_StartTag2 dist_channel<i> Lookup_key_EndTag2;

      item3 = item3+ ItemsTag;

      }

      items=item1item2item3;

      items = items + restQuery;

      query = query + items;

      RfcAccessor accessor = null;

      ByteArrayOutputStream out = null;

      comm_channel = "CC_Recv_RFC";

      try

      {

      Channel channel = LookupService.getChannel(Rec,comm_channel);

      accessor = LookupService.getRfcAccessor(channel);

      InputStream inputStream = new ByteArrayInputStream(query.getBytes());

      importantTrace.addWarning(query);

      XmlPayload payload = LookupService.getXmlPayload(inputStream);

      Payload result1 = accessor.call(payload);

      InputStream in = result1.getContent();

      out = new ByteArrayOutputStream(1024);

      byte[] buffer = new byte[1024];

      for(int read = in.read(buffer);read>0;read = in.read(buffer))

      {

      out.write(buffer,0,read);

      }

      content = out.toString();

      importantTrace.addWarning("RFC Response::" + content);

      //Parsing RFC output

      j= 0;

      while ( content.indexOf(Lookup_Value_StartTag) != -1 )

      {

      Lookup_Value = content.substring( content.indexOf(Lookup_Value_StartTag) + Lookup_Value_StartTag.length() , content.indexOf(Lookup_Value_EndTag) ) ;

      importantTrace.addWarning("LookupValue::" + Lookup_Value);

      j++;

      content = content.substring(content.indexOf(Lookup_Value_EndTag) + Lookup_Value_EndTag.length() );

      result.addValue( Lookup_Value);

      }

      }//end of try

      catch(Exception ex)

      {

      importantTrace.addWarning("Error while lookup"+ ex.getMessage());

      }

      //catch(LookupException e){ importantTrace.addWarning("Error while lookup"+ e.getMessage()); }

      //catch(IOException e) { importantTrace.addWarning("Error while IOException"+ e.getMessage()); }

      finally

      {

      if(out!=null)

      {

      try

      {

      out.close();

      }

      catch(IOException e)

      {

      importantTrace.addWarning("Error while IOException"+ e.getMessage());

      }

      }

      if(accessor!=null)

      {

      try

      {

      accessor.close();

      }

      catch(LookupException e)

      {

      importantTrace.addWarning("Error while lookup"+ e.getMessage());

      }

      }

      }

      result.addValue("");

  • author's profile photo Former Member
    Former Member
    Posted on Nov 13, 2009 at 04:12 PM

    Sachi,

    As suggested by Abhay, there wont be any error message in sxmb_moni even though RFC do not exist. But if you goto Monitoring under Netweaver Administrator page you will see the RFC call and corresponding error message.

    http://XI sever : port / nwa/ --Monitoring --> Logs and Traces ( Select default trace).

    Hope this will help.

    Thanks,

    Nilesh

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.