简体   繁体   English

如何使用 JAVA(JCO3) 将表字段作为导入参数传递给 SAP RFC

[英]How to pass Table Field as import parameter to SAP RFC using JAVA(JCO3)

Following i my code in JCO3.0 to connect to RFC and get the data from function module:按照我在 JCO3.0 中的代码连接到 RFC 并从功能模块获取数据:

    try {
        JCoDestination destination = JCoDestinationManager.getDestination(DESTINATION_NAME);

        JCoFunction function = destination.getRepository().getFunction("funtion_abap");         
        ***function.getImportParameterList().setValue("IM_ID_NAME", "MTC_ZPR008_TEMPB");***
        function.execute(destination);
        JCoTable table = function.getTableParameterList().getTable("export_table");
        }
        catch(Exception e){
            }

Following is my ABAP function:以下是我的 ABAP 函数:

  CALL FUNCTION 'funtion_abap' DESTINATION m_vsyid
  EXPORTING
    IM_ID_NAME =  table_vname
  IMPORTING
    export_table = table_tvarvc
  EXCEPTIONS
    system_failure        = 1
    communication_failure = 2
    resource_failure      = 3
    OTHERS                = 4.

following is an error m getting while passing String as import parameter while it wants Table field as import parameter:以下是在将 String 作为导入参数传递时得到的错误 m,而它希望 Table 字段作为导入参数:

      Exception in thread "main" com.sap.conn.jco.ConversionException: (122) JCO_ERROR_CONVERSION: Cannot convert a value of 'MTC_ZPR008_TEMPB' from type java.lang.String to TABLE at field IM_ID_NAME
at            com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:468)
at com.sap.conn.jco.rt.AbstractRecord.createConversionException(AbstractRecord.java:462)
at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:2958)
at com.sap.conn.jco.rt.AbstractRecord.setValue(AbstractRecord.java:4074)
at com.amgen.rfc.RFC_Connection.main(RFC_Connection.java:47)

Please tell me how to solve this problem.请告诉我如何解决这个问题。

The RFC definition and your code are in direct opposition. RFC 定义和您的代码是直接对立的。 According to the ABAP function (as far as I read it) the result of the call is the value in field IM_ID_NAME and the table is the input parameter.根据 ABAP 函数(据我所知)调用的结果是字段IM_ID_NAME的值,表是输入参数。

I'm not 100% familiar with the declaration of RFCs in ABAP (I only know the Java side of it), but if I interpret the error message correctly, the table seems to be in the input parameter list rather than the table parameter list (not usual but not never seen before, either).我不是 100% 熟悉 ABAP 中 RFC 的声明(我只知道它的 Java 方面),但是如果我正确解释错误消息,该表似乎在输入参数列表中而不是在表参数列表中(不常见,但也不是以前从未见过)。 So instead of getTableParameterList you will possible have to call getInputParameterList .因此,您可能必须调用getInputParameterList而不是getTableParameterList Also you should omit the setting of the field IM_ID_NAME because that's the response value and resides in the output parameter list.此外,您应该省略字段IM_ID_NAME的设置,因为这是响应值并驻留在输出参数列表中。

I know the question is quite old but someone may find my response useful one day since I had the same problem:我知道这个问题已经很老了,但有一天有人可能会发现我的回答很有用,因为我遇到了同样的问题:

JcoTable tab = function.getImportParameterList().getTable("IM_ID_NAME");
tab.appendRow();
tab.firstRow(); // I'm not sure if this is actually reqiured
tab.setValue("PARAM_NAME", paramValue);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM