1 Reply Latest reply on Jan 31, 2017 3:16 PM by Cheng Fang

    Cobol ItemReader and ItemWriter

    Richard Moore Master

      I have a requirement to process data from our legacy Cobol system with Cobol data (comp, comp-3, zoned decimal) formats. Do you have any suggestions or words of warning?


      Here is what the code looks like that will do this. Should I do this with an ItemReader and Writer or just with a batchlet?


      import java.text.SimpleDateFormat;

      import java.util.Date;



      import net.sf.JRecord.Common.Constants;

      import net.sf.JRecord.Common.IFieldDetail;

      import net.sf.JRecord.Details.AbstractLine;

      import net.sf.JRecord.External.CopybookLoader;

      import net.sf.JRecord.IO.AbstractLineReader;

      import net.sf.JRecord.IO.CobolIoProvider;

      import net.sf.JRecord.Numeric.ICopybookDialects;



      public final class TaxDetTest {



        private static final double GST_CONVERSION = 1.1;



        private String installDir = "";

        private String input = installDir + "GO.AGT.QAC070.SORT08.QACDET";

        // private String output = installDir + "DTAR020out.bin";

        private String copybookName = installDir + "TAXDETCC.cbl";




        * Example of LineReader / LineWrite classes


        private TaxDetTest() {




        int lineNum = 0;

        double gstExclusive;

        AbstractLine record;



        try {

        CobolIoProvider ioProvider = CobolIoProvider.getInstance();


        AbstractLineReader reader = ioProvider.getLineReader(







        IFieldDetail dateField = reader.getLayout().getFieldFromName("TAXDET-DET-DATE");

        IFieldDetail taxUnitField = reader.getLayout().getFieldFromName("TAXDET-DET-TAXUNIT");

        IFieldDetail facField = reader.getLayout().getFieldFromName("TAXDET-DET-FAC");



        //AbstractLineWriter writer = ioProvider.getLineWriter(reader.getLayout(), output);



        while ((record = reader.read()) != null) {

        lineNum += 1;



        Map<String, IFieldDetail> map = record.getLayout().getFieldNameMap();

        for (String key : map.keySet()) { System.out.println(key + " = " + map.get(key).getType()); }



        Date d = inputDateFormat.parse(record.getFieldValue(dateField).asString());


        System.out.println("[" + lineNum + "] " + SDF.format(d) + " " +

        record.getFieldValue(taxUnitField).asBigDecimal() + " " +



        System.out.print(record.getFieldValue("KEYCODE-NO").asString() + " "

        + record.getFieldValue("QTY-SOLD").asString() + " "

        + record.getFieldValue("SALE-PRICE").asString());



        gstExclusive = record.getFieldValue("SALE-PRICE").asDouble() / GST_CONVERSION;






        System.out.println(" " + record.getFieldValue("SALE-PRICE").asString());







        } catch (Exception e) {

        System.out.println("~~> " + lineNum + " " + e.getMessage());









        public static void main(String[] args) {

        new TaxDetTest();



        private static final SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyyMMdd");

        private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd");


        • 1. Re: Cobol ItemReader and ItemWriter
          Cheng Fang Master

          JBeret does not have any pre-built components to work with COBOL systems.  I have no experience with it, and don't know how common the use case is.  If it is, we can certainly consider adding it.


          Whether to use batchlet or chunk step, it depends on the volumn of your data, and how you want data to be processed.  If there are limited amount of data, and you don't care about restart, skip, retry, checkpointing, transaction, then you can use batchlet, which treats the total amount of work as one unit.  It either complete successfully or fail.


          With chunk-type steps, you can divide up the data into more manageable chunks (say 1000 rows per chunk).  If 10 chunks succeeded and 11th failed, when you restart the job execution, it will just restart from the 11th chunk.  You can also divide the data in a parallel fashion to run in partitions where multiple partition threads run concurrently.


          If your COBOL system has some sort of data export or dump mechamism, you may want to export the data into some other forms, which may be easier to process.