Oracle DB 12.1.0.2
EBS 12.1
AIX 6
Hello Team,
could you please advise how to rewrite the following functions?
select distinct inventory_item_id, segment1 Item_code, apps.xx_mtg_get_last_poprice(inventory_item_id) Last_PO_Price,
apps.xxmtg_get_max_issuedate(inventory_item_id) Last_Issue_Date
from inv.mtl_system_items_b;
apps.xx_mtg_get_last_poprice(inventory_item_id)
create or replace FUNCTION xx_mtg_get_last_poprice (p_itemid IN NUMBER)
RETURN varchar2
IS
last_po_price varchar2(100);
BEGIN
SELECT max(pha.CURRENCY_CODE)||' ' ||round(max(pla.UNIT_PRICE),2)
INTO last_po_price
FROM po_lines_all pla, po_headers_all pha
WHERE NVL (pla.cancel_flag, 'N') = 'N'
AND pla.po_header_id = pha.po_header_id
AND pha.approved_flag = 'Y'
AND pla.item_id = p_itemid
AND pha.po_header_id =
(SELECT MAX (pla.po_header_id)
FROM po_lines_all pla, po_headers_all pha
WHERE NVL (pla.cancel_flag, 'N') = 'N'
AND pla.po_header_id = pha.po_header_id
AND pha.approved_flag = 'Y'
AND pla.item_id = p_itemid);
RETURN last_po_price;
END;
apps.xxmtg_get_max_issuedate(inventory_item_id)
create or replace FUNCTION xxmtg_get_max_issuedate(p_item_id IN NUMBER)
RETURN DATE
AS
--M. Claire Lock Son
--Function to get the last issue date for a stock item with onhand qty > 0
last_date_issued DATE;
BEGIN
select max(transaction_date)
INTO last_date_issued
from mtl_material_transactions
where inventory_item_id = p_item_id
and transaction_action_id=1;
RETURN last_date_issued;
EXCEPTION
--When no_data_found then
-- Return 'Null';
WHEN OTHERS
THEN
RETURN NULL;
END;
I tried to create 1 view for each function
for price
select b.inventory_item_id inventory_item_id, concat_ws(' ',max(pha.CURRENCY_CODE),cast(max(cast(pla.UNIT_PRICE as decimal(10,2))) as string)) codeprice
FROM oracle_financial.po_lines_all pla, oracle_financial.po_headers_all pha,oracle_financial.mtl_system_items_b b,of_cubes.xx_mtg_get_last_poprice1 xx
WHERE NVL (pla.cancel_flag, 'N') = 'N'
AND pla.po_header_id = pha.po_header_id
AND pha.approved_flag = 'Y'
AND pla.item_id = b.inventory_item_id
AND pha.po_header_id =xx.phi
group by b.inventory_item_id;
and 1 for date
select a.inventory_item_id,max(a.transaction_date) Last_Issue_Date,b.segment1
from oracle_financial.mtl_material_transactions a,oracle_financial.mtl_system_items_b b
where a.inventory_item_id = b.inventory_item_id
and transaction_action_id=1
group by a.inventory_item_id,b.segment1;
Kindly advise how can I combine these?
Thanks,
Roshan