sponsored links

Collapse

Announcement

Collapse
No announcement yet.

How to get output value from AS400 C ILE Program from Java Program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get output value from AS400 C ILE Program from Java Program

    Hi.
    I try to get output value of C ILE program that running on AS400, from Java Code.
    Here the C ILE code and the Java Code.


    The following C ILE code:
    PHP Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    #pragma argument(main, VREF, nowiden)

    int main(int argcchar *argv[]) {
    int i;

    printf("\nNumber Of Arguments Passed: %d\n"argc);
    for (
    0argci++) {
    printf("arg[%d]=%s\n"iargv[i]);
    }
    printf("----------------------\n");

    /* Display parameters sent to the program. */
    printf("Incoming parameter 1 = %s\n"argv[1]);
    printf("Incoming parameter 2 = %s\n"argv[2]);
    printf("----------------------\n");

    /* Concatenate the two incoming parameters */
    argv[3] = (char*) malloc(20);
    memset(argv[3], '\0'20);

    strcpy(argv[3], argv[1]);
    strcat(argv[3], argv[2]);
    printf("Out parameter 3 = %s\n"argv[3]);

    return 
    0;
    }
    ---------------------------------------------------------------------
    The Java code
    I want to get argv
    [3] as output in Java Program:

    public class 
    CPgmCaller1 {
    private static 
    QSYSObjectPathName PGM = new QSYSObjectPathName("MY#LB""C_TEST4""PGM");

    /**
    * @param args
    * @throws DaoException
    */

    private static String executeProgramCall(AS400 as400ObjectString val1String val2throws Exception {
    int systemCCSID as400Object.getCcsid();
    CharConverter conv = new CharConverter(systemCCSID);

    if (
    conv == null)
    return 
    null;
    ProgramParameter[] parameterList = new ProgramParameter[3];
    String result "XXXXXXXXXXXXXXXXXXXX";
    parameterList[0] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENC Econv.stringToByteArray(val1 '\0'));
    parameterList[1] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENC Econv.stringToByteArray(val2 '\0'));
    parameterList[2] = new ProgramParameter(ProgramParameter.PASS_BY_REFERENC Econv.stringToByteArray(result.toString()));


    ProgramCall programCall = new ProgramCall(as400Object);
    programCall.setProgram(PGM.getPath(), parameterList);

    if (!
    programCall.run()) {
    System.err.println("Error Calling C Program: " PGM.getPath());
    return 
    null;
    }

    // This line - return null;
    // Should return the concatination of val1 and val2
    byte[] resultOutput parameterList[2].getOutputData();

    // This line - return "XXXXXXXXXXXXXXXXXXXX";
    byte[] resultInput parameterList[2].getInputData();

    return new 
    String(resultInput);
    }

    }

    //---------------------------------------------------------------------------- 
    Thanks,
    Tomer Sasson
    Last edited by jamief; 2 weeks ago.
Working...
X