REPORT zpo_massupload.
TABLES : ekko,ekpo.
TYPES : BEGIN OF ty_out,
mblnr TYPE mblnr,
ebeln TYPE ekko-ebeln,
END OF ty_out.
DATA it_ekko TYPE TABLE OF ekko WITH HEADER LINE.
DATA it_ekpo TYPE TABLE OF ekpo WITH HEADER LINE.
DATA it_ekbe TYPE TABLE OF ekbe WITH HEADER LINE.
DATA it_out TYPE TABLE OF ty_out WITH HEADER LINE.
DATA: ls_header TYPE bapi2017_gm_head_01,
ls_code TYPE bapi2017_gm_code,
it_item TYPE STANDARD TABLE OF bapi2017_gm_item_create,
wa_item TYPE bapi2017_gm_item_create.
DATA it_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
DATA materialdocument TYPE bapi2017_gm_head_ret-mat_doc.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_ebeln FOR ekko-ebeln.
PARAMETERS: p_budat TYPE sy-datum OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
SELECT * FROM ekbe INTO TABLE it_ekbe WHERE ebeln IN s_ebeln
AND bwart = '351'.
IF it_ekbe[] IS NOT INITIAL.
SELECT * FROM ekko INTO TABLE it_ekko FOR ALL ENTRIES IN it_ekbe WHERE ebeln = it_ekbe-ebeln.
SELECT * FROM ekpo INTO TABLE it_ekpo FOR ALL ENTRIES IN it_ekbe WHERE ebeln = it_ekbe-ebeln
AND matnr = it_ekbe-matnr
AND ebelp = it_ekbe-ebelp
AND ELIKZ <> 'X'
AND STAPO <> 'X'.
ENDIF.
ls_header-pstng_date = p_budat .
ls_header-doc_date = p_budat .
ls_code-gm_code = '01'.
ls_header-header_txt = 'Stock In Transit'.
ls_header-doc_date = p_budat.
LOOP AT it_ekko.
CLEAR it_item[].
LOOP AT it_ekpo WHERE ebeln = it_ekko-ebeln.
READ TABLE it_ekbe WITH KEY ebeln = it_ekpo-ebeln matnr = it_ekpo-matnr
ebelp = it_ekpo-ebelp.
if sy-subrc = 0.
wa_item-material = it_ekpo-matnr.
wa_item-stge_loc = it_ekpo-werks.
wa_item-plant = it_ekpo-werks.
wa_item-move_type = '101'.
wa_item-entry_qnt = it_ekbe-menge.
wa_item-entry_uom = it_ekpo-meins.
wa_item-po_number = it_ekpo-ebeln.
wa_item-po_item = it_ekpo-ebelp.
wa_item-mvt_ind = 'B'.
* wa_item-no_more_gr = 'X'.
* wa_item-line_id = lv_line_id.
* wa_item-parent_id = lv_parent_id.
APPEND wa_item TO it_item.
CLEAR wa_item.
ENDIF.
ENDLOOP.
IF it_item[] IS NOT INITIAL.
CLEAR it_return[].
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = ls_header
goodsmvt_code = ls_code
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
IMPORTING
* goodsmvt_headret = goodsmvt_headret
materialdocument = materialdocument
* matdocumentyear = matdocumentyear
TABLES
goodsmvt_item = it_item
* GOODSMVT_SERIALNUMBER =
return = it_return.
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
COMMIT WORK AND WAIT.
IF materialdocument IS NOT INITIAL .
it_out-mblnr = materialdocument.
it_out-ebeln = it_ekpo-ebeln.
APPEND it_out.
ENDIF.
ENDIF.
REFRESH it_item.
ENDLOOP.
LOOP AT it_out.
WRITE : / it_out-mblnr,
it_out-ebeln.
ENDLOOP.
No comments:
Post a Comment