【MM】基於收貨的發票校驗Bapi Demo
正常我們都會在供應商主檔和資訊記錄主檔中勾選“基於收貨的發票校驗”選項,意味著做採購發票校驗的時候需要基於收貨憑證。
LS_ITEM-REF_DOC = LT_ZMSEG-MBLNR.
LS_ITEM-REF_DOC_YEAR = LT_ZMSEG-MJAHR.
LS_ITEM-REF_DOC_IT = LT_ZMSEG-ZEILE.
下面分享一個簡單的Demo:
1、資料準備
DATA: LS_HEADER TYPE BAPI_INCINV_CREATE_HEADER.
DATA: LT_ITEMS TYPE TABLE OF BAPI_INCINV_CREATE_ITEM.
PERFORM FILL_VALUES TABLES LT_ITEMS
USING LS_HEADER.
PERFORM RUN_TO_CREATE_IV TABLES LT_ITEMS
USING LS_HEADER.
2、資料填充
*&---------------------------------------------------------------------*
*& Form fill_values
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_ITEMS text
* -->PS_HEADER text
*----------------------------------------------------------------------*
FORM FILL_VALUES TABLES PT_ITEMS STRUCTURE BAPI_INCINV_CREATE_ITEM
USING PS_HEADER TYPE BAPI_INCINV_CREATE_HEADER.
DATA: LS_ITEM LIKE LINE OF PT_ITEMS[].
FIELD-SYMBOLS: <LS_ITEM> LIKE LINE OF PT_ITEMS[].
DATA: LS_DATA2 LIKE LINE OF GT_DATA2.
DATA: LV_AMOUNT(40).
DATA: LS_EKPO TYPE EKPO.
DATA: LT_ZMSEG LIKE TABLE OF ZMSEG WITH HEADER LINE.
DATA: LT_ZMSEG1 LIKE TABLE OF ZMSEG WITH HEADER LINE.
DATA: LV_ITEM TYPE N LENGTH 6.
DATA: LV_NETWR TYPE ZMJMIMS0023-NETWR.
"Fill Header data
READ TABLE GT_DATA2 INTO LS_DATA2 INDEX 1.
SELECT SINGLE RETPO
FROM EKPO
INTO LS_EKPO-RETPO
WHERE EBELN = LS_DATA2-EBELN
AND EBELP = LS_DATA2-EBELP.
IF LS_EKPO-RETPO = 'X'.
PS_HEADER-INVOICE_IND = SPACE.
ELSE.
PS_HEADER-INVOICE_IND = 'X'.
ENDIF.
PS_HEADER-DOC_TYPE = 'RE'.
PS_HEADER-DOC_DATE = ZMCAIMS0021-COMDT.
PS_HEADER-PSTNG_DATE = ZMCAIMS0021-BUDAT.
PS_HEADER-COMP_CODE = ZMCAIMS0021-BUKRS.
PS_HEADER-CURRENCY = ZMCAIMS0021-WAERS.
CLEAR: LV_AMOUNT.
WRITE ZMCAIMS0021-RMWWR TO LV_AMOUNT CURRENCY ZMCAIMS0021-WAERS.
REPLACE ALL OCCURRENCES OF ',' IN LV_AMOUNT WITH ''.
PS_HEADER-GROSS_AMOUNT = LV_AMOUNT.
PS_HEADER-PMNTTRMS = ZMCAIMS0021-ZTERM.
PS_HEADER-BLINE_DATE = ZMCAIMS0021-BUDAT.
PS_HEADER-PERSON_EXT = SY-UNAME.
PS_HEADER-HEADER_TXT = ZMCAIMS0021-BLENO.
PS_HEADER-REF_DOC_NO = ZMCAIMS0021-COMIV.
CLEAR :GV_IV,LV_ITEM.
SORT GT_DATA2.
LOOP AT GT_DATA2 INTO LS_DATA2.
REFRESH LT_ZMSEG[].
CLEAR : LV_MENGE_TOL,LV_AMOUNT_TOL."合計校驗
SELECT * FROM ZMSEG
INTO TABLE LT_ZMSEG
WHERE EBELN = LS_DATA2-EBELN
AND EBELP = LS_DATA2-EBELP
AND BWART IN ('101','102','161','162').
"剔除沖銷專案
LT_ZMSEG1[] = LT_ZMSEG[].
LOOP AT LT_ZMSEG1 WHERE SMBLN IS NOT INITIAL.
DELETE LT_ZMSEG WHERE MBLNR = LT_ZMSEG1-SMBLN
AND ZEILE = LT_ZMSEG1-SMBLP.
ENDLOOP.
DELETE LT_ZMSEG WHERE SMBLN IS NOT INITIAL.
LOOP AT LT_ZMSEG.
CLEAR: LS_ITEM.
CHECK LT_ZMSEG-MENGE > 0.
LV_ITEM = LV_ITEM + 1.
LS_ITEM-INVOICE_DOC_ITEM = LV_ITEM.
LS_ITEM-PO_NUMBER = LS_DATA2-EBELN.
LS_ITEM-PO_ITEM = LS_DATA2-EBELP.
LS_ITEM-REF_DOC = LT_ZMSEG-MBLNR."參照收貨憑證
LS_ITEM-REF_DOC_YEAR = LT_ZMSEG-MJAHR.
LS_ITEM-REF_DOC_IT = LT_ZMSEG-ZEILE.
LS_ITEM-TAX_CODE = 'J0'.
LS_ITEM-ITEM_TEXT = PS_HEADER-ITEM_TEXT.
LS_ITEM-QUANTITY = LT_ZMSEG-MENGE.
LS_ITEM-PO_UNIT = LT_ZMSEG-MEINS.
CLEAR: LV_NETWR,LV_AMOUNT.
LV_NETWR = LT_ZMSEG-MENGE * LS_DATA2-NETPR.
WRITE LV_NETWR TO LV_AMOUNT CURRENCY ZMCAIMS0021-WAERS.
REPLACE ALL OCCURRENCES OF ',' IN LV_AMOUNT WITH ''.
LS_ITEM-ITEM_AMOUNT = LV_AMOUNT.
APPEND LS_ITEM TO PT_ITEMS.
ENDLOOP.
ENDLOOP.
ENDFORM. "fill_values
3、Bapi呼叫
*&---------------------------------------------------------------------*
*& Form run_to_create_iv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_ITEMS text
* -->PS_HEADER text
*----------------------------------------------------------------------*
FORM RUN_TO_CREATE_IV TABLES PT_ITEMS STRUCTURE BAPI_INCINV_CREATE_ITEM
USING PS_HEADER TYPE BAPI_INCINV_CREATE_HEADER.
DATA: LT_RET TYPE TABLE OF BAPIRET2.
DATA: LV_INVNO TYPE BAPI_INCINV_FLD-INV_DOC_NO,
LV_FYEAR TYPE BAPI_INCINV_FLD-FISC_YEAR.
DATA: LS_BKPF TYPE BKPF.
CLEAR: LT_RET.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
HEADERDATA = PS_HEADER
* ADDRESSDATA =
IMPORTING
INVOICEDOCNUMBER = LV_INVNO
FISCALYEAR = LV_FYEAR
TABLES
ITEMDATA = PT_ITEMS[]
* ACCOUNTINGDATA =
* GLACCOUNTDATA =
* MATERIALDATA =
* TAXDATA = lt_taxes
* WITHTAXDATA =
* VENDORITEMSPLITDATA =
RETURN = LT_RET.
PERFORM CHECK_BAPI_ERROR USING LT_RET.
IF GV_BAPI_ERROR <> 'X'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.
MESSAGE S398(00) WITH 'Invoice document(' ZMCAIMS0021-INVNO ') created'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
PERFORM SHOW_MESSAGE USING LT_RET.
ENDIF.
ENDFORM. " run_to_create_iv
*&---------------------------------------------------------------------*
*& Form show_message
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_MSG text
*----------------------------------------------------------------------*
FORM SHOW_MESSAGE USING PT_MSG TYPE BAPIRET2_T.
PERFORM CHECK_BAPI_ERROR USING PT_MSG[].
IF GV_BAPI_ERROR = 'X'."오류 메시지가 발생했을 경우
CALL FUNCTION 'FB_MESSAGES_DISPLAY_POPUP'
EXPORTING
* IT_SMESG =
* ID_SMESG_ZEILE =
IT_RETURN = PT_MSG[]
* ID_SEND_IF_ONE =
EXCEPTIONS
NO_MESSAGES = 1
POPUP_CANCELLED = 2
OTHERS = 3.
ENDIF.
ENDFORM. " show_message
*&---------------------------------------------------------------------*
*& Form check_bapi_error
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_BAPI_MSG text
*----------------------------------------------------------------------*
FORM CHECK_BAPI_ERROR USING PT_BAPI_MSG TYPE BAPIRET2_T.
CLEAR: GV_BAPI_ERROR.
READ TABLE PT_BAPI_MSG TRANSPORTING NO FIELDS WITH KEY TYPE = 'E'.
IF SY-SUBRC = 0.
GV_BAPI_ERROR = 'X'.
ENDIF.
READ TABLE PT_BAPI_MSG TRANSPORTING NO FIELDS WITH KEY TYPE = 'A'.
IF SY-SUBRC = 0.
GV_BAPI_ERROR = 'X'.
ENDIF.
ENDFORM. " check_bapi_error
相關文章
- SAP MM 發票預製 Function Module - BAPI_INCOMINGINVOICE_PARKFunctionAPI
- SAP MM BAPI_PO_CREATE1的用法API
- Spring Boot中基於HTML發票/收據生成和下載功能Spring BootHTML
- 基於jquery+html開發的json格式校驗工具jQueryHTMLJSON
- SAP MM 預製發票相關的Function ModulesFunction
- C++發票識別、發票查驗介面示例,您的“發票管理專家”C++
- Java財政票據查驗介面、醫療票據查驗、發票驗真介面Java
- 2.4 一種基於kafka增量資料校驗的方案Kafka
- 學校飯票--區塊鏈對虛擬貨幣的認識區塊鏈
- 全國增值稅發票查驗介面平臺-JavaScript發票驗真api示例JavaScriptAPI
- 發票查驗系統中的發票臺賬具有哪些用處
- Laravel基礎之校驗Laravel
- java校驗指定日期格式yyyy-MM-dd的正規表示式Java
- 數電票如何查驗、管理?C#發票查驗介面整合C#
- 好用的發票核驗API,快速接入API
- 基於react的影院購票應用React
- 基於DataTables的資料操作demo
- 基於crc32實現的記憶體的程式碼校驗記憶體
- JavaScript免費的發票驗真介面示例文件-發票真偽查驗與資訊識別JavaScript
- 「SAP技術」SAP MM 委外加工採購流程裡副產品的收貨
- 基於SpringBoot的策略模式demoSpring Boot模式
- 基於java的RSS線上訂閱demoJava
- 基於Node.js的驗收測試框架—Nightwatch.jsNode.js框架
- SAP MM 一個含有多個賬號分配物件的行專案的PO及其收貨物件
- SAP MM取消採購訂單審批--- BAPI_PO_RESET_RELEASEAPI
- MM採購合同和計劃協議,建立物料主資料分類的特性值 BAPI :BAPI_CONTRACT_CREATE協議API
- WPF 資料繫結之ValidationRule資料校驗綜合Demo
- 一個基於Android的MVP框架DemoAndroidMVP框架
- 基於jwSMTP的C++傳送Email的DemoC++AI
- 基於gin的golang web開發:模型驗證GolangWeb模型
- SAP MM 採購訂單收貨之後自動形成分包商庫存?
- 關於協議首部校驗和的問題協議
- (轉)基於SQL的EAN13、ENA8條形碼校驗位生成SQL
- 前端 - 開發中常用的正則校驗前端
- 關 於 深 圳 哪 裡 有 開 定 額 發 票_百度經驗
- SAP MM VL09試圖取消收貨報錯說某個HU負庫存
- springMVC:校驗框架:多規則校驗,巢狀校驗,分組校驗;ssm整合技術SpringMVC框架巢狀SSM
- Sqlserver關於校驗和_備份還原的CHECKSUMSQLServer