Using the PO_CHANGE_API1_S.update_po, the following columns can be updated in a Purchase Order.

– Promised_date
– Need_by_date
– Quantity
– Unit_price

Importance of LAUNCH_APPROVALS_FLAG
=================================

– Indicates if you want to launch APPROVAL workflow after the update. Its value could be either ‘Y’ or ‘N’. If not provided, the default value is ‘N’.
– If we are passing launch_approvals_flag =>’N’, the PO is remaining in the Requires Reapproval status.

Post Update PO Validation:
====================
1. Set the PO status to REQUIRES REAPPROVAL.
2. Increment revision number if the PO was in APPROVED status before the update.
3. Launch the PO Approval workflow if LAUNCH_APPROVALS_FLAG = ‘Y’.
4. If the quantity was adjusted down to be equal to the total quantity received or billed, then set the appropriate closed code and roll up the closed code to line and header levels.

— R12 – PO – Sample Script to Update PO Using po_change_api1_s
–=================================================

DECLARE

CURSOR po_date_update
IS

SELECT pha.segment1 po_number, pha.revision_num,pha.po_header_id,
pha.authorization_status, pla.po_line_id, pla.line_num, pha.org_id,
pla.unit_price, pola.line_location_id, pola.shipment_num,
pola.quantity, pola.promised_date, pola.need_by_date,
pha.closed_code
FROM po_headers_all pha, po_lines_all pla,
po_line_locations_all pola
WHERE pha.po_header_id = pla.po_header_id
AND pla.po_line_id = pola.po_line_id
AND NVL (pha.approved_flag, ‘N’) = ‘Y’
AND NVL (pola.cancel_flag, ‘N’) <> ‘Y’
AND NVL (pola.closed_code, ‘OPEN’) = ‘OPEN’
AND NVL (pola.quantity_received, 0) = 0
AND NVL (pola.quantity_billed, 0) = 0
AND pha.segment1 = ‘11170007326’
AND pla.line_num = 1
AND pha.type_lookup_code = ‘STANDARD’
AND pha.org_id = 308;

l_user_id NUMBER;
l_resp_id NUMBER;
l_appl_id NUMBER;
l_result NUMBER;
l_api_errors po_api_errors_rec_type;
l_revision_num NUMBER;
l_promised_date DATE;
l_need_by_date DATE;
l_price po_lines_all.unit_price%TYPE;
l_quantity po_line_locations_all.quantity%TYPE;

BEGIN

SELECT user_id
INTO l_user_id
FROM fnd_user
WHERE user_name = ‘CONVERSION’;

SELECT responsibility_id, application_id
INTO l_resp_id, l_appl_id
FROM fnd_responsibility_vl
WHERE responsibility_name = ‘Purchasing Super User’;

fnd_global.apps_initialize (l_user_id, l_resp_id, l_appl_id);

FOR i IN po_date_update

LOOP

mo_global.set_policy_context (‘S’, i.org_id);
mo_global.init (‘PO’);

l_promised_date := i.promised_date + 30;
l_need_by_date := i.need_by_date + 35;
l_quantity := i.quantity + 100;
l_price := i.unit_price – 1;

DBMS_OUTPUT.put_line (‘Calling po_change_api1_s.update_po To Update PO’);
DBMS_OUTPUT.put_line (‘===================================’);
DBMS_OUTPUT.put_line (‘Retrieving the Current Revision Number of PO’);

select revision_num
into l_revision_num
from po_headers_all
where segment1 = i.po_number;

l_result :=
po_change_api1_s.update_po
(x_po_number => i.po_number, –Enter the PO Number
x_release_number => NULL, –Enter the Release Num
x_revision_number => l_revision_num, –Enter the Revision Number
x_line_number => i.line_num, –Enter the Line Number
x_shipment_number => i.shipment_num, –Enter the Shipment Number
new_quantity => l_quantity, –Enter the new quantity
new_price => l_price, –Enter the new price,
new_promised_date => l_promised_date, –Enter the new promised date,
new_need_by_date => l_need_by_date, –Enter the new need by date,
launch_approvals_flag => ‘Y’,
update_source => NULL,
VERSION => ‘1.0’,
x_override_date => NULL,
x_api_errors => l_api_errors,
p_buyer_name => NULL,
p_secondary_quantity => NULL,
p_preferred_grade => NULL,
p_org_id => i.org_id
);

DBMS_OUTPUT.put_line (l_result);

IF (l_result = 1)
THEN
DBMS_OUTPUT.put_line(‘Successfully update the PO :=>’);
END IF;

IF (l_result <> 1)
THEN
DBMS_OUTPUT.put_line (‘Failed to update the PO Due to Following Reasons’);
— Display the errors
FOR j IN 1 .. l_api_errors.MESSAGE_TEXT.COUNT
LOOP
DBMS_OUTPUT.put_line (l_api_errors.MESSAGE_TEXT (j));
END LOOP;
END IF;

END LOOP;

END;

R12 – Sample Script to Cancel Single AP Invoice using ap_cancel_package API
DECLARE
l_message_name VARCHAR2 (1000);
l_invoice_amount NUMBER;
l_base_amount NUMBER;
l_tax_amount NUMBER;
l_temp_cancelled_amount NUMBER;
l_cancelled_by VARCHAR2 (1000);
l_cancelled_amount NUMBER;
l_cancelled_date DATE;
l_last_update_date DATE;
l_original_prepayment_amount NUMBER;
l_pay_curr_invoice_amount NUMBER;
l_token VARCHAR2 (100);
l_boolean BOOLEAN;
l_user_id NUMBER := 2083;
l_resp_id NUMBER := 20639;
l_appl_id NUMBER := 200;

CURSOR C_Inv_Det is
SELECT distinct aia.*
FROM ap_invoices_all aia, ap_invoice_lines_all aila
WHERE aia.invoice_id = aila.invoice_id
AND aia.org_id = aila.org_id
AND aia.org_id = 308
AND aia.invoice_num = ‘300040823’
AND aia.payment_status_flag = ‘N’
AND NVL(aila.cancelled_flag, ‘N’) <> ‘Y’;
BEGIN
fnd_global.apps_initialize(l_user_id, l_resp_id, l_appl_id);
FOR l_inv_rec IN C_Inv_Det LOOP
mo_global.init (‘SQLAP’);
mo_global.set_policy_context (‘S’, l_inv_rec.org_id);
DBMS_OUTPUT.put_line (‘Calling API ap_cancel_pkg.ap_cancel_single_invoice to Cancel Invoice: ‘ l_inv_rec.invoice_num);
DBMS_OUTPUT.put_line (‘**************************************************************’);

l_boolean := ap_cancel_pkg.ap_cancel_single_invoice
(p_invoice_id => l_inv_rec.invoice_id,
p_last_updated_by => l_inv_rec.last_updated_by,
p_last_update_login => l_inv_rec.last_update_login,
p_accounting_date => l_inv_rec.gl_date,
p_message_name => l_message_name,
p_invoice_amount => l_invoice_amount,
p_base_amount => l_base_amount,
p_temp_cancelled_amount => l_temp_cancelled_amount,
p_cancelled_by => l_cancelled_by,
p_cancelled_amount => l_cancelled_amount,
p_cancelled_date => l_cancelled_date,
p_last_update_date => l_last_update_date,
p_original_prepayment_amount => l_original_prepayment_amount,
p_pay_curr_invoice_amount => l_pay_curr_invoice_amount,
P_Token => l_token,
p_calling_sequence => NULL);

DBMS_OUTPUT.put_line (‘l_message_name => ‘ l_message_name);
DBMS_OUTPUT.put_line (‘l_invoice_amount => ‘ l_invoice_amount);
DBMS_OUTPUT.put_line (‘l_base_amount => ‘ l_base_amount);
DBMS_OUTPUT.put_line (‘l_tax_amount => ‘ l_tax_amount);
DBMS_OUTPUT.put_line (‘l_temp_cancelled_amount => ‘ l_temp_cancelled_amount);
DBMS_OUTPUT.put_line (‘l_cancelled_by => ‘ l_cancelled_by);
DBMS_OUTPUT.put_line (‘l_cancelled_amount => ‘ l_cancelled_amount);
DBMS_OUTPUT.put_line (‘l_cancelled_date => ‘ l_cancelled_date);
DBMS_OUTPUT.put_line (‘P_last_update_date => ‘ l_last_update_date);
DBMS_OUTPUT.put_line (‘P_original_prepayment_amount => ‘ l_original_prepayment_amount);
DBMS_OUTPUT.put_line (‘l_pay_curr_invoice_amount => ‘ l_pay_curr_invoice_amount);

IF l_boolean
THEN
DBMS_OUTPUT.put_line (‘Successfully Cancelled the Invoice => ‘ l_inv_rec.invoice_num);
COMMIT;
ELSE
DBMS_OUTPUT.put_line (‘Failed to Cancel the Invoice => ‘ l_inv_rec.invoice_num);
ROLLBACK;
END IF;
END LOOP;
END;
DBMS Output –

Calling API ap_cancel_pkg.ap_cancel_single_invoice to Cancel Invoice: 300040823
*********************************************************************************
l_message_name =>
l_invoice_amount => 0
l_base_amount => 0
l_tax_amount =>
l_temp_cancelled_amount => 15678
l_cancelled_by => 1831
l_cancelled_amount => 15678
l_cancelled_date => 06-OCT-09
P_last_update_date => 06-OCT-09
P_original_prepayment_amount =>
l_pay_curr_invoice_amount => 0
Successfully Cancelled the Invoice => 300040823

Before approving the Purchase Order & when the PO is in INCOMPLETE status, Oracle allows us to delete the same from the Purchase Order Form. The same can be achieved using the following mentioned API.
But we need to remember few points before using this API for deleting Incomplete PO.
– The PO Should be INCOMPLETE & Should not be Approved Once.
– Once the PO is approved, records gets inserted into mtl_supply & all the archive tables.
This API never deletes the records from the mtl_supply & archive tables and only deletes the
records from the base tables.
— Sample Script to Delete Incomplete PO Using ‘PO_HEADERS_SV1’
–=================================================
DECLARE

l_deleted BOOLEAN;

CURSOR c_po_det IS
SELECT po_header_id, segment1,org_id
FROM po.po_headers_all pha
WHERE 1 = 1
AND segment1 = ‘11170002356’
AND org_id = 308
AND NVL (approved_flag, ‘N’) <> ‘Y’
AND NVL (cancel_flag, ‘N’) = ‘N’
AND type_lookup_code = ‘STANDARD’
AND authorization_status = ‘INCOMPLETE’
AND NOT EXISTS ( SELECT 1
FROM po_headers_archive_all a
WHERE pha.po_header_id = a.po_header_id
AND pha.org_id = a.org_id)
AND NOT EXISTS ( SELECT 1
FROM mtl_supply b WHERE pha.po_header_id = b.po_header_id AND
supply_type_code = ‘PO’);
BEGIN
FOR c1 IN c_po_det LOOP
DBMS_OUTPUT.put_line ( ‘Calling PO_HEADERS_SV1 API To Delete PO’);
DBMS_OUTPUT.put_line ( ‘==========================’);
l_deleted := po_headers_sv1.delete_po (c1.po_header_id, ‘STANDARD’);

IF l_deleted = TRUE
THEN
COMMIT;
DBMS_OUTPUT.put_line ( ‘Successfully Deleted the PO’);
ELSE
ROLLBACK;
DBMS_OUTPUT.put_line ( ‘Failed to Delete the PO’);
END IF;
END LOOP;
END;

Performing Back Order in a Move Order Line Using inv_mo_backorder_pvt API *********************************************************************************
What Happens during Pick Release?
*************************************

• A pre-approved Move Order is automatically created in Inventory.
• A Move order is a request for a subinventory transfer from the source (stocking) subinventory to the destination (staging) subinventory.
• A Move order is created for every Sales Order Line that has the status of “Awaiting Shipping” and passes the picking criteria (Use your Release Rules to guide this process).
• The Destination subinventory is the Staging subinventory entered on the Release Sales Orders form or defaulted from the Shipping Parameters. Only one staging subinventory is allowed per Picking Batch.
• Note: A Picking Batch is the total number of Order Lines that were released at one time.
• Inventory uses the move order to manage material requisitions within an Organization.
• Some times, the Pick Release Process (Pick Selection List Generation Program) either completed with warning or with Error. While dubuging, it shows the line has not been pick released & the delivery status is showing as “Released to Warehouse”. In the delivery detail window, the next steps indicate “Transaction Move Order”.

What exactly Release to Warehouse – (Released Status S in the wsh_delivery_details Table) Status is meant by?

