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

4k views Asked by At

Following i my code in JCO3.0 to connect to RFC and get the data from function module:

    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:

  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:

      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.

2

There are 2 answers

0
Lothar On

The RFC definition and your code are in direct opposition. 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.

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). So instead of getTableParameterList you will possible have to call getInputParameterList. 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.

0
user2753480 On

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