Show TOC Start of Content Area

This graphic is explained in the accompanying text SAP JCo Scenario: Online Invoice  Locate the document in its SAP Library structure

Scenario: Displaying invoices online in a Web browser

The following example project describes the use of the SAP JCo in a business scenario that offers customers the option to retrieve and display their invoices online from the SAP vendor system.

The data for customer deliveries is stored in the vendor SAP system, but the actual customer invoices are stored in a document management system. In the document management system, the documents are selected by the document ID, which is stored together with the invoice number in the SAP system. The scenario must therefore find the customer data in the SAP system, and then make a connection to the document management system to retrieve the requested invoice.

Prerequisites

·       The development platform is Java

·       Enterprise JavaBeans (EJB) are used

·       You want to avoid any further installation on the SAP side

·       Transaction control in SAP occurs using BAPIs

·       You want the solution to be platform-independent

·       The project is to be implemented within a short period of time

 

Figure 1     E-Business Scenario: Displaying Invoices Online Using SAP JCo

This graphic is explained in the accompanying text

Standard BAPIs can generally be used in this scenario. In this scenario, however, a new object is developed: Z_BAPI_GET_DOCUMENT_ID .

Figure 2     Business Object and BAPIs

Business Object

BAPI

Description

Z_BAPI_GET_DOCUMENT_ID

GETDOCUMENT

Gets the document ID

 

 

Input: Company code

 

 

Invoice number

 

 

Financial year

 

 

Output: Document ID

 

GETAPPENDIX

Gets the document appendix ID

 

 

Input: Company code

 

 

Invoice number

 

 

Financial year

 

 

Output: Document appendix ID

A SessionBean has been implemented for contacting this object. The bean contains the method getDocid(), which returns the IDs as described in figure 3.

Figure 3     Method getDocid() in the SessionBean

 

  /**

  * Getting Document-ID, Document-Appendix-ID from SAP/R3 by invoice number

  * @return Document-ID

  */

  public String getDocid()

  {

    String sDocid = "";

    JCO.Client jcoConnection = null;

    IRepository repository = null;

   

    // getting properties

    try

    {

      String sClient = vrb.getString("client","");                                  // client

      String sUserid = vrb.getString("userid","");                               // userid

      String sPassword = vrb.getString("password","");                    // password

      String sLanguage = vrb.getString("language","");                    // language

      String sHost = vrb.getString("host","");                                     // host

      String sSysnr = vrb.getString("sysnr","");                                 // system number

      String sBukrs = vrb.getString("buchungskreis","");                   // account number

      String rgID = "";

 

      // SAP-login

      jcoConnection = JCO.createClient(sClient,sUserid,sPassword,sLanguage,sHost,sSysnr);

      jcoConnection.connect();

 

      // building repository

      repository = new JCO.Repository("ASG", jcoConnection);

 

      // executing BAPI

      // Document

      JCO.Function bapiDocument =  repository.                      getFunctionTemplate("Z_BAPI_TOA02_GETDOCUMENT").getFunction();

      if (bapiDocument != null)

      {

        jcoConnection.execute(bapiDocument);

        JCO.ParameterList input = bapiDocument.getImportParameterList();

        input.setValue(sBukrs,"BUKRS");                                   // accounting area

        input.setValue(sBelnr,"BELNR");                                    // invoice number

        input.setValue(sGjahr,"GJAHR");                                   // financial year

 

        jcoConnection.execute(bapiDocument);

        JCO.ParameterList output = bapiDocument.getExportParameterList();

        if (output != null)

        {

          JCO.Structure structure = output.getStructure("DOCUMENT");

          sDocid = structure.getString("DOC_ID");

          sArchivid = structure.getString("ARCHIV_ID");

        }

      }

 

      // Appendix

      if (!sDocid.equals(""))

      {

        JCO.Function bapiAppendix = repository.                           getFunctionTemplate("Z_BAPI_TOA02_GETAPPENDIX").getFunction();

        if (bapiAppendix != null)

        {

          jcoConnection.execute(bapiAppendix);

 

          // Input Parameter

          JCO.ParameterList input = bapiAppendix.getImportParameterList();

          input.setValue(sBukrs,"BUKRS");                            // accounting area

          input.setValue(sBelnr,"BELNR");                             // invoice number

          input.setValue(sGjahr,"GJAHR");                            // financial year

 

          jcoConnection.execute(bapiAppendix);

          JCO.ParameterList output = bapiAppendix.getTableParameterList();

          JCO.Table table = output.getTable(0);

 

          if (table != null)

          {

             if (table.getNumRows() > 0)

            {

         do

               {

                  for (JCO.FieldIterator e = table.fields(); e.hasMoreElements(); )

                  {

                JCO.Field field = e.nextField();

                if (field.getName().equals("ARCHIV_ID"))

                        sAnlagearchivid = field.getString();

                      else if (field.getName().equals("DOC_ID"))

                        sAnlagedocid = field.getString();

             }

         }

              while(table.nextRow());

      }

          }

        }

      }

    }

    catch (Exception e)

    {

      e.printStackTrace();

    }

    finally

    {

      if (jcoConnection != null)

        jcoConnection.disconnect();

    }

 

    this.sDocid = sDocid;

 

    return sDocid;

  }

  // ----------------------------------------------------------------------------------

 

 

End of Content Area