求教JCo连接SAP调用RFC函数能获取到表结构却取不到数据!

qq_32145293 2018-01-09 05:15:41
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/
...全文
621 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_32145293 2018-01-10
  • 打赏
  • 举报
回复
感谢,已经解决了这个问题,数据存在且用户具有访问权限,需要调用function.excute(destination);方法然后对应的JCoTable内就会有数据。但是具体的原因还不是很清楚。
tianfang 2018-01-09
  • 打赏
  • 举报
回复
是否有数据? 你用的用户是否有访问权限?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