• Pick release has processed the delivery line and has created move order headers and lines. Found available quantity and created inventory allocations. Not pick confirmed. In other words Pick Release has started but not completed. Either no allocations were created or the allocations have not been Pick Confirmed.
• If you are using auto-pick confirm during the Pick Release process then it changes release status to Staged. If you are not using auto-pick confirm and want to progress the delivery lines, navigate to Oracle Inventory Move Order Transaction window and perform manual pick confirm that is nothing but Transacting the Move Order.
• Once you navigate to the move order window, either you can Allocate & Transact the move order to complete the Pick Release process orYou can backorder that particular line (In the Move Order Transact Window > Search for the Move Order by the Number > Tools > Back Order Lines) & Proceed with the Pick Release Process Again.

This Particular Operation can be done by using a Private API “inv_mo_backorder_pvt.backorder”.

— R12 – OM – Sample Script to Back Order a Move Order Line Using INV_MO_BACKORDER_PVT API

DECLARE

CURSOR c_order_det IS

SELECT dd.delivery_detail_id, dd.source_code, dd.source_line_id,dd.org_id,
dd.source_header_id, dd.source_header_number,
dd.source_line_number,
NVL (dl.ship_method_code, dd.ship_method_code) ship_method_code,
dd.inventory_item_id,
(SELECT concatenated_segments
FROM mtl_system_items_kfv
WHERE inventory_item_id = dd.inventory_item_id
AND organization_id = dd.organization_id) ordered_item,
NVL (wsn.quantity, dd.requested_quantity) requested_quantity,
NVL (wsn.quantity, dd.shipped_quantity) shipped_quantity,
dd.requested_quantity_uom, dd.src_requested_quantity_uom,
dd.requested_quantity2, dd.shipped_quantity2,
dd.requested_quantity_uom2, dd.src_requested_quantity_uom2,
dd.ship_set_id, dd.revision, dd.lot_number,
NVL (wsn.fm_serial_number,
DECODE (dd.oe_interfaced_flag, ‘Y’, dd.serial_number, NULL)
) serial_number,
dd.released_status, wl2.meaning, dl.delivery_id, dl.NAME,
dl.currency_code, dl.status_code delivery_status_code,
DECODE (NVL (dl.status_code, ‘-99’),
‘-99’, NULL, wl1.meaning ) delivery_status_meaning,
dd.organization_id, dl.initial_pickup_date, dl.ultimate_dropoff_date,
NVL (wsn.to_serial_number, dd.to_serial_number) to_serial_number,
dd.move_order_line_id,
(select request_number from mtl_txn_request_headers where header_id in
(select header_id from mtl_txn_request_lines
where line_id = dd.move_order_line_id)) Move_order,
(select Line_number from mtl_txn_request_lines
where line_id = dd.move_order_line_id) Move_order_Line
FROM wsh_lookups wl1,
wsh_lookups wl2,
wsh_new_deliveries dl,
wsh_delivery_assignments_v da,
wsh_delivery_details dd,
wsh_locations wlf,
wsh_locations wlt,
wsh_serial_numbers wsn
WHERE dd.delivery_detail_id = da.delivery_detail_id
AND da.delivery_id = dl.delivery_id(+)
AND NVL (dl.status_code, ‘OP’) = wl1.lookup_code
AND wl1.lookup_type = ‘DELIVERY_STATUS’
AND ( ( wl2.lookup_code = ‘K’
AND dd.released_status = ‘S’
AND dd.move_order_line_id IS NULL)
OR ( wl2.lookup_code = dd.released_status
AND ( (dd.move_order_line_id IS NOT NULL)
OR (dd.released_status <> ‘S’))
AND (dd.replenishment_status IS NULL))
OR ( wl2.lookup_code = ‘E’
AND dd.released_status IN (‘R’, ‘B’)
AND dd.replenishment_status = ‘R’)
OR ( wl2.lookup_code = ‘F’
AND dd.released_status IN (‘R’, ‘B’)
AND dd.replenishment_status = ‘C’))
AND wl2.lookup_type = ‘PICK_STATUS’
AND dd.ship_from_location_id = wlf.wsh_location_id(+)
AND dd.ship_to_location_id = wlt.wsh_location_id(+)
AND dd.delivery_detail_id = wsn.delivery_detail_id(+)
AND NVL (dd.line_direction, ‘O’) IN (‘O’, ‘IO’)
AND NVL (dl.delivery_type, ‘STANDARD’) = ‘STANDARD’
AND dd.source_header_number = ‘10000596’
AND dd.released_status = ‘S’;

