Pemindahan stok / Transfer Stock tidak lain adalah pemindahan bahan dari satu pabrik ke lokasi penyimpanan lain, dari pabrik ke pabrik, pabrik kode perusahaan ke pabrik kode perusahaan lain. Ketika terjadi perpindahan stok antar plant, maka kuantitasnya berubah di kedua plant tersebut. Kali ini kita akan sharing sample code mengenai Transfer Posting menggunakan BAPI BAPI_GOODSMVT_CREATE
Beriku merupakan sample code bagaimana programmer ABAP membuatnya
FORM tp313.
DATA: c, ld_ref TYPE c LENGTH 20.
DATA: ls_goodsmvt_header TYPE bapi2017_gm_head_01,
ld_goodsmvt_code TYPE bapi2017_gm_code,
lt_goodsmvt_item TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE,
ld_materialdocument TYPE bapi2017_gm_head_ret-mat_doc.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Konfirmasi Post'
* DIAGNOSE_OBJECT = ' '
text_question = 'System Akan Melakukan Proses Posting TP (313), Lanjutkan?'
text_button_1 = 'Ya'(001)
* ICON_BUTTON_1 = ' '
text_button_2 = 'Tidak'(002)
* ICON_BUTTON_2 = ' '
* DEFAULT_BUTTON = '1'
* DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
answer = c
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF c EQ '1'.
LOOP AT lt_output WHERE check EQ 'X'.
CONCATENATE lt_output-mblnr lt_output-zeile INTO ld_ref.
"Header Data
ls_goodsmvt_header-pstng_date = sy-datum.
ls_goodsmvt_header-doc_date = sy-datum.
ls_goodsmvt_header-ref_doc_no = ld_ref.
ls_goodsmvt_header-bill_of_lading = ''.
ls_goodsmvt_header-gr_gi_slip_no = ''.
ls_goodsmvt_header-pr_uname = ''.
ls_goodsmvt_header-header_txt = ld_ref.
ls_goodsmvt_header-ver_gr_gi_slip = ''.
ls_goodsmvt_header-ver_gr_gi_slipx = ''.
ls_goodsmvt_header-ext_wms = ''.
ls_goodsmvt_header-ref_doc_no_long = ''.
ls_goodsmvt_header-bill_of_lading_long = ''.
ls_goodsmvt_header-bar_code = ''.
"GM Code
ld_goodsmvt_code = '04'.
"Item Data
lt_goodsmvt_item-material = lt_output-matnr.
lt_goodsmvt_item-plant = lt_output-werks_po.
lt_goodsmvt_item-move_plant = lt_output-werks_po.
lt_goodsmvt_item-stge_loc = lt_output-lgort_gr.
lt_goodsmvt_item-move_stloc = lt_output-lgort_po.
lt_goodsmvt_item-entry_qnt = lt_output-menge_gr.
lt_goodsmvt_item-entry_uom = lt_output-meins_gr.
lt_goodsmvt_item-move_type = '313'.
lt_goodsmvt_item-item_text = ld_ref.
APPEND lt_goodsmvt_item.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = ls_goodsmvt_header
goodsmvt_code = ld_goodsmvt_code
IMPORTING
materialdocument = ld_materialdocument
TABLES
goodsmvt_item = lt_goodsmvt_item
return = lt_return.
IF ld_materialdocument IS INITIAL.
"Jika nomor material dokumen tidak ada, berarti terjadi error
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
"Tampilkan Error
LOOP AT lt_return WHERE type EQ 'E'.
MESSAGE lt_return-message TYPE 'E'.
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
"Tampilkan Nomor Dokumen Material
CONCATENATE 'Post Successfull with Doc. Number ' ld_materialdocument INTO lt_return-message SEPARATED BY space.
MESSAGE lt_return-message TYPE 'I' .
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM.
Untuk Code Goods Movement bisa mengikuti list berikut ini
- 01: Goods receipt for purchase order
- 02: Goods receipt for production order
- 03: Goods issue
- 04: Transfer posting
- 05: Other goods receipt
- 06: Reversal of goods movements
- 07: Subsequent adjustment with regard to a subcontract order
Berikut merupakan structure dari lt_output
TYPES: BEGIN OF ty_output,
check TYPE c LENGTH 1,
ebeln TYPE ekko-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
maktx TYPE makt-maktx,
bukrs_po TYPE ekpo-bukrs,
werks_po TYPE ekpo-werks,
lgort_po TYPE ekpo-lgort,
menge_po TYPE ekpo-menge,
meins_po TYPE ekpo-meins,
mblnr TYPE mseg-mblnr,
mjahr TYPE mseg-mjahr,
zeile TYPE mseg-zeile,
lgort_gr TYPE mseg-lgort,
menge_gr TYPE mseg-menge,
meins_gr TYPE mseg-meins,
mblnr_tp TYPE mseg-mblnr,
mjahr_tp TYPE mseg-mjahr,
lgort_tp_f TYPE mseg-lgort,
lgort_tp_t TYPE mseg-lgort,
menge_tp TYPE mseg-menge,
meins_tp TYPE mseg-meins,
mblnr_cf TYPE mseg-mblnr,
mjahr_cf TYPE mseg-mjahr,
lgort_cf_f TYPE mseg-lgort,
lgort_cf_t TYPE mseg-lgort,
menge_cf TYPE mseg-menge,
meins_cf TYPE mseg-meins,
werks TYPE mseg-werks, "-------Text: Plant
status TYPE c LENGTH 10,
END OF ty_output,
Semoga Membantu.