首页 > 其他分享 >BAPI

BAPI

时间:2025-01-09 16:22:11浏览次数:1  
标签:BAPI itemdata taxdata lv header lt ls

预制发票:BAPI_INCOMINGINVOICE_PARK

   DATA: ls_header     TYPE bapi_incinv_create_header,
        lt_itemdata   TYPE TABLE OF bapi_incinv_create_item,
        ls_itemdata   TYPE bapi_incinv_create_item,

        lt_taxdata    TYPE TABLE OF bapi_incinv_create_tax,
        ls_taxdata    TYPE bapi_incinv_create_tax,

        bapi_return_t TYPE TABLE OF bapiret2,
        bapi_return_s TYPE bapiret2,
        lv_belnr      TYPE belnr_d,
        lv_gjahr      TYPE gjahr,
        lv_rblgp      TYPE rblgp,
        lv_meins      LIKE ekpo-meins,
        lt_save TYPE TABLE OF znymmt00620,
        ls_save TYPE znymmt00620.


  CLEAR: ls_header, lt_itemdata, lt_taxdata, bapi_return_t,lv_rblgp,
         lv_meins,ls_save,lt_save,ls_tmp,lt_tmp.

  LOOP AT gt_alv ASSIGNING FIELD-SYMBOL(<fs_alv>).
    lv_rblgp = lv_rblgp + 10.
*   如果是第一个行项目,填充表头
    IF lv_rblgp = '10'.
      ls_header-invoice_ind = 'X'.
      ls_header-doc_type    = 'RE'.
      ls_header-doc_date    = <fs_alv>-bldat.
      ls_header-ref_doc_no  = <fs_alv>-xblnr."参考凭证号
      ls_header-pstng_date  = <fs_alv>-budat.
      ls_header-comp_code   = <fs_alv>-bukrs.
      ls_header-bline_date  = <fs_alv>-zfbdt.

*   读取供应商
    SELECT SINGLE lifnr INTO ls_header-diff_inv  FROM ekko WHERE ebeln = <fs_alv>-ebeln.
*   抬头文本
      IF <fs_alv>-ztext IS INITIAL.
        ls_header-header_txt = 'MIS发票预制'.
      ELSE.
        ls_header-header_txt = <fs_alv>-ztext.
      ENDIF.
*   读取币别
      SELECT SINGLE waers  INTO ls_header-currency FROM t001 WHERE bukrs = <fs_alv>-bukrs.
    ENDIF.

*   总金额
*    ls_header-gross_amount =  ls_header-gross_amount + <fs_alv>-wrbtr.
    ls_header-gross_amount =  <fs_alv>-wrbtr.
*   行项目
    ls_itemdata-invoice_doc_item = lv_rblgp.  "发票行项目号
    ls_itemdata-po_number        = <fs_alv>-ebeln.
    ls_itemdata-po_item          = <fs_alv>-ebelp.

*    ls_itemdata-item_amount      = <fs_alv>-wrbtr1.  "changed by gxsk_guoyp 20250106
    ls_itemdata-quantity         = <fs_alv>-menge.
*   单位
    SELECT SINGLE meins INTO ls_itemdata-po_unit FROM ekpo WHERE ebeln = <fs_alv>-ebeln AND ebelp = <fs_alv>-ebelp.
    ls_itemdata-po_unit_iso   = ls_itemdata-po_unit.
    ls_itemdata-tax_code         = <fs_alv>-mwskz1.
    APPEND  ls_itemdata TO lt_itemdata.
    CLEAR: ls_itemdata.
*&-----  税额
    ls_taxdata-tax_code     = <fs_alv>-mwskz1.
    ls_taxdata-tax_amount   = <fs_alv>-wmwst.
    APPEND ls_taxdata TO lt_taxdata.

