问题
There are three different tables (OPTIONS, FIELDS and DATA) in import parameter "QUERY_TABLE" = "LTAP". I created a java program to display column FIELDNAME from the table FIELDS with helping function RFC_READ_TABLE.
It always appears Error com.sap.conn.jco.AbapException: (126) TABLE_NOT_AVAILABLE: TABLE_NOT_AVAILABLE Message 300 of class DA type E, when I call the method step2WorkWithTable(). Can anybody explain the error? And how to fix it?
My codes:
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"));
}
}
}
回答1:
I see you are connecting to an ABAP system using JCoDestinationManager. It means your are using the properties from mySAPSystem destination. Please check if the mySAPSystem connects to a proper ABAP system.
What are these lines are needed for
Properties connectProperties = new Properties();
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "ABC");
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "33");
connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "100");
connectProperties.setProperty(DestinationDataProvider.JCO_USER, "UserID");
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "Passwort");
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "de");
I don't see them to be used anywhere in your program. It seems their are not applied to your connection...
回答2:
There is nothing wrong with your JCo code. The error message comes from the SAP system. So you need to check in the SAP system, what that error code means. This can be done in transaction SE91. You enter message class = "DA" and message number = "300" and click display.
I did this for you, and the result is: "No active nametab exists for &" where '&' needs to be replaced by the input, which is "LTAP" in this case. So we have "No active nametab exists for LTAP".
This error basically means: the database table "LTAP" exists on the database, but has not yet been activated in the ABAP DDIC. (Perhaps because it still contains a syntax error, or a required data element/domain is missing, etc.)
Solution: go to transaction SE11 and try to activate the table. This will probably give you an error message about what is wrong with this table. Fix all the syntax errors, activate it, and then you can use it.
Note: if LTAP is a standard table delivered by SAP, this error probably means that something went wrong when installing a transport/hotpackage from SAP that contained modifications to this table. In this case you should better contact SAP support to get the table back into a "consistent" state again.
来源:https://stackoverflow.com/questions/44806332/table-not-available-when-using-java-sap-rfc-read-table