$Currec: Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
m (mixed case for For Record Number)
 
(4 intermediate revisions by 2 users not shown)
Line 5: Line 5:
</p>
</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>[[Flow_of_control_in_User_Language#LOOP_END_statement|Loop End]]</var> or <var>[[Flow_of_control_in_User_Language#JUMP_TO_statement|Jump]]</var> statement has been encountered, <var>$Currec</var> is restored to its value prior to the <var>For</var> statement. </p>
At the beginning of each pass through a <var>[[Record loops#FOR EACH RECORD statement|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>[[Flow of control in User_Language#LOOP END statement|Loop End]]</var> or <var>[[Flow of control in User Language#JUMP TO statement|Jump]]</var> statement has been encountered, <var>$Currec</var> is restored to its value prior to the <var>For</var> statement. </p>
<p>
<p>
<var>$Currec</var> takes no arguments. </p>
<var>$Currec</var> takes no arguments. </p>
==Usage notes==
<p>
<p>
Be aware of these facts when using <var>$Currec</var>:  </p>
Be aware of these facts when using <var>$Currec</var>:  </p>
Line 13: Line 15:
<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>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>An alternative to <var>$Currec</var> is the <var>[[RecordNumber (Record function)|RecordNumber]]</var> function used against a <var>Record</var> object.  The <var>RecordNumber</var> function returns the record number of the current record being processed in a <var>For</var> loop, and that record number does not change when a <var>[[Data maintenance#STORE RECORD statement|Store Record]]</var> statement is evaluated.  
<li>An alternative to <var>$Currec</var> is the <var>[[RecordNumber (Record function)|RecordNumber]]</var> function used against a <var>[[Record_class|Record]]</var> object.  The <var>RecordNumber</var> function returns the record number of the current record being processed in a <var>For</var> loop, and that record number does not change when a <var>[[Data maintenance#STORE RECORD statement|Store Record]]</var> statement is evaluated.  


<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>In a record loop on the records of a <var>[[Sorting#SORT_RECORDS_statement|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 <var>$Currec</var> is valid only in reference to the file from which the record came. </li>
Line 31: Line 33:
END   
END   
</p>
</p>
Also, as of Model 204 version 7.5, the <var>FOR RECORD NUMBER</var> 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">IN FILE CLAIMS STORE RECORD
<p class="code">IN FILE CLAIMS STORE RECORD
   ...
   ...

Latest revision as of 21:48, 26 April 2018

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.

Usage notes

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.
  • An alternative to $Currec is the RecordNumber function used against a Record object. The RecordNumber function returns the record number of the current record being processed in a For loop, and that record number does not change when a Store Record statement is evaluated.
  • 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