2.3.3 - 通过Java语言进行BAPI调用
2.3.3 - 通过Java语言进行BAPI调用
// 载入所需的类库:
import com.sap.rfc.*;
import com.sap.rfc.exception.*;
import com.ibm.sap.bapi.*;
import com.ibm.sap.bapi.generated.*;
// 连接SAP系统
static private IRfcConnection establishConnection(MiddlewareInfo aMiddlewareInfo)
throws JRfcRemoteException
{
IRfcConnection aConnection = null ;
ConnectInfo aConnectInfo = null ;
UserInfo aUserInfo = null ;
String orbServerName = aMiddlewareInfo.getOrbServerName() ;
boolean bAdjusted = true;
if (!bAdjusted)
{
throw (new JRfcRfcConnectionException (
"Please adjust the Connection-Parameters to your needs!"));
}
//连接信息:调整为所需要输入的值
aConnectInfo = new ConnectInfo (
3,// int Rfc模式 3=R/3 or 2=R/2
null,// String RFC目标
"9.7.12.7",// String 主机名(IP地址)
0,// int 系统编号
null,// String 网关主机
null,// String 网关服务
null,// String 系统名
null,// String 服务器组名
null,// String 消息服务器
false,// Boolean 负载平衡选项
true);// Boolean 权限检查选项
// 用户信息
aUserInfo = new UserInfo (
"MUSTER",// String 用户名
"IDES",// String 密码
"800",// String 集团
"e",// String 登录语言
1103);// int 代码页
// Technical conversion for the selected middleware;
// 打开连接Open connection:
IRfcConnectionFactory aConnectionFactory =
FactoryManager.getSingleInstance().getRfcConnectionFactory() ;
aConnection = aConnectionFactory.createRfcConnection(aConnectInfo, aUserInfo) ;
aConnection.open() ;
// 返回连接
return aConnection ;
}
// 调用main方法
public static void main (java.lang.String[] args)
//通过所指定的中间件设定连接选项
{
MiddlewareInfo aMiddlewareInfo = new MiddlewareInfo(args) ;
FactoryManager aFactoryManager = FactoryManager.getSingleInstance() ;
aFactoryManager.setMiddlewareInfo(aMiddlewareInfo) ;
//初始化连接连接对象
IRfcConnection aConnection = null ;
try
{
aConnection = establishConnection(aMiddlewareInfo) ;
}
catch (Exception ex)
{
System.out.println("ERROR : Could not create connection : " + ex) ;
System.exit(-1) ;
}
System.out.println("Conn