l_return_status VARCHAR2 (100);
l_msg_count NUMBER;
l_msg_data VARCHAR2 (2000);
l_msg_index NUMBER;
l_user_id NUMBER;
l_resp_id NUMBER;
l_appl_id NUMBER;

BEGIN

SELECT user_id
INTO l_user_id
FROM fnd_user
WHERE user_name = ‘A42485’;

SELECT responsibility_id, application_id
INTO l_resp_id, l_appl_id
FROM fnd_responsibility_vl
WHERE responsibility_name = ‘Order Management Super User’;
fnd_global.apps_initialize (l_user_id, l_resp_id, l_appl_id);

FOR i IN c_order_det

LOOP

mo_global.set_policy_context (‘S’, i.org_id);
mo_global.init (‘ONT’);

DBMS_OUTPUT.put_line (‘Calling INV_MO_BACKORDER_PVT to Backorder MO’);
DBMS_OUTPUT.put_line (‘===============================’);

inv_mo_backorder_pvt.backorder (
p_line_id => i.move_order_line_id,
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data
);

DBMS_OUTPUT.put_line (‘Return Status is=> ‘ l_return_status);
— Check Return Status

IF l_return_status = fnd_api.g_ret_sts_success
THEN
DBMS_OUTPUT.put_line (‘Successfully BackOrdered the Move Order Line’);
COMMIT;
ELSE
DBMS_OUTPUT.put_line
(‘Could not able to Back Order Line Due to Following Reasons’ );
ROLLBACK;

FOR j IN 1 .. l_msg_count
LOOP
fnd_msg_pub.get (p_msg_index => j,
p_encoded => fnd_api.g_false,
p_data => l_msg_data,
p_msg_index_out => l_msg_index);
DBMS_OUTPUT.put_line (‘Error Message is=> ‘ l_msg_data);
END LOOP;
END IF;

END LOOP;

END;

DBMS Output: –
***************

Calling INV_MO_BACKORDER_PVT to Backorder MO
===============================
Return Status is=> S
Successfully BackOrdered the Move Order Line

Performing Pick Release Using WSH_DELIVERY_PUB API
************************************************************

Creating Deliveries:
===============• A Delivery is required to perform Ship Confirm. It represent all the goods that were shipped from the same warehouse, going to the same Customer location.
• A Delivery can be created automatically or manually from the Shipping Transaction form at any time after the order lines have become “Awaiting Shipment” or can be automatically created during the Release Sales Order process.

• The delivery can also be created Programatically using shipping API “WSH_DELIVERIES_PUB.Create_update_delivery” by passing the required and optional parameter values.

Specific parameters:

• p_api_version_number => 1.0
• p_action_code => CREATE

— for creating new delivery
• p_delivery_info => Attributes of the delivery entity of type Delivery_Pub_Rec_Type

Performing Pick Release:
===================
What Happens during Pick Release:
**************************************• A pre-approved Move Order is automatically created in Inventory.
• A Move order is a request for a subinventory transfer from the source subinventory to the destination (staging) subinventory.
• A Move order is created for every Sales Order Line that has the status of “Awaiting Shipping” and passes the picking criteria.
• The Destination subinventory is the Staging subinventory entered on the Release Sales Orders form or defaulted from the Shipping Parameters. Only one staging subinventory is allowed per Picking Batch.

Allocate Inventory to the move order:
***************************************
• Allocating can be done automatically after the move order is created by setting “Auto Allocate” to yes on the Release Sales Order form or postponed until later, then manually allocated from the Transaction Move Orders form.
• The Release Sequence Rule, that was entered on the Release Sales Orders form, or defaulted from the Shipping Parameters, will be used to determine in what sequence to fill the move orders.
• Move orders use inventory’s picking rules to suggest the material that should be allocated. The sourcing values for subinventory, locators, revisions, and lots are defaulted on to the move order.
• The source defaults can be manually updated from the Transaction Move Orders form.
• A high level reservation is placed for the Move Order’s material requirements.
• Allocating inventory is a prerequisite for printing Pick Slips. The Pick Slip Grouping Rule entered on the Release Sales Orders form or defaulted from the Shipping Parameters is used while printing pick slips.

