4

I am looking for a function module that does the calculation schema for arbitrary material.

When opening ME23N and looking for the position details you have the tab Conditions where the table showing contains the base price and various conditions and below the "endprice". But since the price finding calculates the (baseprice + conditions) * amount as the netto value and divides this by the amount this can lead to rounding issues where the calculated value of 4,738 gets rounded to 4,74 which gets stored as netto price. Now when calculating nettoprice * amount this value can be different to the original value printed on the purchase document.

Since the purchase-document-value is not stored in the EKPO my goal is to re-evaluate this value by simply calling a function module with the material number and the calculation schema and any necessary parameter to give me the actual value that (again) is printed on the document.

Is there any function module that can do this or do I have to code the logic by myself?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Radinator
  • 1,048
  • 18
  • 58
  • 1
    haven't tried it, but BAPI_PO_CREATE1 with TESTRUN='X' should give you the conditions. With the TESTRUN flag the FM essentially creates the purchase order but doesn't save it. – Dirk Trilsbeek Aug 23 '21 at 09:48
  • Thank you for this comment, I managed to find the FM BAPI_PO_GETDETAIL1 by looking for the tables of your suggested FM and where they are used. Since your solution does require too much input and the BAPI_PO_GETDETAIL1 is easier (just feed it with the PO number and you get a table with the conditions - the data I wanted) I will use this. Feel free to post your comment as an anwer and I will award you with the bounty :) – Radinator Aug 23 '21 at 10:38
  • 2
    BAPI_PO_GETDETAIL1 gives you an existing PO. If that suffices, that's perfectly fine. If you want to know the _current_ price and want to simulate the calculation, you'll have to use BAPI_PO_CREATE1, which will give you the conditions for the date you specify. You will need to provide a few fields, essentially doc type, vendor, purchase org and purchase group in the header and material number, plant, quantity and quantity unit per item. – Dirk Trilsbeek Aug 23 '21 at 11:10
  • Agree with Dirk. In your question it is implied that you want to evaluate conditions by material number only and you you don't have PO number. If you have PO then BAPI_PO_GETDETAIL1 is okay – Suncatcher Aug 23 '21 at 11:29
  • Yes BAPI_PO_GETDETAIL1 suffices my needs. I want to re-evaluate the price that was printed on a PO document so I don't need the *current* price but rather the price the material had costed when the PO was created. – Radinator Aug 23 '21 at 11:59

1 Answers1

2

As I wrote in my comment the solution is the FM BAPI_PO_GETDETAIL1. If you supply the PO number you get several tables containing information that is displayed in the PO create/view transaction. One of them is the iTab POCOND that has all conditions. Then you just have to read this iTab and calculate the values and add them up.

lv_ebeln = 4711
lv_ebelp = 10
" Call FM to get the detail data for one PO and each position
call function 'BAPI_PO_GETDETAIL1'
  exporting
    purchaseorder = lv_ebeln
  tables
    pocond = gt_pocond
.

" Loop over the iTab and only read entries for position 10
loop at gt_pocond
    into gs_pocond
    where itm_number = lv_ebelp.
    
    " Get the netto value NAVS
    if ( gs_pocond-cond_type =  'NAVS' ).
        lv_netwr = gs_pocond-conbaseval.
    endif.

endloop.    
Radinator
  • 1,048
  • 18
  • 58