Thursday, 25 January 2024

Migo_GR Using FM - BAPI_GOODSMVT_CREATE

 



 refresh it_ekpo.
  clearitheaderititem.
  clearwaheader,waititem.
  clearv_matnr,v_majhr.

  select ekpo~ebeln ekpo~ebelp  ekpo~werks ekpo~matnr  ekpo~menge
         ekpo~netpr ekpo~netwr ekpo~txz01 ekpo~banfn ekpo~bnfpo
         ekko~bedat
          into corresponding fields of table it_ekpo
          from ekpo
          inner join ekko as ekko on ekko~ebeln ekpo~ebeln
         where ekpo~ebeln eq ex_po_number.

  describe table it_ekpo lines g_po_cnt.

* Head
  waheader-pstng_date sy-datum.
  waheader-doc_date   sy-datum.
  waheader-ref_doc_no g_mgo_txt.
  append waheader to itheader.

  loop at it_ekpo into wa_ekpo.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  wa_ekpo-matnr
      importing
        output wa_ekpo-matnr.
    waititem-material wa_ekpo-matnr.

    waititem-plant wa_ekpo-werks.
    waititem-move_type '101'.
    waititem-entry_qnt wa_ekpo-menge.
    waititem-po_number wa_ekpo-ebeln.
    waititem-po_item wa_ekpo-ebelp.
    waititem-mvt_ind 'B'.
    waititem-plant '2000'.
    append waititem to ititem.
  endloop.

  gm_code '02'.

*Bapi's
  call function 'BAPI_GOODSMVT_CREATE'
  exporting
    goodsmvt_header               waheader
    goodsmvt_code                 gm_code
*   TESTRUN                       = ' '
*   GOODSMVT_REF_EWM              =
  importing
*   GOODSMVT_HEADRET              =
   materialdocument              v_matnr
   matdocumentyear               v_majhr
  tables
    goodsmvt_item                 ititem
    return                        itreturn.

  if sy-subrc eq 0.

    call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait 'X'.

    migo_gr =  v_matnr.
    gr_year v_majhr.
    clearitheaderititem.

    wait up to seconds.
  else.
    message ' Create Migo Fail' type 'S'.
  endif.

No comments:

Post a Comment

Visitor

Code Syntax Try...Endtry

  Code : Report Try. Parameters  NUMBER  type  I . data  RESULT  type  P  decimals  2 . data  OREF  type  ref  to  CX_ROOT . data  TEXT  typ...