JAVA通过JCO连接SAP例子

 

 环境的搭建,把附件中的所有DLL放入 C://windows/system32下,如果你电脑装过SAP,那可能会有重复,直接忽略即可。将sapjco.jar 放入项目环境中

package test1;

import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.JCO;

public class TTT1 {

	public static void main(String[] args) {
		SAPLogon mySAP = new SAPLogon("300", "gaojunyi", "gaojunyi", "zh",
				"172.16.2.11", "00");
		SAPServer myServer = new SAPServer(mySAP.mRepository);
		myServer.start();
	}
}

class SAPServer extends JCO.Server {
	public SAPServer(JCO.Repository repo) {
		super("10.10.10.50", "sapgw00", "ABC", repo);
	}
}

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连接成功");
			
			// 调用RFC函数
			IFunctionTemplate ft = mRepository
					.getFunctionTemplate("BAPI_MATERIAL_GET_DETAIL");
			JCO.Function f = ft.getFunction();

			// 1.传入参数为Field
			f.getImportParameterList().setValue("000000000010000008", "MATERIAL");
			f.getImportParameterList().setValue("2000", "PLANT");
			mConnection.execute(f);

			// 1.返回参数为Field
			JCO.Structure struct = f.getExportParameterList().getStructure(
					"MATERIAL_GENERAL_DATA");
			String name = struct.getString("MATL_DESC");
			System.out.println("物料名:" + name);
			String MATL_TYPE = struct.getString("MATL_TYPE");
			System.out.println("物料类型:" + MATL_TYPE);

			mRepository = new JCO.Repository("my_repository", mConnection);
			mConnection.disconnect();

		} catch (Exception ex) {
			ex.printStackTrace();
			System.exit(1);

		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值