import test.ConnectionPool;
import com.sap.mw.jco.*;
import com.sap.mw.jco.JCO.Client;
import com.sap.mw.jco.JCO.ParameterList;
import com.sap.mw.jco.JCO.Table;
import com.sap.mw.jco.JCO.Client;
import com.sap.mw.jco.JCO.ParameterList;
import com.sap.mw.jco.JCO.Table;
public class MyMain {
public static void main(String[] args) {
Client mConnection = null;
//创建连接池
ConnectionPool cp = new ConnectionPool();
try{
JCO.Table ret = null;
JCO.Function function = null;
JCO.ParameterList inParm = null;
//RFC函数名
String strRfcName = "zrfc_ddstutas";//rfc函数名
//使用连接池
cp.PoolConnection("mySAPPools",50, "700", "00593987", "shit","192.168.100.4", "03");
//从连接池中取出Connection
mConnection = JCO.getClient("mySAPPools");
// (
// "700", //端口号
// "00593987", //用户名
// "shit", //密码
// "EN", //语言
// "192.168.100.4", //sap服务器ip
// "03"); //系统编号
//sysConfig.getSapGroupName()); //SAP组名
//mConnection.connect();
if(mConnection!=null&& mConnection.isAlive()){
System.out.println("SAP连接成功");
// 从连接获得一个逻辑意义上的“仓库”对象(Repository)
public static void main(String[] args) {
Client mConnection = null;
//创建连接池
ConnectionPool cp = new ConnectionPool();
try{
JCO.Table ret = null;
JCO.Function function = null;
JCO.ParameterList inParm = null;
//RFC函数名
String strRfcName = "zrfc_ddstutas";//rfc函数名
//使用连接池
cp.PoolConnection("mySAPPools",50, "700", "00593987", "shit","192.168.100.4", "03");
//从连接池中取出Connection
mConnection = JCO.getClient("mySAPPools");
// (
// "700", //端口号
// "00593987", //用户名
// "shit", //密码
// "EN", //语言
// "192.168.100.4", //sap服务器ip
// "03"); //系统编号
//sysConfig.getSapGroupName()); //SAP组名
//mConnection.connect();
if(mConnection!=null&& mConnection.isAlive()){
System.out.println("SAP连接成功");
// 从连接获得一个逻辑意义上的“仓库”对象(Repository)
JCO.Repository myRepository = new JCO.Repository("hui",mConnection); // 只是一个名字
//为输入参数赋值
IFunctionTemplate ft = myRepository.getFunctionTemplate(strRfcName.toUpperCase());
//为输入参数赋值
IFunctionTemplate ft = myRepository.getFunctionTemplate(strRfcName.toUpperCase());
// 从这个函数模板获得该SAP函数的对象
function = ft.getFunction();
// function = this.createFunction(strRfcName);
inParm = function.getImportParameterList();
//inParm.clear();
inParm.setValue("8515466119", "BSTNK"); //AUFNR_B 订单号
//inParm.setValue("1997-10-11", "ERDAT_B"); //AUFNR_E 订单号
//inParm.setValue("2011-10-11", "ERDAT_E"); //AUFNR_E 订单号
//inParm.setValue("", "KUNNR"); //AUFNR_E 订单号
//赋值传入参数
function.setImportParameterList(inParm);
mConnection.execute(function);
//执行完毕读取返回信息
ParameterList pList=function.getTableParameterList();
//pList.getTable("OUTPUT");
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+pList.toXML());
ret = function.getTableParameterList().getTable("OUTPUT");
if (ret.getNumRows() > 0) {
System.out.println("查询结果>0");
for (int i = 0; i < ret.getNumRows(); i++) {
ret.setRow(i);//指定行
String strVBELN = ret.getString("VBELN");
System.out.println("strVBELN查询结果为"+strVBELN);
String strKUNNR = ret.getString("KUNNR");
System.out.println("strKUNNR查询结果为"+strKUNNR);
String strERDAT = ret.getString("ERDAT");
System.out.println("strERDAT查询结果为"+strERDAT);
String strMS = ret.getString("MS");
System.out.println("strMS查询结果为"+strMS);
String strSTUTSA1= ret.getString("STUTSA1");
System.out.println("strSTUTSA1查询结果为"+strSTUTSA1);
String strSTUTSA2= ret.getString("STUTSA2");
System.out.println("strSTUTSA2查询结果为"+strSTUTSA2);
String strSTUTSA3= ret.getString("STUTSA3");
System.out.println("strSTUTSA3查询结果为"+strSTUTSA3);
String strSTUTSA4= ret.getString("STUTSA4");
System.out.println("strSTUTSA4查询结果为"+strSTUTSA4);
String strSTUTSA5= ret.getString("STUTSA5");
System.out.println("strSTUTSA5查询结果为"+strSTUTSA5);
String strSTUTSA6= ret.getString("STUTSA6");
System.out.println("strSTUTSA6查询结果为"+strSTUTSA6);
String strSTUTSA7= ret.getString("STUTSA7");
System.out.println("strSTUTSA7查询结果为"+strSTUTSA7);
}
}
System.out.println("查询结果为"+ret.getNumRows());
// function = this.createFunction(strRfcName);
inParm = function.getImportParameterList();
//inParm.clear();
inParm.setValue("8515466119", "BSTNK"); //AUFNR_B 订单号
//inParm.setValue("1997-10-11", "ERDAT_B"); //AUFNR_E 订单号
//inParm.setValue("2011-10-11", "ERDAT_E"); //AUFNR_E 订单号
//inParm.setValue("", "KUNNR"); //AUFNR_E 订单号
//赋值传入参数
function.setImportParameterList(inParm);
mConnection.execute(function);
//执行完毕读取返回信息
ParameterList pList=function.getTableParameterList();
//pList.getTable("OUTPUT");
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+pList.toXML());
ret = function.getTableParameterList().getTable("OUTPUT");
if (ret.getNumRows() > 0) {
System.out.println("查询结果>0");
for (int i = 0; i < ret.getNumRows(); i++) {
ret.setRow(i);//指定行
String strVBELN = ret.getString("VBELN");
System.out.println("strVBELN查询结果为"+strVBELN);
String strKUNNR = ret.getString("KUNNR");
System.out.println("strKUNNR查询结果为"+strKUNNR);
String strERDAT = ret.getString("ERDAT");
System.out.println("strERDAT查询结果为"+strERDAT);
String strMS = ret.getString("MS");
System.out.println("strMS查询结果为"+strMS);
String strSTUTSA1= ret.getString("STUTSA1");
System.out.println("strSTUTSA1查询结果为"+strSTUTSA1);
String strSTUTSA2= ret.getString("STUTSA2");
System.out.println("strSTUTSA2查询结果为"+strSTUTSA2);
String strSTUTSA3= ret.getString("STUTSA3");
System.out.println("strSTUTSA3查询结果为"+strSTUTSA3);
String strSTUTSA4= ret.getString("STUTSA4");
System.out.println("strSTUTSA4查询结果为"+strSTUTSA4);
String strSTUTSA5= ret.getString("STUTSA5");
System.out.println("strSTUTSA5查询结果为"+strSTUTSA5);
String strSTUTSA6= ret.getString("STUTSA6");
System.out.println("strSTUTSA6查询结果为"+strSTUTSA6);
String strSTUTSA7= ret.getString("STUTSA7");
System.out.println("strSTUTSA7查询结果为"+strSTUTSA7);
}
}
System.out.println("查询结果为"+ret.getNumRows());
}
}catch(Exception ex) {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
ex.printStackTrace();
System.out.println("Caught an exception: \n" + ex);
}finally{
// do not forget to close the client connection
cp.RemoveClientPool("Sample_Pool");
}
}
}