导入参数“QUERY_TABLE”=“LTAP”中有三个不同的表(OPTIONS、FIELDS 和 DATA)。我创建了一个 java 程序,使用帮助函数 RFC_READ_TABLE 显示表 FIELDS 中的 FIELDNAME 列。
当我调用方法 step2WorkWithTable() 时,它总是出现 Error com.sap.conn.jco.AbapException: (126) TABLE_NOT_AVAILABLE: TABLE_NOT_AVAILABLE Message 300 of class DA type E 。任何人都可以解释错误吗?以及如何解决?
我的代码:
import java.util.Properties;
import com.sap.conn.jco.AbapException;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.conn.jco.JCoStructure;
import com.sap.conn.jco.JCoTable;
public class RFC_Read_Table {
public static void main(String[] args) throws JCoException
{
System.out.println("Step1: connect SAP without Pool");
step1Connect();
System.out.println("");
System.out.println("Step2: call RFC_Read_Table ");
step2WorkWithTable();
System.out.println("--------------------------------");
System.out.println("finished");
}
static {
String DESTINATION_NAME1 = "mySAPSystem";
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "ABC");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "33");
connectProperties.setProperty(DestinationDataProvider.JCO_SAPROUTER, "/A/123/");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "100");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "UserID");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "Passwort");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "de");
createDestinationDataFile(DESTINATION_NAME1, connectProperties);
}
private static void createDestinationDataFile(String destinationName, Properties connectProperties) {
File destCfg = new File(destinationName+".jcoDestination");
try
{
FileOutputStream fos = new FileOutputStream(destCfg, false);
connectProperties.store(fos, "for tests only !");
fos.close();
}
catch (Exception e)
{
throw new RuntimeException("Unable to create the destination files", e);
}
}
public static void step1Connect() throws JCoException
{
try {
JCoDestination destination = JCoDestinationManager.getDestination("mySAPSystem");
System.out.println("connected");
destination.ping();
} catch (JCoException e) {
e.printStackTrace();
System.out.println("not connected");
}
}
public static void step2WorkWithTable() throws JCoException
{
JCoDestination destination = JCoDestinationManager.getDestination("mySAPSystem");
JCoFunction function = destination.getRepository().getFunction("RFC_READ_TABLE");
if (function == null)
throw new RuntimeException("RFC_Read_Table not found in SAP.");
try
{
function.execute(destination);
}
catch(AbapException e)
{
System.out.println(e.toString());
return;
}
function.getImportParameterList().setValue("QUERY_TABLE","LTAP");
JCoTable codes = function.getTableParameterList().getTable("FIELDS");
codes.appendRow();
for (int i = 0; i < codes.getNumRows(); i++)
{
codes.setRow(i);
System.out.println(codes.getString("FIELDNAME"));
}
codes.firstRow();
for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow())
{
function = destination.getRepository().getFunction("RFC_READ_TABLE");
if (function == null)
throw new RuntimeException("RFC_READ_TABLE not found in SAP.");
function.getImportParameterList().setValue("FIELDNAMEID", codes.getString("FIELDNAME"));
try
{
function.execute(destination);
}
catch (AbapException e)
{
System.out.println(e.toString());
return;
}
JCoStructure detail = function.getExportParameterList().getStructure("FIELDS");
System.out.println(detail.getString("FIELDNAME"));
}
}
}