Declaring Variables

I will write a script below that explains how to declare and print variables. We will declare several variables in the data division (FIRST-VAR, SECOND-VAR, etc) and then print them in the procedure division using DISPLAY.

PIC stands for picture (not sure why it is called this) and it is a keyword we use to define a variable. We use functions of the form type(elements). So 9(3) would correspond to laying aside enough room in memory for storing a number with 3 values. Above we define many variables and then print them out. You may also notice the 01 values before each declaration, and the 05 value before sub variables. These numbers are called level numbers and indicate to cobol what kind of variable we are declaring. 01 is for top level variables, 05 is group level variables under some other variable. Below are the functions and what each data type above corresponds to.

9 — numeric

A — alphabetic

X — alphanumeric

V — decimal

S — sign

A final example:

01 CAT-PEOPLE PIC X(15) VALUE '12@4A!D$'.

Would create a variable called CAT-PEOPLE with space for 15 alphanumeric elements that only actually fills out 8 of them. You may have noticed that I do this above in the subgroup. Here is another data declaration resource.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *