[英]Accessing SAP tables via JCO
我目前正在使用SAP JCO连接到SAP并从SAP表中获取数据。 我使用内部BAPI函数从SAP表中获取数据。 我想通过仅指定表名和应从中检索数据的列来了解如何从SAP表中获取数据的方法。
以下是Im用于通过BAPI函数获取数据的代码。
JCoFunction function = destination.getRepository().getFunction("BAPI_COMPANYCODE_GETLIST");
if(function == null)
throw new RuntimeException("BAPI_COMPANYCODE_GETLIST not found in SAP.");
try
{
function.execute(destination);
}
catch(AbapException e)
{
System.out.println(e.toString());
return;
}
JCoStructure returnStructure = function.getExportParameterList().getStructure("RETURN");
if (! (returnStructure.getString("TYPE").equals("")||returnStructure.getString("TYPE").equals("S")) )
{
throw new RuntimeException(returnStructure.getString("MESSAGE"));
}
JCoTable codes = function.getTableParameterList().getTable("COMPANYCODE_LIST");
final FileWriter outFile = new FileWriter("D:\\out.csv");
for (int i = 0; i < codes.getNumRows(); i++)
{
codes.setRow(i);
}
codes.firstRow();
for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow())
{
function = destination.getRepository().getFunction("BAPI_COMPANYCODE_GETDETAIL");
if (function == null)
throw new RuntimeException("BAPI_COMPANYCODE_GETDETAIL not found in SAP.");
function.getImportParameterList().setValue("COMPANYCODEID", codes.getString("COMP_CODE"));
function.getExportParameterList().setActive("COMPANYCODE_ADDRESS",false);
try
{
function.execute(destination);
}
catch (AbapException e)
{
System.out.println(e.toString());
return;
}
returnStructure = function.getExportParameterList().getStructure("RETURN");
if (! (returnStructure.getString("TYPE").equals("") ||
returnStructure.getString("TYPE").equals("S") ||
returnStructure.getString("TYPE").equals("W")) )
{
throw new RuntimeException(returnStructure.getString("MESSAGE"));
}
JCoStructure detail = function.getExportParameterList().getStructure("COMPANYCODE_DETAIL");
非常感谢您提供有关仅通过指定表名和列来访问SAP表的帮助。 提前致谢
要仅通过指定表名和列来访问SAP表,请使用RFC RFC_READ_TABLE (通过RFC对R / 3表的外部访问)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.