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();
}
}
joc3 例子
最新推荐文章于 2023-03-28 15:21:46 发布