**&   处理税码
*  DATA: ws_taxdata LIKE ls_taxdata.
*  SORT lt_taxdata BY tax_code.
*  CLEAR ws_taxdata.
*  LOOP AT lt_taxdata INTO ls_taxdata.
*    ws_taxdata-tax_code  = ls_taxdata-tax_code.
*    ws_taxdata-tax_amount = ws_taxdata-tax_amount + ls_taxdata-tax_amount.
*    AT END OF tax_code.
*      MODIFY lt_taxdata FROM ws_taxdata TRANSPORTING tax_amount
*                        WHERE tax_code = ws_taxdata-tax_code.
*      CLEAR ws_taxdata.
*    ENDAT.
*  ENDLOOP.
  DELETE ADJACENT DUPLICATES FROM lt_taxdata COMPARING tax_code.

  MOVE-CORRESPONDING <fs_alv> TO ls_save.
  ls_save-i_date = sy-datum.
  ls_save-i_uzeit = sy-uzeit.
  ls_save-uname = sy-uname.
  APPEND ls_save TO lt_save.
  AT END OF HBFLG.
*  调用BAPI 生成预制凭证
  CLEAR:lv_belnr,lv_gjahr.
  CALL FUNCTION 'BAPI_INCOMINGINVOICE_PARK'
    EXPORTING
      headerdata       = ls_header
*     ADDRESSDATA      =
    IMPORTING
      invoicedocnumber = lv_belnr
      fiscalyear       = lv_gjahr
    TABLES
      itemdata         = lt_itemdata
*     ACCOUNTINGDATA   =
*     GLACCOUNTDATA    =
*     MATERIALDATA     =
      taxdata          = lt_taxdata
*     WITHTAXDATA      =
*     VENDORITEMSPLITDATA       =
      return           = bapi_return_t
*     EXTENSIONIN      =
*     TM_ITEMDATA      =
    .
  READ TABLE bapi_return_t INTO bapi_return_s WITH KEY type = 'E'.
  IF sy-subrc = 0.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    <fs_alv>-status = icon_red_light.
    LOOP AT bapi_return_t INTO bapi_return_s WHERE type = 'E'.
      CONCATENATE <fs_alv>-msg '/' bapi_return_s-message INTO <fs_alv>-msg.
    ENDLOOP.
  ELSE.
    <fs_alv>-status = icon_green_light.
    <fs_alv>-msg = '发票创建成功'.
   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING
         WAIT          = 'X'.
    WAIT UP TO 1 SECONDS.
    <fs_alv>-belnr = lv_belnr.
    <fs_alv>-gjahr = lv_gjahr.
  ENDIF.
    MOVE-CORRESPONDING <fs_alv> TO ls_tmp.
    APPEND ls_tmp TO lt_tmp.
    CLEAR:ls_tmp,ls_header,ls_itemdata,lt_itemdata,ls_taxdata,lt_taxdata,
          bapi_return_t,lv_belnr,lv_rblgp.
  ENDAT.

  ENDLOOP.
View Code

发票过账:BAPI_INCOMINGINVOICE_POST

 DATA:message   TYPE c LENGTH 200.
  DATA:lv_awkey  TYPE bkpf-awkey.
  DATA:lt_return LIKE TABLE OF bapiret2 WITH HEADER LINE.
  DATA:lt_save TYPE TABLE OF znymmt00620,
       ls_save TYPE znymmt00620.

  CLEAR:lt_tmp,ls_tmp.

  SORT gt_alv BY belnr.
  LOOP AT gt_alv ASSIGNING FIELD-SYMBOL(<fs_alv>) WHERE status = icon_green_light.
    AT END OF belnr.

   CALL FUNCTION 'BAPI_INCOMINGINVOICE_POST'
    EXPORTING
      invoicedocnumber = <fs_alv>-belnr
      fiscalyear       = <fs_alv>-gjahr
    TABLES
      return           = lt_return.
  CLEAR:message.
  LOOP AT lt_return WHERE type = 'A' OR type = 'E' .
    CONCATENATE message lt_return-message INTO message SEPARATED BY  '/'.
  ENDLOOP.
  IF  sy-subrc <> '0'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

    CLEAR lv_awkey.
    CONCATENATE <fs_alv>-belnr <fs_alv>-gjahr INTO lv_awkey.
    SELECT SINGLE belnr
      INTO @DATA(lv_belnr)
      FROM bkpf
      WHERE awkey = @lv_awkey.
    CONCATENATE '凭证:' lv_belnr '创建成功' INTO message.
    <fs_alv>-status = icon_green_light.
    <fs_alv>-msg = message.
    <fs_alv>-belnr1 = lv_belnr.
  ELSE.
    <fs_alv>-status = icon_red_light.
    <fs_alv>-msg = message.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ENDIF.
