在 COBOL 中搜索和搜索所有内容

Search and Search All in COBOL

我想知道当我们尝试使用 SEARCH 或 SEARCH ALL 在 COBOL 中搜索项目时的结果,并且该项目在 table 中出现多次。 两者中的任何一个都能找到所有出现的地方吗?

Will any of the two will find all the occurrences ?

没有。 SEARCH 中的任何一个都将标识一个,并且只有一个 table 元素。

The SEARCH statement is used to search a table for a table element that satisfies the specified condition and to adjust the value of the associated index to indicate that table element.

对于 SEARCH,索引或标识符的最终值将是第一个 table 符合条件的元素。

对于SEARCH ALL,最终设置的搜索索引等于其中之一,但不确定是哪一个。

两者都不会,但是使用 search 您可以设置初始起始索引并进行第二次搜索以查找后续条目。

搜索

Search 动词通过 table 进行 线性 搜索。 Table 条目可以按任何顺序排列。

如果有多个条目,将找到起始索引后的第一个条目。

您可以使用Set index to动词设置起始位置。

搜索全部

Search All 执行 Table 的 binary search。 table 必须在 Key Sequence 中。 如果有多个匹配项,则可以找到任何一个。对于较大的 tables,Search All 将是更快的选项。