开发者

Searching a Table (COBOL)

I have been trying to use a table for the first time and I have hit a small snag. I have figured out how to make a table, but I cannot figure out how to search the table or move the stored information to another field. Here is the table:

   01  SALESMAN-TABLE.
       05  TABLE-ENTRIES OCCURS 99 TIMES.
           10 SALESMAN-NUMBER              PIC 99    VALUE ZEROS.
           10 SALESMAN-NAME                PIC X(20) VALUE SPACES.
   01  SALESMAN-COUNT                      PIC 9(3)  VALUE ZEROS.

This is what I got so far to try and search for data:

   510-TABLE-SEARCH.
       SEARCH TABLE-ENTRIES
           WHEN SALESMAN-NUMBER (ROUTINE-CHECK) = ROUTINE-CHECK
               PERFORM 520-WRITE-FILE
           WHEN SALESMAN-NUMBER (ROUTINE-CHECK) = 0
               CONTINUE
       END-SEARCH.

开发者_StackOverflow社区And this is what I am using to move the data:

       SET DL-NAME-COLUMN TO SALESMAN-NAME

but it says that DL-NAME-COLUMN should be numeric even though SALESMAN-NAME is alphanumeric. What should I do? Any help will be appreciated.


You should index your table using something like:

05  TABLE-ENTRIES OCCURS 99 TIMES INDEXED BY IND-TABLE-ENTRIES.

Then you can use the SEARCH verb:

510-TABLE-SEARCH.
   SEARCH TABLE-ENTRIES
       UNTIL SALESMAN-NUMBER (IND) = 0
       WHEN SALESMAN-NUMBER (IND) = ROUTINE-CHECK
           PERFORM 520-WRITE-FILE
   END-SEARCH.

Table indices are always numeric since they are used as pointers (they contain a memory address). The SET verb is normally used to modify table indices.


Use

MOVE SALESMAN-NAME (IND)   TO DL-NAME-COLUMN

instead of

SET DL-NAME-COLUMN TO SALESMAN-NAME
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