2017-06-28 223 views
0

導入參數「QUERY_TABLE」=「LTAP」中有三個不同的表(OPTIONS,FIELDS和DATA)。 我創建了一個java程序來顯示錶FIELDS列FIELDNAME與幫助函數RFC_READ_TABLE。使用JAVA時不可用Table_not_available RFC_READ_TABLE

它總是出現錯誤com.sap.conn.jco.AbapException:(126)TABLE_NOT_AVAILABLE:TABLE_NOT_AVAILABLE消息類別DA類型E的300中,當我調用該方法step2WorkWithTable()。 任何人都可以解釋錯誤嗎?以及如何解決它?

我的代碼:

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")); 
    } 

} 
} 
+0

嗨,歡迎來到Stack Overflow,請抽出時間通過[歡迎導覽](https://stackoverflow.com/tour)瞭解你的方式(https://stackoverflow.com/help/mcve)並檢查[如何提出好問題](https)(https://stackoverflow.com/help/mcve),以及如何創建[最小,完整和可驗證的示例] ://stackoverflow.com/help/how-to-ask)所以你增加了獲得反饋和有用答案的機會。 – DarkCygnus

+0

您在哪一行發生錯誤,請將其添加到您的問題 – DarkCygnus

+0

@GrayCygnus:謝謝您的信息。當我調用方法step2()時,它出現錯誤com.sap.conn.jco.AbapException:(126)TABLE_NOT_AVAILABLE:TABLE_NOT_AVAILABLE類DA類型E的消息300 –

回答

0

我看你連接到使用JCoDestinationManager的ABAP系統。這意味着您正在使用mySAPSystem目標中的屬性。請檢查mySAPSystem是否連接到適當的ABAP系統。

都需要爲

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"); 

什麼這些行我沒有看到他們在程序中任何地方使用。看起來它們不適用於你的連接...

+0

感謝您的回答。 實際上,我創建了一個方法createDestinationDataFile(),並調用createDestinationDataFile(DESTINATION_NAME1,connectProperties)來直接連接SAP Server。 對不起另一個愚蠢的問題:我如何檢查mySAPSystem是否連接到適當的ABAP系統? –

+0

您能否爲createDestinationDataFile提供您的代碼? – Skalozub

+0

嗨。我剛纔編輯了上面的代碼。 –