Welcome back! In the previous lesson, you learned about defining and working with alphabetic variables in COBOL. Now, it's time to move on to another important topic: handling numbers. Understanding how to manage numeric data in COBOL is crucial, as many business applications require precise calculations and data manipulations.
In this lesson, you will learn how to define and use numeric variables in COBOL. Specifically, you will cover the following:
-
Numeric Variables:
- How to declare numeric variables.
- How to assign values to numeric variables.
-
Using the
DISPLAYStatement:- How to print numeric values to the screen.
Let's take a look at an example to see these concepts in action:
In COBOL, numeric variables are used to store and manipulate numerical data. They are defined using the PIC clause followed by a specification that indicates the type and size of the number.
For example:
01 Account-Number PIC 9(10).declares a numeric variable namedAccount-Numberthat can store up to 10 digits.01 Short-Account-Number PIC 9(5) VALUE 1234.declares a numeric variable namedShort-Account-Numberthat can store up to 5 digits and is initially set to1234.
Notice how the PIC clause is used to define the variable type and size. In this context, 9 indicates a numeric digit placeholder. When initializing variables, as seen with Short-Account-Number, you can use the VALUE keyword.
