SAP JCo業務情景:在線發票

SAP JCo業務情景:在線發票

以下示例項目描述了SAP JCo在業務場景中的用法,該業務場景使客戶可以選擇從SAP供應商系統在線檢索和顯示其發票。

客戶交貨的數據存儲在供應商SAP系統中,但實際客戶發票存儲在文檔管理系統中。在單據管理系統中,通過單據ID選擇單據,該ID與發票編號一起存儲在SAP系統中。因此,業務情景必須在SAP系統中找到客戶數據,然後連接到文檔管理系統以檢索所請求的發票。
圖1
圖1電子商務方案:使用SAP JCo在線顯示發票

在這種情況下,通常可以使用標準BAPI。但是,在這種情況下,將開發一個新對象:Z_BAPI_GET_DOCUMENT_ID。

業務對象 BAPI 描述
Z_BAPI_GET_DOCUMENT_ID GETDOCUMENT 獲取文檔ID
輸入:公司代碼
發票號碼
財政年度
輸出:文檔ID
GETAPPENDIX 獲取文檔附錄ID
輸入:公司代碼
發票號碼
財政年度
輸出:文檔附錄ID

已實現SessionBean來聯繫該對象。Bean包含方法getDocid(),該方法返回ID,如圖3所示。

圖3 SessionBean中的方法getDocid()

	/**
     * 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("companycode", ""); // 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;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章