您现在的位置: 首页 > 网站导航收录 > 百科知识百科知识
abap开发(SAPJCO3 环境配置与开发)
订单,编号,参数abap开发(SAPJCO3 环境配置与开发)
发布时间:2016-12-08加入收藏来源:互联网点击:
SAPJCO3 环境配置与开发
一、环境变量设置
二、开发
三、问题
一、环境变量设置
1、SAPJCO HOME 路径配置
环境变量配置
2、添加SAPjco3.jar到path中
将jar添加到系统路径中
3、将sapjco3.dll文件放到JDK/bin目录下,该jdk需要是系统环境变量中配置的那个
二、开发1、添加jar
方式1:开发中需要将sapJCo3.jar加入到项目的build path中;
方式2:将其加入 本地 maven 库 或者 上传到maven私服nexus
mvn install:install-File -DgroupId=org.hibersap -DartifactId=sapjco3 -Dversion=3.0 -Dpackaging=jar -Dfile=E:/sapjco3/sapjco3-win32/sapjco3.jar
添加到本地maven仓库
<dependency> <groupId>org.hibersap</groupId> <artifactId>sapjco3</artifactId> <version>3.0</version></dependency>
2、账号申请
1)JCO_USER 和 JCO_PASSWD 申请;2)VPN账号申请;3)SAP对应VPN账号授权申请;
3、参数配置
DestinationDataProvider.JCO_ASHOST, "172.22.xxx.xxx");//服务器DestinationDataProvider.JCO_SYSNR, "00"); //系统编号DestinationDataProvider.JCO_CLIENT, "301"); //SAP集团DestinationDataProvider.JCO_USER, "username"); //SAP用户名 1DestinationDataProvider.JCO_PASSWD, "password"); //密码DestinationDataProvider.JCO_LANG, "zh"); //登录语言 DestinationDataProvider.JCO_POOL_CAPACITY, "0"); //最大连接数DestinationDataProvider.JCO_PEAK_LIMIT, "10"); //最大连接线程
4、创建连接
package com.zijin.sinochem.energyscp.third.sap;import com.sap.conn.jco.JCoDestination;import com.sap.conn.jco.JCoDestinationManager;import com.sap.conn.jco.JCoException;import com.sap.conn.jco.JCoFunction;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;import java.io.File;import java.io.FileOutputStream;import java.util.Properties;/** * SAP连接 */@Slf4j@Componentpublic class SapConnectionService { /** * ABAP管道名称 */ public final static String SAP_POOL = "SAP_POOL"; /** * 服务器 */ @Value("${third.sap.sapIp}") private String sapIp; /** * 系统编号 */ @Value("${third.sap.sapNumber}") private String sapNumber; /** * SAP集团 */ @Value("${third.sap.sapClient}") private String sapClient; /** * SAP用户名 */ @Value("${third.sap.sapUser}") private String sapUser; /** * 密码 */ @Value("${third.sap.sapPassword}") private String sapPassword; /** * 登录语言 */ @Value("${third.sap.sapLang}") private String sapLang; /** * 最大连接数 */ @Value("${third.sap.sapPool}") private String sapPool; /** * 最大连接线程 */ @Value("${third.sap.sapPeakLimit}") private String sapPeakLimit; @PostConstruct public void init() { // 初始化连接 this.createSapPropertiesFile(); } /** * 创建SAP接口属性文件 * 本地缓存 */ public void createSapPropertiesFile() { File cfg = new File(SAP_POOL "." "jcoDestination"); try { FileOutputStream fos = new FileOutputStream(cfg, false); Properties sapConfig = this.getSapConfig(); sapConfig.store(fos, "sap config"); fos.close(); } catch (Exception e) { throw new RuntimeException("Unable to create the destination file " cfg.getName(), e); } } /** * 组装Sap连接配置 */ private Properties getSapConfig() { Properties properties = new Properties(); properties.setProperty("jco.client.ashost", sapIp); properties.setProperty("jco.client.sysnr", sapNumber); properties.setProperty("jco.client.client", sapClient); properties.setProperty("jco.client.user", sapUser); properties.setProperty("jco.client.passwd", sapPassword); properties.setProperty("jco.client.lang", sapLang); properties.setProperty("jco.destination.pool_capacity", sapPool); properties.setProperty("jco.destination.peak_limit", sapPeakLimit); return properties; } public JCoDestination getJcoDestination() throws JCoException { return JCoDestinationManager.getDestination(SAP_POOL); } /** * 调用SAP中的function */ public void execute(JCoDestination destination, JCoFunction function) { try { function.execute(destination); } catch (JCoException e) { e.printStackTrace();// throw new BusinessException("SAP过账调用失败." e.getMessage()); } } public String getSapLang () { return this.sapLang; }}
5、接口名称等常量
package com.zijin.sinochem.energyscp.third.sap;/** * @author liangts * @date 2022/6/23 16:25 */public class SAPFunctionConst { /** * 销售订单 */ public static final String FUNC_ZPILOT01_ZJKY_SALES_ORDER = "ZPILOT01_ZJKY_SALES_ORDER"; /** * 销售入库 */ public static final String FUNC_ZPILOT01_ZJKY_DOC_POST = "ZPILOT01_ZJKY_DOC_POST"; /** * 销售出库 */ public static final String FUNC_ZPILOT01_ZJKY_DEL_CREATE = "ZPILOT01_ZJKY_DEL_CREATE"; /** * 销售开票 */ public static final String FUNC_ZPILOT01_ZJKY_VF01 = "ZPILOT01_ZJKY_VF01";}
6、接口封装调用
package com.zijin.sinochem.energyscp.third.sap;import com.sap.conn.jco.JCoDestination;import com.sap.conn.jco.JCoFunction;import com.sap.conn.jco.JCoRecord;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;/** * @author liangts * @date 2022/6/22 16:30 */@Slf4j@Componentpublic class SAPInterfaceService {// 使用 @Autowired private SapConnectionService sapConnectionService; /** * 1、销售订单 TODO * @author liangts * @date 2022/6/22 16:31 * @param * @return */ public void salesorder() throws Exception { // 获取JCO destination JCoDestination destination = sapConnectionService.getJcoDestination(); // 获取JCO调用的方法 JCoFunction function = destination.getRepository().getFunction(SAPFunctionConst.FUNC_ZPILOT01_ZJKY_SALES_ORDER); // 1、I_HEAD JCoStructure structure = function.getImportParameterList().getStructure("I_HEAD"); structure.setValue("SALES_OPTION", "I"); // (I创建、U修改) structure.setValue("SALESDOCUMENT", ""); // 销售和分销凭证号 structure.setValue("DOC_TYPE", "ZA13"); // 销售凭证类型 structure.setValue("SALES_ORG", "6C01"); // 销售组织 structure.setValue("DISTR_CHAN", "10"); // 分销渠道 structure.setValue("DIVISION", "13"); // 产品组 structure.setValue("SALES_GRP", ""); // 销售组 structure.setValue("SALES_OFF", "Z106"); // 销售办事处 structure.setValue("PARTN_NUMB", "2000258"); // 客户编号 // 2、IT_ITEM JCoTable table = function.getTableParameterList().getTable("IT_ITEM"); table.appendRow(); table.setValue("SALES_ITM_NUM", "10"); // 销售和分销凭证行项目编号 table.setValue("MATERIAL", "5000040542"); // 物料编号 table.setValue("TARGET_QTY", "10"); // 销售单位目标数量 table.setValue("TAXM1", "0"); // 物料的税分类 table.setValue("KBETR", "1000"); // 含税单价 table.setValue("REF_DOC", "348901341034"); // 客户采购订单编号 table.setValue("REF_DOC_ITEM", "1000"); // 客户采购订单行项目编号// table.setValue("MODE", "I"); // 是否新增行项目, 如果是修改销售订单为必填(U修改行,I插入行) log.info("---------------销售订单,请求参数----------------{}", function.toXML()); function.execute(destination); // 表结果取得 JCoRecord output = function.getExportParameterList(); log.info("---------------销售订单,响应参数----------------{}", output.toXML()); } /** * 2、入库 TODO * @author liangts * @date 2022/6/22 16:31 * @param * @return */ public void inStorage() throws Exception { // 获取JCO destination JCoDestination destination = sapConnectionService.getJcoDestination(); // 获取JCO调用的方法 JCoFunction function = destination.getRepository().getFunction("sap函数名"); } /** * 3、出库 TODO * @author liangts * @date 2022/6/22 16:31 * @param * @return */ public void outStorage() throws Exception { // 获取JCO destination JCoDestination destination = sapConnectionService.getJcoDestination(); // 获取JCO调用的方法 JCoFunction function = destination.getRepository().getFunction("sap函数名"); } /** * 4、开票 TODO * @author liangts * @date 2022/6/22 16:31 * @param * @return */ public void makeInvoice() throws Exception { // 获取JCO destination JCoDestination destination = sapConnectionService.getJcoDestination(); // 获取JCO调用的方法 JCoFunction function = destination.getRepository().getFunction(SAPFunctionConst.FUNC_ZPILOT01_ZJKY_VF01); // 1、输入参数设置 JCoRecord record = function.getImportParameterList(); record.setValue("I_FKDAT", "20220623"); // 开票日期 record.setValue("I_USER", "张三丰"); // 开票人 // 2、表参数设置 JCoTable table = function.getTableParameterList().getTable("ITEM"); table.appendRow(); table.setValue("VBELN", "3413413413"); // 交货单号 table.setValue("POSNR", "1000"); // 交货项目 log.info("---------------提交开票信息,请求参数----------------{}", function.toXML()); function.execute(destination); // 表结果取得 JCoRecord output = function.getExportParameterList(); log.info("---------------提交开票信息,响应参数----------------{}", output.toXML()); System.out.println(output); System.out.println(output.getString("O_STATU")); System.out.println(output.getValue("O_STATU")); }}
下一篇:返回列表
相关链接 |
||
网友回复(共有 0 条回复) |