This is probably a rookie question, but I still have a hard time working out how to use tables in COBOL.
Currently I'm writing a simple module that can be called by other programs. My program has to search an internal table for data and if not found, add to it.
I have this table:
01 TB-1 OCCURS 10 INDEXED X1.
03 CLIENT-NAME PIC N(30).
03 ORDER-NUMBER PIC 9(06).
Of course I can increase the amount of OCCURS so the likelihood of table overflow decreases. However, when testing the module, I have to deal with the scenario that there's one more record to add that doesn't fit in the table.
What is the best way of dealing with this? I was thinking of preventing an ABEND by giving back an error message.
To do this, I thought I'd define a new field and using it as a counter. So basically, every time my module adds a record, it adds +1 to the counter as well. Kind of like this:
IF COUNTER < 10
PERFORM ADD-RECORD
ELSE DISPLAY 'INPUT HAS EXCEEDED MAX OF 10 OCCURRENCES'
GOBACK
END-IF
.
ADD-RECORD.
MOVE INPUT-CLIENT-NAME TO CLIENT-NAME(X1) IN TB-1.
MOVE INPUT-ORDER-NUMBER TO ORDER-NUMBER(X1) IN TB-1.
ADD +1 TO COUNTER
.
Is this a good way to do this? Do you have any other ideas? Thanks in advance for your help.