求教JCo连接SAP调用RFC函数能获取到表结构却取不到数据!
SapUtil工具类(获取JCoParameterList对象):
public static JCoParameterList getJCoTable(String funcName){
//读取配置文件,获取JCoDestination对象
JCoDestination dest = null;
try {
dest = JCoDestinationManager.getDestination("ECC");
dest.ping();
} catch (JCoException e) {
e.printStackTrace();
//连接到SAP失败
throw new ServiceRuntimeException("连接到SAP失败,请稍后重试!");
}
JCoFunction func = null;
try {
func = dest.getRepository().getFunction(funcName);
} catch (JCoException e) {
e.printStackTrace();
//创建function对象失败
throw new ServiceRuntimeException("连接到SAP失败,请稍后重试!");
}
if(func == null){
//获取到的function对象为null
throw new ServiceRuntimeException("连接到SAP失败,请稍后重试!");
}
//获取table 接口对象 供后续获取数据使用
JCoParameterList tmlist = func.getTableParameterList();
return tmlist;
}
junit测试代码:
public void test(){
JCoParameterList tmlist = SapUtil.getJCoTable("ZFIF_GET_YY001");
JCoTable cgfpTab = tmlist.getTable("CGFP_OUT");
System.out.println(cgfpTab);
//应该返回一条数据
Assert.assertEquals(1,cgfpTab.getNumRows());
}
断言返回错误:
java.lang.AssertionError: expected:<1> but was:<0>
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit.Assert.assertEquals(Assert.java:645)
at org.junit.Assert.assertEquals(Assert.java:631)
at cn.apcinfo.test.inter.pcminvoice.PcmInvoiceTest.test(PcmInvoiceTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
获取到的表结构部分:
|--------|--------|----------|---|--------|----------------|----------|------------------|---|----------------|----------------|----|----------------|----------------|----------------|----------------|----------|-----|----------|----|
| TABLE 'ZFIS0005'
|--------|--------|----------|---|--------|----------------|----------|------------------|---|----------------|----------------|----|----------------|----------------|----------------|----------------|----------|-----|----------|----|
|BLDAT |BUDAT |BELNR |BUZ|FPLX |XBLNR |LIFNR
|--------|--------|----------|---|--------|----------------|----------|------------------|---|----------------|----------------|----|----------------|----------------|----------------|----------------|----------|-----|----------|----|
|01234567|89012345|6789012345|678|90123456|
|--------|--------|----------|---|--------|----------------|----------|------------------|---|----------------|----------------|----|----------------|----------------|----------------|----------------|----------|-----|----------|----|
|--------|--------|----------|---|--------|----------------|----------|------------------|---|----------------|----------------|----|----------------|----------------|----------------|----------------|----------|-----|----------|----|
参数配置如下:
jco.client.ashost=***.***.***.***
jco.client.client=100
jco.client.lang=ZH
jco.client.passwd=*********
jco.client.sysnr=10
jco.client.user=*********
jco.destination.peak_limit=40
jco.destination.pool_capacity=5
jco.client.saprouter=/H/***.***.***.***/H/