1,直接用CALL PGM(DHCLIB/IN01) PARM(X'F0000000005F' X'F1111111115F' 'DDDDD' 'FFFFF')数据能够插入到物理文件;
2,使用java程序调用IN01,JAVA程序执行到 if(pgm.run())就没有反应了。
请多指教,thanks!
PF:
Columns . . . : 1 71 Edit DHCLIB/QDDSSRC
SEU==> PF001
FMT PF .....A..........T.Name++++++RLen++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
0011.00 UNIQUE
0013.00 R PF001R TEXT('PF001')
0014.00 PFP1 10P 0 TEXT('PF001 P1')
0018.00 PFP2 10P 0 TEXT('PF001 P2')
0026.00 PFSTR1 50A TEXT('PF001 STR1')
0031.00 PFSTR2 50A TEXT('PF001 STR2')
0035.00 K PFP1
****************** End of data ***************************************
RPG:
Columns . . . : 6 76 Edit DHCLIB/QRPGLESRC
SEU==> INSERT01
FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++
*************** Beginning of data *************************************
0005.00 FPF001 O E DISK
0006.01 DP1 S 10P 0
0006.02 DP2 S 10P 0
0006.03 DA1 S 50A
0006.04 DA2 S 50A
0007.00 C *entry PLIST
0008.00 C PARM P1
0009.00 C PARM P2
0011.00 C PARM A1
0012.00 C PARM A2
0018.00 C MOVE P1 PFP1
0019.00 C MOVE P2 PFP2
0020.00 C MOVE A1 PFSTR1
0021.00 C MOVE A2 PFSTR2
0022.00 C WRITE PF001R
0023.00 C SETON LR
JAVA:
package rpgtest;
import java.math.*;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.AS400PackedDecimal;
import com.ibm.as400.access.ProgramParameter;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class In01 {
private AS400 as400;
private ProgramCall pgm;
private String progname = "/QSYS.LIB/DHCLIB.LIB/IN01.PGM";
public In01() {
}
/**
* Application entry point.
*
* @param args String[]
*/
public void connectDPC(String system,String user,String password){
as400=new AS400(system,user,password);
try
{
System.out.println("开始连接远程服务!");
as400.connectService(AS400.COMMAND);
System.out.println("远程服务连接成功!");
}
catch(Exception e)
{
System.out.println("连接AS/400服务失败!");
System.exit(0);
}
//建立远程程序对象
pgm=new ProgramCall(as400);
//设置参数,并转换为AS/400格式
ProgramParameter[] parmlist = new ProgramParameter[4];
AS400PackedDecimal p1 = new AS400PackedDecimal(10,0);
parmlist[0] = new ProgramParameter(p1.toBytes(new BigDecimal(1100000019)),10);
AS400PackedDecimal p2 = new AS400PackedDecimal(10,0);
parmlist[1] = new ProgramParameter(p2.toBytes(new BigDecimal(1100000019)),10);
AS400Text a1 = new AS400Text(50);
parmlist[2] = new ProgramParameter(a1.toBytes("TEST005"));
AS400Text a2 = new AS400Text(50);
parmlist[3] = new ProgramParameter(a2.toBytes("test005"));
try
{ //将程序路径、参数表与ProgramCall对象捆绑
pgm.setProgram(progname,parmlist);
}
catch(Exception e)
{
System.out.println("设置参数失败!");
}
try
{
System.out.println("开始远程调用!");
if(pgm.run())
{
System.out.println("远程调用成功!");
}
else
{
System.out.println("远程调用失败!");
}
}
catch(Exception e)
{
System.out.println("远程调用异常!");
e.printStackTrace();
}
}
public static void main(String[] args) {
In01 rt=new In01();
rt.connectDPC("192.195.29.110","wuser","demo2pwd");
rt.as400.disconnectAllServices();
}
}
qingzhou 回复于:2006-04-28 15:31:50
查看系统有没有需要回复的提示信息?
还有,可以WRKOUTQ QEZDEBUG去查查DUMP的提示信息。
chenzhy 回复于:2006-04-28 15:47:28
没有!我看执行上面的命令后列出的文件都是前几天的,没有今天的,您能帮我看看rpg程序有问题吗?我是新手,麻烦了。thanks!
[ 本帖最后由 chenzhy 于 2006-4-28 15:58 编辑 ]
qingzhou 回复于:2006-04-28 16:03:18
PF001在RPG中为什么定义为O型呢?是打印文件才定义这个类型。
调用PF应该定义为I型(输入)或U型(输入/输出)。
chenzhy 回复于:2006-04-28 16:17:59
我把rpg程序最上面的一行改为
0001.00 FPF001 IF A E DISK
并且用call命令调用,数据能够插入pf中,用java调用还是没有反应~~~
[ 本帖最后由 chenzhy 于 2006-4-28 16:19 编辑 ]
chenzhy 回复于:2006-05-09 15:29:43
这个问题好多天了,查看以前的帖子也有一样的问题,但是都么有解决的方法,不知道是不是真的不能这么做还是怎么的了,要是有其他的替代方法,麻烦哪位老兄给个建议,谢谢了。
span1024 回复于:2006-05-09 15:41:14
哥们儿,好象你的JAVA程序有点问题?
[ 本帖最后由 span1024 于 2006-5-9 15:49 编辑 ]
chenzhy 回复于:2006-05-09 15:50:54
具体说说呗。
我的其他的rpg程序不操作数据库,就能返回数据(简单的传入一个参数,返回3个参数就行),涉及到数据库操作就出来这样的问题。
[ 本帖最后由 chenzhy 于 2006-5-9 15:54 编辑 ]
sunokla 回复于:2006-05-09 16:53:54
引用:原帖由 chenzhy 于 2006-4-28 16:17 发表
我把rpg程序最上面的一行改为
0001.00 FPF001 IF A E DISK
并且用call命令调用,数据能够插入pf中,用java调用还是没有反应~~~
没用过这种方式。想问一下:这种java call rpg 程序 ,在400上能不能debug rpg 程序?
如果不能debug,将传递的参数都改为字符型的先试一下可以吗?
另外f表改为0001.00 FPF001 UF A E DISK //难道我记错了? 我记得声明为i型是只读的?!
[ 本帖最后由 sunokla 于 2006-5-9 17:01 编辑 ]
chenzhy 回复于:2006-05-09 17:28:10
sunokla 兄
能提供个类似的例子吗?多谢了。我现在真是一头雾水。
sunokla 回复于:2006-05-09 21:16:14
引用:原帖由 chenzhy 于 2006-4-28 16:17 发表
我把rpg程序最上面的一行改为
0001.00 FPF001 IF A E DISK
并且用call命令调用,数据能够插入pf中,用java调用还是没有反应~~~
在400上call 没有问题应该说明rpg程序没问题。应该集中精力在java程序上。
因为不会java,帮不了你什么了。
轻舟兄说的对,应该找到程序调用成功或失败的消息。
这个链接看下:
http://publib.boulder.ibm.com/iseries/v5r2/ic2989/index.htm?info/rzahh/pgmc.htm
改一下程序,试试看能不能得到iSeries的 消息。
直接从ibm网站上粘贴下来的:
示例:使用 ProgramCall
注意:请阅读代码示例不保证声明以了解重要的法律信息。
/////////////////////////////////////////////////////////////////////////
//
// Program call example. This program calls the QWCRSSTS server program
// to retrieve the status of the system.
//
// Command syntax:
// PCSystemStatusExample system
//
// This source is an example of IBM Toolbox for Java "ProgramCall".
//
/////////////////////////////////////////////////////////////////////////
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.Thread.*;
import com.ibm.as400.access.*;
public class PCSystemStatusExample extends Object
{
public static void main(String[] parameters)
{
System.out.println( " " );
// if a system was not specified, display help text and exit.
if (parameters.length >= 1)
{
try
{
// Create an AS400 object for the server that contains the
// program. Assume the first parameter is the system name.
AS400 as400 = new AS400(parameters[0]);
// Create the path to the program.
QSYSObjectPathName programName = new QSYSObjectPathName("QSYS",
"QWCRSSTS",
"PGM");
// Create the program call object. Assocate the object with the
// AS400 object that represents the server we get status from.
ProgramCall getSystemStatus = new ProgramCall(as400);
// Create the program parameter list. This program has five
// parameters that will be added to this list.
ProgramParameter[] parmlist = new ProgramParameter[5];
// The server program returns data in parameter 1. It is an output
// parameter. Allocate 64 bytes for this parameter.
parmlist[0] = new ProgramParameter( 64 );
// Parameter 2 is the buffer size of parm 1. It is a numeric input
// parameter. Sets its value to 64, convert it to the server format,
// then add the parm to the parm list.
AS400Bin4 bin4 = new AS400Bin4( );
Integer iStatusLength = new Integer( 64 );
byte[] statusLength = bin4.toBytes( iStatusLength );
parmlist[1] = new ProgramParameter( statusLength );
// Parameter 3 is the status-format parameter. It is a string input
// parameter. Set the string value, convert it to the server format,
// then add the parameter to the parm list.
AS400Text text1 = new AS400Text(8, as400);
byte[] statusFormat = text1.toBytes("SSTS0200");
parmlist[2] = new ProgramParameter( statusFormat );
// Parameter 4 is the reset-statistics parameter. It is a string input
// parameter. Set the string value, convert it to the server format,
// then add the parameter to the parm list.
AS400Text text3 = new AS400Text(10, as400);
byte[] resetStats = text3.toBytes("*NO ");
parmlist[3] = new ProgramParameter( resetStats );
// Parameter 5 is the error info parameter. It is an input/output
// parameter. Add it to the parm list.
byte[] errorInfo = new byte[32];
parmlist[4] = new ProgramParameter( errorInfo, 0 );
// Set the program to call and the parameter list to the program
// call object.
getSystemStatus.setProgram(programName.getPath(), parmlist );
// Run the program then sleep. We run the program twice because
// the first set of results are inflated. If we discard the first
// set of results and run the command again five seconds later the
// number will be more accurate.
getSystemStatus.run();
Thread.sleep(5000);
// Run the program
if (getSystemStatus.run()!=true)
{
// If the program did not run get the list of error messages
// from the program object and display the messages. The error
// would be something like program-not-found or not-authorized
// to the program.
AS400Message[] msgList = getSystemStatus.getMessageList();
System.out.println("The program did not run. Server messages:");
for (int i=0; i<msgList.length; i++)
{
System.out.println(msgList.getText());
}
}
// Else the program did run.
else
{
// Create a server to Java numeric converter. This converter
// will be used in the following section to convert the numeric
// output from the server format to Java format.
AS400Bin4 as400Int = new AS400Bin4( );
// Get the results of the program. Output data is in
// a byte array in the first parameter.
byte[] as400Data = parmlist[0].getOutputData();
// CPU utilization is a numeric field starting at byte
// 32 of the output buffer. Convert this number from the
// server format to Java format and output the number.
Integer cpuUtil = (Integer)as400Int.toObject( as400Data, 32 );
cpuUtil = new Integer(cpuUtil.intValue()/10);
System.out.print("CPU Utilization: ");
System.out.print(cpuUtil);
System.out.println("%");
// DASD utilization is a numeric field starting at byte
// 52 of the output buffer. Convert this number from the
// server format to Java format and output the number.
Integer dasdUtil = (Integer)as400Int.toObject( as400Data, 52 );
dasdUtil = new Integer(dasdUtil.intValue()/10000);
System.out.print("Dasd Utilization: ");
System.out.print(dasdUtil);
System.out.println("%");
// Number of jobs is a numeric field starting at byte
// 36 of the output buffer. Convert this number from the
// server format to Java format and output the number.
Integer nj = (Integer)as400Int.toObject( as400Data, 36 );
System.out.print("Active jobs: ");
System.out.println(nj);
}
// This program is done running program so disconnect from
// the command server on the server. Program call and command
// call use the same server on the server.
as400.disconnectService(AS400.COMMAND);
}
catch (Exception e)
{
// If any of the above operations failed say the program failed
// and output the exception.
System.out.println("Program call failed");
System.out.println(e);
}
}
// Display help text when parameters are incorrect.
else
{
System.out.println("");
System.out.println("");
System.out.println("");
System.out.println("Parameters are not correct. Command syntax is:");
System.out.println("");
System.out.println(" PCSystemStatusExample myServer");
System.out.println("");
System.out.println("Where");
System.out.println("");
System.out.println(" myServer = get status of this server ");
System.out.println("");
System.out.println("For example:");
System.out.println("");
System.out.println(" PCSystemStatusExample mySystem");
System.out.println("");
System.out.println("");
}
System.exit(0);
}
}
[ 本帖最后由 sunokla 于 2006-5-9 21:26 编辑 ]
chenzhy 回复于:2006-05-10 11:29:44
现在的问题明了了,但是还是不能解决。
这次我就用一个参数,使用PCML访问方式处理,第一次rpg程序不访问物理文件,使用java程序调用好用;第二次,只是在rpg程序加上一行物理文件的引用,使用java调用就没反应了。
代码如下:
rpg:
Columns . . . : 6 76 Edit DHCLIB/QRPGLESRC
SEU==> JAVACALL
FMT D DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords
*************** Beginning of data ********************
0000.01 FPF001 UF E DISK//这行加上java调用没有反应,不加就好了。
0006.01 DA1 S 4A
0013.00 C *entry PLIST
0014.02 C PARM A1
0014.03 C A1 DSPLY
0027.00 C RETURN
****************** End of data ***********
java:
package rpgtest;
import com.ibm.as400.data.*;
import com.ibm.as400.access.*;
public class RpgTest {
private AS400 as400;
public RpgTest() {
}
public void connectDPC(String system,String user,String password){
as400=new AS400(system,user,password);
try
{
System.out.println("开始连接远程服务!");
as400.connectService(AS400.COMMAND);
System.out.println("远程服务连接成功!");
}
catch(Exception e)
{ System.out.println("连接AS/400服务失败!");
System.exit(0);
}
ProgramCallDocument pcml;
try{
pcml = new ProgramCallDocument(as400, "JAVACALL"); // open the PCML File
// set all the input parameters for program alias DateCalc
pcml.setValue("JAVACALL.A1","aaaa");
// call the program
boolean rc = pcml.callProgram("JAVACALL");
if (rc == false) {
System.out.println("Program failed");
} else {
System.out.println("A1 Out = " +
pcml.getValue("JAVACALL.A1"));
}
} catch (PcmlException pe) {
System.out.println(" Caught Exception ");
pe.printStackTrace();
}
}
public static void main(String[] args) {
RpgTest rt=new RpgTest();
rt.connectDPC("192.195.29.110","wuser","demo2pwd");
rt.as400.disconnectAllServices();
}
}
所以我感觉现在的问题出在加的那行上。就是引用了物理文件,不知道怎么处理了。
946 回复于:2006-05-10 13:35:02
前二天剛實現了pb調用PGM,我是這樣作的,新建一個CLP程序,在CLP中一定要chglibl包括所有的庫,然後call PGM,在PB里面直接CALL CLP就可以了,希望對你有用。
chenzhy 回复于:2006-05-10 14:46:53
谢谢,我试试。
pl421 回复于:2006-05-10 14:51:01
楼主400进步神速啊~~蛮厉害的!收藏了!
chenzhy 回复于:2006-05-10 15:11:50
太感动了!真是这个问题,不过我比较懒,直接
CommandCall cc = new CommandCall(as400);
cc.run("ADDLIBLE DHCLIB");
这样就返回信息了!!!!!
谢谢!!!
chenzhy 回复于:2006-05-10 16:04:33
说实话真是惭愧,就会照猫画虎,胡乱涂改………………
sunokla 回复于:2006-05-10 16:14:50
引用:原帖由 chenzhy 于 2006-5-10 15:11 发表
太感动了!真是这个问题,不过我比较懒,直接
CommandCall cc = new CommandCall(as400);
cc.run("ADDLIBLE DHCLIB");
这样就返回信息了!!!!!
谢谢!!!
终于找到问题了,替你高兴:D。原来是库列表的问题,呵呵。
不过可以将程序所在库加入库列表中,这样也可以的。
顺便问一下,这样的调用错误在java中有没有方法显示出错误消息呢?
chenzhy 回复于:2006-05-10 16:20:15
我没看到返回信息,问题出在这
boolean rc = pcml.callProgram("JAVACALL");
执行时并没有作任何异常的捕获,还没有试验在这里是不是能够捕获这个异常(不知道是不是异常,有可能是个错误,能够避免的)。
qingzhou 回复于:2006-05-10 18:48:04
LZ辛苦了,,,
一般执行程序出错,很大程度都是通过错误信息来纠正程序的,不然就瞎猜了~~~
推荐为精彩帖子。
|