2

Given two arrays, ( for example 1,2,3,4,5 and 2,3,1,0). Find which number of first array is not present in the second array. How can i get Length of Arrays in progress 4gl ?

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
The Reason
  • 7,705
  • 4
  • 24
  • 42
  • Is it an array? i.e. define variable a as integer no-undo extent 5 initial [1,2,3,4,5]. or a list? i.e. define variable c as character no-undo initial "1,2,3,4,5". – Tom Bascom Mar 10 '15 at 15:02
  • yes this is array not a list – The Reason Mar 10 '15 at 15:30
  • Some code that shows what you have tried would have been useful. As it stands this question reads like homework or an interview question. – Tom Bascom Mar 10 '15 at 15:37
  • I have beed studying progress for 2 weeks, so i have found some exercise and i am trying to do them, Tom, Could you recommend me some book about Porgress 4GL? – The Reason Mar 10 '15 at 15:46

3 Answers3

4

If the object in question is an ARRAY, rather than a LIST, you use the EXTENT() function to determine the number of elements. Using arrays:

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.
Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
1

To have the length of a list (number of items of the list), you can use NUM-ENTRIES() function.

To know if an item is present in a list, you can use LOOKUP() function.

So for your example, you can do something like this:

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, ",").
doydoy44
  • 5,720
  • 4
  • 29
  • 45
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.
Ajinkya
  • 1
  • 3