dev-resources.site
for different kinds of informations.
COBOL Tutorial Series: Condition (IF, ELSE) statement - Session 3
Published at
10/19/2024
Categories
cobol
development
banking
tutorial
Author
Duc Nguyen Thanh
Hello, I'm Duke
In the previous 2 sessions, I have guided you on how to develop, compile and create a simple calculation program using COBOL.
Now, I will systematize the knowledge of the previous two articles and explain more about COBOL syntax
1. Variable declaration
Data in COBOL is declared in the DATA DIVISION
and variables are usually defined in the WORKING-STORAGE SECTION.
IDENTIFICATION DIVISION.
PROGRAM-ID. SimpleVariable.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NAME PIC A(20) VALUE 'Duke'.
01 WS-AGE PIC 9(2) VALUE 32.
PROCEDURE DIVISION.
Main-Process.
DISPLAY 'Name: ' WS-NAME.
DISPLAY 'Age: ' WS-AGE.
STOP RUN.
-
WS-NAME
is a string variable of length 20 and default value is 'Duke'. -
WS-AGE
is a 2-digit integer variable with default value 32. - The program displays the declared name and age
2. Condition (IF..ELSE) statement
COBOL allows the use of IF
... ELSE
statements to test conditions and control the flow of execution based on the test results.
IDENTIFICATION DIVISION.
PROGRAM-ID. LoginCheck.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-USERNAME PIC X(20).
01 WS-PASSWORD PIC X(20).
01 WS-STORED-USERNAME PIC X(20) VALUE 'Duke'.
01 WS-STORED-PASSWORD PIC X(20) VALUE 'HjhXhxw8-P]wY4;'.
PROCEDURE DIVISION.
Main-Process.
DISPLAY 'Enter your username: '.
ACCEPT WS-USERNAME.
DISPLAY 'Enter your password: '.
ACCEPT WS-PASSWORD.
IF WS-USERNAME = WS-STORED-USERNAME AND
WS-PASSWORD = WS-STORED-PASSWORD
DISPLAY 'Login successful! Welcome, ' WS-USERNAME '!'
ELSE
DISPLAY 'Invalid username or password!'.
STOP RUN.
and here is the result
Repository here
Articles
12 articles in total
Hugging Face: The AI Revolution You Can't Ignore!
read article
Introduction to Chatbot (Bot) Framework SDK in .NET
read article
AI Bot: Intelligent Financial Query Assistant Powered by PostgreSQL and Ollama
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
My Experience with GitHub Copilot
read article
My Hacktoberfest 2024 Experience: Pushing Boundaries with C# 12 and .NET 8 🚀
read article
COBOL Tutorial Series: Working with Database - Session 5
read article
COBOL Tutorial Series: Loop statements - Session 4
read article
COBOL Tutorial Series: Condition (IF, ELSE) statement - Session 3
currently reading
COBOL Tutorial Series: A calculation program - Session 2
read article
COBOL Tutorial Series: Developing Without a Mainframe - Session 1
read article
Featured ones: