function mods_prep_final()

$insert logical
$insert rlist_equates
$insert msg_equates
declare function utility, msg, mods_load_control

Stmt = 'SELECT MODS BY APP BY TABLE BY ROW BY MOD_DATE BY MOD_TIME'
* SORTING ASCENDING CAUSE THE WR MODE WILL BE BEFORE THE DR MODE

Stat = utility( 'CURSOR', 'H' )

rlist( Stmt, target_activelist$, '', '', '' )

Stat = utility( 'CURSOR', 'A' )

if @reccount then
   Stat = utility( 'CURSOR', 'H' )
   open 'MODS' to ModsTable else
      Void = msg( '', 'Unable to open MODS...' )
      return 0
   end
	PrevID = ''
	CurID  = ''
	RemIDs = ''
	PrevAllId = ''
	Eof    = false$
	loop
	  readnext Id else Eof = true$
	 until eof
	   CurAllId = Id
	   CurID = field( Id, '`', 1, 3 ) ;* FIRST THREE PARTS ARE: APP*TABLE*ROW
	   Mode  = field( Id, '`', 6, 1 ) ;* LAST PART IS THE MODE
	   if CurId = PrevId and Mode = 'DR' then
	      * DELETE
	      delete ModsTable, CurAllId else
            Void = msg( '', 'Unable to delete MODS ':CurAllId )
            return 0
	      end
	      delete ModsTable, PrevAllId else
            Void = msg( '', 'Unable to delete MODS ':PrevAllId )
            return 0
	      end
	   end else
	      * DIFFERENT MOD
	      PrevId = CurID
	      PrevAllId = CurAllId
	   end  
	repeat
	Stat = utility( 'CURSOR', 'A' )
   void = mods_load_control()	
end else
   MsgInfo = ''
   MsgInfo<mtext$> = 'There are no rows in the MODS table.'
   MsgInfo<micon$> = '!'
   Void = msg( '', MsgInfo )
   return 0
end
return 0


