java调用saprfc(java调用sap接口)

本篇文章给大家谈谈java调用saprfc,以及java调用sap接口对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

1、现在我要使用java 调用sap中的数据 怎么做?采用什么技术 小白一枚 谢谢!2、关于java 通过rfc接口获取sap中的数据,tableParams返回的是二维的数据吗,还有如何获取其中的值3、JAVA怎么才能调用SAP的函数?谢谢4、如何调用sap rfc接口读取数据

现在我要使用java 调用sap中的数据 怎么做?采用什么技术 小白一枚 谢谢!

可以直接调用RFC也可以将RFC发布为webservce,或者直接采用DB connection的方式。

建议直接采用RFC进行集成即可,你可以所搜Java如何调用SAP RFC,会有很多代码案例

关于java 通过rfc接口获取sap中的数据,tableParams返回的是二维的数据吗,还有如何获取其中的值

JCO.ParameterList tableParams = function.getTableParameterList();是指获得RFC中Tables参数列表,再用tableParams.getTable()方法可以获得JCoTable table,获得具体数据表需要利用table.firstRow()、table.nextRow();table.getString();table.getDouble()等方法遍历取得个字段的值,getFieldCount()和getNumRows()可以分别获得table的列数和行数。

java调用saprfc(java调用sap接口)

JAVA怎么才能调用SAP的函数?谢谢

给你举个例子吧,如下:

1:Sap 域模型

package abc;

public class SapSystem implements java.lang.Cloneable {

private final String name;

private final String host;

private final String client;

private final String systemNumber;

private final String user;

private final String password;

private final String language =”en”; // English will be used as login language

/**

* Constructor, Login language is assumed to be English

* @param name

* @param client

* @param user

* @param password

* @param host

* @param systemNumber

*/

public SapSystem(String name, String host, String client

, String systemNumber, String user, String password) {

this.name = name;

this.client = client;

this.user = user;

this.password = password;

this.host = host;

this.systemNumber = systemNumber;

}

public String getName() {

return name;

}

public String getClient() {

return client;

}

public String getUser() {

return user;

}

public String getPassword() {

return password;

}

public String getLanguage() {

return language;

}

public String getHost() {

return host;

}

public String getSystemNumber() {

return systemNumber;

}

@Override

public String toString() {

return “Client ” + client + ” User ” + user + ” PW ” + password

+ ” Language ” + language + ” Host ” + host + ” SysID “

+ systemNumber;

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((client == null) ? 0 : client.hashCode());

result = prime * result + ((host == null) ? 0 : host.hashCode());

result = prime * result

+ ((language == null) ? 0 : language.hashCode());

result = prime * result + ((name == null) ? 0 : name.hashCode());

result = prime * result

+ ((password == null) ? 0 : password.hashCode());

result = prime * result

+ ((systemNumber == null) ? 0 : systemNumber.hashCode());

result = prime * result + ((user == null) ? 0 : user.hashCode());

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

SapSystem other = (SapSystem) obj;

if (client == null) {

if (other.client != null)

return false;

} else if (!client.equals(other.client))

return false;

if (host == null) {

if (other.host != null)

return false;

} else if (!host.equals(other.host))

return false;

if (language == null) {

if (other.language != null)

return false;

} else if (!language.equals(other.language))

return false;

if (name == null) {

if (other.name != null)

return false;

} else if (!name.equals(other.name))

return false;

if (password == null) {

if (other.password != null)

return false;

} else if (!password.equals(other.password))

return false;

if (systemNumber == null) {

if (other.systemNumber != null)

return false;

} else if (!systemNumber.equals(other.systemNumber))

return false;

if (user == null) {

if (other.user != null)

return false;

} else if (!user.equals(other.user))

return false;

return true;

}

@Override

public Object clone() {

try {

return super.clone();

} catch (CloneNotSupportedException e) {

e.printStackTrace();

}

return null;

}

}

=====================================

2:建立连接

import java.util.Properties;

import com.sap.conn.jco.ext.DestinationDataEventListener;

import com.sap.conn.jco.ext.DestinationDataProvider;

import de.vogella.sap.system.model.SapSystem;

/**

* Represents the destination to a specific SAP system.

* The destination is maintained via a property file

*

*/

public class MyDestinationDataProvider implements DestinationDataProvider {

static String SAP_SERVER = “SAP_SERVER”;

private final Properties ABAP_AS_properties;

public MyDestinationDataProvider(SapSystem system) {

Properties properties = new Properties();

properties.setProperty(DestinationDataProvider.JCO_ASHOST, system

.getHost());

properties.setProperty(DestinationDataProvider.JCO_SYSNR, system

.getSystemNumber());

properties.setProperty(DestinationDataProvider.JCO_CLIENT, system

.getClient());

properties.setProperty(DestinationDataProvider.JCO_USER, system

.getUser());

properties.setProperty(DestinationDataProvider.JCO_PASSWD, system

.getPassword());

ABAP_AS_properties = properties;

}

@Override

public Properties getDestinationProperties(String system) {

return ABAP_AS_properties;

}

@Override

public void setDestinationDataEventListener(

DestinationDataEventListener eventListener) {

}

@Override

public boolean supportsEvents() {

return false;

}

}

==================

import com.sap.conn.jco.JCoContext;

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 com.sap.conn.jco.JCoRepository;

import de.vogella.sap.system.model.SapSystem;

/**

* Connection allows to get and execute SAP functions. The constructor expect a

* SapSystem and will save the connection data to a file. The connection will

* also be automatically be established.

*/

public class Connection {

static String SAP_SERVER = “SAP_SERVER”;

private JCoRepository repos;

private JCoDestination dest;

public Connection(SapSystem system) {

MyDestinationDataProvider myProvider = new MyDestinationDataProvider(system);

com.sap.conn.jco.ext.Environment

.registerDestinationDataProvider(myProvider);

try {

dest = JCoDestinationManager.getDestination(SAP_SERVER);

System.out.println(“Attributes:”);

System.out.println(dest.getAttributes());

repos = dest.getRepository();

} catch (JCoException e) {

throw new RuntimeException(e);

}

}

/**

* Method getFunction read a SAP Function and return it to the caller. The

* caller can then set parameters (import, export, tables) on this function

* and call later the method execute.

*

* getFunction translates the JCo checked exceptions into a non-checked

* exceptions

*/

public JCoFunction getFunction(String functionStr) {

JCoFunction function = null;

try {

function = repos.getFunction(functionStr);

} catch (Exception e) {

e.printStackTrace();

throw new RuntimeException(

“Problem retrieving JCO.Function object.”);

}

if (function == null) {

throw new RuntimeException(“Not possible to receive function. “);

}

return function;

}

/**

* Method execute will call a function. The Caller of this function has

* already set all required parameters of the function

*

*/

public void execute(JCoFunction function) {

try {

JCoContext.begin(dest);

function.execute(dest);

} catch (JCoException e) {

e.printStackTrace();

} finally {

try {

JCoContext.end(dest);

} catch (JCoException e) {

e.printStackTrace();

}

}

}

}

======================

3:测试连接

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.sap.conn.jco.JCoFunction;

import com.sap.conn.jco.JCoTable;

import de.vogella.sap.rfc.core.connection.Connection;

import de.vogella.sap.system.model.SapSystem;

public class ConnectionTester {

static String SAP = “SAP_SERVER”;

@Test

public void checkConnection() {

// SAP System

SapSystem system = new SapSystem(“PFT”, “pwdf6394.wdf.sap.corp”, “600”, “76”, “mytester”, “welcome”);

Connection connect = new Connection(system);

JCoFunction function = connect.getFunction(“BAPI_USER_GETLIST”);

function.getImportParameterList().setValue(“MAX_ROWS”, 10);

connect.execute(function);

JCoTable table = function.getTableParameterList().getTable(“USERLIST”);

assertTrue(“User Tabelle should not be empty”, !table.isEmpty());

}

}

