Create a transfer order with an Empty Vendor number - sap

I have a requirement where I have to create a transfer order with empty vendor.
The scenario is:
The client want maintains its in house stock, and in-house stock does not has any Special Stock no. (Vendo) in table LQUA.
If this stock is avaialble then the transfer order should be created with LTAP-SONUM = Empty.
I am trying the login in EXIT: EXIT_SAPLMDBF_002
I am currently applying C_XT434P-BPRIO = Empty and C_XT434P-LIFNR =
Empty in my EXIT after the stock validation.
But still SAP standard re-calculate the Vendor and assigns it an Consignment Vendor.
But if I assign an consignment vendor in the EXIT i.e. C_XT434P-BPRIO = 'K'and C_XT434P-LIFNR = Consignment Vendor no., then Transfer order is created with the vendor I have assigned.
Please help me in creating Transfer order with Empty Vendor.

Related

Access: How to retrieve a certain field from a table and return it?

Background
I am currently working on a simple access database for a small bookstore. The business sells books as well as other items.
See following ER-diagram here
Problem
My problem starts in the table Transaction. I would like to create a simple form where a subtotal is calculated as quantity purchased multiplied by the price (both of a certain item).
However the Price field is either in the BookInfo, FoodAndBev, or ApparelAndSupplies table.
Question
How can I traverse the Transaction table to Items and to one of the tables I listed depending on the StockNum in Transaction?
For example, a customer buys an item with StockNum BK001. I would like to retrieve the Price corresponding to BK001 in the BookInfo table and return to Transaction to be used for calculating the subtotal.
The field StockNum exists in tables BookInfo, FoodAndBev, and ApparelAndSupplies.
Sample Data: BookInfo, Items, Transaction
Ideal Output: Transaction 1: A customer buys 2 copies of a book with StockNum 'BK001' (disregard what I already have in the screenshot). The Price of 'BK001' is $119.99 which I would need to retrieve from BookInfo (my problem is I want to make sure it goes to BookInfo not the other two tables which have StockNum also), so the subtotal would then be calculated and would show $239.98. For now, I've been doing this manually. I want to be able to do this with different StockNum such as those that start with AS for Apparel and Supplies and FB for food and beverage.
Thanks in advance!
Left-Joining all tables and using Case-When-Expression (which is function switch in Access) for different price multiplication:
SELECT t.StockNum, t.NumOrdered,
switch(
Left(t.StockNum,2) = 'BK' , (t.NumOrdered * b.Price),
Left(t.StockNum,2) = 'AS' , (t.NumOrdered * a.Price),
Left(t.StockNum,2) = 'FB' , (t.NumOrdered * f.Price),
) AS subtotal
FROM Transaction t
LEFT JOIN BookInfo b ON b.StockNum = t.SockNum
LEFT JOIN ApparelAndSupplies a ON a.StockNum = t.SockNum
LEFT JOIN FoodAndBev f ON f.StockNum = t.SockNum

How to design a Select statement with in line functions and single fields

I'm attempting to design a single SELECT statement that will do the following.
I'm creating a report that shows a file number, a statement value associated with the file number, a total invoice value that is built from all of the invoices associated with the file number, and then the difference between the statement and invoice values if there is one. finally it shows the payment due date.
The report is only suppose to show files where there is a difference between the total invoices and the value of the statement. It is also restricted by only invoices that are marked as Payable (not 'V'), by certain charge codes, and by not being 'FLAGGED' as being worked on.
The data is arranged into three tables. IMPSTATP is for the file level and contains the file number and statement value. The other two are the Invoice header and Invoice payable files.
Now obviously what I have below won't work, but I'm running into some difficulties visualizing a single select statement that will.
SELECT
P.OFFIV, FILEST, TOTDST, PDUEST,
sum(P.AMTPIV - P.DTDCIV),
TOTDST - sum(AMTPIV - DTDCIV)
FROM
IMPSTATP
JOIN ACCIHEDP AS H ON FILEST = H.FILEIV and BKRST = H.BKRIV
JOIN ACCIPBLP AS P ON H.INVIV = P.INVIV and H.BKRIV = P.BKRIV and H.OFFIV = P.OFFIV
WHERE
H.VDPDIV <> 'V' AND
(P.CHGPIV = '011' OR
P.CHGPIV = '012' OR
P.CHGPIV = '093') AND
P.VNNMIV <> 'FLAGGED'
GROUP BY FILEST
HAVING
TOTDST - sum(P.AMTPIV - P.DTDCIV) <> 0;
Keep in mind that this is with an old DB2 database on an IBM iSeries. Any and all suggestions would be welcome.

Simulating For inside For in SQL

