EGL Development User Group

EGL Development User Group

EGL Development User Group

The EGL Development User Group is dedicated to sharing news, knowledge, and insights regarding the EGL language and Business Developer product. Consisting of IBMers, HCL, and users, this community collaborates to advance the EGL ecosystem.

 View Only

COBOL to EGL Conversion

By Sasi priya posted 06/10/26 05:02 AM

  

Automated conversion of native COBOL programs into EGL programs with a single click. The system accepts a COBOL source file as input and automatically generates a functionally equivalent EGL file using a Java-based conversion tool, while adopting EGL’s modern structure and syntax.

The COBOL-to-EGL conversion process is as follows:

  • Automated COBOL-to-EGL Conversion: Develop a Java-based conversion tool that transforms COBOL programs into equivalent EGL files while maintaining functional accuracy.

  • ANTLR-Based COBOL Parsing:

    • Use ANTLR to parse and tokenize COBOL source code.

    • Generate an Abstract Syntax Tree (AST) for accurate EGL code conversion.

  • Command-Line Batch Execution: Enables a command-line execution using a batch script to make the conversion process efficient and user-friendly.

  • Input and Output Handling: Accept COBOL source files as input and generate structured EGL output files automatically.

  • Logging and Debugging: Creates detailed log files for every conversion process, capturing execution status, warnings, and errors for debugging and analysis.

  • Modular and Scalable Design: Ensure to design the system with a modular structure to support future enhancements and enable the processing of multiple COBOL files efficiently.

 

Specifications

  • The ANTLR-generated parser supports standard COBOL syntax based on the defined grammar rules.

  • The input COBOL program must be syntactically valid. Invalid COBOL syntax may result in parsing errors during conversion.

  • The conversion process is designed for the TANDEM COBOL format. Both TANDEM COBOL and IBM z/OS COBOL follow COBOL 85 standards with minor deviations.

  • Before executing native COBOL programs on Windows, update comment lines from * format to *>, as TANDEM supports only the *> comment format.

  • Sign Function Limitation: The ANTLR parser recognizes the SIGN keyword in the Working-Storage Section. However, when used as a function in the Procedure Division, it may produce a parser error.

  • Temporary Workaround: Replace FUNCTION SIGN with FUNCTION SIGN1 before code generation. After EGL code generation, revert SIGN1 back to SIGN before execution.

    • Example: COMPUTE SIGN-VAL = FUNCTION SIGN1(VAL).

 

Pre-Requisites 

  • The generated EGL code supports IBD version 10.0 and later.

  • Required Software Components:

    • ANTLR 4.7.2 – COBOL parsing and conversion.

    • SLF4J API 2.0.9 – Logging abstraction.

    • Logback 1.3.6 – Logging implementation.

  • System Requirements:

    • Java JDK 17 or later installed.

    • Proper read/write permissions for input and output directories.

  • Required Files:

    • COBOL to EGL batch script.

    • COBOL to EGL runnable JAR file.

 

Steps for Conversion and Execution

Input and Output flow

  • Input File (COBOL File): The COBOL source program provided as input for the conversion process.

  • Conversion Process: The Java-based conversion tool uses ANTLR to parse the COBOL source code and generate the corresponding EGL file.

  • Output File (EGL File): The converted EGL file is generated and stored in the designated output directory.

  • Log File (.log File): A log file with the same name as the input file is created to capture conversion details, warnings, and error messages for troubleshooting and analysis.

 

Batch Script Execution:

1. The COBOL source code is converted to EGL and compiled into a runnable JAR file, and a batch script is created to run it from the command prompt.

2. Configure the JAR file path in the batch script as required.

3. After setting the JAR path, open the command prompt in the same directory and execute the batch script using the following syntax:
<batch script.bat> -sourcefile <CBL file location> -gendirectory <output EGL file location till package name> -format TANDEM -package <package name>

 

  1. Upon successful execution, the generation details are displayed in the console.

  1. A Sample native COBOL program.

  1. The converted EGL program is below. The EGL program is further generated into a corresponding COBOL program from the IBD workspace for execution in the mainframe environment.

  1. Additionally, the EGL log file is also created in the same output location as the EGL file.

  1. The output of the generated EGL program.

 

Limitations

Working storage section:

  • Datatypes:

    • Native COBOL : 01 WS-NUM1 PIC 9(2)

    • EGL : $WsNum1 smallInt

    • Generated COBOL: 05 XWSNUM1-2 PIC S9(4) COMP-4.

    • The data types used in COBOL (e.g., PIC 9(3) or PIC 9(9)) and passing the values beyond the picture clause might throw an onsize error. But in EGL, the corresponding supported datatypes are int 9(9) and small int 9(4) by default. So, the same precision is not supported in EGL.
      Example:

    • National & Pointer not implemented.

  • Conditional variables:
    Conditional variables must follow proper syntax formatting rules https://www.ibm.com/docs/en/cobol-zos/6.5.0?topic=separators-rules

    • ANTLR parser considers 1,2 as one value. 1, 2, or 1 2 as two values. So, the COBOL program must be maintained in a space after the symbol ",". Likewise, THRU should be in uppercase.

    • 88 INTERMEDIATE VALUE 6, 7, 8.

    • 88 BEGINNER VALUE 1 THRU 5.

  • Copy Book Support

    • Copy book is not supported. 

    • The user must manually expand the copybook structure in the native COBOL program.