Pick Confirm the move order
******************************
• Pick Confirm can be done automatically during the picking process by setting “Pick Confirm” to yes on the Release Sales Orders form or by unchecking the Pick Confirm Required checkbox in the Organization Parameters form. If it is not done automatically during pick release it can be done manually from the Transaction Move Orders form by selecting the Transact button.
• The Pick Confirm transaction executes the subinventory transfer, moving the material from it’s source location to it’s destination staging location. Only 1 staging subinventory is supported per picking batch.
• The high level reservations are replaced with detail reservations.
• If you transact less than the requested quantity, the Move Order will stay open until the total quantity is transacted, or the order is closed or cancelled.
• The status of the Sales Order Line, which is linked to the Move Order, is changed to “Picked” making it eligible for Ship Confirm.
• If not all of the Move order quantity was transacted the status of the Sales Order Line, is changed to “Picked Partial”. During Ship Confirm the order line will split into 2 shipment schedules (e.g. 1.1 and 1.2). The status of the unfilled line will be changed to “Awaiting Shipping”.

For performing Pick Release Programatically we can use the shipping public API “WSH_DELIVERIES_PUB.Delivery_Action”, which enables pick release of the sales order line. The relevant pick release parameters are retrieved from the Shipping and Organization Parameter setup.

Specific Parameters:

p_action_code = > PICK_RELEASE
p_delivery_id/p_delivery_name => Id/name of delivery

— R12 – OM – Sample Script to Perform Pick using WSH_DELIVERY_PUB API —
— ======================================================== —


DECLARE

x_return_status VARCHAR2 (2);
x_msg_count NUMBER;
x_msg_data VARCHAR2 (2000);
p_api_version_number NUMBER := 1.0;
init_msg_list VARCHAR2 (200);
x_msg_details VARCHAR2 (3000);
x_msg_summary VARCHAR2 (3000);
p_line_rows wsh_util_core.id_tab_type;
x_del_rows wsh_util_core.id_tab_type;
l_ship_method_code VARCHAR2 (100);
i NUMBER;
l_commit VARCHAR2 (30);
p_delivery_id NUMBER;
p_delivery_name VARCHAR2 (30);
x_trip_id VARCHAR2 (30);
x_trip_name VARCHAR2 (30);
exep_api EXCEPTION;
l_picked_flag VARCHAR2 (10);
l_return_status VARCHAR2 (1000);
l_msg_count NUMBER;
l_msg_data VARCHAR2 (1000);
l_user_id NUMBER;
l_resp_id NUMBER;
l_appl_id NUMBER;

CURSOR c_ord_details
IS

SELECT oha.order_number sales_order, oha.org_id, ola.line_number,
ola.shipment_number, ola.flow_status_code,
wdd.delivery_detail_id, wdd.inv_interfaced_flag,
wdd.oe_interfaced_flag, wdd.released_status
FROM apps.oe_order_headers_all oha,
apps.oe_order_lines_all ola,
apps.wsh_delivery_details wdd
WHERE oha.header_id = ola.header_id
AND oha.org_id = ola.org_id
AND oha.header_id = wdd.source_header_id
AND ola.line_id = wdd.source_line_id
AND oha.booked_flag = ‘Y’
AND NVL (ola.cancelled_flag, ‘N’) <> ‘Y’
AND wdd.released_status in (‘R’,’B’)
AND ola.flow_status_code = ‘AWAITING_SHIPPING’
AND oha.order_number = 10001059
AND oha.org_id = 308;

BEGIN

— Initializing the Applications

SELECT user_id
INTO l_user_id
FROM fnd_user
WHERE user_name = ‘A42485’;

SELECT responsibility_id, application_id
INTO l_resp_id, l_appl_id
FROM fnd_responsibility_vl
WHERE responsibility_name = ‘Order Management Super User’;

fnd_global.apps_initialize (l_user_id, l_resp_id, l_appl_id);

x_return_status := wsh_util_core.g_ret_sts_success;
i := 0;

FOR i IN c_ord_details

LOOP

— Mandatory initialization for R12
mo_global.set_policy_context (‘S’, i.org_id);
mo_global.init (‘ONT’);

p_line_rows (1) := i.delivery_detail_id;

— API Call for Auto Create Deliveries

