Ford will ship and sell cars that are lacking chips

According to Automotive News, Ford will likely start manufacturing and shipping unfinished, but driveable vehicles that lack the chips that enable some non-safety features. Instead, within a year…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




The basics of COBOL programming language.

It is pretty stunning the number of things in the U.S. that this language is responsible for, 80% of all financial transactions, 95% of ATM transactions, the whole social security administration, the department of defenses payment system, the Internal Revenue Service, and the US state financial system just to name some of the most important. With the current pandemic, the need for COBOL programmers has risen. In New Jersey, Governor Phil Murphy is asking for volunteers who can program in COBOL, in order to assist the state’s unemployment-insurance systems, which have experienced an enormous increase in claims.

COBOL is a very English-like program that is pretty simple, it kinda reminds me of SQL. In this blog, I’m going to make a quick explanation of how this language works and the basics of it. COBOL is a very English like language that is pretty simple.

COBOL is a sequential programming language meaning that it runs from top to bottom, line by line. A very important syntactical rule is that after each statement we have to put a dot. Every COBOL program has four divisions: Identification, environment, data, and procedure. Let’s take a look at an example program to understand how these four divisions look in actual code.

Notice that there are two vertical to the left of our code? That space is supposed to be filled with line numbers simulating a punch card.

The objective of this first division is to give the program a name, an author, and even the date when it was written. While giving the program an author and a date are optional, all programs must have a name or a PROGRAM-ID.

Here we have given the program a name and an author.

The objective of this second division is to specify certain specifications regarding, file processing, what computer the program is running on, or country-specific information. All that is inside this section is only used for documentation purposes so it won’t change how the code is compiled or executed. Inside this division we have two sections: The Configuration section and the Input-output section.

Inside of the configuration section we specify the type of computer that the program was compiled and used.

We use a source-computer to specify the type of computer that is used to compile and object-computer for the type of computer that runs the program. In those times computer programs had a lot of dependencies, meaning that certain programs could only be used in certain computers but nowadays you can write a program in Windows and manipulate it with Linux.

The objective of this division is to define all the variables or constants that will be used in the program, so this division is pretty important. This division has four sections, file section where we specify data sent or received from the local storage of your computer, working-storage section where all the variables or constants are defined, linkage defines the data or variables that will be available for other programs, and report is used to write any documentation regarding reports. I will be going over working-storage in this blog because its the most essential part.

Working storage is where all are variables or constants will be declared, there are three main data-types in COBOL: Alphanumeric(A combination of numbers and letters) to define them we need to use an “X”, Alphabetic(only letters) to define them we need to use an “A”, and Numbers, to define them we use a 9. For all data-types, we write “PIC” before defining the data-type of the variable.

When we want to create variables we must follow a certain structure, variables can be nested into other variables, to differentiate the parent variable to its children we must add a number before the given name of the variable this will indicate COBOL the “position of the variable”. So before you get confused let’s see how we can put all this information together to actually write some code and understand what I am saying.

Here we can see that before every variable I am specifying that they are all “parent” variables. If you notice there is a parenthesis after each data-specification, inside of that parenthesis we will specify the number of maximum characters that the variable can have, having in mind that spaces also count as a character. Then we specify the value of each variable using the “VALUE” keyword, so MyName will now be equal to “Sebastian De Lima”, FavoriteNumber will equal 7, and Age “24 years old”, it’s important to keep in mind that we don’t need to necessarily give the variables a value right of the bat, we can always add the value in the next division, the procedure division.

So far our entire program looks like this:

*IMPORTANT NOTE: To write commentaries we use an asterisk symbol.

This is where we give the instructions to our program, here we utilize our variables and generate the flow of our application. I like to think that the DATA-DIVISION are all the ingredients to make a meal and the PROCEDURE-DIVISION is when we actually cook the meal, we add a certain quantity of the ingredients and cook them in a specific time, this is the same with this division. There are a lot of different tools that we can use for this division, here we can perform mathematical operations, get input from the user while saving it to a variable, output things to the console, and so much more.

So to execute are code we have different “verbs” that will tell our program what to do, in this blog I will talk about 4 main ones: DISPLAY, ACCEPT, COMPUTE, and MOVE.

“Display” is the command that will output to the console, you may know it as “console.log()” in JavaScript, “puts” in Ruby, or maybe stdout in C. To use display we simply write display and whatever we want to output, it can be a variable, a string, number, or all of the three combined, you can really display anything you want. Let’s try to display all the variables we previously saved in the past division.

Here I’m simply displaying my name followed by my favorite number and my age, notice how you can interpolate strings and variables without a problem. The “STOP RUN” keyword at the end is simply telling our program to end.

Now COBOL is a compiled language meaning that we have to manually compile it each time we want to run it, to compile it you simply run the command: “cobc -x <filename>” so in my case I would write “cobc -x index.cob” since my file name is index.cob. When we run this command a new file containing binary code will appear in our directory, to run the program we simply type the name of the new file which will always be the name of your other file but without the extension so in this case, I would just type “./index”. So let’s see how our program works!

Great! We can now output thing into the console, now remember I talked about nesting variables? Let’s take a deeper dive into that.

Notice that we didn’t give a value to DateBirth, instead, we added three new variables underneath it with the number two, this means that now those 3 variables are “children” of the DateBirth variable. We are specifying the Month to have 2 digits, day to have 2 digits, and year 3 digits, let’s see how we can access that data using the “ACCEPT” verb.

The accept verb is a command that will display a prompt in the console so that the user can input data, we can ask the user for any information, name, favorite food, and in this case date of birth. To use ACCEPT is the same as DISPLAY.

So we are displaying a question to the user “What is your date of birth?, after the question a prompt will appear waiting for input. Notice that after “ACCEPT” we write the variable DateBirth, so whatever the input of the user is will now be saved in the DateBirth variable. Let’s use that information to display the date.

And this will run execute like this:

There we have it! Now we know how to use the display and the accept verb, let’s see how we can do different mathematical operations with compute.

Compute is used to execute mathematical operations. It’s pretty straight forward so let’s see how it works.

So first we initialize the numbers that we want to use in our operations and another variable to store the result. Let’s see how we can add, subtract, multiply, and divide using this verb.

So here we are simply saving the result of each operation into the result variable and displaying it afterward, let’s see how this code runs:

Awesome! Now we know how to use COMPUTE for basic arithmetic let’s see how “MOVE” works.

“Move” is very simple as well, the function of this verb is to assign values into variables we can change the values of any variables with this verb, let’s see how it work:

Here we are simply creating a variable with no value, so whenever we run the program we won’t get any value, let’s see how we can change that:

Here we are literally moving the value “happy!” into the variable Humor, the syntax is pretty self-explanatory…So whenever we run the program we should get:

We can always change moods though:

Add a comment

Related posts:

How Much Motivation is Good for You

Most of us look at motivational videos as life-changing, what we often don’t realize is that motivational videos can sometimes even ruin our life. First of all, these videos are so well edited and it…