$Currec: Difference between revisions
(Added information on the effects of STORE RECORD on $CURREC) |
m (minor cleanup) |
||
Line 1: | Line 1: | ||
<p>The $ | <p> | ||
<p>At the beginning of a request, $ | The <var>$Currec</var> function returns an integer equal to the internal number of the current record. </p> | ||
<p> | |||
At the beginning of a request, <var>$Currec</var> is set to minus one, an invalid record number. | |||
</p> | </p> | ||
<p> | |||
At the beginning of each pass through a <var>FOR EACH RECORD</var> loop, <var>$Currec</var> is set to the record number of the record to be processed in that pass. When the <var>FOR</var> loop is exited, because all records have been processed or because a <var>LOOP END</var> or <var>JUMP</var> statement has been encountered, <var>$Currec</var> is restored to its value prior to the <var>FOR</var> statement. </p> | |||
<p> | |||
<var>$Currec</var> takes no arguments. </p> | |||
<p> | |||
Be aware of these facts when using <var>$Currec</var>: </p> | |||
<ul> | |||
<li>A <var>[[Data maintenance#STORE RECORD statement|STORE RECORD]]</var> statement resets <var>$Currec</var> to the record number of the newly stored record. If the <var>STORE RECORD</var> statement is issued inside of a <var>FOR RECORD</var> loop, <var>$Currec</var> retains the stored record number until the next pass through the <var>FOR</var> loop or until the next <var>STORE RECORD</var> statement. If the <var>STORE RECORD</var> statement is issued outside of a <var>FOR RECORD</var> loop, <var>$Currec</var> will retain the stored record number until the next <var>STORE RECORD</var> or the next <var>FOR RECORD</var> loop. </li> | |||
<li>In a record loop on the records of a <var>SORT</var> statement, <var>$Currec</var> is set to the record number of the record from which the temporary sort copy was made. </li> | |||
<li>Record numbers are not unique within a file group. The number returned by <var>$Currec</var> is valid only in reference to the file from which the record came. </li> | |||
<li>Record numbers are not unique within a file group. The number returned by $ | |||
</li> | |||
</ul> | </ul> | ||
<p>This request prints the record number of a new record:</p> | ==Examples== | ||
<p> | |||
This request prints the record number of a new record:</p> | |||
<p class="code">BEGIN | <p class="code">BEGIN | ||
GET.RECS: FIND ALL RECORDS | GET.RECS: FIND ALL RECORDS | ||
END FIND | END FIND | ||
FOR 5 RECORDS IN GET.RECS | FOR 5 RECORDS IN GET.RECS | ||
PRINT 'THE INTERNAL RECORD NO IS ' | PRINT 'THE INTERNAL RECORD NO IS ' WITH $CURREC | ||
END FOR | END FOR | ||
END | END | ||
</p> | </p> | ||
Also, as of Model 204 version 7.5, the FOR RECORD NUMBER statement accepts an expression after it, for example: | Also, as of Model 204 version 7.5, the <var>FOR RECORD NUMBER</var> statement accepts an expression after it, for example: | ||
<p class="code"> | <p class="code">IN FILE CLAIMS STORE RECORD | ||
IN FILE CLAIMS STORE RECORD | |||
... | ... | ||
END STORE | END STORE |
Revision as of 23:03, 10 December 2014
The $Currec function returns an integer equal to the internal number of the current record.
At the beginning of a request, $Currec is set to minus one, an invalid record number.
At the beginning of each pass through a FOR EACH RECORD loop, $Currec is set to the record number of the record to be processed in that pass. When the FOR loop is exited, because all records have been processed or because a LOOP END or JUMP statement has been encountered, $Currec is restored to its value prior to the FOR statement.
$Currec takes no arguments.
Be aware of these facts when using $Currec:
- A STORE RECORD statement resets $Currec to the record number of the newly stored record. If the STORE RECORD statement is issued inside of a FOR RECORD loop, $Currec retains the stored record number until the next pass through the FOR loop or until the next STORE RECORD statement. If the STORE RECORD statement is issued outside of a FOR RECORD loop, $Currec will retain the stored record number until the next STORE RECORD or the next FOR RECORD loop.
- In a record loop on the records of a SORT statement, $Currec is set to the record number of the record from which the temporary sort copy was made.
- Record numbers are not unique within a file group. The number returned by $Currec is valid only in reference to the file from which the record came.
Examples
This request prints the record number of a new record:
BEGIN GET.RECS: FIND ALL RECORDS END FIND FOR 5 RECORDS IN GET.RECS PRINT 'THE INTERNAL RECORD NO IS ' WITH $CURREC END FOR END
Also, as of Model 204 version 7.5, the FOR RECORD NUMBER statement accepts an expression after it, for example:
IN FILE CLAIMS STORE RECORD ... END STORE IN FILE CLAIMS FRN $CURREC ... END FOR