Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从返回多条记录的java调用RPGIV程序_Java_Ibm Midrange_Rpgle_Rpg_Jtopen - Fatal编程技术网

如何从返回多条记录的java调用RPGIV程序

如何从返回多条记录的java调用RPGIV程序,java,ibm-midrange,rpgle,rpg,jtopen,Java,Ibm Midrange,Rpgle,Rpg,Jtopen,我正在从java调用一个RPGIV程序,RPGIV程序返回multi-record作为输出参数 我尝试以下方法返回从rpgiv返回的所有行 // Define Output Data Structure AS400DataType[] outputData = { new AS400Text(20), // parentOperationsItemId; new AS400Text(10),

我正在从java调用一个RPGIV程序,RPGIV程序返回multi-record作为输出参数

我尝试以下方法返回从rpgiv返回的所有行

   // Define Output Data Structure 
      AS400DataType[] outputData = 
    {
        new AS400Text(20),              // parentOperationsItemId;
        new AS400Text(10),              // parentOperationsItemType;
        new AS400Text(10),              // parentOperationsItemSubType;
        new AS400Text(20),              // parentKnownbyId;
        new AS400Text(10),              // parentInternalStatus;
        new AS400Text(1),               // parentLeafIndicator;
        new AS400Text(20),              // childOperationsItemId;
        new AS400Text(10),              // childOperationsItemType;
        new AS400Text(10),              // childOperationsItemSubType;
        new AS400Text(20),              // childKnownbyId;
        new AS400Text(10),              // childInternalStatus;
        new AS400Text(1),               // childLeafIndicator;
        new AS400Text(10)               // InternalStatus;
    };

AS400Structure [] outputDataConverter2 = new AS400Structure[3];

    outputDataConverter2[0] = new AS400Structure(outputData);
    outputDataConverter2[1] = new AS400Structure(outputData);
    outputDataConverter2[2] = new AS400Structure(outputData);


    Object[] dataInputInformation = 
    {
        sSqlSelect,
        sFetchDirection,
        sOperationsItemId,
        sparentOperationsItemTypeList,
        sparentOperationsItemSubTpeList,
        sparentInternalStatusList,
        schildOperationsItemType,
        schildOperationsItemSubTpeList,
        schildInternalStatusList,
        sLinkStatus
    };


    Object[] dataInputInformationControl = 
    {
        sPosition,
        new BigDecimal(sRowsFetched)
    };


    // Set up the parameter list
    ProgramParameter[] parameterList = new ProgramParameter[4];
    parameterList[0] = new ProgramParameter(7); //ReturnStatus
    parameterList[1] = new ProgramParameter(inputDataConverter.toBytes(dataInputInformation)); //Input
    parameterList[2] = new ProgramParameter(inputDataControlConverter.toBytes(dataInputInformationControl)); //Control
    parameterList[3] = new ProgramParameter(outputDataConverter2[0].getByteLength()*3); //Output



    try 
    {
        // Set the program name and parameter list.
        program.setProgram(programName, parameterList);
        // Run Function
        if (program.run() != true) 
        {
            // Calling Error
            AS400Message[] messagelist = program.getMessageList();
            for (int i = 0; i < messagelist.length; ++i) 
            {
                output[0].ReturnStatus += messagelist[i] + "\n";
            }
        } 
        else 
        {
            // Set the output
            output[0] = new GetPlannedRoute();
            output[1] = new GetPlannedRoute();
            output[2] = new GetPlannedRoute();



            output[0].SetOutput(parameterList, outputDataConverter2[0]);
            output[1].SetOutput(parameterList, outputDataConverter2[1]);
            output[2].SetOutput(parameterList, outputDataConverter2[2]);
        }
    } 
我不知道如何定义parameterList[3]以便能够接收多行或多个数据结构。以及如何获取输出参数列表的特定实例[3]

RPGIV代码:


*FetchedData OCCURS OCCURS(64)INZ是我要返回到java的输出数据集。

编辑以显示如何转换压缩值

