Cto Wip Wrapper
Cto Wip Wrapper
BEGIN
EXCEPTION
END IF;
END UnLock_Line_Id;
/*****************************************************************************
Procedure: get_order_lines
Parameters:
p_org_id - Organization ID from user input
p_offset_days - Number of days added to the current date
and compared to the release date
p_load_type - Load Type values are:
1. 1 - Configuration Items
2. 2 - ATO Items
3. 3 - Configuration Items and ATO Items
p_class_code - Accounting Class code for job creation (user
parameter)
p_status_type - Unreleased, Released (user input)
p_order_number - Specific order number to process (user input)
p_conc_request_id - concurrent request ID
p_conc_program_id - concurrent program ID
p_conc_login_id - concurrent login ID
p_user_id - User ID
p_appl_conc_program_id - Application Concurrent Program ID
x_orders_loaded - Number of rows inserted into interface table
x_wip_seq i - Group ID in interface table
x_message_name - Error message name
x_message_text - Error message text
IS
l_x_hold_result_out VARCHAR2(1);
l_x_hold_return_status VARCHAR(1);
l_x_error_msg_count NUMBER;
l_x_error_msg VARCHAR2(240);
l_x_result_out VARCHAR2(1);
l_x_return_status VARCHAR2(1);
l_x_error_message VARCHAR2(1000);
l_x_message_name VARCHAR2(30);
l_x_msg_count NUMBER;
l_x_msg_data VARCHAR2(2000);
l_rows_selected NUMBER := 0;
l_rows_inserted NUMBER := 0;
l_rows_on_hold NUMBER := 0;
l_rows_dep_plan NUMBER := 0;
l_rows_errored NUMBER := 0;
--Flow ER 14595064
l_rows_flow NUMBER := 0;
l_supply_type NUMBER;
l_schedule_ship_date DATE;
Not_Planned EXCEPTION;
-- Begin Bugfix 4056151: Added REF Cursor and new variables
sql_stmt VARCHAR2(5000);
drive_mark NUMBER := 0;
l_sourcing_rule_exists varchar2(1);
l_inventory_item_id mtl_system_items.inventory_item_id%type;
l_ship_from_org_id mtl_system_items.organization_id%type;
l_source_type Number;
l_sourcing_org Number;
l_transit_lead_time Number;
l_exp_error_code Number;
-- End of Addition
-- bugfix 3014000
l_client_org_id Number;
l_offset_days NUMBER; -- bugfix 4064726
x_wip_seq := -1;
x_orders_loaded := 0;
/*------------------------------------------------+
If IN parameter equal -1, then parameter value was not
entered. We NULL out the equivalent local variable
so that it will not be used in the SQL.
+-------------------------------------------------*/
if (p_line_id = -1) then
l_line_id := NULL;
end if;
else
l_offset_days := p_offset_days ;
end if;
--end bugfix 4064726
-- rkaza. 07/29/2005. bug 4438574. Item type code will be standard for
-- independent ato item and option for ato under pto.
sql_stmt := sql_stmt ||
'where oel.inventory_item_id = msi.inventory_item_id '||
'and oel.ship_from_org_id = msi.organization_id '||
'and msi.bom_item_type = 4 '|| -- STANDARD
'and oel.open_flag = ''Y'' '||
'and oel.ato_line_id is not null '||
'and (oel.item_type_code = ''CONFIG'' ' ||
'or (oel.ato_line_id = oel.line_id ' ||
'and oel.item_type_code = ''OPTION'') ' ||
--Adding INCLUDED item type code for SUN ER#9793792
'or (oel.ato_line_id = oel.line_id ' ||
'and oel.item_type_code = ''INCLUDED'') ' ||
'or (oel.ato_line_id = oel.line_id ' ||
'and oel.item_type_code = ''STANDARD'' ' ||
'and oel.top_model_line_id is null)) ' ||
'and nvl(oel.cancelled_flag, ''N'') = ''N'' '||
'and oel.booked_flag = ''Y'' '||
'and oel.schedule_status_code = ''SCHEDULED'' '||
'and oel.ordered_quantity > 0 '||
'and msi.replenish_to_order_flag = ''Y'' '||
'and msi.build_in_wip_flag = ''Y'' '||
'and msi.pick_components_flag = ''N'' '||
'and was.item_type = ''OEOL'' '||
'and was.activity_status = ''NOTIFIED'' '||
'and was.item_type = wpa.activity_item_type '||
'and was.process_activity = wpa.instance_id '||
'and wpa.activity_name in '||
'(''EXECUTECONCPROGAFAS'', ''CREATE_SUPPLY_ORDER_ELIGIBLE'',
''SHIP_LINE'') '||
'and ((wpa.activity_name = ''EXECUTECONCPROGAFAS'' and oel.program_id =
-99) ' ||
-- spawned thru workflow
' OR '||
-- Flow ER 14595064
--' (wpa.activity_name<>''EXECUTECONCPROGAFAS'' and
nvl(oel.program_id,0)<>-99)) '||
' (wpa.activity_name<>''EXECUTECONCPROGAFAS'' and
nvl(oel.program_id,0)<>-99)) ';
-- spawned thru SRS
-- Flow ER 14595064
if p_create_flow_schedule = 2 then
sql_stmt := sql_stmt ||
'and not exists (select ''1'' '||
'from bom_operational_routings bor ' ||
'where bor.assembly_item_id = oel.inventory_item_id '||
'and bor.organization_id = oel.ship_from_org_id ' ||
'and bor.alternate_routing_designator is NULL '||
'and nvl(bor.cfm_routing_flag, 2) = 1) ' ;
end if;
end if;
-- bugfix 4064726 : Include offset days condition only when offset days
parameter is passed.
sql_stmt := sql_stmt ||
'order by oel.org_id, oel.line_id';
/*
Below, we execute the sql statement according to which parameters
we have selected. The drive_mark variable tells us which parameters
we are using, so we are sure to send the right ones to SQL.
*/
if (drive_mark = 0) then
-- No (optional) parameter is passed
Open WorkOrder FOR sql_stmt;
else
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add ('INCORRECT COMBINATION of parameters');
END IF;
end if;
--
-- Bugfix 4056151: Replaced implicit cursor with explicit cursor.
-- Replaced "WorkOrder_Rec" with "WorkOrder_Rec" through out the code.
--
l_stmt_num := 1;
LOOP
FETCH WorkOrder INTO WorkOrder_Rec;
EXIT WHEN WorkOrder%NOTFOUND;
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add ('Fetched. System Time : '||to_char(sysdate, 'DD-MON-
YYYY HH24:MI:SS'));
END IF;
-- begin bugfix 3014000: Moved the debug stmt here
--
-- Begin Bugfix 2243672
--
if (lOperUnit <> WorkOrder_Rec.org_id ) then
--
-- Bugfix 2310559: We will call regular
fnd_client_info.set_org_context instead of
-- OM's API Set_Created_By_Context because the conc programs
submitted via WF, call
-- the FND_WF_STANDARD.callback function at the end. This program
tries to
-- retrieve the value of the profile - CONC_REQUEST_ID but cannot
find the
-- profile value as it was cleared during apps_initialize call.
Thus resulting in
-- failures later.
--
--
-- We will call this API only when there is a change in the org.
--
OE_Order_Context_GRP.Set_Created_By_Context (
p_header_id => NULL
,p_line_id => WorkOrder_Rec.line_id
,x_orig_user_id => xUserId
,x_orig_resp_id => xRespId
,x_orig_resp_appl_id => xRespApplId
,x_return_status => l_x_return_status
,x_msg_count => l_x_msg_count
,x_msg_data => l_x_msg_data );
end if;
else
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('get_order_lines: '|| 'NOT Setting the Org
Context since MO:Operating Unit = OEL.org_id.', 5);
END IF;
end if;
-- end bugfix 3014000
--
-- End Bugfix 2243672
--
--
-- bugfix 2227841: Moved the function calls from the cursor for
-- performance reasons.
--
-- bugfix 2868148
-- added new function GET_FLOW_QTY to consider flow supply during
discrete job creation
/**********************************************************************************
*****************
Scenarios
Order Qty = 10
6 6 0 6 6 10 10-6 =
4
6 1 5 1 6 10 10-6 =
4
6 0 6 0 6 10 10-6 =
4
6 8 0* 8 8 10 10-8 =
2
10 10 0 10 10 10
10-10 = 0
10 1 9 1 10 10 10-10
= 0
10 0 10 0 10 10 10-10
= 0
10 12 0* 10 10 10
10-10 = 0
* 0 since FQ = -2
***********************************************************************************
*****************/
--Bugfix 6146803: Checking of GET_NOTINV_QTY - GET_RESERVED_QTY and
locking the corresponding order
-- line has to be atomic. So commenting out the following part.
/*if ( GET_NOTINV_QTY(WorkOrder_Rec.line_id) -
GET_RESERVED_QTY(WorkOrder_Rec.line_id) <= 0 )
then
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('get_order_lines: ' || 'get_notinv_qty() -
get_reserved_qty() <= 0.',2);
-- This should be the incremented only after the line has passed the
previous checks.
-- bug 6146803: Move this line to after obtaining the lock.
--l_rows_selected := l_rows_selected + 1;
l_stmt_num := 2;
begin
SELECT ship_from_org_id
INTO l_ship_from_org_id
FROM OE_ORDER_LINES_ALL
WHERE line_id = WorkOrder_Rec.ato_line_id --- bug fix
5207010 . We should lock based on ATO line id
and (GET_NOTINV_QTY(WorkOrder_Rec.line_id) -
GET_RESERVED_QTY(WorkOrder_Rec.line_id)) > 0
FOR UPDATE NOWAIT; -- bugfix 2388802: lock the row which is
really eligible
l_inventory_item_id := WorkOrder_Rec.inventory_item_id;
exception
WHEN record_locked THEN
IF PG_DEBUG <> 0 THEN
OE_DEBUG_PUB.add ('get_order_lines: ' || 'Could not lock
line id '|| to_char(WorkOrder_Rec.line_id) ||' for update.');
l_stmt_num := 3;
CTO_UTILITY_PK.check_cto_can_create_supply (
P_config_item_id => l_inventory_item_id,
P_org_id => l_ship_from_org_id,
x_can_create_supply => l_can_create_supply,--declare
p_source_type =>l_source_type,
x_return_status =>l_x_return_status,
X_msg_count =>l_x_msg_count,
X_msg_data =>l_x_msg_data,
x_sourcing_org =>l_sourcing_org,
X_message =>l_message --declare
);
-- End 2681321
else
l_stmt_num := 4;
--Bugfix 9319883: Commenting the IF condition.
--The sequence will be generated just before calling
insert_wip_interface.
/*
if (l_rows_selected - l_rows_errored = 1) then
select wip_job_schedule_interface_s.nextval
into x_wip_seq
from dual;
end if;
*/
l_stmt_num := 5;
OE_DEBUG_PUB.add('get_order_lines: ' ||
'Continuing with next line..',3);
END IF;
l_rows_on_hold := l_rows_on_hold + 1;
else
BEGIN
IF PG_DEBUG <> 0 THEN
OE_DEBUG_PUB.add('get_order_lines: ' || 'before
dep plan',1);
END IF;
l_stmt_num := 6;
select nvl(oel.dep_plan_required_flag,'N')
into l_dep_plan_flag
from oe_order_lines_all oel
where oel.line_id = WorkOrder_Rec.line_id;
l_stmt_num := 7;
--
-- For partially reserved sales orders, we will
-- still check if the order line is Delivery
-- Planned for the entire quantity
--
CTO_WIP_UTIL.Delivery_Planned(
p_line_id => WorkOrder_Rec.line_id,
x_result_out => l_x_result_out,
x_return_status => l_x_return_status,
x_msg_count => l_x_msg_count,
x_msg_data => l_x_msg_data);
if (l_x_return_status =
FND_API.G_RET_STS_ERROR) then
IF PG_DEBUG <> 0 THEN
OE_DEBUG_PUB.add('get_order_lines:
' ||
'Expected error in Delivery_Planned: '
|| l_x_return_status
|| ' For Order Line '
||to_char(WorkOrder_Rec.line_id), 1);
END IF;
raise FND_API.G_EXC_ERROR;
elsif (l_x_return_status =
FND_API.G_RET_STS_UNEXP_ERROR) then
IF PG_DEBUG <> 0 THEN
OE_DEBUG_PUB.add('get_order_lines:
' ||
'UnExpected error in Delivery_Planned: '
|| l_x_return_status
|| ' For Order Line '
||to_char(WorkOrder_Rec.line_id), 1);
END IF;
raise FND_API.G_EXC_UNEXPECTED_ERROR;
else
IF PG_DEBUG <> 0 THEN
OE_DEBUG_PUB.add('get_order_lines:
' ||
'Success in Delivery_Planned: '
|| l_x_return_status
|| ' For Order Line '
||to_char(WorkOrder_Rec.line_id), 1);
END IF;
if (l_x_result_out = FND_API.G_FALSE)
then
IF PG_DEBUG <> 0 THEN
OE_DEBUG_PUB.add('get_order_lines: ' ||
'Order line not delivery planned'
||to_char(WorkOrder_Rec.line_id), 1);
END IF;
l_rows_dep_plan :=
l_rows_dep_plan+1;
raise NOT_PLANNED;
end if;
end if;
end if; /* dep_plan_flag = Y */
l_stmt_num := 8;
-- Flow ER 14595064
-- Checking whether the routings are flow
or discrete.
select NVL(cfm_routing_flag,2)
into l_supply_type
from oe_order_lines_all oel,
bom_operational_routings bor
where oel.line_id =
to_number(WorkOrder_Rec.line_id)
and oel.inventory_item_id =
bor.assembly_item_id (+)
and oel.ship_from_org_id =
bor.organization_id (+)
and bor.alternate_routing_designator (+)
is NULL;
l_stmt_num := 9;
select schedule_ship_date
into l_schedule_ship_date
from oe_order_lines_all
where line_id = WorkOrder_Rec.line_id;
if (trunc(l_schedule_ship_date) <
trunc(sysdate)) then
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('get_order_lines:
Schedule ship date:'|| to_char(l_schedule_ship_date) ||
' is earlier than
sysdate. Continuing to the next line.');
END IF;
goto end_of_loop;
end if;
l_stmt_num := 10;
CTO_FLOW_SCHEDULE.cto_fs(p_config_line_id
=> WorkOrder_Rec.line_id,
x_return_status
=> l_x_return_status,
x_msg_name
=> l_x_message_name,
x_msg_txt
=> l_x_error_message);
IF (l_x_return_status =
FND_API.G_RET_STS_ERROR) THEN
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('get_order_lines:
Expected error in Create Flow Schedule. Status:' || l_x_return_status);
END IF;
cto_msg_pub.cto_message('BOM',
l_x_message_name);
l_rows_errored := l_rows_errored + 1;
goto end_of_loop;
ELSIF (l_x_return_status =
FND_API.G_RET_STS_UNEXP_ERROR) THEN
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('get_order_lines:
Unexpected error in Create Flow Schedule. Status:' || l_x_return_status);
END IF;
cto_msg_pub.cto_message('BOM',
l_x_message_name);
l_rows_errored := l_rows_errored + 1;
goto end_of_loop;
ELSE
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('get_order_lines:
Success in Create Flow Schedule. Status:' || l_x_return_status);
END IF;
OE_Order_WF_Util.Update_Flow_Status_Code(p_header_id =>
WorkOrder_Rec.header_id,
l_rows_flow := l_rows_flow + 1;
else
IF PG_DEBUG <> 0 THEN
END IF;
CTO_WIP_UTIL.insert_wip_interface(
p_line_id =>
WorkOrder_Rec.line_id,
p_wip_seq =>
x_wip_seq,
p_status_type =>
p_status_type,
p_class_code =>
p_class_code,
p_conc_request_id =>
p_conc_request_id,
p_conc_program_id =>
p_conc_program_id,
p_conc_login_id =>
p_conc_login_id,
p_user_id =>
p_user_id,
p_appl_conc_program_id =>
p_appl_conc_program_id,
x_return_status =>
l_x_return_status,
x_error_message =>
l_x_error_message,
x_message_name =>
l_x_message_name);
if (l_x_return_status <>
FND_API.G_RET_STS_SUCCESS) then
-- We dont want to raise error here,
since we want to process other lines.
else
l_rows_inserted := l_rows_inserted
+ 1;
EXCEPTION
when NOT_PLANNED then
IF PG_DEBUG <> 0 THEN
END IF;--l_can_create_supply
<< end_of_loop>>
null;
end loop;
oe_debug_pub.add('get_order_lines: ' ||
'****************************************', 5);
END IF;
x_orders_loaded := l_rows_inserted;
l_stmt_num := 9;
exception
when no_data_found then
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add ('get_order_lines: ' || 'Could not find a
WIP job. Records probably stuck in wip job schedule interface.',1);
END IF;
EXCEPTION
-- bugfix 2053360 : handle the record_locked exception.
END get_order_lines;
/*****************************************************************************
Procedure: reserve_work_order
Parameters: p_model_line_id - line id of the configuration item in
oe_order_lines_all
p_wip_seq - group id to be used in interface table
x_error_message - error message if insert fails
x_message_name - name of error message if insert
fails
*****************************************************************************/
RETURN integer
IS
-- WorkOrder_Rec number;
/* Reservation Variables */
l_rec_reserve CTO_RESERVE_CONFIG.rec_reserve;
l_rsv_rec inv_reservation_global.mtl_reservation_rec_type;
l_dummy_sn inv_reservation_global.serial_number_tbl_type;
l_rsrv_qty number := 0;
l_rsrv_id number;
l_status varchar2(1);
l_activity_status varchar2(8);
l_status_type number;
l_err_num number;
l_msg_txt varchar(240);
l_msg_name varchar(30);
l_msg_count number;
l_stmt_num number;
lSourceCode varchar2(30);
cursor c_wip_job_records is
select mso.sales_order_id,
oel.line_id,
oel.ship_from_org_id,
oel.inventory_item_id,
oel.order_quantity_uom,
--oel.ordered_quantity,
oel.source_document_type_id, -- bugfix 1799874: to check if it
is an internal SO or regular
INV_CONVERT.inv_um_convert -- bugfix 1661094: added conversion logic
(oel.inventory_item_id,
5, -- bugfix 2204376: pass precision of 5
wei.start_quantity,
msi.primary_uom_code,
oel.order_quantity_uom,
null,
null) start_quantity,
inv_reservation_global.g_source_type_wip,
wei.wip_entity_id,
oel.schedule_ship_date,
-- Passing revision info only if revision_qty_control_code
-- is not equal to 1
-- wei.bom_revision
-- 2620282: Selecting bom revision info
decode( nvl(msi.revision_qty_control_code , 1 ) , 1, NULL ,
wei.bom_revision) bom_revision,
oel.org_id -- bugfix 3014000
from wip_job_schedule_interface wei,
oe_order_lines_all oel,
mtl_sales_orders mso,
oe_order_headers_all oeh,
--oe_order_types_v oet
oe_transaction_types_tl oet,
mtl_system_items msi -- bugfix 1661094:
where wei.group_id = p_wip_seq
and wei.source_line_id = oel.line_id
and oeh.header_id = oel.header_id
and oet.transaction_type_id = oeh.order_type_id
and mso.segment1 = to_char(oeh.order_number)
and mso.segment2 = oet.name
and oet.language = (select language_code
from fnd_languages
where installed_flag = 'B')
and mso.segment3 = lSourceCode
and wei.load_type = WIP_CONSTANTS.CREATE_JOB
and wei.organization_id = oel.ship_from_org_id
and wei.process_phase = WIP_CONSTANTS.ML_COMPLETE
-- bug 9314772.added warning status jobs for creating reservations.pdube
-- and wei.process_status = WIP_CONSTANTS.COMPLETED --
3202934
and wei.process_status IN (WIP_CONSTANTS.COMPLETED,WIP_CONSTANTS.WARNING)
and msi.inventory_item_id = oel.inventory_item_id
and msi.organization_id = oel.ship_from_org_id;
BEGIN
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('reserve_wo_to_so: ' || 'Beginning Reservation
Loop.',1);
END IF;
lSourceCode := fnd_profile.value('ONT_SOURCE_CODE');
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('reserve_wo_to_so: ' || 'lSourceCode: ' ||
lSourceCode,2);
END IF;
OE_Order_Context_GRP.Set_Created_By_Context (
p_header_id => NULL
,p_line_id => WorkOrder_Rec.line_id
,x_orig_user_id => xUserId
,x_orig_resp_id => xRespId
,x_orig_resp_appl_id => xRespApplId
,x_return_status => l_x_return_status
,x_msg_count => l_x_msg_count
,x_msg_data => l_x_msg_data );
end if;
else
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('reserve_wo_to_so: '|| 'NOT Setting the Org
Context since MO:Operating Unit = OEL.org_id.', 5);
END IF;
end if;
l_rec_reserve.f_header_id :=
WorkOrder_Rec.sales_order_id;
l_rec_reserve.f_line_id := WorkOrder_Rec.line_id;
l_rec_reserve.f_mfg_org_id :=
WorkOrder_Rec.ship_from_org_id;
l_rec_reserve.f_item_id :=
WorkOrder_Rec.inventory_item_id;
l_rec_reserve.f_order_qty_uom :=
WorkOrder_Rec.order_quantity_uom;
--l_rec_reserve.f_quantity :=
WorkOrder_Rec.ordered_quantity;
l_rec_reserve.f_quantity := WorkOrder_Rec.start_quantity;
l_rec_reserve.f_supply_source :=
inv_reservation_global.g_source_type_wip;
l_rec_reserve.f_supply_header_id :=
WorkOrder_Rec.wip_entity_id;
l_rec_reserve.f_ship_date :=
WorkOrder_Rec.schedule_ship_date;
l_rec_reserve.f_source_document_type_id :=
WorkOrder_Rec.source_document_type_id; -- bugfix 1799874
l_rec_reserve.f_bom_revision := WorkOrder_Rec.bom_revision;
-- 2620282 : Passing bom revision info
/*----------------------------------------------------------+
Reserve the sales order against the work order.
If reservation is unsuccessful, purge discrete jobs created.
+----------------------------------------------------------*/
CTO_RESERVE_CONFIG.reserve_config(
p_rec_reserve => l_rec_reserve,
x_rsrv_qty => l_rsrv_qty,
x_rsrv_id => l_rsrv_id,
x_return_status => l_status,
x_msg_txt => l_msg_txt,
x_msg_name => l_msg_name );
l_stmt_num := 100;
update wip_discrete_jobs
set status_type = 7 -- CANCELLED
where wip_entity_id = WorkOrder_Rec.wip_entity_id;
l_stmt_num := 110;
update wip_job_schedule_interface
set process_phase = WIP_CONSTANTS.ML_VALIDATION,
process_status = WIP_CONSTANTS.RUNNING
where wip_entity_id = WorkOrder_Rec.wip_entity_id
and group_id = p_wip_seq;
else
/*--------------------------------------------------+
This is the equivalent of the feedback loop in 11.0.
If the order is placed on hold during AutoCreate FAS,
WIP will put the corresponding work order on hold.
+--------------------------------------------------*/
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('reserve_wo_to_so: ' ||
'Reservation Success for line id ' ||
to_char(WorkOrder_Rec.line_id) ||
' and WIP Entity ID: ' ||
to_char(WorkOrder_Rec.wip_entity_id) ||
'.',1);
END IF;
BEGIN
l_stmt_num := 115;
select status_type
into l_status_type
from wip_job_schedule_interface
where group_id = p_wip_seq
and source_line_id = WorkOrder_Rec.line_id
and last_update_date <> creation_date
and rownum = 1;
WIP_SO_RESERVATIONS.respond_to_change_order(
p_org_id => WorkOrder_Rec.ship_from_org_id,
p_header_id => WorkOrder_Rec.sales_order_id,
p_line_id => WorkOrder_Rec.line_id,
x_status => l_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_txt);
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('reserve_wo_to_so: ' || 'Return Status
from respond to change order ' || l_status,1);
l_rsv_rec.reservation_id := l_rsrv_id;
INV_RESERVATION_PUB.delete_reservation
(
p_api_version_number => 1.0
, p_init_msg_lst => fnd_api.g_true
, x_return_status => l_status
, x_msg_count => l_msg_count
, x_msg_data => l_msg_txt
, p_rsv_rec => l_rsv_rec
, p_serial_number => l_dummy_sn
);
l_stmt_num := 130;
update wip_discrete_jobs
set status_type = 7 -- CANCEL
where wip_entity_id = WorkOrder_Rec.wip_entity_id;
l_stmt_num := 140;
update wip_job_schedule_interface
set process_phase = WIP_CONSTANTS.ML_VALIDATION,
process_status = WIP_CONSTANTS.RUNNING
where wip_entity_id = WorkOrder_Rec.wip_entity_id
and group_id = p_wip_seq;
EXCEPTION
when NO_DATA_FOUND then
end if;
END;
end loop; /* loop through wip job schedules for order line */
return 1;
EXCEPTION
END reserve_wo_to_so;
/
***********************************************************************************
************
Function: Get_Reserved_Qty
Parameters:
pLineId - Line id of order line being processed
Modified by :
Renga Kannan 09/20/01 removed the debug messages
SBhaskaran 11/02/01 Bugfix 2074290
Note: All quantities here are in Primary UOM.
***********************************************************************************
**************/
IS
select nvl(sum(INV_CONVERT.inv_um_convert
(oel.inventory_item_id,
6, -- bugfix 19483532: pass precision of 6
mr.reservation_quantity,
mr.reservation_uom_code,
msi.primary_uom_code,
null,
null)),0)
from mtl_reservations mr,
oe_order_headers_all oeh,
oe_order_lines_all oel,
mtl_system_items msi --bugfix 2074290: added msi
where oel.line_id = pLineId
and oel.header_id = oeh.header_id
and mr.demand_source_line_id = oel.line_id
and mr.organization_id = oel.ship_from_org_id
and oel.inventory_item_id = msi.inventory_item_id --bugfix 2074290: added
joins
and oel.ship_from_org_id = msi.organization_id
and mr.demand_source_type_id = decode(oeh.source_document_type_id, 10,
INV_RESERVATION_GLOBAL.g_source_type_internal_ord,
INV_RESERVATION_GLOBAL.g_source_type_oe); --
bugfix 1799874
cursor c_wjsi_qty is
select nvl(sum(wjs.start_quantity), 0)
from wip_job_schedule_interface wjs,
oe_order_lines_all oel
where oel.line_id = pLineId
and wjs.source_line_id = oel.line_id
and (wjs.process_status = WIP_CONSTANTS.PENDING
or wjs.process_status = WIP_CONSTANTS.RUNNING
or wjs.process_status = WIP_CONSTANTS.COMPLETED)
--Bugfix 12397938
and wjs.source_code = 'WICDOL';
cursor flow_supply is
select nvl(sum(planned_quantity - quantity_completed),0) -- 2946071
from wip_flow_schedules
where demand_source_line = to_char(pLineId)
and demand_source_type = inv_reservation_global.g_source_type_oe;
l_mtl_rsv_qty number := 0;
l_wjsi_qty number := 0;
l_flow_qty number := 0; --bugfix 2868148
l_reserved_qty number := 0;
lStmtNum number := 0;
BEGIN
--oe_debug_pub.add('Entering Get_Reserved_Qty', 6);
lStmtNum := 10;
OPEN c_mtl_rsv_qty;
FETCH c_mtl_rsv_qty INTO l_mtl_rsv_qty;
CLOSE c_mtl_rsv_qty;
lStmtNum := 20;
OPEN c_wjsi_qty;
FETCH c_wjsi_qty INTO l_wjsi_qty;
CLOSE c_wjsi_qty;
lStmtNum := 30;
lStmtNum := 30;
OPEN flow_supply;
FETCH flow_supply INTO l_flow_qty;
CLOSE flow_supply;
/**
In case of overcompletion when
sum (planned_qty - quantity_completed) is < 0 ,
flow_qty will be returned as 0 to prevent extra
supply creation with discrete jobs.
**/
return(l_reserved_qty);
EXCEPTION
WHEN others THEN
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('Get_Reserved_Qty: ' || 'Others exception in
Get_Reserved_Qty::'||to_char(lStmtNum)||'::'||sqlerrm, 1);
END IF;
unlock_line_id (pLineId); -- bugfix 3136206
return(0);
END Get_Reserved_Qty;
Description :
If shipping_interfaced flag is 'Y', then, return OQ in primary UOM.
*****************************************************************************/
BEGIN
-- If shipping_interfaced_flag is 'N', it means WDD is not populated.
-- Pick ordered_quantity (in primary UOM) from OEOL in that case.
--
-- If shipping_interfaced_flag is 'Y', it means WDD is populated.
-- Sum the requested_quantity in WDD for which inv interface is NOT run.
-- If it returns null, all of them has been interfaced to inventory.
-- Return 0 in that case.
--
-- Note : Requested_Quantity in WDD is in primary UOM
return (l_quantity);
EXCEPTION
when OTHERS then
IF PG_DEBUG <> 0 THEN
oe_debug_pub.add('Get_NotInv_Qty: ' || 'Others exception in
Get_NotInv_Qty::'||sqlerrm, 1);
END IF;
unlock_line_id (pLineId); -- bugfix 3136206
return(0);
END Get_NotInv_Qty;
-- end bugfix 2095043
end CTO_WIP_WRAPPER;