JAVA连接sap

本文介绍了一种使用Java连接SAP系统的实现方式,通过创建SAPLogon类完成SAP连接并获取JCO.Repository对象,进而利用SAPServer类监听来自SAP的消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JAVA代码: 类SAPLogon. 只是用来登录SAP,其实是为了取得SAP里的 JCO.Repository 对象。
类SAPServer. 用来监听来自SAP的消息。该类必须继承 JCO.Server,因为JCO.SERVER的监听是单独开的一个线程,而监听到有信号来的时候,JCO.SERVER会自动执行其中的protected的方法handleRequest,所以也必须重写该方法。
package javaapplication3;
import com.sap.mw.jco.*;
import com.sap.mw.jco.JCO.Function;
class SAPServer extends JCO.Server
{
public SAPServer(JCO.Repository repo)
{
super ("10.60.203.100", "sapgw01", "MYABC", repo);
}
protected void handleRequest(Function arg0) throws Exception {
JCO.ParameterList output = arg0.getExportParameterList();
output.setValue("Singel Lee", "RETURN_STR");
this.stop();

}

}
class SAPLogon
{
public JCO.Client mConnection;
public JCO.Repository mRepository;
public SAPLogon(String client, String userid, String password, String language,
String ip, String system_number)
{
try {
mConnection = JCO.createClient(client,
userid,
password,
language,
ip,
system_number);
mConnection.connect();
mRepository = new JCO.Repository("Lee", mConnection);
System.out.println("SAP连接成功");
mRepository = new JCO.Repository("my_repository", mConnection);
mConnection.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);

}

}

}
public class Main {

public static void main(String[] args) {
SAPLogon mySAP = new SAPLogon("800", "DEV0008", "*****", "E", "10.60.203.100", "01");
SAPServer myServer = new SAPServer(mySAP.mRepository);

myServer.start();
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值