Procedure Division statements:

  1. The ALSO keyword is not implemented in the Evaluate statement.
    Example:
    EVALUATE MARKS ALSO TRUE

                        WHEN 30 THRU 50 ALSO GRADE = "D" DISPLAY "JUST PASS"

           END-EVALUATE.

  1. WHEN OTHER should be added in a COBOL program as a mandatory, otherwise the parser will throw an error and generation will be interrupted.

  2. Multiple variables in the GO TO statement are not supported in EGL. GO TO PARA-1 PARA-2 PARA-3 DEPENDING ON WS-P.

            Note: Go To supports only one label. Multiple labels are not supported in EGL.

For more information, refer to https://help.blueproddoc.com/ibd/10.0.0/com.ibm.egl.lr.doc/topics/regl_core_go_to.html?hl=goto%2Cegl

  1. SPACES are required around arithmetic operators to avoid ambiguity. Ambiguous expressions can result in unpredictable output.

           Example:
                 COMPUTE X = (X+Y)*(X-Y)

                 X+Y, while not strictly correct, may get accepted

                 X-Y will be treated as a single variable X-Y, and not X-Y, and will result in an error if a minus was intended.

                 Expected COBOL Syntax:

                       COMPUTE X = (X + Y)*(X - Y)* Y** (-Z)

  1. The ROUNDED keyword is ignored.
    Example:

                   COMPUTE X ROUNDED = (X+Y)*(X - Y)* Y** (-Z)

  1. DISPLAY statement with the keywords as below is ignored.
    AT, UPON, WITH [NO] ADVANCING

  2. Call Statement: JCL is the main program, and COBOL is a subprogram in which JCL passing input to the subprogram is not implemented.

    • The GIVING phrase is not implemented as IBM COBOL does not support this function.

    • CALL BY VALUE supporting datatypes: COMP, COMP-5, BINARY, POINTER, INDEX, FLOAT, DOUBLE, NUMERIC LITERALS.

  3. Onsize Error :         MULTIPLY WS-NUM1 BY WS-NUM3 GIVING WS-RESULT 

ON SIZE ERROR

 DISPLAY "ERROR WITH RESULT SIZE"

 NOT ON SIZE ERROR

DISPLAY "RESULT VALUE IS: " WS-RESULT.

 Native COBOL: WS-NUM1 PIC 9(3). WS-RESULT PIC 9(1).

             EGL Data type: 

                        WSNUM1 smallint;

                        WSRESULT smallint;

             Generated COBOL:

                         WSNUM1 PIC S9(4) COMP-4. 

                         WSRESULT PIC S9(4) COMP-4.

In EGL, we don’t have a length for INT variables like COBOL 9(2) / 9(5).

As WS-RESULT is s9(4) comp-4, it can accommodate only 4 digits.

Hence, the generated COBOL pgm does not throw “On Size Error” statements. If more than 4 digits, then the corresponding “OnSizeError”  statements are invoked.

  1. Post-conversion, Leading Zeros/Spaces are being suppressed: VAR1 PIC 9(3) VALUE 12.

           DISPLAY VAR1 will display in the console as 012.

In the generated COBOL, the output is 12.

           In EGL, smallint converted to S9(4) COMP-4. When displaying any smallint, int, numeric, or decimal variable, the generated COBOL code removes or truncates preceding zeros. 

  1. Intrinsic Functions:

    • Seconds-from-formatted-time: This function implementation is performed in the EGL; however, as a native COBOL program, it throws a compilation error when the first argument is passed.

    • The functions “CHAR, COMBINED-DATETIME, HEX-TO-CHAR” give incorrect results in the native COBOL program.

  2. In COBOL File operations, opening a file in an extended mode (writing to existing files) is not supported in EGL(Generated COBOL).

  3. Dynamic Array (DEPENDING ON CLAUSE):

              Note 1:  We can not initialize dynamic arrays in structure records in EGL.

              Note 2: If we have initialized the static array in the structure record in EGL, we can't resize it in the main function

              Example:

              EGL Record:  

                   Record

                                $EmployeeRecord  type basicRecord

                                 5  $EmpId int ;

                                 5  $EmpName char(30) ;

                                 5  $NumDependents smallint  = 0;

                                 5  rec$DependentInfo $DependentInfo[10] ;

                    end

CASE 1:- Can not initialize the dynamic array inside structured  records:-  

                                            5  rec$DependentInfo  $DependentInfo[];

              OR 5  rec$DependentInfo $DependentInfo[]{maxSize=10};

 

 For reference:-  

https://help.blueproddoc.com/ibd/10.0.0/com.ibm.egl.lr.doc/topics/regl_core_structured_rec.html

 

   CASE 2:-  Can not resize the array "rec$EmployeeRecord.rec$DependentInfo.resize(5);"

 

Author 

Sasipriya B

Developer  – RBD

⚡️IBM z17 is here! Powered by the new IBM Telum II processor, IBM z17 makes more possible, empowering organizations to drive innovation and do more with their data while processing sixty percent more transactions per day than IBM z16. See what sets IBM z17 apart here.

0 comments
17 views

Permalink