Progress
Language Reference


FIRST Function

Interfaces
OS
SpeedScript
All
All
Yes

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

SYNTAX

FIRST ( break-group ) 

break-group

The name of a field or expression you name in the block header with the BREAK BY option.

EXAMPLE

The r-first.p procedure displays the order number, order-lines on the order, the extended price of each order-line, and a total order value for each order record.

r-first.p
DEFINE VARIABLE order-value AS DECIMAL LABEL "Order-value".

FOR EACH order:
  DISPLAY order-num.
  FOR EACH order-line OF order BREAK BY qty * price:
    IF FIRST(qty * price) THEN order-value = 0.
    order-value = order-value + qty * price.
    DISPLAY line-num item-num qty * price 
      LABEL "Extended-price".
  END.
  DISPLAY order-value.
END.  

Because the inner FOR EACH block iterates until Progress reads all the order-lines, the procedure must set the order-value variable to 0 each time a new order is used in that block. The FIRST function uses the (qty * price) expression as the break-group to keep track of whether or not the current iteration is the first iteration of the FOR EACH block.

SEE ALSO

DO Statement, FIRST-OF Function, FOR Statement, LAST Function, LAST-OF Function, REPEAT Statement


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095