public class SapFunction { //JCo 返回参数类型定义 public static final Integer Type_String = 1; public static final Integer Type_Int = 2; public static final Integer Type_Long = 3; public static final Integer Type_Double = 4; public static final Integer Type_Date = 5; public static final Integer Type_Float = 6; /** * @Description: 返回值为List,有入参的情况 * @param functionName 调用的SAP方法名称 * @param paramMap SAP方法所需要的参数MAP,KEY=传入参数名称,VALUE=传入参数值; * @param keyTypeMap SAP方法返回的参数类型,KEY=返回参数名称,VALUE=返回参数类型; * @return List<?> SAP方法返回的List,?为指定类型; * @throws */ public static List<?> getList(String functionName,String tableName, Map<String,Integer> keyTypeMap, Class<?> beanClazz){ JCoDestination jCoDestination = null; JCoFunction function = null; List<Object> list = null; try { jCoDestination = SapFactory.getConnection(); function = jCoDestination.getRepository().getFunction(functionName); function.execute(jCoDestination); JCoTable tb = function.getTableParameterList().getTable(tableName); for (int i = 0; i < tb.getNumRows(); i++) { tb.setRow(i); Map<String,Object> map = new HashMap<String,Object>(); for (Map.Entry<String, Integer> entry : keyTypeMap.entrySet()) { switch(entry.getValue().intValue()){ case 1: map.put(entry.getKey(), tb.getString(entry.getKey())); break; case 2: map.put(entry.getKey(), tb.getInt(entry.getKey())); break; case 3: map.put(entry.getKey(), tb.getLong(entry.getKey())); break; case 4: map.put(entry.getKey(), tb.getDouble(entry.getKey())); break; case 5: map.put(entry.getKey(), tb.getDate(entry.getKey())); break; case 6: map.put(entry.getKey(), tb.getFloat(entry.getKey())); break; } } if(list == null){ list = new ArrayList<Object>(); } Object obj = CommonUtils.getBean(map, beanClazz); list.add(obj); } } catch (Exception e) { e.printStackTrace(); } return list; } /** * @Description: 返回值为List,有入参的情况 * @param functionName 调用的SAP方法名称 * @param paramMap SAP方法所需要的参数MAP,KEY=传入参数名称,VALUE=传入参数值; * @param keyTypeMap SAP方法返回的参数类型,KEY=返回参数名称,VALUE=返回参数类型; * @return List<?> SAP方法返回的List,?为指定类型; * @throws */ public static List<?> getList(String functionName, Map<String,Object> paramMap,String tableName, Map<String,Integer> keyTypeMap, Class<?> beanClazz){ JCoDestination jCoDestination = null; JCoFunction function = null; List<Object> list = null; try { jCoDestination = SapFactory.getConnection(); function = jCoDestination.getRepository().getFunction(functionName); JCoParameterList parameterList = function.getImportParameterList(); for (Map.Entry<String, Object> entry : paramMap.entrySet()) { parameterList.setValue(entry.getKey(), entry.getValue()); } function.execute(jCoDestination); JCoTable tb = function.getTableParameterList().getTable(tableName); for (int i = 0; i < tb.getNumRows(); i++) { tb.setRow(i); Map<String,Object> map = new HashMap<String,Object>(); for (Map.Entry<String, Integer> entry : keyTypeMap.entrySet()) { switch(entry.getValue().intValue()){ case 1: map.put(entry.getKey(), tb.getString(entry.getKey())); break; case 2: map.put(entry.getKey(), tb.getInt(entry.getKey())); break; case 3: map.put(entry.getKey(), tb.getLong(entry.getKey())); break; case 4: map.put(entry.getKey(), tb.getDouble(entry.getKey())); break; case 5: map.put(entry.getKey(), tb.getDate(entry.getKey())); break; case 6: map.put(entry.getKey(), tb.getFloat(entry.getKey())); break; } } if(list == null){ list = new ArrayList<Object>(); } Object obj = CommonUtils.getBean(map, beanClazz); list.add(obj); } } catch (Exception e) { e.printStackTrace(); } return list; } /** * @Description: 返回值为List,有入参的情况 * @param functionName 调用的SAP方法名称 * @param paramMap SAP方法所需要的参数MAP,KEY=传入参数名称,VALUE=传入参数值; * @param keyTypeMap SAP方法返回的参数类型,KEY=返回参数名称,VALUE=返回参数类型; * @return Map<String,Object> SAP方法返回的参数值,KEY=返回参数名称,VALUE=返回参数值; * @throws */ public static List<Map<String,Object>> getList(String functionName, Map<String,Object> paramMap,String tableName, Map<String,Integer> keyTypeMap){ JCoDestination jCoDestination = null; JCoFunction function = null; List<Map<String,Object>> list = null; try { jCoDestination = SapFactory.getConnection(); function = jCoDestination.getRepository().getFunction(functionName); JCoParameterList parameterList = function.getImportParameterList(); for (Map.Entry<String, Object> entry : paramMap.entrySet()) { parameterList.setValue(entry.getKey(), entry.getValue()); } function.execute(jCoDestination); JCoTable tb = function.getTableParameterList().getTable(tableName); for (int i = 0; i < tb.getNumRows(); i++) { tb.setRow(i); Map<String,Object> map = new HashMap<String,Object>(); for (Map.Entry<String, Integer> entry : keyTypeMap.entrySet()) { switch(entry.getValue().intValue()){ case 1: map.put(entry.getKey(), tb.getString(entry.getKey())); break; case 2: map.put(entry.getKey(), tb.getInt(entry.getKey())); break; case 3: map.put(entry.getKey(), tb.getLong(entry.getKey())); break; case 4: map.put(entry.getKey(), tb.getDouble(entry.getKey())); break; case 5: map.put(entry.getKey(), tb.getDate(entry.getKey())); break; case 6: map.put(entry.getKey(), tb.getFloat(entry.getKey())); break; } } if(list == null){ list = new ArrayList<Map<String,Object>>(); } list.add(map); } } catch (Exception e) { e.printStackTrace(); } return list; } /** * @Description: 返回值为List,没有入参的情况 * @param functionName 调用的SAP方法名称 * @param keyTypeMap SAP方法返回的参数类型,KEY=返回参数名称,VALUE=返回参数类型; * @return Map<String,Object> SAP方法返回的参数值,KEY=返回参数名称,VALUE=返回参数值; * @throws */ public static List<Map<String,Object>> getList(String functionName,String tableName, Map<String,Integer> keyTypeMap){ JCoDestination jCoDestination = null; JCoFunction function = null; List<Map<String,Object>> list = null; try { jCoDestination = SapFactory.getConnection(); function = jCoDestination.getRepository().getFunction(functionName); function.execute(jCoDestination); JCoTable tb = function.getTableParameterList().getTable(tableName); for (int i = 0; i < tb.getNumRows(); i++) { tb.setRow(i); Map<String,Object> map = new HashMap<String,Object>(); for (Map.Entry<String, Integer> entry : keyTypeMap.entrySet()) { switch(entry.getValue().intValue()){ case 1: map.put(entry.getKey(), tb.getString(entry.getKey())); break; case 2: map.put(entry.getKey(), tb.getInt(entry.getKey())); break; case 3: map.put(entry.getKey(), tb.getLong(entry.getKey())); break; case 4: map.put(entry.getKey(), tb.getDouble(entry.getKey())); break; case 5: map.put(entry.getKey(), tb.getDate(entry.getKey())); break; case 6: map.put(entry.getKey(), tb.getFloat(entry.getKey())); break; } } if(list == null){ list = new ArrayList<Map<String,Object>>(); } list.add(map); } } catch (Exception e) { e.printStackTrace(); } return list; } /** * @Description: 返回值为MAP,但有入参的情况 * @param functionName 调用的SAP方法名称 * @param paramMap SAP方法所需要的参数MAP,KEY=传入参数名称,VALUE=传入参数值; * @param keyTypeMap SAP方法返回的参数类型,KEY=返回参数名称,VALUE=返回参数类型; * @return Map<String,Object> SAP方法返回的参数值,KEY=返回参数名称,VALUE=返回参数值; * @throws */ public static Map<String,Object> getMap(String functionName, Map<String,Object> paramMap, Map<String,Integer> keyTypeMap){ JCoDestination jCoDestination = null; JCoFunction function = null; Map<String,Object> map = null; try { jCoDestination = SapFactory.getConnection(); function = jCoDestination.getRepository().getFunction(functionName); JCoParameterList parameterList = function.getImportParameterList(); for (Map.Entry<String, Object> entry : paramMap.entrySet()) { parameterList.setValue(entry.getKey(), entry.getValue()); } function.execute(jCoDestination); JCoParameterList resultList = function.getExportParameterList(); for (Map.Entry<String, Integer> entry : keyTypeMap.entrySet()) { if(map == null){ map = new HashMap<String,Object>(); } switch(entry.getValue().intValue()){ case 1: map.put(entry.getKey(), resultList.getString(entry.getKey())); break; case 2: map.put(entry.getKey(), resultList.getInt(entry.getKey())); break; case 3: map.put(entry.getKey(), resultList.getLong(entry.getKey())); break; case 4: map.put(entry.getKey(), resultList.getDouble(entry.getKey())); break; case 5: map.put(entry.getKey(), resultList.getDate(entry.getKey())); break; case 6: map.put(entry.getKey(), resultList.getFloat(entry.getKey())); break; } } } catch (Exception e) { e.printStackTrace(); } return map; } /** * @Description: 返回值为MAP,但没有入参的情况 * @param functionName 调用的SAP方法名称 * @param keyTypeMap SAP方法返回的参数类型,KEY=返回参数名称,VALUE=返回参数类型; * @return Map<String,Object> SAP方法返回的参数值,KEY=返回参数名称,VALUE=返回参数值; * @throws */ public static Map<String,Object> getMap(String functionName, Map<String,Integer> keyTypeMap){ JCoDestination jCoDestination = null; JCoFunction function = null; Map<String,Object> map = null; try { jCoDestination = SapFactory.getConnection(); function = jCoDestination.getRepository().getFunction(functionName); function.execute(jCoDestination); JCoParameterList resultList = function.getExportParameterList(); for (Map.Entry<String, Integer> entry : keyTypeMap.entrySet()) { if(map == null){ map = new HashMap<String,Object>(); } switch(entry.getValue().intValue()){ case 1: map.put(entry.getKey(), resultList.getString(entry.getKey())); break; case 2: map.put(entry.getKey(), resultList.getInt(entry.getKey())); break; case 3: map.put(entry.getKey(), resultList.getLong(entry.getKey())); break; case 4: map.put(entry.getKey(), resultList.getDouble(entry.getKey())); break; case 5: map.put(entry.getKey(), resultList.getDate(entry.getKey())); break; case 6: map.put(entry.getKey(), resultList.getFloat(entry.getKey())); break; } } } catch (Exception e) { e.printStackTrace(); } return map; } /** * @Description: 返回值为String,但没有入参的情况 * @param functionName 调用的SAP方法名称 * @param paramMap SAP方法所需要的参数MAP,KEY=传入参数名称,VALUE=传入参数值; * @param valueKey SAP方法返回的参数名称; * @return String SAP方法返回的参数值; * @throws */ public static String getString(String functionName, Map<String,Object> paramMap, String valueKey){ JCoDestination jCoDestination = null; JCoFunction function = null; try { jCoDestination = SapFactory.getConnection(); function = jCoDestination.getRepository().getFunction(functionName); JCoParameterList parameterList = function.getImportParameterList(); for (Map.Entry<String, Object> entry : paramMap.entrySet()) { parameterList.setValue(entry.getKey(), entry.getValue()); } function.execute(jCoDestination); JCoParameterList resultList = function.getExportParameterList(); return resultList.getString(valueKey); } catch (Exception e) { e.printStackTrace(); } return null; } /** * @Description: 返回值为String,但没有入参的情况 * @param functionName 调用的SAP方法名称 * @param valueKey SAP方法返回的参数名称; * @return String SAP方法返回的参数值; * @throws */ public static String getString(String functionName, String valueKey){ JCoDestination jCoDestination = null; JCoFunction function = null; try { jCoDestination = SapFactory.getConnection(); function = jCoDestination.getRepository().getFunction(functionName); function.execute(jCoDestination); JCoParameterList resultList = function.getExportParameterList(); return resultList.getString(valueKey); } catch (Exception e) { e.printStackTrace(); } return null; } }
public class SapFactory { private static SapFactory instance = null; private static String abap_as_pooled = "ABAP_AS_WITH_POOL"; private SapFactory(){ } public static JCoDestination getConnection(){ if(instance == null){ instance = new SapFactory(); instance.init(); } return instance.connection(); } private void init(){ Properties connectProperties = new Properties(); abap_as_pooled = AppContext.getSystemProperty("formFlowListener.abap_as_pooled"); connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, AppContext.getSystemProperty("formFlowListener.jco_ashost")); //连接IP connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, AppContext.getSystemProperty("formFlowListener.jco_sysnr")); //系统编号 connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, AppContext.getSystemProperty("formFlowListener.jco_client")); //SAP集团 connectProperties.setProperty(DestinationDataProvider.JCO_USER, AppContext.getSystemProperty("formFlowListener.jco_user")); //SAP用户名 connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, AppContext.getSystemProperty("formFlowListener.jco_passwd")); //密码 connectProperties.setProperty(DestinationDataProvider.JCO_LANG, AppContext.getSystemProperty("formFlowListener.jco_lang")); //登录语言 connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, AppContext.getSystemProperty("formFlowListener.jco_pool_capacity")); //最大连接数 connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, AppContext.getSystemProperty("formFlowListener.jco_peak_limit")); //最大连接线程 createDataFile(abap_as_pooled, "jcoDestination", connectProperties); } private void createDataFile(String name, String suffix, Properties properties){ File cfg = new File(name+"."+suffix); if(cfg.exists()){ cfg.deleteOnExit(); } try{ FileOutputStream fos = new FileOutputStream(cfg, false); properties.store(fos, "for tests only !"); fos.close(); }catch (Exception e){ e.printStackTrace(); throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e); } } private JCoDestination connection(){ JCoDestination destination =null; try { destination = JCoDestinationManager.getDestination(abap_as_pooled); } catch (JCoException e) { e.printStackTrace(); } return destination; } }
需要引入的 jar与dll文件
相关推荐
Java 调用 SAP RFC 案例,附博客地址,SAP RFC开发一步一步 http://blog.csdn.net/iberr/article/details/40895453
非常实用的例子,一看就会,最近使用java连接RFC,把这个例子保存,以后方便查看。
包括示例代码,代码说明,所需要的资源(sapjco.jar)文件。
Java 使用JCO远程调用SAP RFC java 连接示例 JCO Linux 下安装详细步骤配置 JCO windows下安装详细步骤及配置 JCO linux windwos 所用到地包文件
SAP ABAP与JAVA之间通过RFC传递数据实例
SAP NetWeaver RFC SDK 英文手册
sapjco.jar JAVA连接SAP-RFC接口的开发包, 欢迎有做SAP开发、JAVA、.net等数据库开发的朋友联系交流,TKS
Java掉sap RFC
java调用sap通用工具类,支持window和linux; 使用步骤: 1。拷贝jar和 dll或者 so文件到项目的lib目录下 2.。初始化DefaultSAPService 3。调用方式为 defaultSAPService.execute("funcitionName", req, Resp.class)...
“Sap RFC联调测试工具”是用于第三方平台连接SAP RFC进行预先测试,在第三方平台未开发好程序,而进行预先联调测试已经开发好的RFC接口。也可以用来ABAP开发者在开发好RFC并且用SAP的SE37测试无误之后,进行第三方...
使用Springboot + mybatis + thymleaf + quartz 2 + shiro + sapjco 建立系统完成与SAP系统的RFC交互
SAP金税接口RFC函数样例,在开票软件通过调用RFC函数,直接获取开票数据,实际开票后自动调用回写函数,将金税发票号码回写到SAP.
SAP RFC基础知识SAP RFC基础知识SAP RFC基础知识SAP RFC基础知识
SAP.Connector.dll 与 SAP.Connector.Rfc.dll两个dll文件,欢迎下载
.netcore项目sap的rfc调用所需的sap组件。.netcore调用rfc需要使用SapNwRfc,开发环境需要SAP NetWeaver RFC Library 7.50 SDK引用。SapNwRfc使用请参考:https://github.com/huysentruitw/SapNwRfc
SAP BAPI和RFC接口技术的详细介绍,有需要的dowm
1、.NET CORE项目SAP的RFC调用所需的SAP组件。 .2、NET CORE调用RFC需要使用SapNwRfc,开发环境需要SAP NetWeaver RFC Library 7.50 SDK引用。 2.1、SapNwRfc使用请参考:https://github.com/huysentruitw/SapNwRfc ...
java连接sap RFC函数 所需文件 包含sapjco3.jar sapjco.jar sapjco3.dll
C#创建WEB SERVICE调用SAP RFC