Showing posts with label FM. Show all posts
Showing posts with label FM. Show all posts

Thursday, 25 January 2024

VF01 - Create Billing FM BAPI_BILLINGDOC_CREATEMULTIPLE


 

typesbegin of ty_sales,
          vbeln type vbak-vbeln,
          vbtyp type vbak-vbtyp,
          auart type vbak-auart,
          vkorg type vbak-vkorg,
          vtweg type vbak-vtweg,
          spart type vbak-spart,
          kunnr type vbak-kunnr,
          posnr type vbap-posnr,
          matnr type vbap-matnr,
          werks type vbap-werks,
        end of ty_sales.

  datait_sale type table of ty_sales with header line.
  datawa_sale type ty_sales.

  datat_success type standard table of bapivbrksuccess with header line.
  datat_billing type standard table of bapivbrk with header line.
  datalv_creatordatain   type bapicreatordata.
  datalv_testrun   type bapivbrktestrun-testrun.
  datalt_conditiondatain   type standard table of bapikomv.
  datalv_posting   type posting_type_ct.
  datalt_ccarddatain   type standard table of bapiccard_vf with header line..
  datalt_textdatain   type standard table of bapikomfktx.
  datalt_errors   type standard table of bapivbrkerrors.

  datat_datain type standard table of  bapicreatordata  with header line.

  datat_return type standard table of bapireturn1 with header line.

  refresh it_sale.
  refresh it_saleclear wa_sale.
  select vbak~vbeln
         vbak~vbtyp
         vbak~auart
         vbak~vkorg
         vbak~vtweg
         vbak~spart
         vbak~kunnr
         vbap~vbeln
         vbap~posnr
         vbap~matnr
         vbap~werks
    into corresponding fields of table it_sale
    from vbak
    inner join vbap as vbap on vbap~vbeln eq vbak~vbeln
    where vbak~vbeln g_cont.

  clear t_billing.
  loop at it_sale into wa_sale.
    t_billing-salesorg   wa_sale-vkorg.
    t_billing-distr_chan wa_sale-vtweg.
    t_billing-division   wa_sale-spart.
    t_billing-doc_type   wa_sale-auart.
    t_billing-ref_doc    wa_sale-vbeln.
    t_billing-ref_item   wa_sale-posnr.
    t_billing-doc_number wa_sale-vbeln.
    t_billing-itm_number wa_sale-posnr.

*    t_billing-ORDBILLTYP = 'ZIW2'.

*    t_billing-ordbilltyp = 'ZIW3'.


    t_billing-price_date sy-datum.
    t_billing-ref_doc_ca wa_sale-vbtyp.
    t_billing-sold_to wa_sale-kunnr.
    t_billing-material wa_sale-matnr.
    t_billing-plant wa_sale-werks.
    append t_billing.
  endloop.

*  Append lt_ccarddatain.


*
  call function 'BAPI_BILLINGDOC_CREATEMULTIPLE'
*    EXPORTING
*      Creatordatain   = t_datain
    tables
      billingdatain   t_billing
*      Conditiondatain = lt_conditiondatain
*      Ccarddatain     = lt_ccarddatain
*      Textdatain      = lt_textdatain
      errors          lt_errors
      return          lt_return
      success         t_success.




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

    loop at t_return where type 'S' and message_v1(1'5'.
      g_bill t_return-message_v1.
    endloop.
  endif.

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.

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