1. 程式人生 > >BAPI_ACC_MANUAL_ALLOC_POST 費用分配函式的小bug及解決辦法

BAPI_ACC_MANUAL_ALLOC_POST 費用分配函式的小bug及解決辦法

function bapi_acc_manual_alloc_post.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  IMPORTING
*"     VALUE(DOC_HEADER) LIKE  BAPIDOCHDRU12P STRUCTURE  BAPIDOCHDRU12P
*"     VALUE(IGNORE_WARNINGS) LIKE  BAPIIW-IGNWARN DEFAULT SPACE
*"  EXPORTING
*"     VALUE(DOC_NO) LIKE  BAPIDOCHDRU12P-DOC_NO
*"  TABLES
*"      DOC_ITEMS STRUCTURE  BAPIMAITM
*"      RETURN STRUCTURE  BAPIRET2
*"      CUSTOMER_FIELDS STRUCTURE  BAPIEXTC OPTIONAL
*"----------------------------------------------------------------------

專案中我們用這個BAPI來做費用分攤,有一次竟然報錯“請輸入有計量單位的數量”。本能的反應以為是沒有輸入單位,後來跟蹤檢查才發現了這個 BAPI的內幕。

BAPI中呼叫了函式 K40C_CO_ACTUAL_POSTING,在這個函式,會對許多引數進行校驗,其中有一個函式 'K40C_DOCUMENT_LINE_CHECK' ,裡面呼叫了一個函式

call  function  'UNIT_CONVERSION_SIMPLE'
  exporting
   input = doc_item-ausbr
   round_sign = 'X'
   unit_in = doc_item-aubeh
   unit_out = itobjects-auseh
  importing


   output = ausbtr

這是個簡單的單位轉換函式,但是由於設定了round_sign = 'X' 表示會在單位轉換後進行四捨五入,這樣就會把5毛錢以下的金額舍為0,於是便出現了錯誤。

之前認為BAPI_ACC_MANUAL_ALLOC_POST 只能進行5毛錢以上的費用分攤,後來向SAP提了message,回覆得到的訊息是已經在一個note中得到解決。

原文如下:

“the message has been forwarded to us in CO-OM development. As far as described, I think note 614127 should be the exact alternative to avoid rounding of quantities for manual CO-postings.”

找到note 614127,描述如下:

Symptom
You enter quantities for manual CO actual postings. Even though you can enter up to three decimal places for the quantity, the system rounds the quantity.

Reason and Prerequisites
You have implemented the corrections from Note 503659 or you have imported one of the Support Packages SAPKH46B41, SAPKH46C32 or SAPKH46C33.

The quantities are always rounded according to the number of decimal places defined for the selected unit of measure. This was not the case for the manual actual postings due to a program error that was corrected with Note 503659.

Solution

  • Change the number of decimal places for the selected unit of measure (transaction CUNI, maintenance of units of measurement). Note the following: The "Decimal pl. rounding" field (number of decimal places to which figure is to be rounded) in the "Conversion" section is relevant for rounding quantities. The "Decimal places" field in the "Display" section is not relevant.

or

Implement the program modification. This prevents the rounding of the quantity.

這裡面提到了note 503659,檢查了一下系統,一般補丁都已經打了。於是按照解決方法裡面寫的步驟,執行CUNI,修改單位的配置引數。在 BAPI_ACC_MANUAL_ALLOC_POST裡面用到的單位是EA,於是雙擊EA,將Decimal pl. rounding填入2,表示小數點後兩位進行四捨五入。然後儲存。

測試通過。