[4GL/ABL] FOR EACH "nested" and "FOR EACH, EACH" is the same thing?

... or there's some substantial differences?

/* Trovare le righe d'ordine associate all'ordine dell'ultimo cliente nella tabella del DB */

FIND LAST customer.
DISPLAY customer.name.

FOR EACH order, EACH orderline OF order WHERE order.custnum = customer.custnum:
    DISPLAY orderline WITH FRAME a TITLE "MODO 1".
END.

FOR EACH order
:
    FOR EACH orderline OF order WHERE order.custnum = customer.custnum
    :
        DISPLAY orderline WITH FRAME b TITLE "MODO 2".
    END.
END.

[PS]
run with DB Sports2000


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The results are the same,

The results are the same, however the first one (MODO 1) will perform better if there are lots of ORDER records without ORDERLINE records. Not a usual situation to have only order headers without some order details but could happen. In the first example a single query is sent to the server whereas the second will request all of the order records in one query first and then for each of those orders it will request a seperate query for the orderline records.


Matrixbob's picture

My friend tell me that the

My friend tell me that the correct syntax should be:

FOR EACH order WHERE order.custnum = customer.custnum, EACH orderline OF order
:
DISPLAY orderline WITH FRAME c TITLE "MODO 3".
END.


Matrixbob's picture

Incredible, i thinked that

Incredible, i thinked that the second (MODO 2) was the extended writting of the compact (MODO 2).
I didn't image that the bytecode in output was different .... O_o

I thinked that the compilator generate the same bytecode... mistery of OE architecture. :)