VF01生成billing憑證:BAPI_BILLINGDOC_CREATEMULTIPLE


VF01生成billing憑證:BAPI_BILLINGDOC_CREATEMULTIPLE

  form frm_generate_billing .
*-------------------------------------------------------------------------
*            EKBE部分 生成VF01憑證
*-------------------------------------------------------------------------
  data: lt_billingdatain   type table of bapivbrk,
        ls_billingdatain   type bapivbrk,
        lt_success         type table of bapivbrksuccess,
        ls_success         type bapivbrksuccess,
        lt_return2          type table of bapiret1,
        ls_return2          type bapiret1.

  data: lv_fkart      type vbrk-fkart,
        lv_vbtyp      type vbrk-vbtyp.

* BAPI賦值
  loop at gt_alv into gs_alv where source = 'EKBE' and jspri ne 0.
    clear: lv_vbtyp,lv_vbtyp.
    ls_billingdatain-doc_number    = gs_alv-ebeln. "采購訂單
    ls_billingdatain-itm_number    = gs_alv-ebelp. "采購訂單行項目
    ls_billingdatain-ref_doc       = gs_alv-belnr. "交貨單號
    ls_billingdatain-ref_item      = gs_alv-buzei. "交貨單行項目
    select single fkaiv vbtyp into (lv_fkart,lv_vbtyp) from likp where vbeln = gs_alv-belnr.
    ls_billingdatain-ordbilltyp    = lv_fkart.
    ls_billingdatain-ref_doc_ca    = lv_vbtyp.
    select single vkorg vtweg spart kunnr
      into (ls_billingdatain-salesorg,ls_billingdatain-distr_chan,
            ls_billingdatain-division,ls_billingdatain-ship_to)
      from ekpv
      where ebeln = gs_alv-ebeln
       and  ebelp = gs_alv-ebelp.
    ls_billingdatain-sold_to       = ls_billingdatain-ship_to. "售達方
    ls_billingdatain-bill_to       = ls_billingdatain-ship_to.  "開票方
    ls_billingdatain-payer         = ls_billingdatain-ship_to.  "付款方
    select single a~zterm a~inco1 a~inco2 b~werks
      into (ls_billingdatain-payment_terms,ls_billingdatain-incoterms1,
             ls_billingdatain-incoterms2,ls_billingdatain-plant)
      from ekko as a
      inner join ekpo as b on b~ebeln = a~ebeln
      where b~ebeln = gs_alv-ebeln
       and  b~ebelp = gs_alv-ebelp.
    ls_billingdatain-material      = gs_alv-matnr.
    ls_billingdatain-req_qty       = abs( gs_alv-jsshl ).
    ls_billingdatain-sales_unit    = gs_alv-meins.
    ls_billingdatain-bill_date     = g_post_date.
    append ls_billingdatain to lt_billingdatain.

    clear: ls_billingdatain.
  endloop.

  sort lt_billingdatain by ref_doc ref_item.
  refresh: gt_ztfi014,lt_return,lt_success.
  clear:ls_return,ls_success.
  call function 'BAPI_BILLINGDOC_CREATEMULTIPLE'
    tables
      billingdatain = lt_billingdatain
      return        = lt_return
      success       = lt_success.

  if lt_success[] is initial.
    cp_eind = 'X'.
  endif.

  if cp_eind eq 'X'.
    call function 'BAPI_TRANSACTION_ROLLBACK'.
  else.
    call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait = 'X'.

    "返回成功的發票號
    loop at lt_success into ls_success.
      clear: gs_log.
      gs_log-docno = ls_success-bill_doc.
      gs_log-message = ls_success-bill_doc_item.
      append gs_log to gt_log.

*---插入值到表ZTFI014
      clear: gs_ztfi014.
      gs_ztfi014-tcode = sy-tcode.
      gs_ztfi014-seqno = p_datum.
      gs_ztfi014-objnr = p_bukr2.
      gs_ztfi014-gjahr = p_datum(4).
      gs_ztfi014-bukrs = p_bukrs.
      gs_ztfi014-belnr = ls_success-bill_doc.
      append gs_ztfi014 to gt_ztfi014.
      clear: gs_log,gs_ztfi014.
    endloop.

    read table lt_success into ls_success index 1.

*----處理ztfi014表
    sort gt_ztfi014 by belnr.
    delete adjacent duplicates from gt_ztfi014 comparing belnr.
    insert ztfi014 from table gt_ztfi014 accepting duplicate keys.

  endif.

  loop at lt_return into ls_return.
    clear gs_log.
    gs_log-type = ls_return2-type.
    gs_log-docno = invoicedocnumber.
    call function 'MESSAGE_TEXT_BUILD'
      exporting
        msgid               = ls_return-id
        msgnr               = ls_return-number
        msgv1               = ls_return-message_v1
        msgv2               = ls_return-message_v2
        msgv3               = ls_return-message_v3
        msgv4               = ls_return-message_v4
      importing
        message_text_output = gs_log-message.

    case gs_log-type.
      when 'S'.
        gs_log-icon = '3'.
      when 'W'.
        gs_log-icon = '2'.
      when 'E' or 'A'.
        gs_log-icon = '1'.
      when others.
    endcase.

    append gs_log to gt_log.
    clear ls_return2.
  endloop.
  if cp_eind eq 'X'."billing憑證 .
    message e001(00) with 'VF01生成billing憑證失敗,請點擊顯示消息查看詳細信息!'.
  endif.
endform.                    " FRM_GENERATE_BILLING


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM