Try OpenEdge Now
skip to main content
ABL Reference
ABL Syntax Reference : LINE-COUNTER function
 

LINE-COUNTER function

Returns the current line number of paged output as an INTEGER value.
The initial value of LINE-COUNTER is 1. At the completion of each DISPLAY statement, the AVM increments LINE-COUNTER by the number of lines that were output in that DISPLAY statement. LINE-COUNTER continues to increase until after at least one line has been printed on a new page.
LINE-COUNTER returns a 0 if the output is not paged.

Syntax

LINE-COUNTER [ ( stream | STREAM-HANDLE handle ) ]
stream
Specifies the name of a stream. If you do not name a stream, the AVM uses the unnamed stream. For more information on streams, see this book's DEFINE STREAM statement reference entry and OpenEdge Development: Programming Interfaces.
STREAM-HANDLE handle
Specifies the handle to a stream. If handle it is not a valid handle to a stream, the AVM generates a run-time error. Note that stream handles are not valid for the unnamed streams. See the chapter on alternate I/O sources in OpenEdge Development: Programming Interfaces for more information on streams and stream handles.

Example

This procedure prints a Customer report, categorized by State. At the end of each State category, it tests to see if there are at least four lines left on the page. The LINE-COUNTER function returns the current line number of output. If that number plus four is greater than the total number of lines on the page (returned by the PAGE-SIZE function), then the procedure starts the new page. If there are four or more lines left, the procedure skips a line before printing the next customer record.
r-linec.p
OUTPUT TO PRINTER.
FOR EACH Customer BREAK BY Customer.State:
  DISPLAY Customer.CustNum Customer.Name Customer.Address Customer.City
    Customer.State.
  IF LAST-OF(Customer.State) THEN DO:
    IF LINE-COUNTER + 4 > PAGE-SIZE THEN PAGE.
    ELSE DOWN 1.
  END.
END.

Notes

*When output is sent to a device other than the terminal screen, the AVM defers displaying a frame until another frame is displayed. That way, if you display the same frame several times consecutively, the AVM performs all those displays at once. Because of this optimization, if the last display fills the page, the value returned by the LINE-COUNTER function can be larger than the page size, even though the next frame is displayed at the start of the new page.
*Use a procedure like this one to verify that output is positioned on the first non-header line of a new page:
DEFINE VARIABLE newpage AS LOGICAL NO-UNDO INITIAL TRUE.

DEFINE STREAM output1.

FOR EACH Customer NO-LOCK:
FORM HEADER "Page Header" PAGE-NUMBER(output1) "Line"
    LINE-COUNTER(output1)
WITH FRAME one PAGE-TOP NO-LABELS NO-BOX.

VIEW STREAM output1 FRAME one.
DISPLAY STREAM output1 name PAGE-NUMBER(output1) LINE-NUMBER(output1)
    WITH NO-LABELS NO-BOX.

IF new-page THEN
    DISPLAY STREAM output1 "First Line".
  newpage = IF LINE-COUNTER(output1) > PAGE-SIZE(output1) THEN
    TRUE ELSE FALSE.
END.

See also

DEFINE STREAM statement, Stream object handle