Consultor Eletrônico



Kbase P75577: 4GL. Is it possible to have multidimention arrays with Progress
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   07/04/2004
Status: Unverified

GOAL:

4GL. Is it possible to have multidimention arrays with Progress

FIX:

Progress only allow 1 dimention arrays.

def var a as int extent 10.
where each element are represented as you know a[1]...a[10}

In way to achieve a 2 to n dimention array you can use a temp-table or physical table with n fields, depending on how many dimentions your array need.
You will have to manage it yourself.
It has, a better management than simple array, in the sense that temp-tables and physical-tables can be indexed and simple array don't.

Array(Array(0, 1), Array(10, 9), Array(15, 1))

TableRecordN((Field1,Field2), (Field10, Field9), (Field15.Field1)).

Only to demonstrate that and Multi-dimension (2 dimention) array can be represented by a table:

Here this small example.
Of course the reference to an array element it's indexed elements, here in the example (PrimaryIndexField, TableField).

The good thing with this approach is that for a row of the array all the elements of that row/array are available.
The reason why multidimention arrays cannot be defined.
Because you can represent an array by a table.
More if you plan to think in more than 2 dimentions arrays, by using a relation form 1 to N between tables this allows a multidimention array


DEFINE VARIABLE browse-hdl AS WIDGET-HANDLE NO-UNDO.
DEFINE BUTTON btn-quit LABEL "&Quit"  AUTO-ENDKEY.
DEFINE FRAME MyFrame SKIP(10) btn-quit WITH SIZE 80 BY 22.
DEFINE VAR year-hdl AS HANDLE NO-UNDO.
DEFINE VAR month-hdl AS HANDLE NO-UNDO.
DEFINE VAR day-hdl AS HANDLE NO-UNDO.
DEFINE VAR element-hdl AS HANDLE NO-UNDO.
DEFINE VAR week-hdl AS HANDLE NO-UNDO.

/* This is a multi-dimention array definition sample */
DEFINE TEMP-TABLE MyArray NO-UNDO
   FIELD ArrayYEAR AS INT LABEL "Year"
   FIELD ArrayMONTH AS INT LABEL "Month"
   FIELD ArrayDAY AS INT LABEL "Day"
   FIELD arrayCounter AS INT LABEL "Element"
   FIELD arrayweek AS INT LABEL "week"
   INDEX IArrayElement IS PRIMARY ArrayCounter ASCENDING
   INDEX IArrayYear ArrayYear ArrayMONTH Arrayday ASCENDING.

DEF VAR i AS INT INIT 2004 NO-UNDO.
DEF VAR j AS INT INIT 1 NO-UNDO.
DEF VAR K AS INT INIT 1 NO-UNDO.
DEF VAR z AS INT INIT 0 NO-UNDO.
DEF VAR Y AS INT INIT 1 NO-UNDO.

DEFINE QUERY q1 FOR myarray SCROLLING.

/* Creating a Dynamic Browse for my array elements (Temp-table) */
CREATE BROWSE browse-hdl
       ASSIGN TITLE = "Dynamic Browse"
       FRAME = FRAME MyFrame:HANDLE
       QUERY = QUERY q1:HANDLE
       X = 2
       Y = 2
       WIDTH = 74
       DOWN = 10
       VISIBLE = YES
       SENSITIVE = TRUE
       READ-ONLY = NO.

/* Adding columns to the browser */
year-hdl = browse-hdl:ADD-LIKE-COLUMN("myarray.arrayyear").
month-hdl = browse-hdl:ADD-LIKE-COLUMN("myarray.arraymonth").
day-hdl = browse-hdl:ADD-LIKE-COLUMN("myarray.arrayday").
element-hdl = browse-hdl:ADD-LIKE-COLUMN("myarray.arraycounter").
week-hdl = browse-hdl:ADD-LIKE-COLUMN("myarray.arrayweek").

/* Feeding the Multidimention Array (Temp-Table) with elements (record) */
DO j = 1 TO 12:
 IF (j = 1 OR j = 3 OR J = 5 OR j = 7 OR j = 8 OR j = 10 OR j = 12) THEN DO:
   DO k = 1 TO 31:
       z = z + 1.
       RUN createday (INPUT i, INPUT j, INPUT k, INPUT z, INPUT Y).
   END.
 END.
 IF J = 2 THEN DO:
    DO k = 1 TO 29:
        z = z + 1.
       RUN createday (INPUT i, INPUT j, INPUT k, INPUT z, INPUT Y).
   END.
 END.
 IF (j = 4 OR j = 6 OR j = 9 OR j = 11) THEN DO:
    DO k = 1 TO 30:
        z = z + 1.
       RUN createday (INPUT i, INPUT j, INPUT k, INPUT z, INPUT Y).
   END.
 END.
END.

/* procedure to create elements in the array (temp-table records) */
PROCEDURE createday:
   DEFINE INPUT PARAMETER pi AS INT NO-UNDO.
   DEFINE I.NPUT PARAMETER pj AS INT NO-UNDO.
   DEFINE INPUT PARAMETER pk AS INT NO-UNDO.
   DEFINE INPUT PARAMETER pz AS INT NO-UNDO.
   DEFINE INPUT PARAMETER py AS INT NO-UNDO.

CREATE myarray.
    arrayYear = pi.  /* Element 1 */
    ArrayMonth = pj. /* Element 2 */
    arrayday = pk.   /* Element 3 */
    arraycounter = pz. /* Element 4 */
    arrayweek = pz / 7 .

END procedure.

OPEN QUERY q1 FOR EACH myarray NO-LOCK.

ENABLE ALL WITH FRAME MyFrame.
WAIT-FOR CLOSE OF CURRENT-WINDOW..