PERFORM UNTIL EOF —

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

Romanian Web developer’s plugin provides a bridge to the mid-20th century.

Grace Hopper presents COBOL in this 1961 image.
Grace Hopper presents COBOL in this 1961 image.

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 Bizău Ionică 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 Ionică:

// 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://stackoverflow.com/q/938760/1420197

       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!
// => ------------

Ionică 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.

Channel Ars Technica