发送数据给sap和接收

放肆的年华 提交于 2019-12-21 11:05:38

1.确保已经连通sap

2.发送数据:这是以表的形式发送,而且是批量发送给sap

3.接收sap返回信息:这个比较特别,碰到时试一试

package com.yiyezhiqiu.lyh.utils;import com.alibaba.fastjson.JSON;import com.sap.conn.jco.*;import com.yiyezhiqiu.lyh.domain.Job;import com.yiyezhiqiu.lyh.service.IWorkTimeService;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Autowired;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;@Slf4jpublic class TestSap {    @Autowired    IWorkTimeService workTimeService;  public  Map  contextLoads(List<Job> jobList) {       String  xmlStr = "";      Map<String ,Object> maps = null;        for(Job list:jobList){            System.out.println("joblist"+list.getID()+"一叶知秋"+jobList.size()+list.getLSTAR());        }      JCoDestination destination = null;        try{            SapConnection connection = new SapConnection();          destination =   connection.connection();        }catch(Exception e){            return maps;        }       log.info("JCoDestination: "+destination);        try {            if (destination != null) {                JCoFunction function;                try{                    function = destination.getRepository().getFunction("ZFMMM_READ_ZPP012");                }catch(Exception e){                    return maps;                }                //    function.getImportParameterList().setValue("I_DATA", jobList);                for(Job list:jobList){                    JCoTable table = function.getTableParameterList().getTable("I_DATA");                    table.appendRow();                    table.setValue("ID",list.getID());                    table.setValue("ARWKS",list.getARWKS());                    table.setValue("VGE01",list.getVGE01());                    table.setValue("TELPO",list.getTELPO());                    table.setValue("PTYPE",list.getPTYPE());                    table.setValue("BUDAT",list.getBUDAT());                    table.setValue("CARDNAME",list.getCARDNAME());                    table.setValue("CARDNO",list.getCARDNO());                    table.setValue("ARBPL",list.getARBPL());                    table.setValue("WRTNR",list.getWRTNR());                    table.setValue("ZZPROJE",list.getZZPROJE());                    table.setValue("WORKP",list.getWORKP());                    table.setValue("AUFNR",list.getAUFNR());                    table.setValue("JOBTYPENAME",list.getJOBTYPENAME());                    table.setValue("JOBTYPE",list.getJOBTYPE());                    table.setValue("LIFNR",list.getLIFNR());                    table.setValue("LINEDNAME",list.getLINEDNAME());                    table.setValue("LINED",list.getLINED());                    table.setValue("ISDDZ",list.getISDDZ());                    table.setValue("IEDDZ",list.getIEDDZ());                    table.setValue("BGTYP",list.getBGTYP());                    table.setValue("VGWRT",list.getVGWRT());                    table.setValue("LSTAR",list.getLSTAR());                    table.setValue("SJPNO",list.getSJPNO());                    table.setValue("USNAM",list.getUSNAM());                    table.setValue("CPUDT",list.getCPUDT());                    table.setValue("AEDAT",list.getAEDAT());                    table.setValue("FLAG",list.getFLAG());                    table.setValue("TEXT",list.getTEXT());                    table.setValue("ZDEL",list.getZDEL());                    table.setValue("CPUDT1",list.getCPUDT1());                    table.setValue("CPUTM1",list.getCPUTM1());                    table.setValue("APUDT1",list.getAPUDT1());                    table.setValue("APUTM1",list.getAPUTM1());                    table.setValue("PHASE",list.getPHASE());                    table.setValue("BATCH",list.getBATCH());                    table.setValue("RUECK",list.getRUECK());                    table.setValue("RMZHL",list.getRMZHL());                    table.setValue("BLART",list.getBLART());                    table.setValue("DSNAM",list.getDSNAM());                    table.setValue("DEDAT",list.getDEDAT());                    table.setValue("BELNR",list.getBELNR());                    table.setValue("F01",list.getF01());                    table.setValue("F02",list.getF02());                    table.setValue("F03",list.getF03());                    table.setValue("F04",list.getF04());                    table.setValue("F05",list.getF05());                    table.setValue("F06",list.getF06());                    table.setValue("F07",list.getF07());                    table.setValue("F08",list.getF08());                }                function.execute(destination);          //      JCoParameterList tablePort =   function.getTableParameterList();                //info = tablePort.toXML();               // System.out.println("info:"+info);               // XmlParse xmlParse = new XmlParse();               //xmlStr =    xmlParse.getXmlAttribute(info);                JCoStructure r1 =   function.getExportParameterList().getStructure("GS_RET2");                String type = "";                String message = "";                type = r1.getString("TYPE");                message = r1.getString("MESSAGE");                maps = new HashMap<>();                maps.put("type",type);                maps.put("message",message);             return maps;            }        }catch (JCoException e){            e.printStackTrace();        }    return maps;    }}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!