Follow

Java Generation Options

Several Elastic COBOL compiler options allow variations in the generation of Java source code.  Although the basic structure of the Java program is roughly the same no matter what the options are, the generated code can be simplified or expanded as necessary.  This document covers the primary options influencing the output.  See other Forum articles for related topics such as,

Java Integration Options

Use -out:importjava java-import-class to include specific Java import statements at the top of the generated code.  Use -out:package your-package-name to create Java output directory hierarchy and include the Java package statement in each Java class.

$ ecobol -out:importjava org.springframework.batch.core.Job -out:package com.example hello.cbl
$ cat com/example/hello.java

package com.example;
import com.heirloomcomputing.ecs.exec.*;
import org.springframework.batch.core.Job;
...

COBOL in Java

Use -out:cobolinjava to generate the original COBOL program's comments and statements in the generated Java for readability

$ ecobol -out:cobolinjava hello.cbl
$ cat hello.java
...
  //#0-00007:       WORKING-STORAGE SECTION.
  //#0-00008:       01 WS-LVL1.
  //#0-00009:          03 WS-LVL3 PIC X(10).
...

  //#0-00013:           MOVE 'COBOL' TO WS-LVL3.
  wrk.ws_lvl3_OF_ws_lvl1.move("COBOL");

Dealing with Java Restrictions

Java programs have more restrictions than COBOL programs, they can contain only so many source lines and variable declarations.  Use -opt:large if Java errors occur because of size issues (javac error message "Java: Too many lines.").  For finer control, use -opt:break n to break up a large program into Java modules of n lines or less.  To break any program, large or small, on COBOL section or paragraph boundaries use -opt:break section or -opt:break para.

$ ecobol -out:cobolinjava -opt:break section hello.cbl
$ cat hello_Prc_main.java

//#0-00012:       MAIN SECTION.
 //#0-00013:       MAIN-PARA.
 // COBOL Paragraph MAIN-PARA OF MAIN
    public final int main_para_OF_main() {
        //#0-00014:           MOVE 'COBOL' TO WS-LVL3.
        wrk.ws_lvl3_OF_ws_lvl1.move("COBOL");
        ...

$ cat hello_Prc_sub.java
//#0-00019:       SUB SECTION.
 //#0-00020:       SUB-PARA.
 // COBOL Paragraph SUB-PARA OF SUB
    public final int sub_para_OF_sub() {
        //#0-00021:           MOVE 'COBOL' TO WS-LVL3.
        wrk.ws_lvl3_OF_ws_lvl1.move("COBOL");
        ...

Simplify Java Names

Use -out:translate to translate COBOL element names to simpler Java variable names without the implied group hierarchy.  Deduplification of names will occur.  Elastic COBOL must generate a COBOL-compatible linear memory array to back groups and elements so that either internally or externally (e.g., by invoking business rules) referenced groups and elements within them can be modified or referenced in such a way that the other "view" is available at all times.  This option also generates an offset

$ ecobol -out:cobolinjava -opt:break section hello.cbl
$ cat hello.java
   public void declarations() {
       //#0-00008:       01 WS-LVL1.
       //#0-00009:          03 WS-LVL3-A PIC X(10).
       //#0-00010:          03 WS-LVL3-B PIC X(20).

       final Memory _memory=this._memory;
       offset=0;
       ws_lvl3.declare(_memory,offset,10,null,null,null,ws_lvl1,null,null,
            Variable.FLAG_TYPE_ALPHANUMERIC);
       ws_lvl1.declare(_memory,offset,10,null,null,null,null,ws_lvl3_a,null,
            Variable.FLAG_TYPE_ALPHANUMERIC);
       offset+=10;
       ws_lvl1.declare(_memory,offset,20,null,null,null,null,ws_lvl3_b,null,
            Variable.FLAG_TYPE_ALPHANUMERIC);
       offset+=20;
   }
   public  Variable ws_lvl1;
   public  Variable ws_lvl3_a;
   public  Variable ws_lvl3_b;

...

        //#0-00014:           MOVE 'COBOL' TO WS-LVL3.
        wrk.ws_lvl3_a.move("COBOL");
        //#0-00014:           MOVE 'JAVA' TO WS-LVL3-B.
        wrk.ws_lvl3_b.move("JAVA");
        //#0-00014:           DISPLAY WS-LVL1.
        _sizeError=!_context.system().display(_context,wrk.ws_lvl1.toText());

Unused Code Removal

Use -opt:deleteunusedvars to remove unused COBOL groups and element variables from Java generation (the default) or -opt:keepunusedvars to retain them.

Compressed Code

Use -out:nopretty to generate compressed Java code and without comments.

$ ecobol -out:nopretty hello.cbl
$ cat main.java
...
public final int main_para_OF_main(){final Wrk wrk=this.wrk;wrk.ws_lvl3.move("COBOL");boolean _sizeError=false;_sizeError=!_context.system().display(_context,wrk.ws_lvl1.toText());int _performResult=0;if((_performResult=sub_OF_main())>0) perform(_performResult,_sub_OF_main_Label);if(true) throw ExitProgramException.EXIT_GOBACK;return 0; }

Optimized Sparse Arrays

Use -opt:occurs to optimize OCCURS (arrays) to generate simulated array Java objects in such as way that sparsely populated arrays will take limited time to initialize and reduce the memory footprint.  Use -opt:nooccurs (default) to generate all COBOL arrays as standard Java arrays.

$ ecobol -out:cobolinjava hello.cbl
$ cat hello.java
  ...
  //#0-00017:           MOVE 'G' to WS-LVL3-B(3).
  wrk.ws_lvl3_b_OF_ws_lvl1__1[3].move("G");

$ ecobol -out:cobolinjava -opt:occurs hello.cbl
$ cat hello.java
   ...
   //#0-00017:           MOVE 'G' to WS-LVL3-B(3).
   wrk.ws_lvl3_b_OF_ws_lvl1__1.get(3).move("G");

 

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk