Introduction to tables/arrays

Speaker Notes

Slide 1:

COBOL allows the programmers to set up TABLES in the Data Division to access information. Similar structures in other languages are frequently called ARRAYS.

Slide 2:

In this example, I am going to follow the first table program at the Web site called

In this example, I have employees that are assigned to 4 depts:

DEPT-NO

DEPT-NAME

1

MENS

2

WOMENS

3

GIRLS

4

BOYS

The department number comes in on the input. I need to set up a table in WORKING-STORAGE to use to access the department name.

Slide 3:

When the program is moving the other fields from the input to the output, it also has to move the name of the department. To do this, the programmer will move the redefined name that occurs 4 times, DEPT-NAME modified by the input DEPT-NO which has a number 1. 2. 3 or 4 and therefore can be used as the subscript to tell which DEPT-NAME to move.

If DEPT-NO = 1 than DEPT-NAME(DEPT-NO) will move MENS.

If DEPT-NO = 2 than DEPT-NAME(DEPT-NO) will move WOMENS.

If DEPT-NO = 3 than DEPT-NAME(DEPT-NO) will move GIRLS.

If DEPT-NO = 4 than DEPT-NAME(DEPT-NO) will move BOYS.

Slide 4:

This slide shows sample data being processed. Mary Smith has a DEPT-NO of 2 so when DEPT-NAME(DEPT-NO) is moved it is as if DEPT-NAME(2) was moved. This puts WOMENS on the line in the DEPT-NAME-PR field.

Slide 5:

This slide shows sample data being processed. Jennifer has a DEPT-NO of 3 so when DEPT-NAME(DEPT-NO) is moved it is as if DEPT-NAME(3) was moved. This puts GIRLS on the line in the DEPT-NAME-PR field.

Slide 6:

This slide shows sample data being processed. Stephen Daniels has a DEPT-NO of 4 so when DEPT-NAME(DEPT-NO) is moved it is as if DEPT-NAME(4) was moved. This puts BOYS on the line in the DEPT-NAME-PR field.

Slide 7:

This slide shows sample data being processed. Carl Hersey has a DEPT-NO of 1 so when DEPT-NAME(DEPT-NO) is moved it is as if DEPT-NAME(1) was moved. This puts MENS on the line in the DEPT-NAME-PR field.