======================

4:简化JCo存取

import com.sap.conn.jco.JCoTable;

/**

* TableAdapter is used to simplify the reading of the values of the Jco tables

*/

public class TableAdapterReader {

protected JCoTable table;

public TableAdapterReader(JCoTable table) {

this.table = table;

}

public String get(String s) {

return table.getValue(s).toString();

}

public Boolean getBoolean(String s) {

String value = table.getValue(s).toString();

return value.equals(“X”);

}

public String getMessage() {

return table.getString(“MESSAGE”);

}

public int size() {

return table.getNumRows();

}

public void next() {

table.nextRow();

}

}

5:最后测试

import static org.junit.Assert.assertNotNull;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.sap.conn.jco.JCoFunction;

import com.sap.conn.jco.JCoTable;

import de.vogella.sap.rfc.core.connection.Connection;

import de.vogella.sap.rfc.helper.TableAdapterReader;

import de.vogella.sap.system.model.SapSystem;

public class TableAdapterTester {

@Test

public void checkConnection() {

// SAP System

SapSystem system = new SapSystem(“PFT”, “pwdf6394.wdf.sap.corp”, “600”,

“76”, “mytester”, “welcome”);

Connection connect = new Connection(system);

JCoFunction function = connect.getFunction(“BAPI_USER_GETLIST”);

function.getImportParameterList().setValue(“MAX_ROWS”, 10);

connect.execute(function);

JCoTable table = function.getTableParameterList().getTable(“USERLIST”);

TableAdapterReader adapter = new TableAdapterReader(table);

System.out.println(“Number of Users: ” + adapter.size());

for (int i = 0; i adapter.size(); i++) {

// USERNAME is a column in the table “USERLIST”

String s = adapter.get(“USERNAME”);

assertNotNull(s);

assertTrue(s.length() 0);

System.out.println(s);

adapter.next();

}

assertTrue(“User Tabelle should not be empty”, !table.isEmpty());

}

}

如何调用sap rfc接口读取数据

把我调试的全过程都记录一下,以后有人遇到相同问题就可以参考了。

1.【关键前提】:

(1) 你安装了VS2003 (注意:一定要VS2003,原因在下面)

(2)安装SAP.NET Connector 2.0 (这东东目前只支持.net framework 1.X, 即IDE 7.5版本,所以只能用VS2003)

(3) 有Java runtime environment (后面导入SAP的Function时有用)

(4) 安装SAP Logon

关于java调用saprfc和java调用sap接口的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

本文来自投稿,不代表【】观点,发布者:【

本文地址: ,如若转载,请注明出处!

举报投诉邮箱:253000106@qq.com

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2024年3月30日 13:42:50
下一篇 2024年3月30日 13:46:55

