正在进行的阵列长度?

时间:2015-03-10 14:27:19

标签: progress-4gl openedge

给定两个数组(例如1,2,3,4,52,3,1,0)。查找第二个数组中不存在第一个数组的数量。如何才能获得正在进行的阵列长度4gl?

3 个答案:

答案 0 :(得分:4)

如果有问题的对象是ARRAY而不是LIST,则使用EXTENT()函数来确定元素的数量。使用数组:

define variable a1 as integer no-undo extent 5 initial [ 1, 2, 3, 4, 5 ].
define variable a2 as integer no-undo extent 4 initial [ 2, 3, 1, 0 ].

define variable i as integer no-undo.
define variable j as integer no-undo.

define variable ok as logical no-undo.

do i = 1 to extent( a1 ):
  ok = no.
  do j = 1 to extent( a2 ):
    if a1[i] = a2[j] then ok = yes.
  end.
  if ok = no then message a1[i] "is not in a2".
end.

答案 1 :(得分:1)

要获得列表的长度(列表中的项目数),您可以使用NUM-ENTRIES()函数。

要知道某个项目是否存在于列表中,您可以使用LOOKUP()功能。

因此,对于您的示例,您可以执行以下操作:

DEFINE VARIABLE wclist1 AS CHARACTER  NO-UNDO   INITIAL "1,2,3,4,5".
DEFINE VARIABLE wclist2 AS CHARACTER  NO-UNDO   INITIAL "2,3,1,0".

DEFINE VARIABLE wc-list-no-present AS CHARACTER  NO-UNDO.

DEFINE VARIABLE wi-cpt AS INTEGER    NO-UNDO.

/* For each items of list1 */
DO wi-cpt = 1 TO NUM-ENTRIES(wclist1, ","):

    /* Test if the item is in list 2 */
    IF LOOKUP(ENTRY(wi-cpt, wclist1, ","), wclist2, ",") = 0 
    THEN
        wc-list-no-present = wc-list-no-present + "," + ENTRY(wi-cpt, wclist1, ",").
END.

/* TRIM is to remove the first "," */
DISPLAY TRIM(wc-list-no-present, ",").

答案 2 :(得分:0)

def var a as int extent 5 initial [1,2,3,4,5] no-undo.
def var b as int extent 4 initial [2,3,1,0] no-undo.
def var i as int no-undo.
def var j as int no-undo.

loop:
repeat i = 1 to extent(a):

    repeat j = 1 to extent(b):
        if a[i] = b[j]
        then next loop.
    end.
    Display a[i] "not in b array" format "x(20)".
end.