Why COBOL ? True is that my 1st touch with COBOL was at SUN Microsystem in around 2004 or 2005. I don't exactly remember but it was due to some Bank system project. Yes, Cobol is even nowadays widely used in Government, Banks or Industrial systems. Maybe not so much on mainframes but ;) they are still there too. COBOL is used in many legacy applications such as batch and transaction processing jobs. Actually you may be surprised how JVM helps to run COBOL programs, but this is out of the scope of this short post.
1. Installing a COBOL compiler on MAC Mojave.
I'll use the homebrew (The missing package manager for the macOS). Open your terminal and type:
$ brew install gnu-cobol
2. Writing the 1st COBOL Program
I'm using VIM on Mac. Sure when you are on Windows or Linux machine you have a possibility to use Visual COBOL for Eclipse from MicroFocus which has a lot more features, or maybe others but I'm familiar with this one. For this post purposes the VIM is more than enough.
Open the terminal create a "hello_cobol.cob" file with the following content:
$ vi hello_cobol.cob
--- hello_cobol.cob ---
program-id. hello_cobol.
data division.
working-storage section.
01 HELLO_MESSAGE PIC X(12) VALUE "Hello COBOL!".
procedure division.
display HELLO_MESSAGE.
goback.
end program hello_cobol.
---
--- hello_cobol.cob ---
program-id. hello_cobol.
data division.
working-storage section.
01 HELLO_MESSAGE PIC X(12) VALUE "Hello COBOL!".
procedure division.
display HELLO_MESSAGE.
goback.
end program hello_cobol.
---
3. Compiling and running the program
As you can see code is very nicely separated into the sections. To get more information about the code structure see for example following guide. To compile a code executed the following command:
$ cobc -free -x hello_cobol.cob
After the successful execution the hello_cobol file is created. This file contains the compiled code and we can run it by:
$ ./hello_cobol
Output:
Hello COBOL!
Output:
Hello COBOL!
Conclusion:
Cobol is pretty imperative, procedural language it can be a lot fun. As a Java programer you may don't want to forget that the parameters in COBOL are mostly passed by the references not by values. Java does manipulated object by references, and all object variables are references but Java doesn't not pass arguments by references, Java passes them by value!
Keep Coding!
No comments:
Post a Comment