我使用 SAPJCo3.jar 进行 java 连接和通信,但是当执行程序时,在 JcoStructure 部分出错。调试器成功传递到我在调试器中看到的功能模块连接部分,但在这一行我得到有趣的错误:
JCoStructure returnStructure = function.getExportParameterList().getStructure("ET_CUSTOMERS");
我在运行程序时得到了这个异常:
Exception in thread "main" com.sap.conn.jco.ConversionException: (122) JCO_ERROR_CONVERSION: Cannot convert field ET_CUSTOMERS of type TABLE to StructureRecord
at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:416)
at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:411)
at com.sap.conn.jco.rt.AbstractRecord.getStructure(AbstractRecord.java:2585)
at com.sap.conn.jco.rt.AbstractRecord.getStructure(AbstractRecord.java:3060)
at com.sap.conn.jco.rt.AbstractRecord.getStructure(AbstractRecord.java:53)
at SAP.GetCustomers.step4WorkWithTable(GetCustomers.java:100)
at SAP.Main.main(Main.java:13)
这是我的功能的完整代码:
public static void step4WorkWithTable() throws JCoException
    {
        JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME2);
        JCoFunction function = destination.getRepository().getFunction("Z_SYCLO1_GET_CUSTOMERS");
        if(function == null)
            throw new RuntimeException("Z_SYCLO1_GET_CUSTOMERS not found in SAP.");
        JCoStructure returnStructure = function.getExportParameterList().getStructure("ET_CUSTOMERS");
        if (! (returnStructure.getString("TYPE").equals("")||returnStructure.getString("TYPE").equals("S"))) 
        {
           throw new RuntimeException(returnStructure.getString("MESSAGE"));
        }
        JCoTable codes = function.getTableParameterList().getTable("Z_SYCLO1_CUSTOMERS_LIST_TT");
        for (int i = 0; i < codes.getNumRows(); i++) 
        {
            codes.setRow(i);
            System.out.println(codes.getString("KUNNR") + '\t' + 
                               codes.getString("NAME1") + '\t' + 
                               codes.getString("NAME2") + '\t' + 
                               codes.getString("TELF1") + '\t' + 
                               codes.getString("STRAS") + '\t' + 
                               codes.getString("ORT01") + '\t' + 
                               codes.getString("REGIO") + '\t' + 
                               codes.getString("PSTLZ") + '\t' + 
                               codes.getString("LAND1"));
        }
        codes.firstRow();
        for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) 
        {
            function = destination.getRepository().getFunction("Z_SYCLO1_GET_CUSTOMERS");
            if (function == null) 
                throw new RuntimeException("Z_SYCLO1_GET_CUSTOMERS not found in SAP.");
            function.getImportParameterList().setValue("IV_USERNAME", codes.getString("UOZKER"));
            function.getExportParameterList().setActive("ET_CUSTOMERS",false);
            try
            {
                function.execute(destination);
            }
            catch (AbapException e)
            {
                System.out.println(e.toString());
                return;
            }
            returnStructure = function.getExportParameterList().getStructure("ET_CUSTOMERS");
            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("ET_CUSTOMERS");
            System.out.println(codes.getString("KUNNR") + '\t' + 
                   codes.getString("NAME1") + '\t' + 
                   codes.getString("NAME2") + '\t' + 
                   codes.getString("TELF1") + '\t' + 
                   codes.getString("STRAS") + '\t' + 
                   codes.getString("ORT01") + '\t' + 
                   codes.getString("REGIO") + '\t' + 
                   codes.getString("PSTLZ") + '\t' + 
                   codes.getString("LAND1"));
        }