Bharat
Bharat

Reputation: 177

PROGRESS 4GL - When to use FOR FIRST, CAN-FIND and FIND FIRST?

I am new to progress 4GL. I'm always willing to write a proper code and willing to know each end every keyword that we are using but following sample queries giving same results. I don't know when to use FIND FIRST, FOR FIRST and CAN-FIND? Please help me by re-writing with impeccable answer

FOR EACH Customer NO-LOCK:
    FOR FIRST Order OF Customer:
    /*somelogic*/
    END.
END.

FOR EACH Customer NO-LOCK:
    FIND FIRST Order OF Customer NO-LOCK NO-ERROR.
    IF AVAILABLE Order THEN
    /*somelogic*/
END.

FOR EACH Customer NO-LOCK:
  IF CAN-FIND(FIRST  Order OF Customer ) THEN
  DO:
        /*somelogic*/
  END.
END.

Upvotes: 2

Views: 3561

Answers (1)

jdpjamesp
jdpjamesp

Reputation: 772

FOR FIRST scopes the record you find to a block. It avoids having to check the availability of the record when you reference it in the block as the block won't execute if it's not available.

FIND FIRST should never really be used. You have no control over which record will be the first to be found if there are many, and if there is just one you should just use FIND without the FIRST. That way the code explains what is expected, and you can test for AMBIGUOUS to ensure someone hasn't done something silly.

CAN-FIND is used for checking if a record exists without actually pulling that record back to the client side. There will be no record available in the buffer so you can't use the data. It's an excellent way of checking if a record exists without the overhead of pulling the content back across the wire. Use it if you don't care about the data.

Upvotes: 5

Related Questions