繁体   English   中英

从JAVA调用RPG程序

[英]Call RPG Program from JAVA

我想从JAVA调用一个RPG程序,该RPG程序接收以下参数:

0013.00       * Entry parameters                             
0013.10      C           *ENTRY    PLIST                     
0013.20      C                     PARM           P0RTN   7  
0013.30      C           P1ATCD    PARM           WP0001  1  
0013.40      C           P2AMCD    PARM           WP0002  7  
0013.50      C           P3ARCD    PARM           WP0003  70 
0013.60      C           P4BGCD    PARM           WP0004  6  
0013.70      C           P5EFDX    PARM           WP0005  80 
0013.80      C           P6V9VA    PARM P6V9VA    WP0006 132 

这是RPG中的数据结构:

0010.70       * Parameter declarations                            
0010.80      IP1PARM      DS                                      
0010.90       * I : MAP Company ID                                
0011.00      I                                        1   1 P1ATCD
0011.10      IP2PARM      DS                                      
0011.20       * I : MAP Product ID                                
0011.30      I                                        1   7 P2AMCD
0011.40      IP3PARM      DS                                      
0011.50       * I : MAP Person/Company ID                         
0011.60      I                                    P   1   40P3ARCD
0011.70      IP4PARM      DS                                      
0011.80       * I : MAP Fund ID                                   
0011.90      I                                        1   6 P4BGCD
0012.00      IP5PARM      DS                                      
0012.10       * I : MAP Wk Evaluation Date                        
0012.20      I                                    P   1   50P5EFDX
0012.30      IP6PARM      DS                                      
0012.40       * B : MAP Capital Total                             
0012.50      I                                    P   1   72P6V9VA
0012.60      I            DS                                      

这是我在JAVA中调用该程序的代码:

ProgramParameter[] parameterList = new ProgramParameter[6];
// First parameter is to input a name.
AS400Text nametext = new AS400Text(1);
parameterList[0] = new ProgramParameter(nametext.toBytes("F"));
parameterList[0].setParameterType(ProgramParameter.PASS_BY_VALUE);
nametext = new AS400Text(7);
parameterList[1] = new ProgramParameter(nametext.toBytes("XXX"));
parameterList[1].setParameterType(ProgramParameter.PASS_BY_VALUE);
AS400ZonedDecimal  person = new AS400ZonedDecimal(4,0);
//AS400Text person= new AS400Text(4);
parameterList[2] = new ProgramParameter(person.toBytes(452));
parameterList[2].setParameterType(ProgramParameter.PASS_BY_VALUE);
nametext = new AS400Text(6);
parameterList[3] = new ProgramParameter(nametext.toBytes("XXXXXX"));
AS400PackedDecimal evaluationDate = new AS400PackedDecimal(8, 0);
parameterList[4] = new ProgramParameter(evaluationDate.toBytes(20150715));
//parameter is to get the answer, up to 50 bytes long.
parameterList[5] = new ProgramParameter(50);

但是,当我运行程序时,我从AS400收到一条消息,内容为:

Message ID . . . . . . :   RPG0907       Severity . . . . . . . :   99         
Message type . . . . . :   Inquiry                                             
Date sent  . . . . . . :   20/11/15      Time sent  . . . . . . :   19:38:27   

Message . . . . :   PROGRAM 1350 decimal-data error in field (C G S D F).      
Cause . . . . . :   The RPG program PROGRAM in library LIBRARY found a        
decimal-data error at statement 1350. One field did not contain valid        
numeric data.  The digit and/or sign is not valid.                           
Recovery  . . . :   Enter C to cancel, G to continue processing at *GETIN, S   
to obtain a system dump, or D to obtain an RPG formatted dump.               
Possible choices for replying to message . . . . . . . . . . . . . . . :       
D -- Obtain RPG formatted dump.                                              
S -- Obtain system dump.                                                     
G -- Continue processing at *GETIN.                                          
C -- Cancel.                                                                 
                                                                   More... 