DBMS_OUTPUT.put_line
(‘Calling WSH_DELIVERY_DETAILS_PUB to Perform AutoCreate Delivery’);
DBMS_OUTPUT.put_line
(‘====================================================’);

wsh_delivery_details_pub.autocreate_deliveries
(p_api_version_number => 1.0,
p_init_msg_list => apps.fnd_api.g_true,
p_commit => l_commit,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data,
p_line_rows => p_line_rows,
x_del_rows => x_del_rows
);

DBMS_OUTPUT.put_line (x_return_status);
DBMS_OUTPUT.put_line (x_msg_count);
DBMS_OUTPUT.put_line (x_msg_data);

IF (x_return_status <> wsh_util_core.g_ret_sts_success) THEN

DBMS_OUTPUT.put_line
(‘Failed to Auto create delivery for Sales Order’);
RAISE exep_api;

ELSE

DBMS_OUTPUT.put_line
(‘Auto Create Delivery Action has successfully completed for SO’);
DBMS_OUTPUT.put_line (‘=============================================’);
END IF;

— Pick release.
p_delivery_id := x_del_rows (1);
p_delivery_name := TO_CHAR (x_del_rows (1));

DBMS_OUTPUT.put_line
(‘Calling WSH_DELIVERIS_PUB to Perform Pick Release of SO’);
DBMS_OUTPUT.put_line (‘=============================================’);
— API Call for Pick Release

wsh_deliveries_pub.delivery_action (p_api_version_number => 1.0,
p_init_msg_list => NULL,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data,
p_action_code => ‘PICK-RELEASE’,
p_delivery_id => p_delivery_id,
p_delivery_name => p_delivery_name,
p_asg_trip_id => NULL,
p_asg_trip_name => NULL,
p_asg_pickup_stop_id => NULL,
p_asg_pickup_loc_id => NULL,
p_asg_pickup_stop_seq => NULL,
p_asg_pickup_loc_code => NULL,
p_asg_pickup_arr_date => NULL,
p_asg_pickup_dep_date => NULL,
p_asg_dropoff_stop_id => NULL,
p_asg_dropoff_loc_id => NULL,
p_asg_dropoff_stop_seq => NULL,
p_asg_dropoff_loc_code => NULL,
p_asg_dropoff_arr_date => NULL,
p_asg_dropoff_dep_date => NULL,
p_sc_action_flag => ‘S’,
p_sc_intransit_flag => ‘N’,
p_sc_close_trip_flag => ‘N’,
p_sc_create_bol_flag => ‘N’,
p_sc_stage_del_flag => ‘Y’,
p_sc_trip_ship_method => NULL,
p_sc_actual_dep_date => NULL,
p_sc_report_set_id => NULL,
p_sc_report_set_name => NULL,
p_sc_defer_interface_flag => ‘Y’,
p_sc_send_945_flag => NULL,
p_sc_rule_id => NULL,
p_sc_rule_name => NULL,
p_wv_override_flag => ‘N’,
x_trip_id => x_trip_id,
x_trip_name => x_trip_name
);

DBMS_OUTPUT.put_line (x_return_status);
DBMS_OUTPUT.put_line (x_msg_count);
DBMS_OUTPUT.put_line (x_msg_data);

IF (x_return_status <> wsh_util_core.g_ret_sts_success) THEN

DBMS_OUTPUT.put_line (‘Failed to Pick Release the sales order’);
RAISE exep_api;

ELSE

DBMS_OUTPUT.put_line (‘Sales Order has successfully Pick Released’);
DBMS_OUTPUT.put_line (‘==============================’);

END IF;

–for pick confirm
COMMIT;

END LOOP;

EXCEPTION

WHEN exep_api THEN

DBMS_OUTPUT.put_line (‘==============’);
DBMS_OUTPUT.put_line (‘Error Details If Any’);
DBMS_OUTPUT.put_line (‘==============’);

wsh_util_core.get_messages (‘Y’,
x_msg_summary,
x_msg_details,
x_msg_count
);

IF x_msg_count > 1 THEN

x_msg_data := x_msg_summary x_msg_details;
DBMS_OUTPUT.put_line (x_msg_data);

ELSE

x_msg_data := x_msg_summary x_msg_details;
DBMS_OUTPUT.put_line (x_msg_data);

END IF;

END;