SAP移库接口实现(Java版)

 SAP移库接口Java代码实现:

移库接口:
public static Map<String, Object> storageMoveToSap(StorageTransfer storageTransfer) throws Throwable{
	SapBapiInvoker sap  =  new SapBapiInvoker();
	JCoDestination destination  =  sap.connectSAPserver(propPath);
	JCoFunction function  =  null;
	JCoTable returntable  =  null;
	Map<String, Object> subMap  =  new HashMap<String, Object>();
	boolean sapSuccessFlag=false;
	 try{
		    JCoContext.begin(destination);  
		   
		    JCoRepository res=destination.getRepository();
			function  =  res.getFunction("BAPI_GOODSMVT_CREATE");
			if(function  ==  null){
				throw new RuntimeException("BAPI_GOODSMVT_CREATE not found in SAP.");
			}
			JCoStructure goodsmvt_header  =  function.getImportParameterList().getStructure("GOODSMVT_HEADER");
			JCoStructure goodsmvt_code  =  function.getImportParameterList().getStructure("GOODSMVT_CODE");
			String year = TimeUtil.getCurrentDate("");
			goodsmvt_header.setValue("PSTNG_DATE",year);//记账日期
			goodsmvt_header.setValue("DOC_DATE",year);//凭证日期
			goodsmvt_header.setValue("PR_UNAME",getSAPConnUser());//连接用户
			goodsmvt_code.setValue("GM_CODE", "04");// BAPI 货物移动分配事务代码
			String outWerks = storageTransfer.getOutplantErpCode();
			String outLgort = storageTransfer.getOutLgortErpCode();
			String inWerks = outWerks;// 同一工厂
			String inLgort = storageTransfer.getInLgortErpCode();
			JCoTable goodsmvt_item = function.getTableParameterList().getTable("GOODSMVT_ITEM");
			goodsmvt_item.appendRow();
			String matnr  = AutoGenericCodeUtil.autoGenericCode(storageTransfer.getOutMatnr(), 18);
			goodsmvt_item.setValue("MATERIAL",matnr);//物料号  18位
			goodsmvt_item.setValue("PLANT",outWerks);
			goodsmvt_item.setValue("STGE_LOC",outLgort);
			goodsmvt_item.setValue("MOVE_TYPE","311");//同一个工厂下不同库存地移库   固定写死311
			goodsmvt_item.setValue("ENTRY_QNT",storageTransfer.getInMatnrQty());//入库数量
			goodsmvt_item.setValue("MOVE_PLANT",inWerks);
			goodsmvt_item.setValue("MOVE_STLOC",inLgort);
			function.execute(destination);
			JCoStructure export = function.getExportParameterList().getStructure("GOODSMVT_HEADRET");
			String MAT_DOC = export.getValue("MAT_DOC").toString();
			returntable = function.getTableParameterList().getTable("RETURN");
			if(StringUtils.isNotBlank(MAT_DOC)&&returntable.isEmpty()){
				function=res.getFunction("BAPI_TRANSACTION_COMMIT");//提交
				function.execute(destination);  
				subMap.put("MAT_DOC", MAT_DOC);
				sapSuccessFlag=true;
			}else{
				for(int i = 0; i<returntable.getNumRows(); i++){
					subMap  =  new HashMap<String, Object>();
					for(int j = 0; j<returntable.getMetaData().getFieldCount(); j++){
						subMap.put(returntable.getMetaData().getName(j).toLowerCase(), returntable.getString(j));
					}
					returntable.nextRow();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} catch (Throwable e) {
			e.printStackTrace();
		}finally {
			JCoContext.end(destination);  
			returntable  =  null;
			function  =  null;
			destination  =  null;
			sap  =  null;
		}
	subMap.put("sapSuccessFlag", sapSuccessFlag);
	return subMap;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Favor_Yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值