Function Module untuk Update Data Infotype

  1. lock pernr dengan FM ENQUEUE_EPPRELE.
  2. update data infotype dengan FM HR_INFOTYPE_OPERATION. Bila mennggunakan parameter export nocommit = ‘X’, gunakan FM BAPI_TRANSACTION_ROLLBACK & HR_PSBUFFER_INITIALIZE apabila return message-nya error. Gunakan FM BAPI_TRANSACTION_COMMIT bila return messagenya sukses atau initial. Umumnya nocommit diset ‘X’ apabila dalam satu program mengupdate beberapa infotype sehingga bila salah satunya gagal bisa di-rollback. Namun apabila parameter export nocommit diset space, FM di atas tidak perlu digunakan.
  3. unlock pernr dengan FM DEQUEUE_EPPRELE.


Berikut ini contoh line code penggunaan FM untuk update data infotype :

DATA: ls_p0002 TYPE p0002,
      ld_opera TYPE actio,
      ld_return LIKE bapireturn1,
      ld_key LIKE bapipakey.

ls_p0002-infty = '0002'.  "infotye yg ingin diupdate
*ls_p0002-.....           "move data infotype 0002 ke dalam ls_p0002

ld_opera = 'INS'. "gunakan 'MOD' untuk modify atau 'DEL' untuk delete

CALL FUNCTION 'ENQUEUE_EPPRELE'
  EXPORTING
    pernr          = ls_p0002-pernr
    mode_prel      = 'X'
  EXCEPTIONS
    foreign_lock   = 2
    system_failure = 3.

IF sy-subrc = 0.
  CALL FUNCTION 'HR_INFOTYPE_OPERATION'
    EXPORTING
      infty         = '0002'
      subtype       = ls_p0002-subty
      number        = ls_p0002-pernr
      validityend   = ls_p0002-endda
      validitybegin = ls_p0002-begda
      record        = ls_p0002
      operation     = ld_opera
    IMPORTING
      return        = ld_return
      key           = ld_key.
ENDIF.

CALL FUNCTION 'DEQUEUE_EPPRELE'
  EXPORTING
    pernr     = ls_p0002-pernr
    mode_prel = 'X'.

Berikut ini contoh line code penggunaan FM untuk delimit data infotype :

DATA: ls_p0002 TYPE p0002,
      ld_opera TYPE actio,
      ld_return LIKE bapireturn1,
      ld_key LIKE bapipakey.

ls_p0002-infty = '0002'.  "infotye yg ingin diupdate
*ls_p0002-.....           "move data infotype 0002 ke dalam ls_p0002

ld_opera = 'LIS9'.

CALL FUNCTION 'ENQUEUE_EPPRELE'
  EXPORTING
    pernr          = ls_p0002-pernr
    mode_prel      = 'X'
  EXCEPTIONS
    foreign_lock   = 2
    system_failure = 3.

IF sy-subrc = 0.
  CALL FUNCTION 'HR_INFOTYPE_OPERATION'
    EXPORTING
      infty         = '0002'
      subtype       = ls_p0002-subty
      number        = ls_p0002-pernr
      validityend   = ls_p0002-endda "ganti dengan old endda
      validitybegin = ls_p0002-begda "ganti dengan old begda
      record        = ls_p0002 "begda dan endda di sini adalah yang terbaru
      operation     = ld_opera
    IMPORTING
      return        = ld_return
      key           = ld_key.
ENDIF.

CALL FUNCTION 'DEQUEUE_EPPRELE'
  EXPORTING
    pernr     = ls_p0002-pernr
    mode_prel = 'X'.

Bila nocommit = ‘X’.

CALL FUNCTION 'ENQUEUE_EPPRELE'
  EXPORTING
    pernr          = ls_p0002-pernr
    mode_prel      = 'X'
  EXCEPTIONS
    foreign_lock   = 2
    system_failure = 3.

IF sy-subrc = 0.
  CALL FUNCTION 'HR_INFOTYPE_OPERATION'
    EXPORTING
      infty         = '0002'
      subtype       = ls_p0002-subty
      number        = ls_p0002-pernr
      validityend   = ls_p0002-endda
      validitybegin = ls_p0002-begda
      record        = ls_p0002
      operation     = ld_opera
      nocommit      = 'X'
    IMPORTING
      return        = ld_return
      key           = ld_key.
  if ld_return is initial or ld_return-TYPE = 'S'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
  else.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    CALL FUNCTION 'HR_PSBUFFER_INITIALIZE'.
  endif.
ENDIF.

CALL FUNCTION 'DEQUEUE_EPPRELE'
  EXPORTING
    pernr     = ls_p0002-pernr
    mode_prel = 'X'.
Advertisements

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s