Lesson 1

Hello World - Your First Program and its Structure. Simple Display Statement

Getting Started with COBOL

Welcome to our first dive into COBOL programming! In this lesson, you'll write your very first COBOL program. We'll look at the basic structure of a COBOL program and learn how to display text on the screen.

Understanding the structure and basic commands is your foundation for all future COBOL programming. By the end of this lesson, you'll have a solid grasp of how to structure your COBOL code and generate output. Let's get coding!


COBOL is a high-level programming language that was designed for business applications. It's been around since the late 1950s and is still widely used today. COBOL is known for its readability and self-documenting code, making it easy to understand and maintain. COBOL code is first compiled using a COBOL compiler and then executed on a mainframe or other compatible system. It's a powerful language that's used in many critical systems, such as banking, insurance, and government applications.

What You'll Learn

In this lesson, we will cover the basic structure of a COBOL program and focus on how to use the DISPLAY statement. Here’s a breakdown of what we'll explore:

  1. Program Structure: Understanding the key divisions in a COBOL program.
  2. Comments: Learning how to add comments to your code.
  3. Display Statement: Using the DISPLAY statement to show text on the screen.

Here's the complete code we'll be working with:

1IDENTIFICATION DIVISION. 2PROGRAM-ID. HelloWorld. 3 4*> This is a comment and will be ignored by the compiler 5PROCEDURE DIVISION. 6 *> Another comment 7 DISPLAY "Hello, Banking World". 8 STOP RUN.
Understanding the Structure of the Code

Every COBOL program starts with the IDENTIFICATION DIVISION. This section is mandatory, and it provides basic information about the program.

  • IDENTIFICATION DIVISION: The header that starts every COBOL program.
  • PROGRAM-ID: This is used to specify the name of the program. In our example, the program name is HelloWorld.

The PROCEDURE DIVISION is where the actual program logic and instructions are written. This is where your code tells the computer what to do.

1*> This is a comment and will be ignored by the compiler 2PROCEDURE DIVISION. 3 *> Another comment 4 DISPLAY "Hello, Banking World". 5 STOP RUN.
  • PROCEDURE DIVISION: This signals the beginning of the procedural part of the COBOL program where actions are specified.
  • DISPLAY "Hello, Banking World": This command outputs the text "Hello, Banking World" to the screen.
  • STOP RUN: This command terminates the program. It tells the operating system that the program has finished its execution.

Let's pay attention to several key points regarding the syntax:

  • The period (.) at the end of each line is essential in COBOL. It indicates the end of a statement,. It is not mandatory for some statements, but it is a good practice to include it.
  • Notice that the keywords are written in uppercase. COBOL is not case-sensitive, but it is a common practice to write keywords in uppercase to make the code more readable.
  • Similarly, indentation is not mandatory in COBOL, but it is a good practice to use it to make the code more readable.
Adding Comments to Your Code

Comments are an essential part of programming. They help you and others understand what your code is doing. In COBOL, comments are started with *>. Here is the comment extracted from the previous code:

1*> This is a comment and will be ignored by the compiler

Comments are ignored by the compiler and are used to provide information about the code. They can be used to explain the purpose of the program, describe the logic, or provide any other relevant information.

Main Divisions in COBOL Programs

COBOL programs are divided into four main divisions:

  • IDENTIFICATION DIVISION: Contains information about the program, such as the program name and author.
  • ENVIRONMENT DIVISION: Describes the environment in which the program will run. It's also used for input/output files. We'll not cover this division in this lesson.
  • DATA DIVISION: Defines the data structures used in the program. We'll cover this in future lessons.
  • PROCEDURE DIVISION: Contains the actual program logic and instructions.
Why It Matters

Knowing how to create and structure a COBOL program is essential. COBOL stands for Common Business-Oriented Language, and it's widely used in business, finance, and administrative systems for companies and governments.

Mastering the basics will set you up for more complex tasks later on. Being able to display output is a fundamental skill, useful for debugging and providing user information.

Are you ready to see your first COBOL program in action? Let's jump into the practice section and make it happen!

Enjoy this lesson? Now it's time to practice with Cosmo!

Practice is how you turn knowledge into actual skills.