I brought the tool from my first job back to life, in a browser

· · 5 min read

Lire cet article en français

In 2005, I was 20 and starting my first job as a developer. It looked nothing like what I do today. No framework, no Git, no browser. A green-screen emulator on a PC, 80 columns by 24 lines, a keyboard with PF keys, and a COBOL generator: PACBASE.

We didn't type COBOL, or hardly any. We described things. Data items first, in a dictionary shared by the whole team: a code, a label, a format. Then records, built from those items. Then the processing, line by line, in a simplified language organised into numbered functions. The generator did the rest, and the rest was hundreds of lines of COBOL that we almost never read.

What stayed with me is that green screen. Glowing letters on a black background, a blinking cursor, and nothing else.

And it hasn't completely gone away. Look over a sales assistant's shoulder in some big retail chains, when they look up a product or place an order: there's a good chance you'll see the same screen. Somewhere behind it, COBOL is still running.

This weekend, I wanted to find out whether I could bring that way of working back to life. Not to write COBOL again: out of curiosity, and a bit of nostalgia.

What the workshop does

The COBOL Workshop is not a copy of PACBASE (neither its name nor its screens). It's an original generator, inspired by its approach, that runs entirely in the browser:

  • a data dictionary (code, label, PIC format);
  • records built from those items, and control breaks on up to three levels;
  • a structured language: you write lines grouped by function and sub-function, with a handful of operators (M to move, A to add, C to compute, MES to display, ECR to write a file, SQL for the database);
  • a batch skeleton generated around it: initialisation, reading (with read-ahead), control break detection, end of processing, report printing, in old-school numbered functions;
  • a DB2-style database, with EXEC SQL and an SQLCODE (0, 100, -803…) just like back then;
  • and a 3270 terminal mode: green screen, keyboard only, Tab, PF keys, keyboard lock and Esc to reset.

You describe, you generate, you read the COBOL it produces (fixed format, columns 8 and 12, as it should be), and you run it. The SYSOUT is displayed, along with any output files.

How do you run COBOL in a browser?

My first idea was to do what this site does for PHP: compile the real compiler to WebAssembly. For PHP, that works very well. For COBOL, it's another story: GnuCOBOL translates COBOL into C, and then you need a C compiler. Shipping both in a web page adds up to tens of megabytes.

So the workshop contains a COBOL interpreter written in JavaScript (a little over a thousand lines, no dependencies). It only covers a subset of the language: sequential files, SORT, PERFORM, COMPUTE, PIC clauses and their editing symbols (Z, 9, -, .)… But it really reads the source: you can edit the generated COBOL by hand and run it again.

The trap with a home-made interpreter is fooling yourself. So every test program without a database is also compiled with the real GnuCOBOL, and the two outputs are compared line by line. On every test case (multi-level control breaks, negative numbers, three decimal places, filters…), they are identical.

The database is SQLite compiled to JavaScript (sql.js). The interpreter turns the host variables (:NAME) in EXEC SQL statements into bound parameters and returns DB2's SQLCODEs. There's even an interactive query screen, for those who remember SPUFI.

What it reminded me of

Seeing those screens again mostly reminded me of an idea we've somewhat forgotten: describe rather than write. A shared data dictionary, an imposed skeleton, custom code only where it's needed. Twenty years later, we find it again in our code generators (Symfony's makers, for example), and now in the code AI writes for us. But that's another article.

And I have to admit I had forgotten a lot. The keystrokes, where control breaks were declared… I had to reopen the old manuals to remember. What I did remember very well was the order of the functions: initialisation at the start, the read loop in the middle, end of processing last.

Your turn

The workshop is online, no account, nothing to install: apprendre.forelse.fr/en/cobol-workshop (the terminal mode, green screen included, is at /en/cobol-workshop/terminal).

And for those who want to get their hands dirty, here's the first of the old-timer's challenges: the sales report. It's 2005, and the sales director wants his report on his desk by 8 a.m. tomorrow: sales grouped by salesperson, a subtotal and a sales count for each, then the grand total. Zero-value sales don't count. The file and the dictionary are ready; only the processing is left: open challenge #1.

Never used this kind of tool? The cheat sheet explains the screens, functions and control breaks in ten minutes. No hints, though: it's a challenge.

The workshop checks your result. When it says "Challenge passed", click "Send my solution": it comes straight to me.

And if you've worked on green screens yourself, tell me the memory that has stuck with you the most.

One last question: would you be interested in a course for learning COBOL this way, by describing rather than typing? Let me know in the comments, or through the contact form. If enough of you are, I'll get to work on it.

← All articles