0

I am trying to invoke a simple Hello World Cobol program through java. The java code is in IFS file structure and the cobol object is parked in a library. I am facing multiple problems:

  1. The error stream returned by process execution is not in readable format.
  2. I am getting error stream result even if the termination of cobol code returns 0.
  3. I cannot see the cobol output result in the inputstream of the process.(May be I can solve this if i understand the error stream )

The cobol code works when invoke independently. I have tried encoding UTF8,UTF16, Cp943 and default. When I use UTF8,UTF16 I get MalformedInputException, else a garbage value.

Java code:(compiled @ AS 400 itself -java 1.5)

    import java.io.*;

    public class CallCLPgm
    {
       public static void main(String[] args)
       {
          try
          {
          Process theProcess =  Runtime.getRuntime().exec("system CALL PROG6");
          //error stream
            BufferedReader inStream1 = new BufferedReader(new InputStreamReader
                     (theProcess.getErrorStream(),"UTF8"));
             System.out.println(inStream1.readLine());
            inStream1.close();
          //input stream   
             BufferedReader inStream = new BufferedReader(new InputStreamReader
                     (theProcess.getInputStream()));
             System.out.println(inStream.readLine());
             inStream.close();


             System.out.println("termination : "+theProcess.waitFor());

 
 //Cobol code
      PROCEDURE DIVISION.        
      PROGRAM-BEGIN.     
          DISPLAY "Hello World".   
          STOP RUN.  

2 Answers 2

2

I should have focused on IBM encoding format http://publib.boulder.ibm.com/html/as400/v4r5/ic2924/index.htm?info/java/rzaha/fileenc.htm

I used "Cp037" for USA instead of UTF8 and other format.

BufferedReader inStream1 = new BufferedReader(new InputStreamReader (theProcess.getErrorStream(),"Cp037"));

Sign up to request clarification or add additional context in comments.

2 Comments

I can finalize it as accepted after 2 days, since I answered my own question I guess :)
Note that in order to work correctly internationally you must ask the server about its encoding, and use that.
1

I am not a Cobol programmer but I think that the Cobol verb DISPLAY does not write to stdout. Check with the Cobol manual, but my guess is that you will need to actually open stdout in your Cobol program and write to it rather than use DISPLAY.

When I want to call a program on IBM i, I use the JTOpen IBM Toolbox for Java. The Javadoc can be hard to find if you're not familiar with the IBM Infocenter.

3 Comments

I am able to read output that cobol spits using display, using the above java code itself. The process object actually returns all the output that you will see if you are doing it from a terminal.
Buck, I've done COBOL in a few prior lives. DISPLAY can write stuff out to a CONSOLE session, similar to what SAY does in REXX.
JT400 javadoc can also be found at javadoc.midrange.com in a much simpler format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.