I'm using HP Vertica 7 as data warehouse DB.
I need to update two tables at the same time.
foreach (row r in table_1)
{
foreach (row r2 in table_2)
{
if(r.key1 == r2.key1 && r.key2 ==r2.key2 && r.soldQuantity > r2.Quantity)
{
updateRowInT1(); //r.Partner = r2.Partner;
updateRowInT2(); //r2.Quantity = r2.Quantity - r.soldQuantity;
break;
}
}
}
This part of code best describes what I need to do.
Is there any way to do this in SQL (with user-defined functions).
Because of changes in second table I can't use update and join. Or I can?
Also, this is part of ETL process done by Pentaho Kettle. Is perhaps way to do this inside this tool.?
Thanks
Edit:
I have changed code above.
What I need to achieve?
Regular Sales by Partner.
What's wrong right now?
When some SKU is sold in retail shop, I can see SKU LAST Partner. But, company I work for is buying same SKU from more Partners.
Slowly Changing Dimension is not applicable because when we switch partner on SKU, there is still some quantity of that SKU on shelf.
Assumption:
FIFO - first In first Out.
So, for initial matching, I need to compare (in date order) both sales and buying and to decrement bought quantity.
You probably should be thinking in a more set oriented way.
Assuming I understand what you are trying to do properly, I would do this in two update statements:
-- Update table_1's Partner based on a row in table_2.
UPDATE table_1 r
SET Partner = r2.Partner
FROM table_2 r2
WHERE r2.key1 = r.key1
AND r2.key2 = r.key2;
-- Reduce the Quantity in table_2 based on table_1's soldQuantity
UPDATE table_2 r2
SET Quantity = r2.Quantity - r.soldQuantity
FROM table_1 r
WHERE r.key1 = r2.key1
AND r.key2 = r2.key2
AND r2.Quantity >= r.soldQuantity;
-- Both of these should be done in a transaction so it is all or none. Commit the work.
COMMIT;
You can see the SQLFiddle here.

How to delete a sales order which is in sales order status?

I am a newbie to openerp. I have a sales order under the module 'sales' which is in 'Sales Order' status. The order number is 'SO019' . And i want to delete this sales order in the list.
When i tried to delete this sales order i got the following OpenErp Warning
Invalid Action!
In order to delete a confirmed sales order, you must cancel it.
To do so, you must first cancel related picking for delivery orders.
But i have no option to cancel this delivery in the 'warehouse/Delivery Orders'
Instead of this i have the following two options
Print Delivery Slip
Return Products
When i click onto the Return products i am getting the following warning
Warning!
No products to return (only lines in Done state and not fully returned yet can be returned)!
Is there anyway that i can delete this sales order(SO019) in the sales orders list?
Thanks in advance..
When you save the Confirm Sale Order, The Delivery Order is made. So first you need to cancel first delivery order. In Delivery Order has button name Cancel Transfer.
If your delivery order is in Delivered state than you can not delete Sale Order.
At first time for Delivery Order, click on Return Product. The reverse entry is create. You can see that entry in Incoming Shipment. for example IN/001-OUT/002-return entry is created.
Now At Second time you click on Return Product from the Same Delivery order as you do above step than you got your above warning. Because you can not return product twice for same Delivery Order.
Hope this will help you.
If the column status shows 'Sales Order' that means your invoice for that order is created and you can not delete sale order until you delete invoice related to it or order is cancelled.
To delete sale order with status 'Sale order',
Short way:
1] Just click on 'Cancel Order' [and its automatically deleted]
(But invoice related to it is go to cancel state and is visible)
Long way
1] Go to Accounting-> customer invoice
2]Cancel invoice for your sale order.[Invoice status changed to 'Cancelled']
3]Delete that invoice [More-Delete]
4]Go to Sale->Sale Order [Now status is Changed to 'Invoice Exception']
5]Now click on your sale order and then 'Cancel Order' [Now its automatically deleted]

Updating a field within a table based on a field within the same table

HI ALL
I wish to update a row within my table from a row within that same table,
I have a table called INVENTORY. it stores PRICES for products.
I have SALES codes and I have STOCK codes which are related.
I wish to transfer all the PRICING from the SALES codes to the STOCK codes.
I wish to do something like this:
update INVENTORY
set PRICE = (SELECT PRICE WHERE CODE = "SALES CODE EQUIVALENT OF THE STOCK CODE IM IN")
WHERE
CODE = "SOME STOCK CODE"
a SALES CODE would look like this "U_12345", its STOCK code equivalent would look like "S_12345"
thanks
You're very close, you just need to specify which table you're selecting from as part of your sub-query...
update INVENTORY
set PRICE = (SELECT PRICE FROM your_table WHERE CODE = "SALES CODE EQUIVALENT OF THE STOCK CODE IM IN")
WHERE
CODE = "SOME STOCK CODE"
Even if "your_table" is INVENTORY, you still need to specify it in there.
The only time it gets 'tricky' is when your selecting from the same table that you're update, AND when you need a value from the updated record in the SELECT statement. In that case you need to differentiate between the two references, using an alias. For example...
update INVENTORY
set PRICE = (SELECT PRICE FROM INVENTORY AS [new_price] WHERE [new_price].CODE = INVENTORY.NEW_CODE)
WHERE
CODE = "SOME STOCK CODE"
UPDATE INVENTORY
SET PRICE = i_sales.PRICE
FROM INVENTORY, INVENTORY i_sales
WHERE INVENTORY.CODE LIKE 'S\_%'
AND i_sales.CODE = REPLACE(INVENTORY.Code, 'S', 'U')
This updates prices for all 'stock' records in INVENTORY with prices from the corresponding 'sales' records.
If you would prefer to update individual prices, change WHERE to something like this:
WHERE i_stock.CODE = 'S_12345'
or this:
WHERE i_stock.CODE IN ('S_12345', 'S_12346')
Note: The FROM syntax used is based on this doc page.