
Larry C. answered 07/26/19
Computer Science and Mathematics professional
One thing that COBOL does fairly well is deal with internal tables. These are typically sections of the WORKING-STORAGE SECTION that have a layout of data that is repeated a number of times and then redefined as a table for easy searching, keeping running totals and so on. For example:
05 STATE-ABBREVIATIONS.
10 FILLER PIC X(15) VALUE 'AKAlaska'.
10 FILLER PIC X(15) VALUE 'ALAlabama'.
...
10 FILLER PIC X(15) VALUE 'WYWyoming'.
05 ST-ABBREV-TABLE REDEFINES STATE-ABBREVIATIONS OCCURS 50 TIMES.
10 ST-ABBREVIATION PIC XX.
10 ST-NAME PIC X(13).
Then you can use the table to do things like validate a state field in a file.
SEARCH ST-ABBREV-TABLE VARYING SUB1
AT END some code to execute because the file data wasn't a valid state abbreviation
WHEN SOME-FILE-FIELD EQUAL ST-ABBREVIATION(SUB1) some code to handle valid state abbreviation
END-SEARCH.
We also could've specified that the abbreviations were in order (assuming the table was coded correctly) and done a binary search instead of a sequential one.