让我们把这个减少一点。下面是一个小型RPG程序,其结构与您的类似:

 D V00001          DS                  OCCURS(64)
 D  F0000G                       20A
 D  F0000H                       10A
 D  F0000I                       10A
 D  F0000J                       20A
 D  F0000K                        9p 0
 D  F0000L                        1A
 D  F0000M                       20A
 D  F0000N                       10A
 D  F0000O                       10A
 D  F0000P                       20A
 D  F0000Q                       10A
 D  F0000R                        1A
 D  F0000S                       10A

 c     *entry        plist
 c                   parm                    v00001

   // populate the first entry
   %occur(v00001) = 1;
   F0000G = *ALL'1234567890';
   F0000H = *ALL'A';
   F0000I = *ALL'B';
   F0000J = *ALL'C';
   F0000K = 123456789;
   F0000L = *ALL'E';
   F0000M = *ALL'F';
   F0000N = *ALL'G';
   F0000O = *ALL'H';
   F0000P = *ALL'I';
   F0000Q = *ALL'J';
   F0000R = *ALL'K';
   F0000S = *ALL'a';

   // populate the 2nd entry
   %occur(v00001) = 2;
   F0000G = *ALL'1234567890';
   F0000H = *ALL'1234567890';
   F0000I = *ALL'1234567890';
   F0000J = *ALL'1234567890';
   F0000K = 200;
   F0000L = *ALL'1234567890';
   F0000M = *ALL'1234567890';
   F0000N = *ALL'1234567890';
   F0000O = *ALL'1234567890';
   F0000P = *ALL'1234567890';
   F0000Q = *ALL'1234567890';
   F0000R = *ALL'1234567890';
   F0000S = *ALL'b';

   // populate the third entry
   %occur(v00001) = 3;
   F0000G = *ALL'1234567890';
   F0000H = *ALL'1234567890';
   F0000I = *ALL'1234567890';
   F0000J = *ALL'1234567890';
   F0000K = 300;
   F0000L = *ALL'1234567890';
   F0000M = *ALL'1234567890';
   F0000N = *ALL'1234567890';
   F0000O = *ALL'1234567890';
   F0000P = *ALL'1234567890';
   F0000Q = *ALL'1234567890';
   F0000R = *ALL'1234567890';
   F0000S = *ALL'c';

   // reset back to the beginning
   %occur(v00001) = 1;
   dump(a);

   *inlr = *on;
下面是成功读取各种“记录”的Java(我不是Java程序员!):

public String testSO(AS400 system, String programName) {
    boolean success = false;
    final int ONE_ROW_LEN = 147;
    final int DS_ROWS = 64;
    AS400Text dsText = new AS400Text(ONE_ROW_LEN * DS_ROWS);
    AS400Text p0000g = new AS400Text(20);
    AS400Text p0000h = new AS400Text(10);
    AS400Text p0000i = new AS400Text(10);
    AS400Text p0000j = new AS400Text(20);
    int p0000k;  // packed(9, 0) is 5 bytes
    AS400Text p0000l = new AS400Text( 1);
    AS400Text p0000m = new AS400Text(20);
    AS400Text p0000n = new AS400Text(10);
    AS400Text p0000o = new AS400Text(10);
    AS400Text p0000p = new AS400Text(20);
    AS400Text p0000q = new AS400Text(10);
    AS400Text p0000r = new AS400Text( 1);
    AS400Text p0000s = new AS400Text(10);
    String ds = null;

    String returnString = null;

    try
    {
        ProgramCall program = new ProgramCall(system);

        // Set up the parameter list
        ProgramParameter[] parameterList = new ProgramParameter[1];
        parameterList[0] = new ProgramParameter(ONE_ROW_LEN * DS_ROWS); 
        program.setProgram(programName, parameterList);
        success = program.run();

        if(success!=true){
            AS400Message[] messagelist = program.getMessageList();
            System.out.println("\nMessages received:\n");
            for (int i = 0; i < messagelist.length; i++) {
                System.out.println(messagelist[i]);
            }
        } else {
            // RPG is returning a giant chunk of memory
            //allBytes = parameterList[0].getOutputData();
            ds = (String)dsText.toObject(parameterList[0].getOutputData());
            System.out.println("ds=" + ds);
            System.out.println("ds len=" + ds.length());

            // Need to index our way into the block of memory
            // zero-based!
            int row = 0;
            int x = row * ONE_ROW_LEN;
            System.out.println("x=" + x);

            // parse out the individual elements for this row
            int len = p0000g.getByteLength();
            String s0000g = ds.substring(x, x+len);
            x += len;
            len = p0000h.getByteLength();
            String s0000h = ds.substring(x, x+len);
            x += len;
            len = p0000i.getByteLength();
            String s0000i = ds.substring(x, x+len);
            x += len;
            len = p0000j.getByteLength();
            String s0000j = ds.substring(x, x+len);

        // this is packed(9, 0)
        x += len;
        len = 5;
        byte[] b0000k = dsText.toBytes(ds.substring(x, x+len));
        BigDecimal d0000k = (BigDecimal)new AS400PackedDecimal(9, 0).toObject(b0000k);
        p0000k = d0000k.intValue();
        String s0000k = d0000k.toString();

            x += len;
            len = p0000l.getByteLength();
            String s0000l = ds.substring(x, x+len);
            x += len;
            len = p0000m.getByteLength();
            String s0000m = ds.substring(x, x+len);
            x += len;
            len = p0000n.getByteLength();
            String s0000n = ds.substring(x, x+len);
            x += len;
            len = p0000o.getByteLength();
            String s0000o = ds.substring(x, x+len);
            x += len;
            len = p0000p.getByteLength();
            String s0000p = ds.substring(x, x+len);
            x += len;
            len = p0000q.getByteLength();
            String s0000q = ds.substring(x, x+len);
            x += len;
            len = p0000r.getByteLength();
            String s0000r = ds.substring(x, x+len);
            x += len;
            len = p0000s.getByteLength();
            String s0000s = ds.substring(x, x+len);


            returnString = s0000s;
            System.out.println("Return=" + returnString);
            System.out.println("g=" + s0000g);
            System.out.println("h=" + s0000h);
            System.out.println("i=" + s0000i);
            System.out.println("i=" + s0000i);
            System.out.println("j=" + s0000j);
            System.out.println("k=" + s0000k);
            System.out.println("l=" + s0000l);
            System.out.println("m=" + s0000m);
            System.out.println("n=" + s0000n);
            System.out.println("o=" + s0000o);
            System.out.println("p=" + s0000p);
            System.out.println("q=" + s0000q);
            System.out.println("r=" + s0000r);
            System.out.println("r=" + s0000s);
        }

    } catch (Exception e) {
        System.out.println("\ne:\n");
        System.out.println(e);
        System.out.println("\nStack trace:\n");
        e.printStackTrace();

    }
    return returnString;
}
公共字符串testSO(AS400系统,字符串程序名){
布尔成功=假;
最终整数一行长度=147;
最终整数DS_行=64;
AS400Text dsText=新AS400Text(一行*多行);
AS400Text p0000g=新AS400Text(20);
AS400Text p0000h=新AS400Text(10);
AS400Text p0000i=新AS400Text(10);
AS400Text p0000j=新AS400Text(20);
int p000k;//压缩(9,0)是5字节
AS400Text p0000l=新AS400Text(1);
AS400Text p0000m=新AS400Text(20);
AS400Text p0000n=新AS400Text(10);
AS400Text p0000o=新AS400Text(10);
AS400Text p0000p=新AS400Text(20);
AS400Text p0000q=新AS400Text(10);
AS400Text p0000r=新AS400Text(1);
AS400Text p0000s=新AS400Text(10);
字符串ds=null;
字符串returnString=null;
尝试
{
ProgramCall program=新程序调用(系统);
//设置参数列表
ProgramParameter[]parameterList=新的ProgramParameter[1];
parameterList[0]=新的程序参数(一行×多行);
program.setProgram(程序名、参数列表);
success=program.run();
如果(成功!=true){
AS400Message[]messagelist=program.getMessageList();
System.out.println(“\n收到的消息:\n”);
for(int i=0;i
Java中需要理解的关键部分是,在这种设计中,Parameter.getOutputData()返回字节[]。我不是Java程序员,所以我的Java代码很难看。我将返回的字节[]转换为字符串,并将其作为块分配给ds。然后,我强制执行一段代码,将各个变量逐个替换为子字符串。如果我了解更多的Java,我可能会将这些垃圾放在构造函数中,并将其作为列表公开

在发布了所有这些之后,我不可能在productio中以这种方式操作
public String testSO(AS400 system, String programName) {
    boolean success = false;
    final int ONE_ROW_LEN = 147;
    final int DS_ROWS = 64;
    AS400Text dsText = new AS400Text(ONE_ROW_LEN * DS_ROWS);
    AS400Text p0000g = new AS400Text(20);
    AS400Text p0000h = new AS400Text(10);
    AS400Text p0000i = new AS400Text(10);
    AS400Text p0000j = new AS400Text(20);
    int p0000k;  // packed(9, 0) is 5 bytes
    AS400Text p0000l = new AS400Text( 1);
    AS400Text p0000m = new AS400Text(20);
    AS400Text p0000n = new AS400Text(10);
    AS400Text p0000o = new AS400Text(10);
    AS400Text p0000p = new AS400Text(20);
    AS400Text p0000q = new AS400Text(10);
    AS400Text p0000r = new AS400Text( 1);
    AS400Text p0000s = new AS400Text(10);
    String ds = null;

    String returnString = null;

    try
    {
        ProgramCall program = new ProgramCall(system);

        // Set up the parameter list
        ProgramParameter[] parameterList = new ProgramParameter[1];
        parameterList[0] = new ProgramParameter(ONE_ROW_LEN * DS_ROWS); 
        program.setProgram(programName, parameterList);
        success = program.run();

        if(success!=true){
            AS400Message[] messagelist = program.getMessageList();
            System.out.println("\nMessages received:\n");
            for (int i = 0; i < messagelist.length; i++) {
                System.out.println(messagelist[i]);
            }
        } else {
            // RPG is returning a giant chunk of memory
            //allBytes = parameterList[0].getOutputData();
            ds = (String)dsText.toObject(parameterList[0].getOutputData());
            System.out.println("ds=" + ds);
            System.out.println("ds len=" + ds.length());

            // Need to index our way into the block of memory
            // zero-based!
            int row = 0;
            int x = row * ONE_ROW_LEN;
            System.out.println("x=" + x);

            // parse out the individual elements for this row
            int len = p0000g.getByteLength();
            String s0000g = ds.substring(x, x+len);
            x += len;
            len = p0000h.getByteLength();
            String s0000h = ds.substring(x, x+len);
            x += len;
            len = p0000i.getByteLength();
            String s0000i = ds.substring(x, x+len);
            x += len;
            len = p0000j.getByteLength();
            String s0000j = ds.substring(x, x+len);

        // this is packed(9, 0)
        x += len;
        len = 5;
        byte[] b0000k = dsText.toBytes(ds.substring(x, x+len));
        BigDecimal d0000k = (BigDecimal)new AS400PackedDecimal(9, 0).toObject(b0000k);
        p0000k = d0000k.intValue();
        String s0000k = d0000k.toString();

            x += len;
            len = p0000l.getByteLength();
            String s0000l = ds.substring(x, x+len);
            x += len;
            len = p0000m.getByteLength();
            String s0000m = ds.substring(x, x+len);
            x += len;
            len = p0000n.getByteLength();
            String s0000n = ds.substring(x, x+len);
            x += len;
            len = p0000o.getByteLength();
            String s0000o = ds.substring(x, x+len);
            x += len;
            len = p0000p.getByteLength();
            String s0000p = ds.substring(x, x+len);
            x += len;
            len = p0000q.getByteLength();
            String s0000q = ds.substring(x, x+len);
            x += len;
            len = p0000r.getByteLength();
            String s0000r = ds.substring(x, x+len);
            x += len;
            len = p0000s.getByteLength();
            String s0000s = ds.substring(x, x+len);


            returnString = s0000s;
            System.out.println("Return=" + returnString);
            System.out.println("g=" + s0000g);
            System.out.println("h=" + s0000h);
            System.out.println("i=" + s0000i);
            System.out.println("i=" + s0000i);
            System.out.println("j=" + s0000j);
            System.out.println("k=" + s0000k);
            System.out.println("l=" + s0000l);
            System.out.println("m=" + s0000m);
            System.out.println("n=" + s0000n);
            System.out.println("o=" + s0000o);
            System.out.println("p=" + s0000p);
            System.out.println("q=" + s0000q);
            System.out.println("r=" + s0000r);
            System.out.println("r=" + s0000s);
        }

    } catch (Exception e) {
        System.out.println("\ne:\n");
        System.out.println(e);
        System.out.println("\nStack trace:\n");
        e.printStackTrace();

    }
    return returnString;
}