Java使用JCO调用RFC函数
配置SAP集成开发环境
windows
librfc32.dll,sapjcorfc.dll 放到c:\windows\system32下面
sapjco.jar 放到当前项目的\web-inf\lib下面
linux
librfccm.so、libsapjcorfc.so放到jdk所安装的路径下的jre/lib/amd64下面
sapjco.jar 放到当前项目的WEB-INF\lib下面
代码示例
// sap连接属性
Properties logonProperties = new Properties();
logonProperties.put("jco.client.ashost", "192.168.255.256");
logonProperties.put("jco.client.client", "800");
logonProperties.put("jco.client.sysnr", "12");
logonProperties.put("jco.client.user", "username");
logonProperties.put("jco.client.passwd", "password");
logonProperties.put("jco.client.lang", "zh");
logonProperties.put("jco.client.CodePage", "8400");
JCO.Client client = JCO.createClient(logonProperties);
// 建立连接
client.connect();
// 建立repository
JCO.Repository repository = new JCO.Repository("myRepository", client);
// 获取函数模版
IFunctionTemplate functionTemplate = repository.getFunctionTemplate("Y_FUNCTION_NAME");
// 获取函数对象
JCO.Function function = functionTemplate.getFunction();
// 输入参数列表
JCO.ParameterList parameterList = function.getImportParameterList();
// 输入结构赋值
JCO.Structure oaidStructure = parameterList.getStructure("IS_OAID");
oaidStructure.setValue("12", "OAID");
oaidStructure.setValue("23", "MATNR");
// client 执行函数
client.execute(function);
// 获取输出参数列表
ParameterList exportParameterList = function.getExportParameterList();
// 根据参数名获取参数值
System.out.println("EX_TYPE : " + exportParameterList.getString("EX_TYPE"));
System.out.println("EX_MESSAGE : " + exportParameterList.getString("EX_MESSAGE"));
// 获取表
ParameterList tableParameterList = function.getTableParameterList();
Table etOaid = tableParameterList.getTable("ET_OAID");
for (int i = 0; i < etOaid.getNumRows(); i++) {
etOaid.setRow(i); // 设置游标
System.out.print("MANDT : " + etOaid.getString("MANDT"));
System.out.print(" MATNR : " + etOaid.getString("MATNR"));
System.out.print(" OAID : " + etOaid.getString("OAID"));
System.out.println(" CONFX : " + etOaid.getString("CONFX"));
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
其它
如图,RFC函数包括:
* 导入-输入参数(普通参数,结构)
* 导出-输出参数(普通参数,结构)
* 表-不区分导入导出,同一个表可作为导入表,也可作为导出表,甚至可以同时作为导入导出表