Sunday, May 24, 2009

Cobol data + Cobol copybook + Java conversion

Although I'm absolutely not a fan of Cobol, it's still inevitable in the Finance IT development sector.

Lately, we needed a way to let Cobol and Java data work together, and we didn't want to hard code the complete data structure. To make this possible we noticed different non-free applications exist, but the open source project Cb2Xml got our attention.

This project already worked out some Java code to parse a Cobol copybook and convert it into an XML representation. (The copybook can be seen as the interface of the Cobol data). But this project was mend to import and export data from xml to Cobol stream and vice-versa, while we needed some Java objects to work with the received Cobol data input.

So I added some extra code to convert a Cobol data stream (String) into a Java object (using a Hashtable internally). Now, it's possible to provide a String of Cobol data and its interface definition (Cobol copybook file) and return a Java CobolElements object. One can search in this CobolElements object based on the name or xpath. I made a simple example to test, which might make it clear how to use the code.

A simple example of Cobol copybook used as data interface:

 01 ACCOUNT-GROUP                                               .
  02 ACCOUNT                                              .
   03 DFND                                 PIC  9(4)             .
   03 DCTB                                                       .
    04 DUPD                                PIC  9(8)             .
    04 DNUMCTB                                                   .
     05 DCTB-12                            PIC  9(12)            .
     05 DCTB-04                            PIC  9(4)             .
     05 DFMT                               PIC  9(2)             .
    04 DCDRCTB                                                   .
     05 DRGOCDRCTB                         PIC  9(1)             .
     05 DROFCMCCDRCTB                      PIC  9(3)             .
     05 DBRACMCCDRCTB                                            .
      06 DBRACMCCDRCTB                     PIC  9(6)             .
      06 GBRACDRCTB                                               
             REDEFINES DBRACMCCDRCTB                             .
       07 DROFCDRCTB                       PIC  9(3)             .
       07 DBRACDRCTB                       PIC  9(3)             .
    04 DBLK                                PIC  9(2)              
             OCCURS 5                                            .
    04 DBLK2                               PIC  9(3)              
             OCCURS 5                                            .

The data that should match this copybook:

input = "00000000000039300022955600000123703602231122334455111222333444555"; 

Converting the data to a Java CobolElements object:

  • Converting the copybook to an xml representation (this XML Document should be created once for each copybook and can be cached):

Document cb2doc = Cb2Xml.convert(new File(_cobolCopybookFileName), _debug); 

  • Converting the Cobol data stream (input string) to it's matching Java representation:

CobolElements cobolElements = Dat2Java.convertWithDoc(input, cb2doc); 

Retrieving data from the CobolElements object:

CobolElement childElement = cobolElements.retrieveChildElement("GOUTCTT-CSISEQ/GANSCTT-CSISEQ/GCTB/GNUMCTB/NCTB-12"); 
//returns: 393000229556 
childElement = cobolElements.retrieveChildElement("ACCOUNT-GROUP/ACCOUNT/DCTB/DBLK[3]"); 
//returns: 44 

Download source and jar (zip 1,78MB) (link updated 16/09/2009)

Update (27/11/2009): After creating the cobol2java, we found another interesting open source project called LegStar. They have a completely worked out solution, while the code we use is quite basic and only usable with simple copy books...

Eclipse project

eclipse Each project (workspace) in Eclipse has it's own .project file. To easily open the correct workspace with Eclipse, I wrote a little batch script that can be associated in Windows with the .project files. Now, I only have to double click the .project file and Eclipse will be loaded in the correct workspace.

  • Save the batch script bellow and make sure the correct Eclipse.exe file is used. You might want to change the Eclipse options if required.
  • Double click on a .project file, the first time Windows will ask how to open this file. Choose the .bat batch file script to open your .project file and make sure to make Windows remembers this option.
  • Eclipse will now open with the correct workspace loaded.
@echo off
set ECLIPSE_BIN=R:\tools\eclipse\eclipse.exe
set ECLIPSE_OPTIONS=-refresh -showlocation -Xmx512M -XX:MaxPermSize=512m
cd ..
@echo on

Download batch script.

Monday, May 11, 2009

LogExpert - Windows tail freeware

Today I tested yet another Windows tail application, LogExpert, and I was very amazed with its features!
It has most of the features I'm used to work with in BareTail Pro, like adding some filters (regex) or highlighting lines matching some text. And unlike WinLogTail, it does support opening multiple files at one with a tabbed interface as in BareTail.
Besides all this, I really appreciate the following functions:
  • run some specified application and providing some information of the selected line. This way, one can easily open the tailed file within UltraEdit on the selected line.
  • parse the timestamps of a log file and show these in separated columns
  • freeze some columns to make these alway be shown and only scrolling other columns (horizontal scrolling)
  • advanced filtering with possibility to show some lines before or after the line matching your filter
  • activate an 'edit' mode to easily copy some parts of a line
  • add some bookmarks and comments on a line to easily find these back afterwards
  • support for multifiles (show files as app.log, app.log1, app.log2, etc as one big file)
  • support for different files provided on the command line while opening, so the scripts we used to open many files with BareTail also work with LogExpert (but opening many files from shared drives is not as lighting fast as with BareTail)

So, compared to BareTail it has many benefits and it's completely free! But one should know, it's not always as fast and stable as BareTail, but so far it worked very well for me.

Some nice screenshots (but those only show a small subset of all it's features):