[vc_row][vc_column][vc_column_text]Using a dimensioned matrix in basic can be used to increase performance in some applications. The matrix can cache records commonly read from the disk. This works best when you are reading a small number of records over a much larger set of records.
An example is you have 100 stores and you are updating the store records with credit card transactions which number in the thousands or millions. You would cache the store records in the dimensioned matrix and then write them out at the end of the process. The code is written for brevity in the post.
Example:
[/vc_column_text][/vc_column][/vc_row]
PROGRAM UPDATE.STORE.CC
DIM STORES(100)
STORE.IDS = "" ;* ATTR 1 = STORE.ID, ATTR 2 = POINTER TO WHERE THE RECORD IS AT IN THE MATRIX
STORE.PTR = 0
*
OPEN '','STORES' TO STOTRES.FV ELSE STOP
OPEN '','CC.TRANS' TO CC.TRANS.FV ELSE STOP
SELECT CC.TRANS.FV
EOF = @FALSE
LOOP
READNEXT CC.TRANS.ID ELSE EOF = @TRUE
UNTIL (EOF) DO
READ CC.TRANS.REC FROM CC.TRANS.FV, CC.TRANS.ID ELSE CONTINUE
STORE.ID = CC.TRANS.REC<1>
LOCATE(STORE.ID,STORE.IDS,1;STORE.POS;"AR") ELSE ;* LOCATE IS FASTER THAN A DISK IO
STORE.PTR = STORE.PTR + 1 ;* MAKE ROOM FOR A NEW STORE RECORD
READ STORES(STORE.PTR) FROM STORES.FV, STORE.ID ELSE CONTINUE ;* READ THE STORE RECORD ONCE
INS STORE.ID BEFORE STORE.IDS<1,STORE.POS> ;* UPDATE ATTR 1
INS STORE.PTR BEFORE STORE.IDS<2,STORE.POS> ;* UPDATE ATTR 2
END
STORE.PTR = STORE.IDS<2,STORE.POS> ;* GET POINTER TO STORE IN MATRIX
STORE.REC = STORES(STORE.PTR) ;* CACHED STORE RECORD
...
REPEAT
* WRITE OUT CACHE TO DISK
FOR I = 1 TO STORE.PTR
STORE.ID = STORES.IDS<1,I>
STORE.PTR = STORES.ID<2,I>
WRITE STORES(STORE.PTR) ON STORES.FV, STORE.ID
NEXT I
STOP
END