-1

我使用 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"));
        }
4

1 回答 1

0

命名ET_表明这ET_CUSTOMERS是一张桌子。您不能将表格视为结构 - 您必须首先获取表格引用,然后导航到现有行或创建新行,然后您可以将该行视为结构。另请参阅具有类似背景的此答案。

(“可能”,因为表也可能基于非结构化类型创建,当与 JCo 结合时会导致非常奇怪的情况,因此您应该避免这种情况。)

于 2013-07-15T13:20:31.973 回答