Mainframe programming — NATURAL/ADABAS tutorial. Part 1— setup process and “Hello World” code

Basics of Mainframe programming for beginners.

Natalia Nazaruk
codeburst

--

This is my second article about developing on Mainframe in NATURAL language and the first one in which we actually will get our hands dirty programming. If you want to read the previous one, which was a gentle introduction to the world of Mainframes, don’t hesitate to check it.

You can find all the parts of this tutorial in the links below:

  1. Intro — a few words of introduction.
  2. Part 1 — setup process and “Hello World” code
  3. Part 2 — how to work with database
  4. Part 3 — error Handling and Debugging Techniques

How to install NATURAL on your PC?

As I am working directly (well…through the emulator to be honest) on the Mainframe machine, I didn’t need to install the language or the IDE on my laptop. However, it is perfectly possible to program in NATURAL on your own PC. To do that, you should navigate to Software AG website, as they are the creators of the language, as well as ADABAS database. You can find everything you need there. Just note that you can download for free only trial version, so do that at the time you want to start playing around with NATURAL.

Once you have installed NATURAL/ABADAS you can also try NaturalONE, which is a nice, eclipse-like IDE. They provide in documentation all the instructions you might need, along with some basic programs’ examples.

Basic syntaxt and our first, simplest programs

Let’s take a look at the language’s syntax. It is fairly easy, much easier that most modern programming languages like Java, C# or even Kotlin. Most commands or keywords are just the same words you would use in natural language (sic!). Sometimes these are shortcuts or delicate modifications, however, for the vast majority of the time you can easily guess what the given keyword means. Some examples of simple yewords are: move, if, end, define etc. More on this later in next parts of this tutorial!

Now let’s talk about some other simple rules of NATURAL. As in any programming language you can define your variables. Those variables can be local or global (sound familiar?). By convention you should name local variables with # at the beginning. That way it is easy to distinguish them from global variables or database fields.

Commenting in NATURAL is as easy as placing an asterisk at the start of the line. There are also other possibilities. You can use * or ** or /*. One thing to remember is that if you want to put a comment at the end of the code line you need to use /*. Other options won’t work in that case.

You don’t need any other symbols, brackets or anything you would normally expect while learning programming. Of course NATURAL use brackets here and there, but we’ll get to that later. To end a program you simply put “END” in the last line of it. Similarly, when you want to end variables definition you write “end-define”, when you want to end if statement you write “end-if” end so on.

Simplest “Hello World”

Ok, so I guess it’s time to see some examples. Those below are pretty self-explanatory, so let’s just dive in the code. What would be language tutorial without a “Hello World” example?

0010 * THIS PROGRAM PRINTS “HELLO WORLD”
0020 WRITE ‘HELLO WORLD’
0030 END

“Hello World” with input from user

The previous example was something really looking just boring, so let’s try more complicated (to some extend) example. Here you can see the variables definition at the beginning of the program. Note, that when you define a variable you need to declare what type it is and how many characters it can have on maximum. You can also see a “level” of the variable (more on this in the future). So the line below means, that we have a 1st level variable named #NAME and it should be alphanumeric no longer than 20 characters.

1 #NAME (A20)

In the line 0050 we can see our first keyword “INPUT”, and it does what you could expect. It waits for user to put something on the screen and then do something with it. Pretty straightforward, right?

0010 * THIS PROGRAM TAKES INPUT FROM THE USER AND THEN PRINTS IT
0020 DEFINE DATA LOCAL
0030 1 #NAME (A20)
0040 END-DEFINE
0050 INPUT 'WHAT IS YOUR NAME?'#NAME
0060 WRITE 'HELLO ' #NAME
0070 END

I guess it is enough for now. What do you think about this 4GL language? I hope you like it and you will follow my tutorials in the future. Happy coding!

This article is part of a series I write about NATURAL programming. Please note, that I am currently working as a junior mainframe developer, so I learn the secrets of the language myself. If you see any errors in my articles, please let me know! If you like the article and you believe there should be more articles about Mainframes please clap a bit, leave a comment or share this link wherever you want.

--

--

Android developer (Kotlin 💯). #GDG3city organiser 💻 Soft Skills advocate. Winner of Google & Udacity scholarships. Dogs & Cats 😍