Previous Topic: IF Control StatementNext Topic: ON Control Statement


NEXT Control Statement

Use the NEXT control statement to retrieve the next occurrence of a database field or record.

Syntax

NEXT field [, field, …]
field

Specifies the name of the next field to retrieve, one of the following options:

JOBDS

Obtains the next data set list entry for the job.

RECORD

Obtains the next record or sort record from the database.

When the NEXT control statement is issued for a field that has no more occurrences, the related field is set to zeros (for data set list entries) or blanks (for database records).

Note: You can use JOBDS in pre-sort logic only.

Example 1

To print data set list information for a job, specify this code:

/DEFINE I BIN                                        
/PRINT JOBNAME   'Jobname ' COL(1)                   
/PRINT JOBID     'Jobid'                             
/DO I = 1 TO JOBNDS BY 1                             
/   PRINT JOBDDNAM  'DDname' COL(19)                 
/   PRINT JOBSTEP   'Stepname'                       
/   PRINT JOBPROC   'Procstep'                       
/   PRINT JOBDSID   'DSID   '                        
/   PRINT EDIT(JOBDLINES,'ZZZ,ZZZ,ZZ9') '      Lines'
/   PRINT EDIT(JOBDPAGES,'ZZZ,ZZZ,ZZ9') '      Pages'
/   NEXT JOBDS                                       
/END                                                 

Example 2

To print data set list information for a job without using a do loop or NEXT statement, use the following statements. These statements print the same report as Example 1:

/IF JOBNAME NE PREV(JOBNAME) OR JOBID NE PREV(JOBID) 
/   PRINT JOBNAME   'Jobname' COL(1)                 
/   PRINT JOBID     'Jobid'                          
/END                                                 
/PRINT JOBDDNAM  'DDname' COL(19)                    
/PRINT JOBSTEP   'Stepname'                          
/PRINT JOBPROC   'Procstep'                          
/PRINT JOBDSID   'DSID   '                           
/PRINT EDIT(JOBDLINES,'ZZZ,ZZZ,ZZ9') '      Lines'   
/PRINT EDIT(JOBDPAGES,'ZZZ,ZZZ,ZZ9') '      Pages'