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;
@Slf4j
public class TestSap {
@Autowired
IWorkTimeService workTimeService;
public Map contextLoads(List
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\_XXXXX");
}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\_XXXX");
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;
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章