User Tools

Site Tools


previous_read_previous_view_record_in_sequence_.htm
Navigation:  Language Reference > 13 - Built-in Functions >====== PREVIOUS (read previous view record in sequence) ====== Previous pageReturn to chapter overviewNext page

PREVIOUS( entity )

blk2blue.jpg

PREVIOUS Reads the previous record in sequence.
entity The label of a FILE or VIEW declaration.

PREVIOUS reads the previous record(s) in sequence from a FILE or VIEW. The SET (or RESET) statement determines the sequence in which records are read. Executing PREVIOUS without a preceding SET, or attempting to read past the beginning of a file posts the “Record Not Available” error.

FILE Usage

black.jpg

PREVIOUS reads the previous record in sequence from a data file and places it in the RECORD structure data buffer. The first PREVIOUS following a SET reads the record at the position specified by the SET statement. Subsequent PREVIOUS statements read subsequent records in reverse sequence. The sequence is not affected by any GET, REGET, ADD, PUT, or DELETE.

VIEW Usage

black.jpg

PREVIOUS reads the previous record(s) in sequence from a VIEW and places the appropriate fields in the VIEW structure component files' data buffer(s). If the VIEW contains JOIN structures, PREVIOUS retrieves the appropriate previous set of related records.

Either the SET statement issued on the VIEW's primary file before the OPEN(view) statement, or the SET(view) statement issued after the OPEN(view) determines the sequence in which records are read. The first PREVIOUS(view) reads the record at the position specified by the SET statement. Subsequent PREVIOUS statements read subsequent records in that sequence. The sequence is not affected by PUT or DELETE statements.

Errors Posted:

33 Record Not Available
37 File Not Open
43 Record Is Already Held

Example:

ViewOrder VIEW(Header)

          PROJECT(Hea:OrderNumber)

          JOIN(Dtl:OrderKey,Hea:OrderNumber)  !Join Detail file

           PROJECT(Det:Item,Det:Quantity)

           JOIN(Pro:ItemKey,Dtl:Item)         !Join Product file

            PROJECT(Pro:Description,Pro:Price)

           END

         END

        END

CODE

OPEN((Header,22h)

OPEN(Detail,22h)

OPEN(Product,22h)

SET(Cus:AcctKey)

OPEN(ViewOrder)

 LOOP                            !Read all records through beginning of primary file

PREVIOUS(ViewOrder)             !read a record sequentially

 IF ERRORCODE() THEN BREAK END   !break on end of file

 DO PostTrans                    !call transaction posting routine

END                              !End loop

See Also:

SET

RESET

NEXT

BOF

HOLD

WATCH

REGET

ADD

PUT

DELETE

previous_read_previous_view_record_in_sequence_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1