我目前正在使用 SAP JCo 连接到 SAP 系统并从 SAP 表中获取数据。我正在使用内部 BAPI 函数从 SAP 表中获取数据。我想知道如何从 SAP 表中获取数据,只需指定表名和应从中检索数据的列。
下面是我用来通过 BAPI 函数获取数据的代码。
非常感谢有关如何通过仅指定表名称和列来访问 SAP 表的任何帮助。提前致谢。
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 表,请使用 RFC RFC_READ_TABLE (通过 RFC 对 R/3 表进行外部访问)
- 参数QUERY_TABLE - 在此处指定表名称
- (可选)参数ROWSKIPS - 跳过第一条记录
- (可选)参数ROWCOUNT - 要加载的最大行数,出于性能考虑
关于java - 通过 JCo 访问 SAP 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25661491/