Monday, August 17

Calling 1959 from your Web code: A COBOL bridge for Node.js

Have you ever wanted to just cut and paste some of that legacy COBOL code from mainframe applications into your latest Web application? No? Well, Romanian Web developer Ionică Bizău has developed a way to do just that, creating a COBOL bridge for Node.js, the JavaScript-based cross-platform runtime environment that has become a go-to technology for server-side Web development. The plugin is an attempt to breathe new life into the programming language derived from the work of computing pioneer Admiral Grace Hopper.

Published under the “Kindly” license (as in, if you want to use it in a commercial application, you should “kindly ask the author”), Node COBOL requires you install GNUCobol along with it. COBOL code can then be embedded in JavaScript. Here’s an example provided by Bizău:

// Dependencies
var Cobol = require("cobol");

// Execute some COBOL snippets
Cobol(function () { /*
       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLO.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       PROCEDURE DIVISION.

       PROGRAM-BEGIN.
           DISPLAY "Hello world".

       PROGRAM-DONE.
           STOP RUN.
*/ }, function (err, data) {
    console.log(err || data);
});
// => "Hello World"

Cobol(__dirname + "/args.cbl", {
    args: ["Alice"]
}, function (err, data) {
    console.log(err || data);
});
// => "Your name is: Alice"

// This will read data from stdin
Cobol(function () { /*
       IDENTIFICATION DIVISION.
       PROGRAM-ID. APP.
      *> http://ift.tt/1gQFy0X

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       SELECT SYSIN ASSIGN TO KEYBOARD ORGANIZATION LINE SEQUENTIAL.

       DATA DIVISION.
       FILE SECTION.
       FD SYSIN.
       01 ln PIC X(64).
          88 EOF VALUE HIGH-VALUES.
       WORKING-STORAGE SECTION.
       PROCEDURE DIVISION.
       DISPLAY "Write something and then press the  key"
       OPEN INPUT SYSIN
       READ SYSIN
       AT END SET EOF TO TRUE
       END-READ
       PERFORM UNTIL EOF
       DISPLAY "You wrote: ", ln
       DISPLAY "------------"
       READ SYSIN
       AT END SET EOF TO TRUE
       END-READ
       END-PERFORM
       CLOSE SYSIN
       STOP RUN.
*/ }, {
    stdin: process.stdin
  , stdout: process.stdout
}, function (err) {
    if (err) {
        console.log(err);
    }
});
// => Write something and then press the  key
// <= Hi there! // => You wrote: Hi there!
// => ------------

Bizău notes on his GitHub page that Node COBOL is ready for use in production—though he knows of no one who is doing so as of yet.

Read on Ars Technica | Comments

No comments:

Post a Comment