功能:java调用ABAP接口
分析:java通过jco连接器调用ABAP结构(我采用的是SAP JCO)。
环境搭建:1:拷贝librfc32.dll到C:/WINDOWS/system32目录下。
2:拷贝sapjco.jar(sapjco.jar位于D:/Program Files/SAP/IDE/IDE70/eclipse/plugins/com.sap.mw.jco_2.0.0/lib目录下)到项目环境中。
程序代码:
import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.JCO;
import com.sap.mw.jco.JCO.Structure;
public class TutorialConnect1 {
JCO.Client mConnection;
JCO.Repository mRepository;
public TutorialConnect1() {
try {
// Change the logon information to your own system/user
mConnection = JCO.createClient("600", // SAP client
"zzwanghy", // userid
"1234qwer", // password
null, // language
"10.209.3.16", // application server host name
"00"); // system number
mConnection.connect();
//System.out.println(mConnection.getAttributes());
// 连接R/3系统代码结束
// 调用RFC接口代码如下:
JCO.Function function = this.createFunction ("BAPI_COMPANYCODE_GETLIST");
// function.getImportParameterList().setValue("C0209","CUSTOMER_NUMBER");//客户代号
// function.getImportParameterList().setValue( "1000", "SALES_ORGANIZATION");//销售组织
mConnection.execute(function); //执行函数
// Structure structure = function.getTableParameterList().getStructure(0);
JCO.Table Order = function.getTableParameterList().getTable("COMPANYCODE_LIST");//.getTable(0);//.getTable("COMP_CODE");
for(int i=0;i<Order.getNumRows();i++){
Order.setRow(i);
System.out.println(Order.getString("COMP_CODE")+" " +Order.getString("COMP_NAME"));
}
// 调用RFC接口代码结束
mConnection.disconnect();
// 断开R/3系统
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
public JCO.Function createFunction (String name) throws Exception {
// System.out.println(mConnection);
mRepository = new JCO.Repository ("SAPJCorep", mConnection);
try {
IFunctionTemplate ft =mRepository.getFunctionTemplate (name.toUpperCase ());
if (ft == null)
return null;
return ft.getFunction ();
}catch (Exception ex) {
throw new Exception ("Problem retrieving JCO.Function object.");
}
}
public static void main(String args[]) {
new TutorialConnect1();
}
}