View Code

 

标签:BAPI,itemdata,taxdata,lv,header,lt,ls
From: https://www.cnblogs.com/coderfarmer/p/18662358

相关文章

  • webapi 集成 log4net 写入 ElasticSearch
    log4net.config<log4net><appendername="RollingLogFileAppender"type="log4net.Appender.RollingFileAppender"><!--定义文件存放位置--><filevalue="log/"/><appendToFilevalue="true"......
  • webapi 集成 之 freesql 注入
    usingEasyCaching.SQLite;usingjxc.Repository;usingjxc.Service;namespacejxc.Api;publicclassProgram{publicstaticvoidMain(string[]args){WebApplicationBuilderbuilder=WebApplication.CreateBuilder(args);//Addser......
  • 在 ASP.NET Core WebAPI如何实现版本控制?
    在ASP.NETCoreWebAPI中实现版本控制(Versioning)是一种常见的做法,用于管理API的演进和兼容性。通过版本控制,我们可以在不破坏现有客户端的情况下引入新功能或修改现有功能。以下是实现版本控制的几种常见方法:1.使用URL路径版本控制将版本号嵌入到URL路径中,例如/api/v......
  • WebApi使用 (.Net Framework版)
    1创建使用.Net做web后端,推荐使用.NetCore,微软在此基础上做了很多适配,包括内置Swagger,可以直接启动等等。而.NetFramework版,需要手动配置很多内容。如果需要调用的项目是基于.NetFramework,那么web项目也应基于.NetFramework开发。或者其他原因不得不使用.NetFramework开发w......
  • .net6 WebApi 使用特性实现自动依赖注入
    首先搞三个特性类///<summary>///作用域///</summary>[AttributeUsage(AttributeTargets.Class)]publicclassDiScopedAttribute:Attribute{}///<summary>///单例///</summary>[AttributeUsage(AttributeTargets.Class)]publicclassDiSing......
  • dotnet最小webApi开发实践
    dotnet最小webApi开发实践软件开发过程中,经常需要写一些功能验证代码。通常是创建一个console程序来验证测试,但黑呼呼的方脑袋界面,实在是不讨人喜欢。Web开发目前已是网络世界中的主流,微软在asp.net框架大行其道之下,也整了个最小webapi项目开发向导。今天,我也拥抱一下新的开发......
  • WebApiDemo
    以下是一个使用ASP.NETWebAPI(基于.NETFramework)的简单示例。1.创建ASP.NETWebAPI项目首先,确保你已经安装了VisualStudio,并且选择了包含ASP.NET和Web开发工作负载的安装选项。打开VisualStudio。选择“创建新项目”。在搜索栏中输入“ASP.NETWeb应用程序(.NETFra......
  • asp.net core webapi 向前端返回一个文件
    后端接口返回文件[Authorization]//给下载模版添加权限[HttpGet]publicIActionResultDownloadTemplate(){//AppContext.BaseDirectory用于获取项目根目录varfilePath=$"{AppContext.BaseDirectory}/MyStaticFiles/取货模板.csv";if(!System.IO.File.E......
  • C# 在Windform程序中搭建Webapi
    1.在NuGet引用owinMicrosoft.AspNet.WebApi.OwinMicrosoft.AspNet.WebApi.OwinSelfHostMicrosoft.Owin.StaticFiles2.添加服务启动配置类 Startup1usingWebapiTest.App_Start;2usingMicrosoft.Owin.FileSystems;3usingMicrosoft.Owin.StaticFiles;4usingO......
  • ABAP开发-批量导入BAPI和BDC_1
    系列文章目录文章目录系列文章目录@[TOC](文章目录)前言一、概念二、BDC和BAPI数据导入1、BDC数据导入(录屏)2、BAPI数据导入三、实例1、BAPI2、BDC总结前言一、概念SAP中,对一个事务码反复操作并且达到批量处理数据的效果,即批量导入,重复操作一类数据,从而用程序模......