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?
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.
Related
I am stuck at a problem that I want to solve with REDUCE syntax.
I have this this internal table
I need to sum the values of the column "quantity" and update column called "Totals quantity"
And the same thing with column price in column "Total Price".
This is for each Purchase order.
I have this code right now
Loop at it_numpos Into Data(ls_numpos).
lv_valort = lv_valort + ls_numpos-netpr. " Purchase Order Total Price
lv_cantt = lv_cantt + ls_numpos-menge. " Purchase Total Quantity
At end of ebeln.
ls_numpos-zmenge3 = lv_cantt.
ls_numpos-znetpr6 = lv_valort.
Modify it_numpos From ls_numpos Transporting zmenge3 znetpr6 Where ebeln = ls_numpos-ebeln.
Clear: lv_cantt, ls_numpos, lv_valort.
Endat.
EndLoop.
It is possible to transform this code to abap new syntax?
I don't think REDUCE is the right tool for the job here, as it is meant to reduce the values of a table to one single value. In your case there is not one single value, as you're calculating new values for each sales order. So you would need to somehow loop over the table grouping the items together, then use reduce, then loop again to assign the values back into the table. That would rather complicate the code and just for the sake of using new synax is probably not worth the trouble. I think a LOOP AT is the better choice here, though I'd use a LOOP AT ... GROUP BY and then two LOOP AT GROUP loops, which makes the whole processing quite readable:
LOOP AT order_items ASSIGNING FIELD-SYMBOL(<order_item>) GROUP BY <order_item>-id INTO DATA(order).
DATA(total_price) = 0.
LOOP AT GROUP order ASSIGNING <order_item>.
total_price = total_price + <order_item>-price.
ENDLOOP.
LOOP AT GROUP order ASSIGNING <order_item>.
<order_item>-total_price = total_price.
ENDLOOP.
ENDLOOP.
However whether that is better than group level processing is up to you.
I am working on an assignment and I am trying to display one of the column's values in my data frame as currency $. When doing all the calculations the data displayed on a float but I want to style it to a currency value as it's referring to Total Revenue.
I would really appreciate it if someone could help me out with this one. I am attaching my code. I attached a screenshot of the summary table data returned.
# I created variables to hold the values to later create the summary table with them. I needed to go back and look at the decimal places that were used in the solution. To be able to match the solution format I decided to use the method round()
ItemCount = df["Item Name"].nunique()
AveragePrice = round(df["Price"].mean(),2)
PurchasedNumber = df["Purchase ID"].count()
Revenue = round(df["Price"].sum(),2)
#After I created the variables I need to store them in a summary table like so:
SummaryTable = pd.DataFrame([{"Number of Unique Items": ItemCount, "Average Price": AveragePrice, "Number of Purchases": PurchasedNumber, "Total Revenue": Revenue}])
SummaryTable
Try this:
SummaryTable.loc[:, "Total Revenue"] = SummaryTable["Total Revenue"].map(lambda x: '$' + str(x))
I have the following situation: List A has two columns (Name, Amount) and in List B (Name) I want to add a calculated column which should be the sum of all entries in List A that have the same name as in List B. Example:
List A:
NAME Amount
L0011 100
L0011 50
L0020 234
So in List B I want the calculated column to show:
NAME Amount
L0011 150
L0020 234
How can this be done? Workflow (as soon as I add/mod an entry in List A, update List B) or something else? Thanks
lem.mallari's answer is a huge pain unless you can assume that the Amounts in List A never change, since it's not tracking whether an item has already been added to the sum. There is no way for a Workflow to iterate through a SharePoint list, which means there is no easy way to calculate the sum or average of multiple list items.
The correct way to implement this will will require some development. The SharePoint Developer Training (2010, 2013) will actually get you most of the way there: an event receiver should trigger when items are added or changed in Lists A and B that uses SharePoint's API to go through List A and average values by Name, then update all (or just affected) items in List B. Alternatively, you can use JavaScript to display the sum of all entries in List A that have the same name as the item in List B as long as all the data is displayed on your page. If you're handy with XPath and InfoPath, you could add List A as a secondary data source to List B's form and select only applicable items in List A to sum from.
But if we're talking Workflows, here's the "workflow only" method. This was tested and successful in 2010. Create custom List C with the following columns:
Title (string, mandatory, enforce unique values)
TotalItems (integer, mandatory, default 0)
Sum (number, decimal places however you want, mandatory, default 0)
Average (calculated, =IF(TotalItems=0,0,Sum/TotalItems)) (optional)
Replace the Name columns in Lists A and B with lookup columns pointing at List C. Delete the Amount column in List B, instead including the Sum column as an additional column. Add the following columns to List A, and ensure that users cannot change them directly. This can be restricted by making InfoPath forms or by making alternative view and edit forms.
AmountArchive (number, identical to Amount, default 0)
AmountHasBeenSubmitted (yes/no, default no)
Create a Workflow to run each time an item is created or modified in List A. Use these commands (I'm using a list for readability; it was getting ugly when formatted as code):
If Current Item:Amount not equals Current Item:AmountArchive
Set Variable:Item Count to (Data source: List C; Field from source: TotalItems; Find the List Item: Field Title; Value: Current Item:Name(Return field as: Lookup Value (as Text)))
Calculate Variable:ItemCount plus 1 (Output to Variable: ItemCount)
Calculate List C:Sum (similar settings as above; be sure to use Lookup Value (as Text) and not String!) minus Current Item:AmountArchive (Output to Variable: SumWithoutValue)
Calculate Variable: SumWithoutValue plus Current Item:Amount (Output to Variable: NewSum)
If Current Item:AmountHasBeenSubmitted equals No
Set AmountHasBeenSubmitted to Yes
Update item in List C (Set TotalItems to Variable:ItemCount; Set Sum to Variable:NewSum; Find the List Item in the same way of Field:Title; Value: Current Item:Name(Return field as: Lookup Value (as Text))
Else
Update item in List C (don't do anything to TotalItems; use the same logic to set Sum to Variable:NewSum)
Set Amount to Current Item:AmountArchive
This can't be done using calculated columns because calculated columns can only be used for columns on the same list.
Using SharePoint Designer Workflows you can just use Create List Item and Update List Item actions so that whenever a user adds a value for L0011 the amount will be added in another list's column which contains the previous amounts already.
Let me know if you need a more detailed answer for the SharePoint approach and I'll provide you a step by step instruction on what to do.
What about using the DSum function? https://support.office.com/en-us/article/DSum-Function-08F8450E-3BF6-45E2-936F-386056E61A32
List B
NAME Amount
L0011 =DSum("[Amount]","List A","[NAME]=''" & [NAME] & "'")
L0020 =DSum("[Amount]","List A","[NAME]=''" & [NAME] & "'")
I feel stupid asking this, but I really need an excample on how to get a value of a field in one table (in the end in my report) depending on a value of a field from an other table in Access.
So I have (for excample) a table:
Products and in my report I do a formule using the value of price (field of Products) and adding to that I must have the value of the field VAT-Type (a nummeric var, in the table VATS) depending on what is there in the record (of the one in the table Products) in the field VAT-Sort, also a nummeric var that must meet one of the values used in the field VAT-Type).
So in the report I must have something like:
Product: X Count Price'=(price+21%)'
where 21% comes from the dependensy between the field VAT-Type and VAT-Sort.
I know I can do something like result=select 'VAT-Sort' from 'VATS' WHERE 'VAT-Sort' = or equals 'VAT-type'
But how do I use it in a report of Access to get the right result?
You can use DLookUp:
Numeric data type:
DlookUp("Value","Vats","Vat_Type=" & Vat_Sort)
Text data type:
DlookUp("Value","Vats","Vat_Type='" & Vat_Sort & "'")
Or you can base your report on a query, say:
SELECT Value, Other, Field, names FROM Products
LEFT JOIN Vats
ON Products.VAT_Sort = Vats.Vat_Type
Edit re comments
I have a report that is supposed to show the Stock Value of products before and after conversion.
I have the source products product code and stock value displayed on the form, now I need to get the value of the items converted from that one piece of stock.
I assumed this would be possible to achieve using some simple SQL to calculate the sum of all resulting products with the same SCID (Stock Conversion ID). My SCID is used to link a source product to a number of resulting products in a different table.
In this image I have named the SCID boc in the detail section sSCID to try and differentiate it from any fields in tables that it may try to pick up. But basically I need to get the code to look for result products that match the SCID displayed in that box and add them all together to get the sum total of converted stock.
If context helps I am trying to create a form that shows the value of stock before and after a conversion process in order to try and calculate the wastage.
Thanks,
Bob P
You can either use DSum or build your report query to include the calculation. I would prefer the second option. This assumes that SCID is numeric, you would need quotes for a text SCID.
=DSum("sValue","[Stock Conversion Items]","SCID=" & sSCID)
Or
SELECT r.This,r.That,s.ConvValue
FROM ReportTable r
INNER JOIN (
SELECT SCID, Sum(sValue) As ConvValue
FROM [Stock Conversion Items]
GROUP BY SCID) s
ON r.sSCID = s.SCID
The above query uses aliases r and s for the tables : ReportTable r or ReportTables As r