1.下载jco,将里边的文件拷贝到lib目录,下载地址http://download.youkuaiyun.com/source/2539321
2.将里面的两个dll文件拷贝到system32
3.编写如下代码
public List<RRSInvVO> getRRSInvFromSAP(String beginPlant, String endPlant,
String year, String week) throws Exception{
// 日日顺库存
List<RRSInvVO> rrsInvs = new ArrayList<RRSInvVO>();
JCO.Client mConnection = null;
JCO.Repository mRepository = null;
try {
/**
* 测试
*/
//mConnection = JCO.createClient("客户端编号", "用户名", "密码",
// "语言", "服务器地址", "服务器编号");
mConnection.connect();
JCO.Function function = RRSInvImpl.createFunction(
"接口名", mRepository, mConnection);
//设置输入参数
JCO.ParameterList input = function.getImportParameterList();
if (beginPlant != null) {
input.setValue(beginPlant, "BEGIN_WERKS");
}
if (endPlant != null) {
input.setValue(endPlant, "END_WERKS");
}
mConnection.execute(function);
//获取输出参数
JCO.Table flights = function.getTableParameterList().getTable(0);
RRSInvVO rrsInv = null;
for (int i = 0; i < flights.getNumRows(); i++) {
flights.setRow(i);
rrsInv = new RRSInvVO();
rrsInv.setCharg(flights.getString("CHARG"));
rrsInv.setClabs(flights.getDouble("CLABS"));
rrsInv.setClabs1(flights.getDouble("CLABS1"));
rrsInv.setGmms_xgy(flights.getString("GMMS_XGY"));
rrsInv.setLgort(flights.getString("LGORT"));
rrsInv.setMaktx(flights.getString("MAKTX"));
rrsInv.setMatkl(flights.getString("MATKL"));
rrsInv.setMatnr(flights.getString("MATNR"));
rrsInv.setMenge1(flights.getDouble("MENGE1"));
rrsInv.setMenge2(flights.getDouble("MENGE2"));
rrsInv.setOmeng1(flights.getDouble("OMENG1"));
rrsInv.setOmeng2(flights.getDouble("OMENG2"));
rrsInv.setSpart(flights.getString("SPART"));
rrsInv.setVtext(flights.getString("VTEXT"));
rrsInv.setWeek(week);
rrsInv.setWerks(flights.getString("WERKS"));
rrsInv.setWgbez(flights.getString("WGBEZ"));
rrsInv.setYear(year);
rrsInvs.add(rrsInv);
}
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
throw ex;
} finally {
if (mConnection != null)
mConnection.disconnect();
}
return rrsInvs;
}