NP(ABORT,PGDATA) ;
        ; Next Page Handler
        ; Generic display utility.  Prints HDR and FTR when needed.
        ; Caller should check ABORT and terminate when 1.
        ; Caller needs to make initial call to their HDR code
        ; and to call their FTR code at end if needed.
        ; Note: Header code should place cursor on start
        ; of newline when done.
        ; Inputs
        ;  ABORT : <byref> Equals 1 if user enters "^" at "MORE" prompt
        ; PGDATA : <byref> Page Data array
        ;        :  "PGNUM": current page number
        ;        :  "BM": Bottom Margin (# of lines in footer)
        ;        :  "HDR": Executable M code for header
        ;        :  "FTR": Executable M code for footer
        ;        :  "PROMPT": (string) Replacement for "More" prompt
        ;        :  "PROMPTX": Executable M code to run for "More" prompt
        ;        :    The M Code must set var X equal to the prompt to use.
        ;        :  "WFTR": the footer was written (=1)
        ;        :  "ERASE": Erase MORE prompt (1=Erase 0=Dont erase dflt=1)
        ;Outputs
        ;  ABORT : 0 or 1 if user wants to quit display
        ; PGDATA : "PGNUM" incremented as needed
        ;        : "WFTR" = 1 if footer was written
        ;        : "NP": Is it a "New Page"? (Was "MORE" prompt displayed)
        ;
        ;
        ; Example code to write last footer if needed
        ; I 'STOP I '$G(PGDATA("WFTR")) D  ;
        ; . I $G(PGDATA("FTR"))="" Q
        ; . I $E($G(IOST),1,2)'="C-" D  ;
        ; . . N I,BM
        ; . . S BM=$G(PGDATA("BM"))
        ; . . F I=$Y+1:1:($G(IOSL,60)-BM-1) W !
        ; . X PGDATA("FTR")
        ;
        N X,PGNUM,BM,HDR,FTR,INHDR,INFTR,ERASE
        S ABORT=$G(ABORT)
        S PGNUM=$G(PGDATA("PGNUM"))
        S BM=$G(PGDATA("BM"))
        S PGDATA("WFTR")=0
        S PGDATA("NP")=0
        I PGNUM<1 S PGNUM=1 S PGDATA("PGNUM")=PGNUM
        Q:ABORT
        I BM<0 S BM=0
        I $Y+1<($G(IOSL,24)-BM) Q
        ;
        S HDR=$G(PGDATA("HDR"))
        S FTR=$G(PGDATA("FTR"))
        S ERASE=$G(PGDATA("ERASE"),1)
        S (INHDR,INFTR)=0
        S PGDATA("NP")=1
        ;
        I FTR'="" I 'INFTR D  ;
        . N POSY
        . S POSY=$Y
        . S INFTR=1
        . X FTR
        . S PGDATA("WFTR")=1
        . S INFTR=0
        . I $E($G(IOST),1,2)'="C-" D  ;
        . . Q:$Y<POSY  ;dont FF if already on new page
        . . I $G(IOF)'="" W @IOF
        . ;
        ;
        ; do "MORE" prompting
        I $E($G(IOST),1,2)="C-" D  Q:ABORT  ;
        . S X=0
        . Q:$D(ZTQUEUED)
        . I $G(PGDATA("PROMPTX"))'="" D  ;
        . . K X
        . . X PGDATA("PROMPTX")
        . . S X=$G(X)
        . . S ABORT=$$MORE(X,ERASE)
        . ;
        . I $G(PGDATA("PROMPTX"))="" D  ;
        . . S ABORT=$$MORE($G(PGDATA("PROMPT")),ERASE)
        . ;
        ;
        S $Y=0
        S PGNUM=PGNUM+1
        S PGDATA("PGNUM")=PGNUM
        I HDR'="" I 'INHDR D  ;
        . S INHDR=1
        . X HDR
        . S INHDR=0
        Q
        ;
MORE(PROMPT,ERASE) ;
        ; Prompts user to hit ENTER to continue
        ; Returns 1 if user enters "^" else returns 0
        N DIR,DIRUT,DTOUT,DUOUT,X,Y
        S PROMPT=$G(PROMPT)
        S ERASE=$G(ERASE,1)
        I '$D(ZTQUEUED) D  ;
        . I $E($G(IOST),1,2)'="C-" Q
        . S DIR(0)="E"
        . I PROMPT'="" S DIR("A")=PROMPT S DIR(0)="EA"
        . D ^DIR
        . I ERASE W $C(13)_$J("",$G(IOM,80))_$C(13)
        I $Q Q $D(DIRUT)
        Q
        ;
	
 
	 

Samples