0

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.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Coder1
  • 1
  • 1
  • 2
  • could you provide a screenshot of the BAPI you are trying to call showing the input parameter (in transaction SE37)? – Loic Mouchard Sep 04 '17 at 10:29
  • Your funtion_abap is not only lacking a 'c', it calls a second 'funtion_abap' module on another (distant) ABAP system? Are you sure what your scenario shall do? An endless recursive loop calling some other ABAP system (or maybe itself)? And where is m_vsyid coming from? I would think about this first before looking at the Java code. Did you already execute this with SE37? – Trixx Sep 04 '17 at 12:21
  • ignore spelling mistakes. issue is i have to pass table field as parameter dont know how to pass. m_vsyid this is destination variable ignore that too – Coder1 Sep 04 '17 at 13:02
  • Obviously "IM_ID_NAME" is not defined as a CHAR or STRING type but as a TABLE type. So you have to pass a JCoTable object in setValue(...) and not the string value "MTC_ZPR008_TEMPB". I guess your ABAP RFM definition is wrong but you are showing it to us, so nobody can help. Usually one only gets the JCoTable and fills it (instead of creating a new instance and setting it). – Trixx Sep 04 '17 at 14:12
  • @Trixx can you give me code line. m new to it so not able to understand to pass the JCoTable as parameter. – Coder1 Sep 05 '17 at 13:15
  • JCoTable mytable = function.getImportParameterList().getTable("IM_ID_NAME"); Then append new rows to the empty table and fill the field contents. Afterwards you don't have to set the JCoTable again. It is still part of the function object. Then you can call function.execute(destination); – Trixx Sep 05 '17 at 14:32
  • Trixx : I am able to append the row to the table but "IM_ID_NAME" is not passing to the function after execution. JCoTable table1 = function.getImportParameterList().getTable("IM_ID_NAME"); table1.appendRow(); table1.setValue( "NAME","ZPTS"); function.execute(destination); JCoTable table = function.getTableParameterList().getTable("export_table"); export table is showing null but there are values in table it should show those values. – Coder1 Sep 09 '17 at 09:11
  • Update your question or ask a new one and show us also your ABAP function module interface definition and your new Java code. StackOverflow is not a discussion forum. – Trixx Sep 10 '17 at 23:07

2 Answers2

0

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.

Lothar
  • 5,323
  • 1
  • 11
  • 27
0

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