on 11-06-2008 1:08 PM
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
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 ='" + pernr + "'</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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
RFC look up is the best method for querying an ABAP table..!!
VJ
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
use db lookup, below link can help you
/people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler
Regards,
Sukarna.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.