Wednesday, November 20, 2013

How to enqueue and dequeue (lock) a pernr (Employee) in sap abap




Hi folks,

here are two forms to lock and unlock employees. I took the copding out of the payroll drivers (adapting it slightly) so it should be more or less the standard way to lock unlock persons.

HTH
Enjoy!

*&---------------------------------------------------------------------*
*&      Form  enqueue_pernr_prel
*&---------------------------------------------------------------------*
FORM enqueue_pernr_prel USING    p_pernr_pernr.
  STATICS: s_message_handler  TYPE REF TO cl_hrpl_masterdata_messages.
  DATA: l_error        TYPE hrplog_msg,
        l_not_locked   TYPE boole_d,
        l_locking_user TYPE syuname.

  IF s_message_handler IS INITIAL.
    CREATE OBJECT s_message_handler.
  ENDIF.
  CALL METHOD cl_hrpa_masterdata_enq_deq=>enqueue_by_pernr
    EXPORTING
      tclas           = 'A'
      pernr           = p_pernr_pernr
      message_handler = s_message_handler
    IMPORTING
      is_ok           = l_not_locked
      locking_user    = l_locking_user.
  IF l_not_locked <> 'X'.
    MESSAGE a016(rp) WITH 'PERNR:' pernr-pernr 'Locket by user' l_locking_user.
    STOP.
  ENDIF.

ENDFORM.                               " ENQUEUE_PERNR_PREL

*&---------------------------------------------------------------------*
*&      Form  dequeue_pernr_prel
*&---------------------------------------------------------------------*
FORM dequeue_pernr_prel USING p_pernr TYPE pernr_d.

*TRY.
  CALL METHOD cl_hrpa_masterdata_enq_deq=>dequeue_by_pernr
    EXPORTING
      tclas = 'A'
      pernr = p_pernr.
* CATCH CX_HRPA_VIOLATED_ASSERTION .
*ENDTRY.

ENDFORM.                    "dequeue_pernr_prel