| **Navigation:**  [[introduction.htm|Language Reference]] > 13 - Built-in Functions >====== PREVIOUS (read previous view record in sequence) ====== | [[presskey put a keystroke in the buffer .htm|{{btn_prev_n.gif|Previous page}}]][[introduction.htm|{{btn_home_n.gif|Return to chapter overview}}]][[print print a report structure .htm|{{btn_next_n.gif|Next page}}]] | | || **PREVIOUS(**// entity //**)** {{blk2blue.jpg|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|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|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 initiate sequential file processing .htm|SET]] [[reset reset record sequence position .htm|RESET]] [[next read next record in sequence .htm|NEXT]] [[bof return beginning of file .htm|BOF]] [[hold exclusive record access .htm|HOLD]] [[watch automatic concurrency check .htm|WATCH]] [[reget re get record .htm|REGET]] [[add add an entry .htm|ADD]] [[put re write record .htm|PUT]] [[delete delete a record .htm|DELETE]]