相关推荐

  • 深入java虚拟机pdf,深入java虚拟机 中村成洋 pdf

    在linux环境下,java怎么实现从word格式转换为pdf格式 //设置当前使用的打印机,我的Adobe Distiller打印机名字为 Adobe PDF wordCom.setProperty( ActivePrinter , new Variant( Adobe PDF ));//设置printout的参数,将word文档打印为postscript…

    2024年5月23日
    4400
  • java截取指定长度字符串,java截取指定字符串之后的

    java中如何截取字符串中的指定一部分 第一个参数是开始截取的字符位置。(从0开始)第二个参数是结束字符的位置+1。(从0开始)indexof函数的作用是查找该字符串中的某个字的位置,并且返回。 int end);截取s中从begin开始至end结束时的字符串,并将其赋值给s;split讲解:java.lang.string.split split 方法 将…

    2024年5月23日
    4200
  • java绑定一个端口,java使用端口

    java如何多个service共用一个端口 你如果有多个项目的话,你可以把多个项目放到一个tomcat里面,这样端口相同使用项目名称来进行区分项目。你如果非要使用同一个,你也可以配置不同的域名导向不同的项目。就是访问的域名不同转接到的项目不同。 如果需要同时启动多个程序,要么修改tomcat的配置文件中的监听端口。要么修改jar包程序的监听端口。不能在一台服…

    2024年5月23日
    3400
  • java多线程并发编程基础,Java多线程并发执行返回

    电脑培训分享Java并发编程:核心理论 电脑培训发现本系列会从线程间协调的方式(wait、notify、notifyAll)、Synchronized及Volatile的本质入手,详细解释JDK为我们提供的每种并发工具和底层实现机制。 人们开始意识到了继承的众多缺点,开始努力用聚合代替继承。软件工程解决扩展性的重要原则就是抽象描述,直接使用的工具就是接口。接…

    2024年5月23日
    4600
  • 自学java找工作,自学java找工作需要包装简历吗

    自学java学多久可以找到工作 1、自学Java至少需要一年以上的时间才能达到找工作的水平。报班培训四到六个月的时间就可以找到一份不错的工作。 2、自学Java至少需要一年以上的时间才能达到找工作的水平。 3、如果要想找到一份Java相关的工作,需要至少学习5-6个月时间才能就业。Java开发需要掌握一些基础的编程语言知识,比如掌握面向对象的编程思想、基本的…

    2024年5月23日
    4300
  • java左移右移,java 左移

    java位移问题 1、思路:直接用Integer类的bit运算操作。 2、移位操作:左移:向左移位,符号后面的数字是移了多少位,移的位用0补齐,例如2进制数01111111左移一位后变为11111110,移位是字节操作。 3、Java 位运算 Java 位运算[转]一,Java 位运算表示方法: 在Java语言中,二进制数使用补码表示,最高位为符号位,正数的…

    2024年5月23日
    4200
  • java技术规范,java规范性要求

    现在主流的JAVA技术是什么? java最流行开发技术程序员必看 1 、Git Git一直是世界上最受欢迎的Java工具之一,也是Java开发人员最杰出的工具之一。Git是一个开源工具,是-种出色的分布式版本控制解决方案。 (1).Java基础语法、数组、类与对象、继承与多态、异常、范型、集合、流与文件、反射、枚举、自动装箱和注解。(2).Java面向对象编…

    2024年5月23日
    4000
  • javasocket编程,Java socket编程中,禁用nagle算法的参数

    Java进行并发多连接socket编程 1、Java可利用ServerSocket类对外部客户端提供多个socket接口。基本的做法是先创建一个ServerSocket实例,并绑定一个指定的端口,然后在这个实例上调用accept()方法等待客户端的连接请求。 2、Socket socket=server.accept(0;Thread handleThrea…

    2024年5月23日
    4600
  • java死亡,java死代码是什么意思

    我的世界传送回死亡点指令是什么? 1、下面就让我们一起来了解一下吧:我的世界回到死的地方的指令是输入/back,就可以回到死亡地点了,当然也可以看信标,因为死亡后会有一道光集中在死亡点,只要循着光就可以找到目的地了。 2、在服务器中的指令 首先打开指令台,在指令行输入“/back”就可以回到自己的死亡地点了。在单人游戏中的指令 在单人游戏中,您无法直接返回到…

    2024年5月23日
    4800
  • myeclipse能部署java工程么,myeclipse支持jdk18

    myeclipse如何建java文件 1、点击【File】—【New】–【Class】在如下界面,输入Class的名字,如Test,点击【Finish】。Test.java文件创建成功。 2、点击【File】—【New】–【Class】 在如下界面,输入Class的名字,如Test,点击【Finish】。 Te…

    2024年5月23日
    3900

发表回复

登录后才能评论



关注微信