The following lines contain the word 'select', 'insert', 'update' or 'delete':
* we don't have to select from MTL_DEMAND.
*/
IF p_supply_source_id = -1 THEN
DECLARE
BEGIN
SELECT supply_source_header_id INTO x_wip_entity_id
FROM mtl_demand
WHERE organization_id = p_org_id
AND supply_source_type = 5
AND demand_source_header_id = p_so_header_id
AND demand_source_line = p_so_line
AND Decode(p_so_delivery, NULL, '@@@', demand_source_delivery) = Nvl(p_so_delivery,'@@@')
AND demand_source_type = 2
AND reservation_type in (2,3)
AND ROWNUM = 1;
SELECT entity_type INTO x_wip_entity_type
FROM wip_entities
WHERE wip_entity_id = x_wip_entity_id;
SELECT transaction_source_id INTO x_wip_entity_id
FROM mtl_transactions_interface
WHERE organization_id = p_org_id
/* Bug fix 4889919 */
and transaction_source_type_id = 5
/* End of bug fix 4889919 */
AND demand_source_header_id = p_so_header_id
AND demand_source_line = p_so_line
AND Decode(p_so_delivery, NULL, '@@@', demand_source_delivery) = Nvl(p_so_delivery,'@@@')
AND flow_schedule = 'Y'
AND process_flag = 1
AND ROWNUM = 1;
SELECT Nvl(primary_uom_quantity,0) INTO x_qty
FROM mtl_demand
WHERE organization_id = p_org_id
AND demand_source_header_id = p_so_header_id
AND demand_source_line = p_so_line
AND demand_source_delivery = p_so_delivery
AND demand_source_type = 2
AND reservation_type = 1
AND row_status_flag = 1
AND parent_demand_id IS NOT null
AND ((config_status = 20 AND demand_type= 4)
OR (config_status = 20 AND NVL(demand_type,6) = 6));