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.

ME21N - Create Purchase Order from PR Using FM BAPI_PO_CREATE1

 



*Get PR Data
  select into corresponding fields of table it_ebpo
    from eban
   where banfn g_banfn.


  describe table it_ebpo lines g_pr_cnt.

*  Get Net Price
  loop at it_ebpo into wa_ebpo.
    read table it_dat2 into wa_dat2 with key col_02 wa_ebpo-bednr "txz01
                                                     binary search.
    if sy-subrc eq 0.
      wa_ebpo-netpr wa_dat2-col_04.
      wa_ebpo-doctyp wa_dat2-col_17.
      wa_ebpo-kostl wa_dat2-col_16.
    endif.
    modify it_ebpo from wa_ebpo.
  endloop.


  it_ebpos[] it_ebpo[].

  delete adjacent duplicates from it_ebpos comparing banfn.

  clear pohead,poitem,poitemtext,poaccount.
  refresh poitem,poitemtext,poaccount.

  loop at it_ebpos into wa_ebpos.
    pohead-comp_code  =  '1000'.
    pohead-doc_type   =  wa_ebpos-doctyp.
    pohead-vendor     =  wa_ebpos-lifnr.
    pohead-purch_org  =  '1000'.
    pohead-pur_group  =   wa_ebpos-ekgrp.
    pohead-currency   'IDR' .
    pohead-doc_date   =  sy-datum.

*    Append pohead to pohead.

    poheadx-comp_code  c_x.
    poheadx-doc_type   c_x.
    poheadx-vendor     c_x.
    poheadx-purch_org  c_x.
    poheadx-pur_group  c_x.
    poheadx-currency   c_x.
    poheadx-doc_date   c_x.

  endloop.

*  memory_uncomplete =  c_x.

*    Item level
  loop at it_ebpo into wa_ebpo.
*      if sy-subrc eq 0.
    poitem-po_item     =  wa_ebpo-bnfpo.
    poitem-short_text  =  wa_ebpo-txz01.
*   poitem-material    =  it_dat2-co
    poitem-plant       =  wa_ebpo-werks.
*   poitem-stge_loc    = 0.
*   poitem-trackingno  =  it_dat2-col_06.
    poitem-matl_group  =  wa_ebpo-matkl"it_dat2-col_07.
    poitem-preq_no    =   wa_ebpo-banfn.
    poitem-preq_item =    wa_ebpo-bnfpo.
    poitem-quantity    =  wa_ebpo-menge.
    poitem-po_unit     =  wa_ebpo-meins.
    poitem-net_price   =  wa_ebpo-netpr.
*   poitem-acctasscat  =  it_dat2-col_11.
*   poitem-gr_basediv  =  ''.     "Effect on Costcentre
*   poitem-po_price = '2'.        "1 = Gross 2. Net price
    append poitem.

    poitemx-po_item     =   wa_ebpo-bnfpo"it_dat2-col_01."c_x.
    poitemx-po_itemx    c_x.
*   poitemx-short_text  = c_x.
*   poitemx-material    = c_x.
    poitemx-plant       c_x.
    poitemx-stge_loc    c_x.
    poitemx-trackingno   c_x.
    poitemx-matl_group  c_x.
    poitemx-preq_no    c_x.
    poitemx-preq_item   c_x.
    poitemx-quantity    c_x.
    poitemx-po_unit     c_x.
    poitemx-net_price   c_x.
*    poitemx-acctasscat  = c_x.
*    poitemx-gr_basediv  = c_x.   "Effect on Costcentre
*    poitemx-po_price = c_x.
    append poitemx.

    poaccount-po_item       wa_ebpo-bnfpo.
*   poaccount-quantity      = it_dat2-col_08.
*   poaccount-net_value     = it_dat2-col_10.
    poaccount-costcenter    wa_ebpo-kostl.
*   poaccount-orderid       = it_dat2-col_13.
    append poaccount.

    poaccountx-po_item    =   wa_ebpo-bnfpo"it_dat2-col_01.
    poaccountx-quantity   c_x.
    poaccountx-net_value  c_x.
    poaccountx-costcenter c_x.
    poaccountx-orderid    c_x.
    append poaccountx.
  endloop.

  call function 'BAPI_PO_CREATE1'
    exporting
      poheader         pohead
      poheaderx        poheadx
*          testrun          = 'X'
      memory_uncomplete 'X'
    importing
      exppurchaseorder ex_po_number
      expheader        exp_head
    tables
      return           return
      poitem           poitem
      poitemx          poitemx
      poaccount        poaccount
      poaccountx       poaccountx
      potextitem       poitemtext.

  if sy-subrc eq 0.
    call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait 'X'.
    g_po_no ex_po_number.
  endif.

  data mess(35).
  mess ex_po_number.

  wait up to seconds.

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...