Skip to Content
avatar image
Former Member

How to use JCo through WebService Navigator?

Hi all ..can anybody plz tell how to use JCo through WebService Navigator ?

I want to call BAPI through JCO code in EJB perspective to create a WebService Model,so as to acess fast the BAPIs result from R3,etc...

Waiting for reply..

Regards:

Hanif

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Jul 08, 2009 at 01:05 PM

    Hi,

    Please use the below sample Standalone program

    Hi,

    Use this sample standalone program and convert it to your EJB.

    package SalesOrderJCO;
    
    import java.math.BigDecimal;
    import java.sql.Date;
    import java.sql.Time;
    import java.util.Calendar;
    import java.util.StringTokenizer;
    import com.sap.mw.jco.IFunctionTemplate;
    import com.sap.mw.jco.IRepository;
    import com.sap.mw.jco.JCO;
    import com.sap.mw.jco.JCO.Function;
    import com.sap.mw.jco.JCO.ParameterList;
    import com.sap.mw.jco.JCO.Structure;
    import com.sap.mw.jco.JCO.Table;
     
    
    // method starting
    
    Time t = new Time(1);
    System.out.println("Time:"+t);
    JCO.Client objClient = null;
    IRepository objIRepository = null; 
    
    objClient = JCO.createClient("800","SAPUSER","india123","EN","sapserver","01");
    objClient.connect();
    objIRepository = JCO.createRepository("myrep",objClient);
    IFunctionTemplate objFunctionTemplate = objIRepository.getFunctionTemplate("BAPI_SALESORDER_CREATEFROMDAT2");
    Function objFunction = objFunctionTemplate.getFunction();
    ParameterList objImpParameterList = objFunction.getImportParameterList();
    Structure objHeaderStructure =objImpParameterList.getStructure("ORDER_HEADER_IN");
    ParameterList objParameterList = objFunction.getTableParameterList();
    Table objItemsTable = objParameterList.getTable("ORDER_ITEMS_IN");
    Table objPartnersTable = objParameterList.getTable("ORDER_PARTNERS");
    Table objOrderSchedulesTable = objParameterList.getTable("ORDER_SCHEDULES_IN");
    
    
    objHeaderStructure.setValue("","DOCTYPE");
    objHeaderStructure.setValue("","SALES_ORG");
    objHeaderStructure.setValue("","DISTR_CHAN");
    objHeaderStructure.setValue("","DIVISION");
    objHeaderStructure.setValue("","PMNTTRMS");
    objHeaderStructure.setValue("","INCOTERMS1");
    objHeaderStructure.setValue("","INCOTERMS2");
    objHeaderStructure.setValue("","ORD_REASON");
    objHeaderStructure.setValue("","PURCH_NO_C");
    
    objItemsTable.appendRow();
    objItemsTable.setValue("00010","ITM_NUMBER");
    objItemsTable.setValue("PK-100","MATERIAL");
    objItemsTable.setValue("1000","PLANT");
    objItemsTable.setValue("ST","SALES_UNIT");
    
    objOrderSchedulesTable.appendRow();
    objOrderSchedulesTable.setValue("00010","ITM_NUMBER");
    String ReqQuty = "10";
    BigDecimal reqqty = new BigDecimal(ReqQuty.trim());
    objOrderSchedulesTable.setValue(reqqty,"REQ_QTY");
    Date reqdate = getDate("29.07.2008");
    objOrderSchedulesTable.setValue(reqdate,"REQ_DATE");
    
    

    Regards,

    Jaya.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi jaya i am using the below code to acess the data from BAPI_SALESORDER_GETSTATUS through JCo connection and displaying it through wsnavigator...<br>

      But after deploying i am getting error i.e..excetion in JCo......<br>

      Kindly confirm me were i am going wrong...in the below EJB method....<br>

      public String[] getJCObapi() <br>

      { <br>

      String[] JcoBapi = null;<br>

      ArrayList arrayval=new ArrayList();<br>

      String SID = "JCObapiWS"; //system ID used throughout the example <br>

      com.sap.mw.jco.IRepository rep = null; //the repository we gonna be using<br>

      JCO.Client mc = null;<br>

      try<br>

      { <br>

      //Add a connection pool for the specified system<br>

      JCO.addClientPool ( SID , //alias for this pool <br>

      • , //max. number of connections<br>

      "***" , //SAP client<br>

      "****" , //userid<br>

      "****" , //password <br>

      "**" , //language<br>

      "*****" , //host name<br>

      "**" //system number<br>

      ); <br>

      rep = com.sap.mw.jco.JCO.createRepository("mrep", SID); <br>

      }<br>

      catch(JCO.Exception ex) <br>

      {<br>

      ex.printStackTrace();<br>

      }<br>

      try<br>

      {<br>

      IFunctionTemplate ft = rep.getFunctionTemplate("BAPI_SALESORDER_GETSTATUS");<br>

      JCO.Function function = ft.getFunction();<br>

      mc = JCO.getClient(SID); // Get a client from the pool <br>

      JCO.ParameterList input = function.getImportParameterList();<br>

      input.setValue("0*******", "SALESDOCUMENT");<br>

      mc.execute(function);<br>

      JCO.Structure ret = function.getExportParameterList().getStructure("RETURN"); <br>

      // Print return message<br>

      // Get table containing the orders<br>

      JCO.Table STATUSINFO = function.getTableParameterList().getTable("STATUSINFO");<br>

      // Print results<br>

      if (STATUSINFO.getNumRows() > 0) <br>

      {<br>

      do <br>

      { <br>

      // Loop over all columns in the current row<br>

      for (JCO.FieldIterator e = STATUSINFO.fields(); e.hasMoreElements(); )<br>

      {<br>

      JCO.Field field = e.nextField();<br>

      JcoBapi = new String[6];<br>

      JcoBapi[0] = field.getString();<br>

      }<br>

      } while(STATUSINFO.nextRow());<br>

      }<br>

      }<br>

      catch (Exception ex)<br>

      {<br>

      ex.printStackTrace();<br>

      }<br>

      // Releasing AND Removing JCO.Client Object of JCO CLIENT POOL<br>

      JCO.releaseClient(mc);<br>

      JCO.removeClientPool(SID);<br>

      return JcoBapi;<br>

      }<br>

      Edited by: Shaikh Hanif on Jul 9, 2009 8:35 AM

      Edited by: Shaikh Hanif on Jul 9, 2009 8:44 AM

  • avatar image
    Former Member
    Jul 09, 2009 at 06:57 AM

    Hi,

    Refer this link to create JCO connections and get the values from the FM to your ejb.

    http://www.apentia-forum.de/viewtopic.php?t=1962&sid=9ac1506bdb153c14edaf891300bfde25

    https://wiki.sdn.sap.com/wiki/display/Snippets/AutomatedBackupMonitoringSystem-ImplementingJCobasedapplications.

    Refer this link to expose your ejb as a web service.

    https://wiki.sdn.sap.com/wiki/display/Java/ExcelcreationusingApachePOIAPIsinEJBandexposingitasweb+service.

    Best Wishes

    Idhaya R

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      I am just looking over a simple JCO connection through EJB perspective to access RFC data from webservice model of wsnavigator of EP 7.0...

      Kindly guide over this...

  • avatar image
    Former Member
    Jul 22, 2009 at 04:44 AM

    closing

    Add comment
    10|10000 characters needed characters exceeded