Monday, March 9, 2020

BAPI BAPI_GOODSMVT_CREATE Program Example IN SAP ABAP.


BAPI BAPI_GOODSMVT_CREATE Program Example.




BAPI BAPI_GOODSMVT_CREATE  Create Example.

* Declare Structures for BAPI
  data: gm_header1  type bapi2017_gm_head_01,
        gm_code1    type bapi2017_gm_code,
        gm_headret1 type bapi2017_gm_head_ret,
        gm_item1    type table of bapi2017_gm_item_create with header line.
  data: gm_return1  type bapiret2 occurs 0.
  data: gm_retmtd1  type bapi2017_gm_head_ret-mat_doc.

  clear: gm_return1, gm_retmtd1. refresh gm_return1.


*Declare BAPI header data.
  gm_header1-pstng_date = sy-datum.
  gm_header1-doc_date   = sy-datum.
  gm_code1-gm_code      = '06'.                              " MB11

*  551 movement type to table
  clear gm_item.
  move:  '551'        to gm_item1-move_type ,
         '000000000040001234' to gm_item1-material,
         '2'        to gm_item1-entry_qnt,
         'EA'       to gm_item1-entry_uom,
         '0006'     to gm_item1-plant,
         '4010'     to gm_item1-stge_loc,
         '202'      to gm_item1-move_reas.

* Determine cost center per plant
  case xresb-werks.
    when '0011'.
      move '0000041431' to gm_item1-costcenter.
    when '0012'.
      move '0000041631' to gm_item1-costcenter.
    when '0013'.
      move '0000041734' to gm_item1-costcenter.
    when '0014'.
      move '0000041836' to gm_item1-costcenter.
  endcase.

  append gm_item1.

* Call goods movement BAPI
  call function 'BAPI_GOODSMVT_CREATE'
       exporting
            goodsmvt_header  = gm_header1
            goodsmvt_code    = gm_code1
       importing
            goodsmvt_headret = gm_headret1
            materialdocument = gm_retmtd1
       tables
            goodsmvt_item    = gm_item1
            return           = gm_return1.


   call function 'BAPI_TRANSACTION_COMMIT'
       exporting
            wait = 'X'.

No comments:

Post a Comment