【发布时间】:2021-02-08 08:19:58
【问题描述】:
我正在基于业务逻辑在 RPGLE 程序中加载一个数组,这可能会导致数组中出现重复数据。
我首先想知道如何检测重复。
最后我想知道如何删除数组中的重复项。
【问题讨论】:
标签: ibm-midrange rpgle
我正在基于业务逻辑在 RPGLE 程序中加载一个数组,这可能会导致数组中出现重复数据。
我首先想知道如何检测重复。
最后我想知道如何删除数组中的重复项。
【问题讨论】:
标签: ibm-midrange rpgle
在添加之前,您可以使用 %LOOKUP 查看该条目是否已在数组中。
if %lookup(newValue : array : 1 : numElems) = 0;
// the element is not in the array yet
numElems += 1;
array(numElems) = newValue;
endif;
【讨论】:
检测数组中的重复条目非常简单:
0.) sort the array
1.) loop through the array and check if the current item matches the previous item
2.) if so, then remove the current item or
或者你可以
0.) create a temporary array
1.) loop through the original array and check if the current item is already contained in the temp arrayitem
2.) if not, then copy the current item into the temp array
3.) clear the original array and copy them from the temp to the oiginal array
这里你有一个关于这个主题的一般问题:Array remove duplicate elements 这是一个关于在 RPGLE 中执行此操作的线程:https://code400.com/forum/forum/iseries-programming-languages/rpg-rpgle/7270-check-for-duplicates-in-array-of-size-50
如果删除重复项后原始数组中的条目顺序必须相同,那么第二种方法会更好
编辑:犯了一个错误,第二种方法不需要任何排序(删除这一点)
【讨论】: