*----------------------------------------------------------------
* goodsmvt_header-pstng_date: 전표전기일
* goodsmvt_header-doc_date: 전표 내 증빙일
*----------------------------------------------------------------
* 자재이동코드는 해당 비지니스플로우별로 다음과 같습니다.
* 01: Goods receipt for purchase order
* 02: Goods receipt for production order
* 03: Goods issue
* 04: Transfer posting
* 05: Other goods receipts
* 06: Reversal of goods movements
* Goodsmvt_code: 자재이동코드
* ----------------------------------------------------------------
* Goodsmvt_item-material: 자재번호
* Goodsmvt_item-plant: 플랜트
* Goodsmvt_item-stge_loc: 저장위치
* Goodsmvt_item-move_type: '311' 등...
* Goodsmvt_item-entry_Qnt: 이동수량
* Goodsmvt_item-move_stloc: 이동저장위치
----------------------------------------------------------------
DATA : st_goodsmvt_header LIKE bapi2017_gm_head_01,
st_goodsmvt_code LIKE bapi2017_gm_code,
st_goodsmvt_headret LIKE bapi2017_gm_head_ret,
g_goodsmvt_doc LIKE bapi2017_gm_head_ret-mat_doc,
g_materialdocument TYPE bapi2017_gm_head_ret-mat_doc,
g_matdocumentyear TYPE bapi2017_gm_head_ret-doc_year,
it_goodsmvt_item LIKE bapi2017_gm_item_create
OCCURS 0 WITH HEADER LINE,
it_goodsmvt_serialnumber LIKE bapi2017_gm_serialnumber
OCCURS 0 WITH HEADER LINE,
it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
*================================================================================
DATA l_tabix LIKE sy-tabix.
CLEAR st_goodsmvt_header.
REFRESH: it_goodsmvt_item, it_goodsmvt_serialnumber, it_return.
CLEAR: it_goodsmvt_item, it_goodsmvt_serialnumber, it_return.
LOOP AT gt_display.
l_tabix = sy-tabix.
CLEAR st_goodsmvt_header.
st_goodsmvt_header-pstng_date = sy-datum. " 기표일자
st_goodsmvt_header-doc_date = sy-datum. " 증빙일자
st_goodsmvt_code-gm_code = '04'. " 재고이동
REFRESH: it_goodsmvt_item, it_goodsmvt_serialnumber, it_return.
CLEAR: it_goodsmvt_item, it_goodsmvt_serialnumber, it_return.
it_goodsmvt_item-move_type = '309'.
it_goodsmvt_item-material = gt_display-fr_matnr.
it_goodsmvt_item-plant = gt_display-fr_werks.
it_goodsmvt_item-stge_loc = gt_display-fr_lgort.
it_goodsmvt_item-batch = gt_display-fr_charg.
it_goodsmvt_item-move_mat = gt_display-to_matnr.
it_goodsmvt_item-move_plant = gt_display-to_werks.
it_goodsmvt_item-move_stloc = gt_display-to_lgort.
it_goodsmvt_item-move_batch = gt_display-to_charg.
it_goodsmvt_item-entry_qnt = gt_display-fr_labst.
it_goodsmvt_item-entry_uom = gt_display-fr_meins.
APPEND it_goodsmvt_item.
CLEAR : g_materialdocument, g_matdocumentyear.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = st_goodsmvt_header
goodsmvt_code = st_goodsmvt_code
IMPORTING
goodsmvt_headret = st_goodsmvt_headret
materialdocument = g_materialdocument
matdocumentyear = g_matdocumentyear
TABLES
goodsmvt_item = it_goodsmvt_item
return = it_return.
CLEAR g_goodsmvt_doc.
IF NOT st_goodsmvt_headret IS INITIAL.
g_goodsmvt_doc = st_goodsmvt_headret-mat_doc.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
gt_display-msgty = 'S'.
gt_display-msglin = g_goodsmvt_doc.
MODIFY gt_display INDEX l_tabix TRANSPORTING msgty msglin.
ELSE.
READ TABLE it_return INDEX 1.
gt_display-msgty = 'E'.
gt_display-msglin = it_return-message.
MODIFY gt_display INDEX l_tabix TRANSPORTING msgty msglin.
ENDIF.
ENDLOOP.