How to delete HR Infotype with ABAP

You can use FM HR_INFOTYPE_OPERATION for all types of infotype opertions.

 

 

data :  lv_begda type prelp-begda,
        lv_endda type prelp-endda,
        lv_pernr type prelp-pernr,
        lv_infty type prelp-infty,
        lt_p0021 type table of p0021,
        ls_p0021 type p0021,
        ls_bapiret type bapireturn1,
        ls_bapiret2 type bapireturn1,
lv_operation type pspar-actio.
.

lv_pernr = 'PERNR'.
lv_begda = sy-datum.
lv_endda = sy-datum.
lv_infty = '0021'.

call function 'HR_READ_INFOTYPE'
exporting
*   TCLAS                 = 'A'
pernr                 = lv_pernr
infty                 = lv_infty
begda                 = lv_begda
endda                 = lv_endda
*   BYPASS_BUFFER         = ' '
*   LEGACY_MODE           = ' '
* IMPORTING
*   SUBRC                 =
tables
infty_tab             = lt_p0021
exceptions
infty_not_found       = 1
others                = 2
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.

loop at lt_p0021 into ls_p0021.
  write : ls_p0021-infty , ls_p0021-begda , ls_p0021-endda , / .

  clear ls_bapiret.
  call function 'BAPI_EMPLOYEE_ENQUEUE'
    exporting
    number = ls_p0021-pernr
    importing
    return = ls_bapiret.

  if ls_bapiret is not initial.
  endif.

  lv_operation = 'DEL'.

  call function 'HR_PSBUFFER_INITIALIZE'.
  call function 'HR_INFOTYPE_OPERATION'
  exporting
  infty         = '0021'
  subtype       = ls_p0021-subty
  number        = ls_p0021-pernr
  recordnumber  = ls_p0021-seqnr
  record        = ls_p0021
  validitybegin = ls_p0021-begda
  validityend   = ls_p0021-endda
  operation     = lv_operation
  nocommit      = 'X'
  dialog_mode   = '0'
  importing
  return        = ls_bapiret2.

  if ls_bapiret2 is not initial.
  write 'Error Deleting Infotype 21'.
  else.
  commit work.
  write 'Delete operation...Success'.
  endif.

  call function 'BAPI_EMPLOYEE_DEQUEUE'
  exporting
  number = ls_p0021-pernr
  importing
  return = ls_bapiret.


endloop.




Leave a comment

Your email address will not be published. Required fields are marked *