Type reply below, then press Enter.                                            
Reply  . . . .      

我试图从可变人(在JAVA中)更改数据类型,我尝试使用AS400Bin2,AS400Bin4,AS400Bin8,AS400Floa4,AS400Float8,AS400DecFloat,AS400PackedDecimal和AS400ZonedDecimal,但是没有人可以使用,运行类时出现相同的错误。

非常感谢您的帮助。

问题出在语句13.50 P3ARCD PARM WP0003 70。

RPG参数列表包含7个条目,但是您在Java代码中仅占6个。 我认为您的参数被“上移”了七个字节。 尝试传递七个前导空格以说明P0RTN。

首先,您应该检查是否在所有变量中传递了正确的数据。 当RPG中的十进制变量接收到垃圾值时,将出现十进制数据错误,因此,在您的情况下,可能没有将任何值传递给AS400的十进制变量,而是在通讯时传递了垃圾值。

可能需要在RPG程序中添加验证以先验证数据,然后再处理错误(如果错误在处理逻辑内)。 您可以找到传递给RPG的参数,也可以将其提供给RPG开发人员,他可以使用这些参数调试该参数以查找问题。

从JAVA致电RPG。
不要在数据结构中放置任何参数。

针对AS400程序接受了两个字符串参数,创建了只能用于通信的特殊用户ID,经过测试并可以正常使用,lib使用jt400.jar

import com.ibm.as400.access.AS400;
import com.ibm.as400.access.AS400Message;
import com.ibm.as400.access.AS400Text;
import com.ibm.as400.access.ProgramCall;
import com.ibm.as400.access.ProgramParameter;

public class CallingAS400PGM {

private static final String HOST = "192.168.1.1";//AS400 IP
private static final String UID = "UNAME"; //userid
private static final String PWD = "PWORD"; //password

public static void main(String[] args) {
    //AS400 RPG progam path
    String fullProgramName = "/QSYS.LIB/PBFORM12.LIB/PBFORM12CL.PGM";

    AS400 as400 = null;
    ProgramParameter[] parmList;//parameter list witch is accepting AS400 RPG program
    ProgramCall programCall;
    try {
        // Create an AS400 object
        as400 = new AS400(HOST, UID, PWD);

        // Create a parameter list
        // The list must have both input and output parameters
        parmList = new ProgramParameter[2];

        // Convert the Strings to IBM format
        AS400Text nametext1 = new AS400Text(2);
        AS400Text nametext2 = new AS400Text(200);

        // Create the input parameter // get the exact patameter type and length, if 
        not this not be working  
        parmList[0] = new ProgramParameter(nametext1.toBytes("1"),2);
        parmList[1] = new ProgramParameter(nametext2.toBytes("Ravinath 
        Fernando"),200);
        // Create the output parameter

        programCall = new ProgramCall(as400);
        programCall.setProgram(fullProgramName, parmList);

        if (!programCall.run()) {
            /**
             * If the AS/400 is not run then look at the message list to
             * find out why it didn't run.
             */
            AS400Message[] messageList = programCall.getMessageList();
            for (AS400Message message : messageList) {
                System.out.println(message.getID() + " - " + message.getText());
            }
        } else {
            System.out.println("success");
            /**
             * Else the program is successfull. Process the output, which
             * contains the returned data.
             */
            //use same parameter type which will be return from AS400 program
            AS400Text text1 = new AS400Text(2);
            System.out.println(text1.toObject(parmList[0].getOutputData()));
            AS400Text text2 = new AS400Text(200);
            System.out.println(text2.toObject(parmList[1].getOutputData()));
        }
        as400.disconnectService(AS400.COMMAND);
        //-----------------------
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(":: Exception ::" + e.toString());
    } finally {
        try {
            // Make sure to disconnect 
            if (as400 != null) {
                as400.disconnectAllServices();
            }
        } catch (Exception e) {
            System.err.println(":: Exception ::" + e.toString());
        }
    }
}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM