Swap.Cursor Subroutine

SWAP.CURSOR allows the contents of one SELECT cursor to be swapped with or copied to, (destructive or non-destructive) the contents of another cursor.

SWAP.CURSOR (sourceCursor, destCursor, Mode)

ParameterDescription
SourceCursor Cursor Handle to move from
destCursor Cursor Handle to move to
Mode indicates swap, move, copy - default to swap
mode = 0 - Swap source and dest cursors
mode = 1 - SourceCursor is moved to destCursor
mode = 2 - SourceCursor is copied (non-destructive) to destCursor
     Declare Subroutine swap. Cursor
     $Insert logical
     $Insert RLIST_EQUATES     ; * parameters for RLIST
     $Insert SELECT.CONSTANTS ; * defines the cursor structure

     * Valid Swap.cursor modes     
     EQU MODE_SWAP$  TO 0
     EQU MODE_MOVE$  TO 1
     EQU MODE_COPY$  TO 2    

     * Run a select
     Cmd = 'SELECT MYTABLE WITH MYCOL EQ "MYCRITERIA"'
     call rlist(cmd, target_activelist$)
     
     * The select defaults to cursor 0, whose contents are not accessible
     * I want to pull the keys out, so swap to cursor 2, which puts the pieces in @cursors, where they are accessible
     sourceCursor = 0
     targetCursor = 2
     swap.Cursor(sourceCursor, targetCursor, mode_swap$)

     // Keys are in memory if select is fully resolved and not overflowed into SYSLISTS table
     is_active = ( @cursors(targetCursor,  CURS.LIST.ACTIVE$) gt 0 )
     reduction_done = ( @cursors(targetCursor, CURS.REDUCTION.DONE$) eq true$ )
     if is_active and not(reduction_Done) then
        * Force the select to complete, check again for an active select
        call resolve_Select(targetCursor)
        is_active = ( @cursors(targetCursor,  CURS.LIST.ACTIVE$) gt 0 )
     end
     
      If is_active Then
          // Pull the keys from the cursor. This saves a loop readnext
          keys =  @cursors(targetCursor, CURS.LIST$)
      end    
         
  • guides/programming/programmers_reference_manual/swap.cursor.txt
  • Last modified: 2024/10/14 19:06
  • by bshumsky