| **Navigation:**  [[introduction.htm|Language Reference]] > 13 - Built-in Functions >====== NEXT (read next record in sequence) ====== | [[name return file name .htm|{{btn_prev_n.gif|Previous page}}]][[introduction.htm|{{btn_home_n.gif|Return to chapter overview}}]][[nomemo read file record without reading memo .htm|{{btn_next_n.gif|Next page}}]] | | || **NEXT(**// entity //**)** {{blk2blue.jpg|blk2blue.jpg}} | **NEXT** | Reads the next record in sequence from a FILE or VIEW. | | //entity// | The label of a FILE or VIEW declaration. | **NEXT** reads the next record in sequence from a FILE or VIEW. The SET (or RESET) statement determines the sequence in which records are read. The first NEXT following a SET reads the record at the position specified by the SET statement. Subsequent NEXT statements read subsequent records in that sequence. The sequence is not affected by any GET, REGET, ADD, PUT, or DELETE. Executing NEXT without a preceding SET, or attempting to read past the end of file posts the "Record Not Available" error. **FILE Usage** {{black.jpg|black.jpg}} NEXT reads the next record in sequence from the data FILE and places it in the RECORD structure data buffer. **VIEW Usage** {{black.jpg|black.jpg}} NEXT reads the next 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, NEXT retrieves the appropriate next set of related records. Either the last 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. **Errors Posted:** | 33 | Record Not Available | | 37 | File Not Open | | 43 | Record Is Already Held | | 90 | Driver Specific Error (returned by [[fileerrorcode return file driver error code number .htm|FILEERRORCODE]]) | **Example:** **ViewOrder VIEW(Customer)                       !Declare VIEW structure** **           PROJECT(Cus:AcctNumber,Cus:Name)** **           JOIN(Hea:AcctKey,Cus:AcctNumber)    !Join Header file** **            PROJECT(Hea:OrderNumber)** **            JOIN(Dtl:OrderKey,Hea:OrderNumber) !Join Detail file** **             PROJECT(Det:Item,Det:Quantity)** **            END** **           END** **          END** ** CODE** ** OPEN(Customer,22h)** ** SET(Cus:NameKey)                !Beginning of file in keyed sequence** ** LOOP                            !Read all records through end of file** ** ****NEXT****(Customer)                 !read a record sequentially** **  IF ERRORCODE() THEN BREAK.     !break on end of file** **  DO PostTrans                   !call transaction posting routine** ** END   ** ** OPEN((Header,22h)** ** OPEN(Detail,22h)** ** OPEN(Product,22h)** ** SET(Cus:AcctKey)** ** OPEN(ViewOrder)** **  LOOP                           !Read all records through end of primary file** ** ****NEXT****(ViewOrder)                !read a record sequentially** **  IF ERRORCODE() THEN BREAK.     !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]] [[previous read previous view record in sequence .htm|PREVIOUS]] [[eof return end of file .htm|EOF]] [[hold exclusive record access .htm|HOLD]] [[watch automatic concurrency check .htm|WATCH]]