Skip to Content
0
Former Member
Aug 18, 2010 at 10:45 AM

Problem inserting Multiple Rows in SAP using JCO 2.1.8

140 Views

Hi,

We have been working with a Java based (Web) application which interacts with SAP using JCO 2.1.8 APIs. Weu2019ve successfully used JCO to push and retrieve data from SAP u2013 thanks to the documentation provided by Arasoft. Lately my team has been facing a problem trying to insert multiple records into a SAP table using the JCO.Table object. Even though multiple records are in the JCO.Table object no record gets inserted into the corresponding SAP table.

I have also observed that only one records get added to the SAP table - the first time I use JCO.Table with just one record in it. Subsequent data push into SAP fails with no error message at all.

I have attached the code snippet which we use to insert records into JCO.Table and the subsequent pushing of this information to SAP. The Employee's ID is passed as a parameter to the below method - whose records need to be pushed into SAP.

 public  void showEngPerpormanceRecords(String sapId){
  JCO.Client client = null;
  try {
   // Get a function template from the repository
   IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_QUALIPROF_CHANGE");
   // if the function definition was found in backend system
   if (ftemplate != null) {
    // Create a function from the template
    JCO.Function function = ftemplate.getFunction();
    // Get a client from the pool
    client = JCO.getClient(SID);
    
    // Fill in input parameters
    JCO.ParameterList input = function.getImportParameterList();
    input.setValue("01", "PLVAR");
    input.setValue("P", "OTYPE");
    input.setValue(sapId, "SOBID");//TODO SAP ID
    // Call the remote system
    client.execute(function);
    
    /*JCO.Structure ret = function.getExportParameterList().getStructure("RETURN");
    System.out.println("Return Value from Grade Update BAPI: " + ret.getString("NUMBER"));*/
    
    // Successful Condition
    //if (ret.getString("MESSAGE").equals("")){
     JCO.ParameterList tableList = function.getTableParameterList();
     JCO.Table table =  tableList.getTable("PROFILE_ADD");
     if(table.getNumRows()>0){
      System.out.println("Grade record from SAP" + table.getNumRows());
      for(int i=0;i<table.getNumRows();i++, table.nextRow()){
       table.setRow(i);
       System.out.println("row "+i+"--->startdate:"+table.getValue("BEGDA")+"     enddate:"+table.getValue("ENDDA")+"    score:"+table.getValue("RATING"));
      }
     }
     else
     {
      System.out.println("Adding Grade record into SAP");
       
      SimpleDateFormat fromdf = new SimpleDateFormat("dd MMM yyyy");
      SimpleDateFormat todf = new SimpleDateFormat("dd.MM.yyyy");
      Calendar testDateObj = Calendar.getInstance();
      testDateObj.setTime(fromdf.parse("13 Nov 2010"));
      
      System.out.println("Target Date is: "+todf.parse(todf.format(testDateObj.getTime())));
      table.appendRow();
      table.setValue("80007801", "OBJ_ID");
      table.setValue(todf.parse(todf.format(testDateObj.getTime())), "BEGDA");
      testDateObj.add(Calendar.MONTH,24);
      System.out.println("Target Date + 12 months is: "+todf.parse(todf.format(testDateObj.getTime())));
      table.setValue(todf.parse(todf.format(testDateObj.getTime())),"ENDDA");
      table.setValue(2225, "RATING");
      table.setValue("80007800", "QGROUP_ID");
      table.setValue("00000062", "SCALE_ID");
      testDateObj.setTime(fromdf.parse("14 Nov 2012"));
      table.appendRow();
      table.setValue("80007801", "OBJ_ID");
      table.setValue(todf.parse(todf.format(testDateObj.getTime())), "BEGDA");
      testDateObj.add(Calendar.MONTH,12);
      System.out.println("Target Date + 12 months is: "+todf.parse(todf.format(testDateObj.getTime())));
      table.setValue(todf.parse(todf.format(testDateObj.getTime())),"ENDDA");
      table.setValue(5555, "RATING");
      table.setValue("80007800", "QGROUP_ID");
      table.setValue("00000062", "SCALE_ID");
      tableList.setValue(table,"PROFILE_ADD");
      function.setTableParameterList(tableList);
      client.execute(function);
      for(int i=0;i<table.getNumRows();i++){
       table.setRow(i);
       System.out.println("row "+i+"--->startdate:"+table.getValue("BEGDA")+"     enddate:"+table.getValue("ENDDA")+"    score:"+table.getValue("RATING"));
      }

     }
    //}
   }
  }catch (Exception e) {
   e.printStackTrace();
  }
 }
 

It would be of great help if you could help us with this problem and also suggest what is that we are missing. Is the problem with the code or with SAP BAPI? Any help and guidance on this would be highly appreciated.

Edited by: Mohideen Buhari on Aug 20, 2010 6:57 AM