joc3 例子

以下是代码,亲自测试过




package test;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Properties;

import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoTable;
import com.sap.conn.jco.ext.DestinationDataProvider;
import com.sap.mw.jco.JCO;

public class Test {
	static String   ABAP_AS = "ABAP_AS_WITHOUT_POOL";
	 static     
	    {     
	        Properties connectProperties = new Properties();     
	        connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "10.1.11.62");     
	        connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR,  "00");     
	        connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "200");     
	        connectProperties.setProperty(DestinationDataProvider.JCO_USER,   "RFCSIAM");  
	        //Must use Upper case for password, otherwise, SAP server will report password is incorrect.  
	       connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "P@ss1234");     
	        connectProperties.setProperty(DestinationDataProvider.JCO_LANG,   "en");     
	       createDataFile(ABAP_AS, "jcoDestination", connectProperties);     
	    }
	 static void createDataFile(String name, String suffix, Properties properties)     
	    {     
	        File cfg = new File(name+"."+suffix);     
	        if(!cfg.exists())     
	        {     
	            try     
	            {     
	                FileOutputStream fos = new FileOutputStream(cfg, false);     
	                properties.store(fos, "for tests only !");     
	                fos.close();     
	            }     
	            catch (Exception e)     
	            {     
	                throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);     
	            }     
	        }     
	    }  
	 public void test() throws Exception{
		 JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS);   
		 JCoFunction function = destination.getRepository().getFunction("ZFM_MODIFYTABLE_VUSREXTID");     
		 com.sap.conn.jco.JCoParameterList list = function.getImportParameterList();
		 com.sap.conn.jco.JCoParameterList tables = function.getTableParameterList();
		 
		 JCoTable table = tables.getTable("IT_USREXTID");
		 System.out.println(table);
		 System.out.println(table.getNumRows());
		 
		 table.appendRow();
		 /**
		  * EV_FLAG1这个直接就是等于返回值,0表示成功,其他(2 4 8等)表示失败 
			日期格式:20130530   
			时间格式:104350
		  */
         table.setValue("TYPE", "DN");
         table.setValue("EXTID", "CN=SUBOTEST02, O=SINOPEC, C=CN");
         table.setValue("SEQNO", "12");
         table.setValue("BNAME", "SUBOTEST02");
         table.setValue("STATUS", "X");
         table.setValue("CNAME", "SUBOTEST02");
         table.setValue("CDATE", "20130530");
         table.setValue("CTIME", "104317");
         table.setValue("VERSION", "0");
         
         function.execute(destination);
         //execute the fucntion
         System.out.println("");
         System.out.println("");
         System.out.println("");
         System.out.println("");
         System.out.println("");
         
         JCoFunction function2 = destination.getRepository().getFunction("ZFM_MODIFYTABLE_VUSREXTID");  
//         javaCallRFC.client.execute(function);
         com.sap.conn.jco.JCoParameterList tables2 = function.getTableParameterList();
         JCoTable table2 = tables2.getTable("IT_USREXTID");
         System.out.println(table2);
         System.out.println(table2.getNumRows());
//		 function.getTableParameterList().setValue("TYPE", "DN");  
//		 function.getTableParameterList().setValue("EXTID", "CN=SUBOTEST01, O=SINOPEC, C=CN");
//		 function.getTableParameterList().setValue("SEQNO", "13");  
//		 function.getTableParameterList().setValue("BNAME", "SUBOTEST01");  
//		 function.getTableParameterList().setValue("STATUS", "X");  
//		 function.getTableParameterList().setValue("CNAME", "SUBOTEST01");  
//		 function.getTableParameterList().setValue("CDATE", "2013.05.30");  
//		 function.getTableParameterList().setValue("CTIME", "10:43:17");  
//		 function.getTableParameterList().setValue("VERSION", "0");  
//		 function.getTableParameterList().setValue("SEQNO", "13");  
//		 function.execute(destination);     
//		 if(list !=null){
//			 for
//		 }
	 }
	 
	 public static void main(String args[]) throws Exception{
		 new Test().test();
	 }
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值