Try OpenEdge Now
skip to main content
ABL Reference
ABL Syntax Reference : LAST function
 

LAST function

Returns a TRUE value if the current iteration of a DO, FOR EACH, or REPEAT . . . BREAK block is the last iteration of that block.

Syntax

LAST ( break-group )
break-group
The name of a field or expression you named in the block header with the BREAK BY option.

Example

The first FOR EACH block produces a list of the on hand values of the items in inventory. It also automatically generates a total of these on hand values.
The second FOR EACH block does exactly the same thing, except it does not generate the total. Instead, the procedure uses the ACCUMULATE statement and the LAST function. Thus, you can substitute your own labels and formats for the grand total.
r-last.p
FOR EACH Item NO-LOCK BY Item.OnHand * Item.Price DESCENDING:
  DISPLAY Item.ItemNum Item.OnHand * Item.Price (TOTAL) LABEL "Value-oh"
    WITH USE-TEXT.
END.

FOR EACH Item NO-LOCK BREAK BY Item.OnHand * Item.Price DESCENDING:
  FORM Item.ItemNum value-oh AS DECIMAL LABEL "Value-oh"
    WITH COLUMN 40 USE-TEXT.
  DISPLAY Item.ItemNum Item.OnHand * Item.Price @ value-oh.
  ACCUMULATE Item.OnHand * Item.Price (TOTAL).
  IF LAST(Item.OnHand * Item.Price) THEN DO:
    UNDERLINE value-oh.
    DISPLAY ACCUM TOTAL Item.OnHand * Item.Price @ value-oh.
  END.
END.

See also

FIRST function, FIRST-OF function, LAST-OF function