cancel
Showing results for 
Search instead for 
Did you mean: 

How to access a ztable created in PI using JAVA MAPPING

former_member189354
Contributor
0 Kudos

Hi,

I need to accesss a ZTABLE created in PI using mapping(java). What is the best way to access it.Can anybody help with sample code of JRA approach.

Thanks,

Mallikarjun.M

Accepted Solutions (0)

Answers (3)

Answers (3)

ik69
Participant
0 Kudos

Hi Rao,

here is example code for UDF - it uses rfc call for RFC_READ_TABLE FM:


import java.io.*;com.sap.aii.mapping.lookup.*;

public String GetSomethingRfc(String pernr, String table,String field,Container container){

String content = "";
AbstractTrace importanttrace = null;
String m = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:RFC_READ_TABLE xmlns:ns0=\"urn:sap-com:document:sap:rfc:functions\"><QUERY_TABLE>"+ table + "</QUERY_TABLE><DATA></DATA><FIELDS><item><FIELDNAME>" + field +"</FIELDNAME></item></FIELDS><OPTIONS><item><TEXT>PERNR =&apos;" + pernr + "&apos;</TEXT></item></OPTIONS></ns0:RFC_READ_TABLE>";
RfcAccessor accessor = null;
ByteArrayOutputStream _out = null;
Channel channel = null;

try
	{
   channel  = LookupService.getChannel("BUSINESSSYSTEMNAME", "RFCCOMMUNICATIONCHANEL");
   accessor = LookupService.getRfcAccessor(channel);
   }
   catch (LookupException e) {}
   catch (NullPointerException e) {}
  }
}
  
try 
  {
    InputStream inputStream = new ByteArrayInputStream(m.getBytes());
     XmlPayload payload = LookupService.getXmlPayload(inputStream);
     Payload result = accessor.call(payload);
      InputStream _in = result.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("UTF-8"); 
        //parse response here
  }

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

catch(IOException e)
  {
    importanttrace.addWarning("Error " + e.getMessage() );
  }

  finally
  {
    if (_out != null) {
      try {
        _out.close();
      } catch (IOException e) {
          importanttrace.addWarning("Error while closing stream " + e.getMessage() );
        }
    }
    if (accessor != null) {
      try {
        accessor.close();
      } catch (LookupException e) {
          importanttrace.addWarning("Error while closin accessor " + e.getMessage() );
        }
     }
}

return content;

}

Have a look at https://help.sap.com/javadocs/pi/SP3/xpi/index.html as well.

Regards,

Igor.

VijayKonam
Active Contributor
0 Kudos

RFC look up is the best method for querying an ABAP table..!!

VJ

Former Member
0 Kudos

use db lookup, below link can help you

/people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler

Regards,

Sukarna.