1. 程式人生 > >java調SAP RFC介面

java調SAP RFC介面

程式碼如下:

package com.hk;
import com.sap.mw.jco.*;

public class TestSap {
    public static void main(String[] args) {

        JCO.Client client = null;
        //此處引數請略
        client = JCO.createClient("200", "", "", "ZH", "", "00");

        client.connect();
        IRepository repository=null;
        repository = JCO.createRepository
("MYRepository", client); IFunctionTemplate ftemplate = repository.getFunctionTemplate("Z_FI_DOCUMENT_POST"); JCO.Function function = new JCO.Function(ftemplate); JCO.Table bkpf = function.getTableParameterList().getTable("Z_BKPF"); JCO.Table bseg = function.getTableParameterList
().getTable("Z_BSEG"); bkpf.appendRow(); bkpf.setValue("C20161101000001","ZACCUID"); bkpf.setValue("N","ZSTATE"); bkpf.setValue("1000","BUKRS"); bkpf.setValue("20161104","BLDAT"); bkpf.setValue("20161104","BUDAT"); bkpf.setValue("2016","GJAHR"); bkpf.setValue
("11","MONAT"); bkpf.setValue("C1","BLART"); bkpf.setValue("CNY","WAERS"); //bkpf.setValue("1200000000","XBLNR"); bkpf.setValue("提取現金10000元_wangke","BKTXT"); bkpf.setValue("0L","LDGRP"); //bkpf.setValue("0","KURSF"); bseg.appendRow(); bseg.setValue("C20161101000001","ZACCUID"); bseg.setValue("N","ZSTATE"); bseg.setValue("1000","BUKRS"); bseg.setValue("2016","GJAHR"); bseg.setValue("001","BUZEI"); bseg.setValue("40","BSCHL"); bseg.setValue("0012219900","HKONT"); // bseg.setValue("","KUNNR"); // bseg.setValue("","LIFNR"); // bseg.setValue("","UMSKZ"); bseg.setValue("10000","WRBTR"); // bseg.setValue("0.00","DMBTR"); // bseg.setValue("0.00","DMBE2"); // bseg.setValue("","GSBER"); // bseg.setValue("","PRCTR"); // bseg.setValue("","KOSTL"); // bseg.setValue("","AUFNR"); // bseg.setValue("","XREF1"); // bseg.setValue("","XREF2"); // bseg.setValue("","XREF3"); // bseg.setValue("","HKBID"); // bseg.setValue("101","RSTGR"); // bseg.setValue("","ZUONR"); // bseg.setValue("","SGTXT"); // bseg.setValue("","NEWBK"); // bseg.setValue("","XNEGP"); // bseg.setValue("","LGTXT"); //bseg.setValue("","ZZ0001"); //bseg.setValue("","ZZ0002"); //bseg.setValue("","ZZ0003"); // bseg.setValue("","BELNR"); // bseg.setValue("","CPUDT"); // bseg.setValue("","CPUTM"); System.out.println("hello world"); bseg.appendRow(); bseg.setValue("C20161101000001","ZACCUID"); bseg.setValue("N","ZSTATE"); bseg.setValue("1000","BUKRS"); bseg.setValue("2016","GJAHR"); bseg.setValue("001","BUZEI"); bseg.setValue("50","BSCHL"); bseg.setValue("0012219900","HKONT"); // bseg.setValue("","KUNNR"); // bseg.setValue("","LIFNR"); // bseg.setValue("","UMSKZ"); bseg.setValue("10000","WRBTR"); // bseg.setValue("","DMBTR"); // bseg.setValue("","DMBE2"); // bseg.setValue("","GSBER"); // bseg.setValue("","PRCTR"); // bseg.setValue("","KOSTL"); // bseg.setValue("","AUFNR"); // bseg.setValue("","XREF1"); // bseg.setValue("","XREF2"); // bseg.setValue("","XREF3"); // bseg.setValue("","HKBID"); // bseg.setValue("111","RSTGR"); // bseg.setValue("","ZUONR"); // bseg.setValue("","SGTXT"); // bseg.setValue("","NEWBK"); // bseg.setValue("","XNEGP"); // bseg.setValue("","LGTXT"); //bseg.setValue("","ZZ0001"); //bseg.setValue("","ZZ0002"); //bseg.setValue("","ZZ0003"); // bseg.setValue("","BELNR"); // bseg.setValue("","CPUDT"); // bseg.setValue("","CPUTM"); client.execute(function); JCO.Table log = function.getTableParameterList().getTable("ZFIDETAIL_LOG"); for (int i = 0; i < log.getNumRows(); i++) { log.setRow(i); System.out.print("belnr-->"+log.getValue("BELNR")); System.out.println(",message-->"+log.getValue("MESSAGE")); } System.out.println("finished"); } }