How to empty a table and repopulate it using a locking mechanisme by admin

ABAP May 15th, 2008

Sometimes it’s just easier and more performant to delete all rows from a table and repopulate it.

I used this scenario for a weekly sheduled job to refresh a custom table,containing all the email adresses from our employes.

In the first step, i populate an internal table with the type of the database table.

  1. LOOP AT INPUT-MT_adusers_CRM-RECORD-ROW into ls_adusers_data.
  2.     IF ls_adusers_data-email CA '@'.
  3.       MOVE sy-mandt TO wa_admails_data-mandt.
  4.       MOVE ls_adusers_data-userid TO wa_admails_data-userid.
  5.       MOVE ls_adusers_data-fullname TO wa_admails_data-fullname.
  6.       MOVE ls_adusers_data-email TO wa_admails_data-email.
  7.       APPEND wa_admails_data TO it_admails_data.
  8.    ENDIF.
  9. ENDLOOP.
  1. *enqueue table
  2.     CALL FUNCTION 'ENQUEUE_E_TABLEE'
  3.     EXPORTING
  4.     mode_rstable = 'E'
  5.     tabname = '/G/ADMAILS'
  6.     EXCEPTIONS
  7.     foreign_lock = 1
  8.     system_failure = 2
  9.     OTHERS = 3.
  1. *delete all mails
  2.     DELETE FROM /G/ADMAILS.
  1. *insert
  2.     insert /G/ADMAILS from table it_admails_data.
  1. *dequeue table
  2.    CALL FUNCTION 'DEQUEUE_E_TABLEE'
  3.    EXPORTING
  4.      mode_rstable = 'E'
  5.      tabname = '/G/ADMAILS'.
  1.