The Data Monster Under my bed : Migrating Cobol to the cloud – Part 5: Lets display a variable

If you remember in PART 3 we, going trough the divisions and there where we saw that there is a “DATA DIVISION

DATA DIVISION – description (s) and definition (s) of data items referenced by the program (names, lengths, decimal point location, formats, and other)

Data division explanation from part 3

The “DATA DIVISION” takes care of not only the defining and describing data items.
It also refers to the items and all memory allocations that are required and used in the program in order to manipulate data.

It consists of 3 main sections ( FILE SECTION, WORKING-STORAGE SECTION, LINKAGE SECTION), but in order to keep it short and on the point we will use the:

WORKING-STORAGE SECTION

Initialised and used as temporary storage when you execute the program this section is where we define our variables for internal usage, names and their memory allocations, that cannot be accessed from outside of the program.

sample WORKING-STORAGE SECTION

Why so strange ???

You see the data types of COBOL are the most frustrating and fascinating in the same time definitions considered.

Cobol is graded in simple and group such data items, that you can freely create your data with all needed priorities to create your own types and structures.

Initially looks really frustrating (and at certain extend over time you may fine really strange cases) when you start, but once you get it, it gets really addictive and helps you understand the meaning of the words “data type” in its fullest potential.

In the DATA DIVISION everythin is defined by several really good placed markers.

Lets take a single line from the example above:

Disclamer:

In order to keep it short, we are going to briefly touch the topic and expand with time, in order to focus more on the hands on experience, the topic will be furthermore explored in upcoming series.

The correct terms that are defining variable here are as follows:

Level Number –

  • Level number – specifying the level of data in a given record, can (most often) used to differentiate between elementary items and group items.
    • Elementary items – describe a single data item and cannot be divided. As you can see it is mandatory for them to hold all of the terms (level number, data name, picture clause and value)
    • Group Items – are composition of one or more elementary items. Difference from the elementary items is that the only mandatory terms to be used are level number and data name.
  • Data name – Is memory location of the data being stored as defined by the user variable name. Consisting of non reserved word name of the variable, defined in the DATA DIVISION in order to be used in the PROCEDURE DIVISION.
  • Picture clause – the picture clause defines the shape, size and type of the variable itself, this is the place where you get creative and use only what you need and consider for appropriate use with some room for growth or not. We define the type if it is numeric, alphabetical, alpha-numeric, with or without special signs, the sign (+-), decimal point positions, and the length of the variable in bytes. We will explore the levels and the picture clause on their own, as the topic can expand to a quite big and boring for some. But yet again this freedom is so fascinating that it is one of the major key selling points that COBOL has.
  • Value clause – following the rules of the picture clause and initialising the data item, this clause is optional.

Lets display variable and expand our previous example

As we remember in the last example we displayed a simple hello world literal string in the procedure division.

but based on the limitations of the language we know (line number for example) and the rules that we have inbuilt to tackle those limitations (how a sentence is defined for example) we can construct a concatenation and overcome the limitations we have.

And knowing that and the fact that we can use the variable name, we can expand our example by displaying different mixes of both.

Now lets run our example

Lets rerun the docker build and run our new example:

The full codebase and the docker build for this article, is available for my patrons on PATREON

TO BE CONTINUED …