RecordEditor Generate Option

  • Java JRecord Cobol code generation
  • Generate Options
  • Standard Template.
  • Pojo Template
  • Line Wrapper Template
  • Standard Pojo Template.
  • JRecord Utilities
  • Generate Code from file being edited.
  • Generate Java JRecord
  • Generate Python/Ruby

  • RecordEditor Generate Option

    The RecordEditor/ReCsvEditor Generate Menu has 2 basic functions:

    1. Generate Java~JRecord code from a Cobol Copybook/Cobol Data file (Option Java~JRecord code for Cobol) . The RecordEditor/ReCsvEditor will analyse the data file and try and work out the correct attributes for you.

    2. Generate code (Java~JRecord, Python etc) from the file being editted (Java and Python options).

    Note: You can download JRecord and its utilities from:

    JRecord.

    https://sourceforge.net/projects/jrecord/ - This package provides IO routines for reading Cobol Data files in Java.

    CobolToCsv

    https://sourceforge.net/projects/coboltocsv/ - Converts cobol data files to/from CSV files using a Cobol Copybook.

    CobolToXml

    https://sourceforge.net/projects/coboltoxml/ - Converts cobol data files to/from Xml files using a Cobol Copybook.


    Java JRecord Cobol code generation

    Select Generate >>> Java~JRecord code for Cobol:

    The the Generate screen is displayed:

    On the Generate Code for Cobol you should enter the Cobol Copybook, a sample Cobol Data file and the Cobol Dialect (most likely Mainframe Cobol). The RecordEditor/ReCsvEditor will try an work out what attributes apply to the file. You should change the attributes the attributes if needed. When happy you can either:

    Generate Options

    On this screen you select the Code Template and enter varous options

    Fields on the screen:

    Template Directory

    You can write use your own Code Templates instead of using those supplied with the RecordEditor/ReCsvEditor see JRecord CodeGen for details.

    Template

    A template is a set of skelton Java classes. The standard templates supplied with the RecordEditor/ReCsvEditor are:

    • "Standard Template." This template generates a Cobol Field Name class and sample read / write programs.

    • "Line Wrapper Template" This template generates

      • a Cobol Field Name class

      • a Line Wrapper class where access the fields by java getter/setter's for each field.

      • Sample read / write programs

    • "Standard Pojo Template." This is an extension of the "Line Wrapper Template" template. It adds these extra classes:

      • a a Java Pojo class for each Record type.

      • a class to copy the LineWrapper class to/from the pojo-line class

    Field Name Conversion

    Controls how Cobol-field names are converted into jeva names. Options include, Standard Camel Case, Replace minus (-) with underscore (_) and Replace minus (-) with 2 underscores (__).

    Package Id

    Java package id to use in the Generated java code.

    Output Directory

    Output directory where code is written.

    Directory Extension

    The variables get replace with current values and it is added to the Output Directory

    Standard Template.

    The standard is a fairly simple "Template", it generates 3 files

    1. A field name Class. This field name class holds all the Cobol Field names as java final variables. Rather than having to remember the Cobol Field names, you can then use Auto-Completion in your IDE. There will be issues if there are duplicate field names.
    2. A sample Read program.
    3. A sample Write program.

    The generated FieldName class is

    32 public class FieldNamesDtar020 {
    33 
    34     public static final RecordDtar020 RECORD_DTAR020 = new RecordDtar020();
    35 
    36     public static class RecordDtar020 {
    37        public final String keycodeNo = "KEYCODE-NO";
    38        public final String storeNo = "STORE-NO";
    39        public final String date = "DATE";
    40        public final String deptNo = "DEPT-NO";
    41        public final String qtySold = "QTY-SOLD";
    42        public final String salePrice = "SALE-PRICE";
    43     }
    44 }
    45 
    

    The generated read code is

    60         AbstractLine line;
    61         int lineNum = 0;
    62 
    63         try {
    64             ICobolIOBuilder iob = JRecordInterface1.COBOL
    65                                        .newIOBuilder(copybookName)
    66                                            .setFont("CP037")
    67                                            .setFileOrganization(Constants.IO_FIXED_LENGTH)
    68                                            .setSplitCopybook(CopybookLoader.SPLIT_NONE)
    69                                            .setDropCopybookNameFromFields(true)
    70                                        ;
    71 
    72 
    73             FieldNamesDtar020.RecordDtar020 rDtar020 = FieldNamesDtar020.RECORD_DTAR020;
    74             AbstractLineReader reader = iob.newReader(salesFile);
    75             while ((line = reader.read()) != null) {
    76                 lineNum += 1;
    77                 System.out.println(
    78                               line.getFieldValue(rDtar020.keycodeNo).asString()
    79                       + " " + line.getFieldValue(rDtar020.storeNo).asString()
    80                       + " " + line.getFieldValue(rDtar020.date).asString()
    81                       + " " + line.getFieldValue(rDtar020.deptNo).asString()
    82                       + " " + line.getFieldValue(rDtar020.qtySold).asString()
    83                       + " " + line.getFieldValue(rDtar020.salePrice).asString()
    84                    );
    85             }
    86 
    87             reader.close();
    88         } catch (Exception e) {
    

    Pojo Template

    With Pojo template you can Read/Write a Cobol data file as a java Pojo. To do this, the template will generate code to convert a Cobol Data Record to/from a Java Pojo + readers / writers for the file.

    Generated example Reader class:

    65         IReader<LineDtar027Pojo> reader = null;
    66         int lineNum = 0;
    67         try {
    68             IoBuilder<LineDtar027Pojo> iob = IoBuilderDtar027.newIoBuilder(copybookName);
    69             LineDtar027Pojo line;
    70 
    71             reader = iob.newReader(dataFile);
    72 
    73             while ((line = reader.read()) != null) {
    74                 lineNum += 1;
    75 
    76                System.out.println(
    77                               line.getKeycodeNo()
    78                       + " " + line.getQtySold()
    79                       + " " + line.getSalePrice()
    80                    );
    81             }
    

    Generated Pojo Class:

    36     private String keycodeNo;
    37     private int qtySold;
    38     private BigDecimal salePrice;
    39 
    40     public String getKeycodeNo() {
    41         return keycodeNo;
    42     }
    43 
    44     public void setKeycodeNo(String value) {
    45         this.keycodeNo = value;
    46     }
    47 
    48     public int getQtySold() {
    49         return qtySold;
    50     }
    51 
    52     public void setQtySold(int value) {
    53         this.qtySold = value;
    54     }
    55 
    56     public BigDecimal getSalePrice() {
    57         return salePrice;
    58     }
    59 
    60     public void setSalePrice(BigDecimal value) {
    61         this.salePrice = value;
    62     }
    63 }
    64 
    

    Line Wrapper Template

    The lineWrapper is an extension of the "Standard Template.", it adds a LineWrapper class

    1. The LineWrapper class - this class has getter/setters methods for the Cobol Fields. These getter/setter call the getFieldValue(...) method of the "wrapped" line.
    2. A field name Class. This field name class holds all the Cobol Field names as java final variables. Rather than having to remember the Cobol Field names, you can then use Auto-Completion in your IDE. There will be issues if there are duplicate field names.
    3. A sample Read program.
    4. A sample Write program.

    The generated FieldName class is

    36 public class FieldNamesDtar027 {
    37 
    38     public static final RecordDtar027 RECORD_DTAR027 = new RecordDtar027();
    39 
    40     public static class RecordDtar027 {
    41        public final String keycodeNo = "DTAR027-KEYCODE-NO";
    42        public final String qtySold = "DTAR027-QTY-SOLD";
    43        public final String salePrice = "DTAR027-SALE-PRICE";
    44     }
    45 }
    46 
    

    Note: This is exactly the same as fieldname class generated by "Standard Template."

    The generated LineWrapper class is

    36 public class LineDtar027JR implements IGetByteData {
    37 
    38     private AbstractLine line;
    39 
    40     private static FieldNamesDtar027.RecordDtar027 fn
    41                    = FieldNamesDtar027.RECORD_DTAR027;
    42 
    43 
    44 
    45     public String getKeycodeNo() {
    46         return line.getFieldValue(fn.keycodeNo).asString();
    47     }
    48 
    49     public void setKeycodeNo(String value) {
    50         this.line.getFieldValue(fn.keycodeNo).set(value);
    51     }
    52 
    53     public int getQtySold() {
    54         return line.getFieldValue(fn.qtySold).asInt();
    55     }
    56 
    57     public void setQtySold(int value) {
    58         this.line.getFieldValue(fn.qtySold).set(value);
    59     }
    60 
    61     public BigDecimal getSalePrice() {
    62         return line.getFieldValue(fn.salePrice).asBigDecimal();
    63     }
    64 
    65     public void setSalePrice(BigDecimal value) {
    66         this.line.getFieldValue(fn.salePrice).set(value);
    67     }
    68 
    69 
    70 
    71 
    72 
    73     @Override
    74     public byte[] getData() {
    75         return line.getData();
    76     }
    77 
    78     @Override
    79     public void setData(byte[] data) {
    80 
    81         if (line instanceof Line) {
    82             ((Line) line).setData(data);
    83         } else {
    84             throw new RuntimeException("Invalid line for setdata");
    85         }
    86     }
    87 
    88     public LineDtar027JR setLine(AbstractLine l) {
    89         line = l;
    90         return this;
    91     }
    92 }
    93 
    

    The generated read code is

    69             ICobolIOBuilder iob = JRecordInterface1.COBOL
    70                                        .newIOBuilder(copybookName)
    71                                            .setFont("cp037")
    72                                            .setFileOrganization(Constants.IO_FIXED_LENGTH)
    73                                            .setSplitCopybook(CopybookLoader.SPLIT_NONE)
    74                                        ;
    75 
    76 
    77            LineDtar027JR lineDtar027JR = new LineDtar027JR();
    78 
    79 
    80            AbstractLineReader reader = iob.newReader(dataFile);
    81            while ((line = reader.read()) != null) {
    82                lineNum += 1;
    83                lineDtar027JR.setLine(line);
    84                System.out.println(
    85                               lineDtar027JR.getKeycodeNo()
    86                       + " " + lineDtar027JR.getQtySold()
    87                       + " " + lineDtar027JR.getSalePrice()
    88                    );
    89             }
    90 
    91             reader.close();
    

    Standard Pojo Template.

    The StdPojo template is an extension of the "Line Wrapper Template". The Read/write programs + the FieldName and Line**JR classes are very similar to the LineWrapper versions.

    What you need to understand with StdPojo template is the relationship between the ILine... interface and it's two implementing classes. For DTAR027:

           Interface                    Implementing class
     
                           +---- LineDtar027JR   - Implemented as a wrapper around a
                           |     |           ^     JRecord Line
                           |     |           |
      ILineDtar027Upd -----+     | toPojo()  | set(ILineDtar027 line)
                           |     |           |
                           |     V           |
                           +---- LineDtar027Pojo - Implemented using standard java
                                                   types, it does no reference JRecord
     
     
    

    For the Read, FieldName and LineDtar027JR classes see there versions in the <a href="#lwdtls">LineWrapper</a> template.

    For IDtar027Pojo:

    30 public interface IDtar027Pojo extends IDtar027Upd, IDtar027 { }
    

    32 public interface IDtar027 {
    33 
    34     public String getKeycodeNo();
    35     public int getQtySold();
    36     public BigDecimal getSalePrice();
    37 }
    38 
    

    32 public interface IDtar027Upd {
    33 
    34     public abstract void setKeycodeNo(String value);
    35     public abstract void setQtySold(int value);
    36     public abstract void setSalePrice(BigDecimal value);
    37 
    38     public abstract void set(IDtar027 value);
    39 }
    40 
    

    Finally the LinePojo looks like:

    35 public class LineDtar027Pojo implements IDtar027Pojo {
    36 
    37     private String keycodeNo;
    38     private int qtySold;
    39     private BigDecimal salePrice;
    40 
    41     @Override
    42     public String getKeycodeNo() {
    43         return keycodeNo;
    44     }
    45 
    46     @Override
    47     public void setKeycodeNo(String value) {
    48         this.keycodeNo = value;
    49     }
    50 
    51     @Override
    52     public int getQtySold() {
    53         return qtySold;
    54     }
    55 
    56     @Override
    57     public void setQtySold(int value) {
    58         this.qtySold = value;
    59     }
    60 
    61     @Override
    62     public BigDecimal getSalePrice() {
    63         return salePrice;
    64     }
    65 
    66     @Override
    67     public void setSalePrice(BigDecimal value) {
    68         this.salePrice = value;
    69     }
    70 
    71 
    72     public void set(IDtar027 value) {
    73         CodeDtar027
    74             .assignDtar027(
    75                 this, value);
    76     }
    77 }
    78 
    

    JRecord Utilities

    Generating bet / shell script / Javascript for the all the utilities is basically the same. You need to enter the Cobol Copybook, a sample Cobol Data file and adjust attributes as necessary:

     

    When ready select the Generate drop down menu and select the utility / language:

     

    The destination screen should be displayed next:

     

    Click the Generate Code button and the generated code will be displayed:


    Generate Code from file being edited.

    When editing a file in the RecordEditor/ReCsvEditor, you can generate code to read / write the file via the generate menu:

     

    Select the language/template combination and thendestination screen is displayed:

     

    Enter the required fields and hit the Generate Code button an the system should display the generated code:


    Generate Java JRecord

    This option will generate Java code to read/write Csv and Fixed width (Single record files) using the JRecord package (https://sourceforge.net/projects/jrecord).

    In the ReCsvEditor you can generate code either from the <i>Open File</i> or the Editor screens:

    There are 3 models available.

    IoBuilder

    This very basic JRecord. This <i>model</i> generates a <i>FieldName</i> class + sample read/write classes.

    LineWrapper

    This <i>model</i> generates a <i>Java Wrapper</i> class for the Csv/Fixed-Width record + sample read/write classes

    Pojo

    This <i>model</i> generates both a <i>Java Wrapper</i> and <i>Pojo/JavaBean</i> classes for the record (as well as sample read/write programs.


    Generate Python/Ruby

    This option generates python/ruby code from a file read/write the file being viewed.

    Finally the geneated python Code