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.

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