dev-resources.site
for different kinds of informations.
COBOL Tutorial Series: A calculation program - Session 2
Published at
10/19/2024
Categories
development
cobol
banking
Author
ngtduc693
Author
9 person written this
ngtduc693
open
Hello. I'm Duke
In the previous article, I showed you how to program and compile COBOL applications on Windows 11 without a mainframe computer through WSL (Debian) and Visual Studio Code.
Now, I will guide you how to write a very simple calculation program, allowing you to calculate the sum of 2 numbers entered from the keyboard.
First, create the calculate.cbi
file
IDENTIFICATION DIVISION.
PROGRAM-ID. SimpleAddition.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Number1 PIC 9(4).
01 Number2 PIC 9(4).
01 Result PIC 9(4).
PROCEDURE DIVISION.
Main-Process.
DISPLAY "Enter first number (0-9999): "
ACCEPT Number1
DISPLAY "Enter second number (0-9999): "
ACCEPT Number2
COMPUTE Result = Number1 + Number2
DISPLAY "The sum of " Number1 " and " Number2 " is " Result
STOP RUN.
Then, run the following commands:
cobc -x calculate.cbl
./calculate
and here is the result
Some notes:
PIC 9(4)
means:
-
9
: indicates that the variable will containdigits
(0-9). -
(4)
: specifies that the variable can contain up to4 digits
.
Repository here
cobol Article's
30 articles in total
Modernizing COBOL Applications for Free: A Practical Guide with GnuCOBOL
read article
COBOL Interpreter
read article
COBOL Tutorial Series: DB2 vs SQL Server Architecture Comparison - Session 7
read article
COBOL Tutorial Series: Install the DB2 on Windows/Linux - Session 6
read article
COBOL Tutorial Series: Working with Database - Session 5
read article
COBOL Tutorial Series: Condition (IF, ELSE) statement - Session 3
read article
COBOL Tutorial Series: A calculation program - Session 2
currently reading
COBOL Tutorial Series: Loop statements - Session 4
read article
COBOL Tutorial Series: Developing Without a Mainframe - Session 1
read article
Warum?
read article
Awesome COBOL!
read article
#12in24: Learning COBOL in 1h.
read article
The World Depends on 60-Year-Old Code No One Knows Anymore ๐ด๐ป๐
read article
Tests Everywhere - COBOL
read article
COBOL: El Lenguaje de Programaciรณn que Desafรญa el Paso del Tiempo
read article
Entiende de una vez los lenguajes de alto y bajo nivel
read article
How Did You Get Started with COBOL?
read article
How to make an XML element optional in a Cobol provider webservice (DFHLS2WS), based on a Cobol structure
read article
How to create a flexible number of xml-elements in a cobol provider webservice (DFHLS2WS), starting from a cobol-structure.
read article
Advent of Code, but differently
read article
Covid led me to my first open-source contribution
read article
Test Driven Design in COBOL
read article
OpenCobolIde "no compiler found or not working"
read article
Mainframe Interview Experience with XYZ Bank | Jan 2022
read article
100 Languages Speedrun: Episode 50: COBOL
read article
COBOL gets a hip replacement
read article
How to deal with COBOL REDEFINES?
read article
They're still talking COBOL
read article
Video and Q&A: Learn how COBOL and open source are used in modern mainframe ecosystem
read article
Programming language full forms and definition
read article
Featured ones: