How to purge big table data

define temp-table tt-recfield tt-rowid as rowid. 

for each table_name no-lock where /* creteria */: 

  /* some more checks and validations */ 
  create tt-rec.
  tt-rec.tt-rowid = rowid( table_name ).

  /* here instead of delete I record rowids */  
  tran-cnt = tran-cnt + 1.
  if tran-cnt = 1000 then do: 
    /* When enough is enough I do-transaction */
    run do-transaction.
    tran-cnt = 0.
  end. 
end. 
run do-transaction. /* last transaction before exit */ 

procedure do-transaction:
  define buffer b-table_name for table_name.

  do TRANSACTION:
    for each tt-rec:

      find b-table_name where rowid( b-table_name ) = tt-rec.tt-rowid
        exclusive-lock no-wait no-error.
      if available b-table_name then
         delete b-table_name.
      else put unformatted string(time,"HH:MM:SS") " No table_name" skip.

      delete tt-rec.
    end. /* tt-rec */
  end. /* TRANSACTION */

end. /* do-transaction */
message "Done".

Return to myProgress Home Page