order management api's use

Upload: akvoracle

Post on 01-Mar-2018

269 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 Order Management API's Use

    1/47

    CREATE OR REPLACE PACKAGE BODY APPS.XXORT_ALAMEDA_PROCESS_SO_PKGIS-- +==============================================================================+-- | SGTC|

    -- | Gurgaon, India|

    -- +==============================================================================+-- | Procedure|

    -- ||

    -- | Filename : XXORT_ALAMEDA_PROCESS_SO_PKG.pkb|

    -- | Program Name : XXORT ALAMEDA Process Sales Orders|

    -- | Purpose : This package will pick the International Sales Orders of|

    -- | ALAMEDA and complete the booking to shipping process for|

    -- | them|

    -- ||-- | Change Record:|

    -- | ===============|

    -- | Date Version Author Comments|

    -- | =========== ========= ================ ===================================|-- | 11-OCT-2010 1.0 Dhiraj Kain Initial Version|

    -- +============================================================================

    ==+

    PROCEDURE update_shipment_priority ( p_header_id IN NUMBER ) IS

    ---------------------------------------- Variable Declaration ---------------------------------------- l_header_val_rec OE_ORDER_PUB.header_val_rec_type; l_line_tbl OE_ORDER_PUB.line_tbl_type;

    x_line_out_tbl OE_ORDER_PUB.line_tbl_type;

    v_return_status VARCHAR2(1); v_msg_count NUMBER; v_msg_data VARCHAR2(2000); v_msg_index_out NUMBER; v_count NUMBER;

    --------------------------------------

  • 7/25/2019 Order Management API's Use

    2/47

    -- Cursor Declaration ---------------------------------------- CURSOR c_rec IS SELECT oola.line_id FROM oe_order_lines_all oola WHERE oola.header_id = p_header_id;

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    BEGIN -- Main --

    ---------------------------------------- Call API to Update Shipment Prior---- for Order Header ----------------------------------------

    BEGIN -- 1 --

    L_HEADER_VAL_REC.shipment_priority := 'DO NOT USE - Alameda';

    OE_MSG_PUB.initialize;

    FND_FILE.put_line(FND_FILE.log, 'Calling API to Update Order Header Shipment Priority...');

    OE_ORDER_PUB.update_header ( p_header_id => p_header_id, p_header_val_rec => l_header_va

    l_rec, x_return_status => v_return_status, x_msg_count => v_msg_count, x_msg_data => v_msg_data );

    ----------------------------------------- Display Error Message if API fails----------------------------------------- IF (v_return_status FND_API.g_ret_sts_success)

    THEN -- If 1.1 --

    IF (v_msg_count > 0) THEN -- If 1.1.1 --

    FOR v_index in 1 .. v_msg_count LOOP -- Loop 1.1.1.1 --

    OE_MSG_PUB.get( p_msg_index => v_index,

  • 7/25/2019 Order Management API's Use

    3/47

    p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || v_msg_data);

    END LOOP; -- Loop 1.1.1.1 --

    END IF; -- If 1.1.1 --

    RAISE e_exception;

    ELSE -- If 1.1 --

    FND_FILE.put_line(FND_FILE.output, 'Shipment Priority at Order Header updated Successfully');

    END IF; -- If 1.1 --

    END; -- 1 --

    ---------------------------------------- Call API to Update Shipment Prior--

    -- and Schedule Ship Date for Order ---- Line ---------------------------------------- BEGIN -- 2 --

    OE_MSG_PUB.initialize;

    v_count := 0; v_return_status := NULL; v_msg_count := NULL; v_msg_data := NULL;

    FOR a_rec IN c_rec

    LOOP -- Loop 2.1 --

    v_count := v_count + 1;

    L_LINE_TBL(v_count) := OE_ORDER_PUB.g_miss_line_rec; L_LINE_TBL(v_count).operation := OE_GLOBALS.g_opr_update; L_LINE_TBL(v_count).line_id := A_REC.line_id; L_LINE_TBL(v_count).schedule_ship_date := (SYSDATE + 7); L_LINE_TBL(v_count).shipment_priority_code := 'ALAMEDA';

    END LOOP; -- Loop 2.1 --

    FND_FILE.put_line(FND_FILE.log, 'Calling API to Update Order Line Shipment Priority...');

    OE_ORDER_PUB.process_line ( p_line_tbl => l_line_tbl, x_line_out_tbl => x_line_out_tbl, x_return_status => v_return_status, x_msg_count => v_msg_count, x_msg_data => v_msg_data

  • 7/25/2019 Order Management API's Use

    4/47

    );

    ----------------------------------------- Display Error Message if API fails----------------------------------------- IF (v_return_status FND_API.g_ret_sts_success) THEN -- If 2.2 --

    IF (v_msg_count > 0) THEN -- If 2.2.1 --

    FOR v_index in 1 .. v_msg_count LOOP -- Loop 2.2.1.1 --

    OE_MSG_PUB.get( p_msg_index => v_index, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || v_msg_data);

    END LOOP; -- Loop 2.2.1.1 --

    END IF; -- If 2.2.1 --

    RAISE e_exception;

    ELSE -- If 2.2 --

    FND_FILE.put_line(FND_FILE.output, 'Shipment Priority at Order Linesupdated Successfully');

    END IF; -- If 2.2 --

    END; -- 2 --

    EXCEPTION -- 1 --

    WHEN e_exception THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Update Shipment Priority'); ROLLBACK;

    RAISE;

    WHEN OTHERS

    THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Update Shipment Priority ::' || SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END update_shipment_priority; -- Main --

  • 7/25/2019 Order Management API's Use

    5/47

    PROCEDURE book_order ( p_header_id IN NUMBER ) IS

    ---------------------------------------- Variable Declaration ---------------------------------------- v_booked_flag VARCHAR2(1); l_action_request_tbl OE_ORDER_PUB.request_tbl_type;

    v_return_status VARCHAR2(1); v_msg_count NUMBER; v_msg_data VARCHAR2(2000); v_msg_index_out NUMBER;

    x_header_rec OE_ORDER_PUB.header_rec_type; x_header_val_rec OE_ORDER_PUB.header_val_rec_type; x_header_adj_tbl OE_ORDER_PUB.header_adj_tbl_type; x_header_adj_val_tbl OE_ORDER_PUB.header_adj_val_tbl_type; x_header_price_att_tbl OE_ORDER_PUB.header_price_att_tbl_type;

    x_header_adj_att_tbl OE_ORDER_PUB.header_adj_att_tbl_type; x_header_adj_assoc_tbl OE_ORDER_PUB.header_adj_assoc_tbl_type; x_header_scredit_tbl OE_ORDER_PUB.header_scredit_tbl_type; x_header_scredit_val_tbl OE_ORDER_PUB.header_scredit_val_tbl_type; x_header_payment_tbl OE_ORDER_PUB.header_payment_tbl_type; x_header_payment_val_tbl OE_ORDER_PUB.header_payment_val_tbl_type; x_line_tbl OE_ORDER_PUB.line_tbl_type; x_line_val_tbl OE_ORDER_PUB.line_val_tbl_type; x_line_adj_tbl OE_ORDER_PUB.line_adj_tbl_type; x_line_adj_val_tbl OE_ORDER_PUB.line_adj_val_tbl_type; x_line_price_att_tbl OE_ORDER_PUB.line_price_att_tbl_type; x_line_adj_att_tbl OE_ORDER_PUB.line_adj_att_tbl_type; x_line_adj_assoc_tbl OE_ORDER_PUB.line_adj_assoc_tbl_type;

    x_line_scredit_tbl OE_ORDER_PUB.line_scredit_tbl_type; x_line_scredit_val_tbl OE_ORDER_PUB.line_scredit_val_tbl_type; x_line_payment_tbl OE_ORDER_PUB.line_payment_tbl_type; x_line_payment_val_tbl OE_ORDER_PUB.line_payment_val_tbl_type; x_lot_serial_tbl OE_ORDER_PUB.lot_serial_tbl_type; x_lot_serial_val_tbl OE_ORDER_PUB.lot_serial_val_tbl_type; x_action_request_tbl OE_ORDER_PUB.request_tbl_type;

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    BEGIN -- Main --

    ---------------------------------------- Call API to Book Sales Order ---------------------------------------- BEGIN -- 1 --

    L_ACTION_REQUEST_TBL(1).request_type := OE_GLOBALS.g_book_order;

  • 7/25/2019 Order Management API's Use

    6/47

    L_ACTION_REQUEST_TBL(1).entity_code := OE_GLOBALS.g_entity_header; L_ACTION_REQUEST_TBL(1).entity_id := p_header_id;

    OE_MSG_PUB.initialize;

    FND_FILE.put_line(FND_FILE.log, 'Calling API to Book Order...');

    OE_ORDER_PUB.process_order ( p_api_version_number => 1.0, p_init_msg_list => FND_API.g_true, p_action_commit => FND_API.g_false, p_return_values => FND_API.g_true, x_return_status => v_return_status, x_msg_count => v_msg_count, x_msg_data => v_msg_data, p_action_request_tbl => l_action_request_tbl, x_action_request_tbl => x_action_request_tbl,

    x_header_rec => x_header_rec, x_header_val_rec => x_header_val_rec, x_header_adj_tbl => x_header_adj_tbl, x_header_adj_val_tbl => x_header_adj_val_tbl, x_header_price_att_tbl => x_header_price_att_tbl, x_header_adj_att_tbl => x_header_adj_att_tbl, x_header_adj_assoc_tbl => x_header_ad

    j_assoc_tbl, x_header_scredit_tbl => x_header_scredit_tbl, x_header_scredit_val_tbl => x_header_scredit_val_tbl, x_header_payment_tbl => x_header_payment_tbl, x_header_payment_val_tbl => x_header_payment_val_tbl, x_line_tbl => x_line_tbl, x_line_val_tbl => x_line_val_tbl, x_line_adj_tbl => x_line_adj_

    tbl, x_line_adj_val_tbl => x_line_adj_val_tbl, x_line_price_att_tbl => x_line_price_att_tbl, x_line_adj_att_tbl => x_line_adj_att_tbl, x_line_adj_assoc_tbl => x_line_adj_assoc_tbl, x_line_scredit_tbl => x_line_scre

  • 7/25/2019 Order Management API's Use

    7/47

    dit_tbl, x_line_scredit_val_tbl => x_line_scredit_val_tbl, x_line_payment_tbl => x_line_payment_tbl, x_line_payment_val_tbl => x_line_payment_val_tbl, x_lot_serial_tbl => x_lot_serial_tbl, x_lot_serial_val_tbl => x_lot_serial_val_tbl );

    BEGIN -- 1.1 --

    SELECT NVL(ooha.booked_flag, 'N') INTO v_booked_flag FROM oe_order_headers_all ooha WHERE ooha.header_id = p_header_id;

    END; -- 1.1 --

    ----------------------------------------- Display Error Message if API fails----------------------------------------- IF (v_return_status FND_API.g_ret_sts_success) THEN -- If 1.2 --

    IF (v_msg_count > 0) THEN -- If 1.2.1 --

    FOR v_index in 1 .. v_msg_count LOOP -- Loop 1.2.1.1 --

    OE_MSG_PUB.get( p_msg_index => v_index, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || v_msg_data);

    END LOOP; -- Loop 1.2.1.1 --

    END IF; -- If 1.2.1 --

    RAISE e_exception;

    ELSIF (v_booked_flag = 'N') THEN -- If 1.2 --

    RAISE e_exception;

    ELSE -- If 1.2 --

    FND_FILE.put_line(FND_FILE.output, 'Order Booked successfully');

  • 7/25/2019 Order Management API's Use

    8/47

    END IF; -- If 1.2 --

    COMMIT;

    EXCEPTION -- 1 --

    WHEN e_exception THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Order Booking'); ROLLBACK;

    RAISE;

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Order Booking :: ' || SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END; -- 1 --

    END book_order; -- Main --

    PROCEDURE delete_reservation ( p_header_id IN NUMBER ) IS

    --------------------------------------

    -- Variable Declaration ---------------------------------------- v_return_status VARCHAR2(1); v_msg_count NUMBER; v_msg_data VARCHAR2(2000); v_msg_index_out NUMBER;

    v_sales_order_id NUMBER; l_rsv INV_RESERVATION_GLOBAL.mtl_reservation_rec_type; l_dummy_sn INV_RESERVATION_GLOBAL.serial_number_tbl_type;

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    ---------------------------------------- Cursor Declaration ---------------------------------------- CURSOR c_res_rec (

  • 7/25/2019 Order Management API's Use

    9/47

    p_sales_order_id NUMBER ) IS SELECT mr.reservation_id FROM oe_order_lines_all oola, mtl_reservations mr WHERE oola.header_id = p_header_id AND mr.demand_source_line_id = oola.line_id AND mr.demand_source_header_id = p_sales_order_id AND mr.demand_source_type_id = 2 AND mr.organization_id = oola.ship_from_org_id ORDER BY mr.reservation_id;

    BEGIN -- Main --

    BEGIN -- 1 --

    ---------------------------------------- Fetch MTL Sales Order ID ---------------------------------------- BEGIN -- 1.1 --

    v_sales_order_id := NULL;

    SELECT mso.sales_order_id INTO v_sales_order_id FROM oe_order_headers_all ooha,

    mtl_sales_orders mso WHERE ooha.header_id = p_header_id AND mso.segment1 = ooha.order_number AND mso.segment2 = 'US ORTHO INTL SHIP + BILL ORDR' AND mso.segment3 = 'ORDER ENTRY' AND ROWNUM < 2;

    EXCEPTION -- 1.1 --

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: While fetching MTL Sales Order'); RAISE e_exception;

    END; -- 1.1 --

    ---------------------------------------- Loop to fetch existing Reservation----------------------------------------

  • 7/25/2019 Order Management API's Use

    10/47

    FOR a_res_rec in c_res_rec(v_sales_order_id) LOOP -- LOOP 1.2 --

    ---------------------------------------- Call API to Delete Sales Order ---- Reservations ---------------------------------------- BEGIN -- 1.2.1 --

    L_RSV.reservation_id := A_RES_REC.reservation_id;

    FND_FILE.put_line(FND_FILE.log, 'Calling Delete Sales Order Reservation API...'); FND_MSG_PUB.initialize;

    INV_RESERVATION_PUB.delete_reservation ( p_api_version_number=> 1.0, p_init_msg_lst=> FND_API.g_true, x_return_status=> v_return_status,

    x_msg_count=> v_msg_count, x_msg_data=> v_msg_data, p_rsv_rec=> l_rsv, p_serial_number=> l_dummy_sn );

    ----------------------------------------- Display Error Message if API fails--

    --------------------------------------- IF (v_return_status FND_API.g_ret_sts_success) THEN -- If 1.2.1.1 --

    FND_FILE.put_line(FND_FILE.log, 'ERROR: Reservation ID - ' ||A_RES_REC.reservation_id);

    IF (v_msg_count > 0) THEN -- If 1.2.1.1.1 --

    FOR v_index in 1 .. v_msg_count LOOP -- Loop 1.2.1.1.1.1 --

    FND_MSG_PUB.get( p_msg_index => v_index, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || v_msg_data);

    END LOOP; -- Loop 1.2.1.1.1.1 --

  • 7/25/2019 Order Management API's Use

    11/47

    END IF; -- If 1.2.1.1.1 --

    RAISE e_exception;

    END IF; -- If 1.2.1.1 --

    EXCEPTION -- 1.2.1 --

    WHEN OTHERS THEN

    RAISE e_exception;

    END; -- 1.2.1 --

    END LOOP; -- Loop 1.2 --

    FND_FILE.put_line(FND_FILE.output, 'Order Reservation Deleted Successfully'); COMMIT;

    EXCEPTION -- 1 --

    WHEN e_exception THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Delete Order Reservation'); ROLLBACK;

    RAISE;

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Delete Order Reservation

    :: ' || SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END; -- 1 --

    END delete_reservation; -- Main --

    PROCEDURE reserve_order (

    p_header_id IN NUMBER, p_cust_po_number IN VARCHAR2 ) IS

    ---------------------------------------- Variable Declaration ---------------------------------------- v_return_status VARCHAR2(1); v_msg_count NUMBER;

  • 7/25/2019 Order Management API's Use

    12/47

    v_msg_data VARCHAR2(2000); v_msg_index_out NUMBER;

    v_sales_order_id NUMBER; v_previous_item MTL_SYSTEM_ITEMS_B.segment1%TYPE; v_lot_code VARCHAR2(60); v_count NUMBER; v_loop_count NUMBER;

    l_rsv INV_RESERVATION_GLOBAL.mtl_reservation_rec_type; l_dummy_sn INV_RESERVATION_GLOBAL.serial_number_tbl_type;

    x_rsv_id NUMBER; x_dummy_sn INV_RESERVATION_GLOBAL.serial_number_tbl_type; x_qty NUMBER;

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    ---------------------------------------- Cursor Declaration ---------------------------------------- CURSOR c_line_rec IS SELECT msib.segment1 Item_Number, msib.inventory_item_id, oola.line_id, oola.ordered_quantity, oola.order_quantity_uom FROM oe_order_lines_all oola,

    mtl_system_items_b msib WHERE oola.header_id = p_header_id AND msib.inventory_item_id = oola.inventory_item_id AND msib.organization_id = oola.ship_from_org_id ORDER BY msib.segment1, oola.line_id;

    BEGIN -- Main --

    BEGIN -- 1 --

    v_previous_item := NULL; v_count := 0;

    ---------------------------------------- Fetch MTL Sales Order ID ---------------------------------------- BEGIN -- x --

  • 7/25/2019 Order Management API's Use

    13/47

    v_sales_order_id := NULL;

    SELECT mso.sales_order_id INTO v_sales_order_id FROM oe_order_headers_all ooha, mtl_sales_orders mso WHERE ooha.header_id = p_header_id AND mso.segment1 = ooha.order_number AND mso.segment2 = 'US ORTHO INTL SHIP + BILL ORDR' AND mso.segment3 = 'ORDER ENTRY' AND ROWNUM < 2;

    EXCEPTION -- x --

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: While fetching MTL Sales Order');

    RAISE e_exception;

    END; -- x --

    ---------------------------------------- Loop to fetch Item Number and ---- Order Line ID ---------------------------------------- FOR a_line_rec in c_line_rec LOOP -- LOOP 1.1 --

    ---------------------------------------- Run loop to fetch Lot Code and ---- then run API to reserve order ---- line. ---------------------------------------- FOR v_loop_count in 1 .. A_LINE_REC.ordered_quantity LOOP -- Loop 1.1.1 --

    ---------------------------------------- Reset Counter if Order line Item ---- changes ----------------------------------------

    IF ( v_previous_item IS NULL OR v_previous_item = A_LINE_REC.item_number ) THEN -- If 1.1.1.1 --

    v_count := v_count + 1;

    ELSE -- If 1.1.1.1 --

  • 7/25/2019 Order Management API's Use

    14/47

    v_count := 1;

    END IF; -- If 1.1.1.1 --

    ---------------------------------------- Fetch Lot Code for Sales Order ---- Line ---------------------------------------- BEGIN -- 1.1.1.2 --

    v_lot_code := NULL;

    SELECT query.lot_code INTO v_lot_code FROM ( SELECT ROWNUM row_number, a.lot_code FROM (

    SELECT xaos.lot_code FROM xxort_alameda_orders_stg xaos WHERE xaos.cust_po_number = p_cust_po_number AND xaos.cust_type = 'I' AND xaos.process_flag NOT IN ('9', 'X', 'P') AND xaos.item_number = A_LINE_REC.item_number ORDER BY xaos.lot_code ) a

    ) query WHERE query.row_number = v_count;

    END; -- 1.1.1.2 --

    ---------------------------------------- Call API to Reserve Sales Order ---- Line ---------------------------------------- BEGIN -- 1.1.1.3 --

    L_RSV.requirement_date := SYSDATE + 1; L_RSV.organization_id := 84; L_RSV.inventory_item_id := A_LINE_REC.inventory_item_id; L_RSV.demand_source_type_id := INV_RESERVATION_GLOBAL.g_source_type_oe; L_RSV.demand_source_name := NULL; L_RSV.demand_source_header_id := v_sales_order_id; L_RSV.demand_source_line_id := A_LINE_REC.line_id; L_RSV.demand_source_delivery := NULL;

  • 7/25/2019 Order Management API's Use

    15/47

    L_RSV.primary_uom_code := A_LINE_REC.order_quantity_uom; L_RSV.primary_uom_id := NULL; L_RSV.reservation_uom_code := A_LINE_REC.order_quantity_uom; L_RSV.reservation_uom_id := NULL; L_RSV.reservation_quantity := 1; L_RSV.primary_reservation_quantity := 1; L_RSV.detailed_quantity := NULL; L_RSV.autodetail_group_id := NULL; L_RSV.external_source_code := NULL; L_RSV.external_source_line_id := NULL; L_RSV.supply_source_type_id := INV_RESERVATION_GLOBAL.g_source_type_inv; L_RSV.supply_source_header_id := NULL; L_RSV.supply_source_line_id := NULL; L_RSV.supply_source_name := NULL; L_RSV.supply_source_line_detail := NULL; L_RSV.revision := NULL; L_RSV.subinventory_code := 'ALAMEDA'; L_RSV.subinventory_id := NULL; L_RSV.locator_id := NULL; L_RSV.lot_number := v_lot_code; L_RSV.lot_number_id := NULL;

    L_RSV.pick_slip_number := NULL; L_RSV.lpn_id := NULL; L_RSV.attribute_category := NULL; L_RSV.attribute1 := NULL; L_RSV.attribute2 := NULL; L_RSV.attribute3 := NULL; L_RSV.attribute4 := NULL; L_RSV.attribute5 := NULL; L_RSV.attribute6 := NULL; L_RSV.attribute7 := NULL; L_RSV.attribute8 := NULL; L_RSV.attribute9 := NULL; L_RSV.attribute10 := NULL;

    L_RSV.attribute11 := NULL; L_RSV.attribute12 := NULL; L_RSV.attribute13 := NULL; L_RSV.attribute14 := NULL; L_RSV.attribute15 := NULL; L_RSV.ship_ready_flag := NULL;

    FND_FILE.put_line(FND_FILE.log, 'Calling Reserve Order API...'); FND_MSG_PUB.initialize;

    INV_RESERVATION_PUB.create_reservation ( p_api_version_number

    => 1.0, x_return_status

    => v_return_status, x_msg_count

    => v_msg_count, x_msg_data

    => v_msg_data, p_rsv_rec

    => l_rsv, p_serial_number

  • 7/25/2019 Order Management API's Use

    16/47

    => l_dummy_sn, x_serial_number

    => x_dummy_sn, x_quantity_reserved

    => x_qty, x_reservation_id

    => x_rsv_id );

    ----------------------------------------- Display Error Message if API fails----------------------------------------- IF (v_return_status FND_API.g_ret_sts_success) THEN -- If 1.1.1.3.1 --

    FND_FILE.put_line(FND_FILE.log, 'ERROR: Order Line ID - ' || A_LINE_REC.line_id);

    IF (v_msg_count > 0) THEN -- If 1.1.1.3.1.1 --

    FOR v_index in 1 .. v_msg_count LOOP -- Loop 1.1.1.3.1.1.1 --

    FND_MSG_PUB.get( p_msg_index => v_index, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || v_msg_data);

    END LOOP; -- Loop 1.1.1.3.1.1.1 --

    END IF; -- If 1.1.1.3.1.1 --

    RAISE e_exception;

    END IF; -- If 1.1.1.3.1 --

    EXCEPTION -- 1.1.1.3 --

    WHEN OTHERS THEN

    RAISE e_exception;

    END; -- 1.1.1.3 --

    v_previous_item := A_LINE_REC.item_number;

    END LOOP; -- Loop 1.1.1 --

    END LOOP; -- LOOP 1.1 --

    FND_FILE.put_line(FND_FILE.output, 'Order Reserved Successfully'); COMMIT;

  • 7/25/2019 Order Management API's Use

    17/47

    EXCEPTION -- 1 --

    WHEN e_exception THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Reserve Order'); ROLLBACK;

    RAISE;

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Reserve Order :: ' || SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END; -- 1 --

    END reserve_order; -- Main --

    PROCEDURE autocreate_delivery ( p_header_id IN NUMBER ) IS

    ---------------------------------------- Variable Declaration ---------------------------------------- v_return_status VARCHAR2(1); v_msg_count NUMBER;

    v_msg_data VARCHAR2(2000); v_msg_index_out NUMBER; v_count NUMBER;

    l_delivery_detail_tab WSH_UTIL_CORE.id_tab_type; x_del_rows WSH_UTIL_CORE.id_tab_type;

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    ---------------------------------------- Cursor Declaration ---------------------------------------- CURSOR c_rec IS SELECT DISTINCT wdd.delivery_detail_id FROM oe_order_headers_all ooha,

  • 7/25/2019 Order Management API's Use

    18/47

    oe_order_lines_all oola, wsh_delivery_details wdd WHERE ooha.header_id = p_header_id AND ooha.booked_flag = 'Y' AND NVL(ooha.cancelled_flag, 'N') = 'N' AND oola.header_id = ooha.header_id AND oola.org_id = ooha.org_id AND oola.flow_status_code = 'AWAITING_SHIPPING' AND wdd.source_header_id = ooha.header_id AND wdd.source_line_id = oola.line_id AND wdd.released_status IN ('R', 'B');

    BEGIN -- Main --

    ---------------------------------------- Call API to Autocreate Delivery ---- for Order lines ---------------------------------------- BEGIN -- 1 --

    v_count := 0;

    FND_MSG_PUB.initialize;

    FOR a_rec IN c_rec LOOP -- Loop 1.1 --

    v_count := v_count + 1; L_DELIVERY_DETAIL_TAB(v_count) := A_REC.delivery_detail_id;

    END LOOP; -- Loop 1.1 --

    FND_FILE.put_line(FND_FILE.log, 'Calling API to Autocreate Delivery...');

    WSH_DELIVERY_DETAILS_PUB.autocreate_deliveries ( p_api_version_number=> 1.0, p_init_msg_list=> FND_API.g_true, p_commit=> FND_API.g_false, x_return_status=> v_return_status, x_msg_count=> v_msg_count, x_msg_data=> v_msg_data,

    p_line_rows=> l_delivery_detail_tab, x_del_rows=> x_del_rows );

    ----------------------------------------- Display Error Message if API fails-----------------------------------------

  • 7/25/2019 Order Management API's Use

    19/47

    IF (v_return_status FND_API.g_ret_sts_success) THEN -- If 1.1 --

    IF (v_msg_count > 0) THEN -- If 1.1.1 --

    FOR v_index in 1 .. v_msg_count LOOP -- Loop 1.1.1.1 --

    FND_MSG_PUB.get( p_msg_index => v_index, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || v_msg_data);

    END LOOP; -- Loop 1.1.1.1 --

    END IF; -- If 1.1.1 --

    RAISE e_exception;

    ----------------------------------------- Display Delivery IDs created if ---- API runs successfully ----------------------------------------- ELSE -- If 1.1 --

    IF (X_DEL_ROWS.count() > 0) THEN -- If 1.2.1 --

    FOR i IN x_del_rows.FIRST .. x_del_rows.LAST LOOP -- Loop 1.2.1.1 --

    FND_FILE.put_line (FND_FILE.output, 'Delivery ID: ' || x_del_r

    ows(i));

    END LOOP; -- Loop 1.2.1.1 --

    END IF; -- If 1.2.1 --

    END IF; -- If 1.1 --

    COMMIT;

    EXCEPTION -- 1 --

    WHEN e_exception

    THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Autocreate Delivery'); ROLLBACK;

    RAISE;

    WHEN OTHERS THEN

  • 7/25/2019 Order Management API's Use

    20/47

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Autocreate Delivery :: '|| SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END; -- 1 --

    END autocreate_delivery; -- Main --

    PROCEDURE pick_release ( p_header_id IN NUMBER ) IS

    ---------------------------------------- Variable Declaration ---------------------------------------- v_return_status VARCHAR2(1); v_msg_count NUMBER; v_msg_data VARCHAR2(2000);

    v_msg_index_out NUMBER;

    x_trip_id VARCHAR2(30); x_trip_name VARCHAR2(30);

    v_request_id NUMBER; v_boolean BOOLEAN; v_phase VARCHAR2(20); v_status VARCHAR2(20); v_dev_phase VARCHAR2(20); v_dev_status VARCHAR2(20); v_message VARCHAR2(200);

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    ---------------------------------------- Cursor Declaration ---------------------------------------- CURSOR c_rec IS SELECT DISTINCT

    wda.delivery_id FROM oe_order_headers_all ooha, oe_order_lines_all oola, wsh_delivery_details wdd, wsh_delivery_assignments wda WHERE ooha.header_id = p_header_id AND ooha.booked_flag = 'Y' AND NVL(ooha.cancelled_flag, 'N') = 'N'

  • 7/25/2019 Order Management API's Use

    21/47

    AND oola.header_id = ooha.header_id AND oola.org_id = ooha.org_id AND oola.flow_status_code = 'AWAITING_SHIPPING' AND wdd.source_header_id = ooha.header_id AND wdd.source_line_id = oola.line_id AND wdd.released_status IN ('R', 'B') AND wda.delivery_detail_id = wdd.delivery_detail_id;

    BEGIN -- Main --

    ---------------------------------------- Call API to Pick Release Sales ---- Order ---------------------------------------- BEGIN -- 1 --

    FOR a_rec IN c_rec LOOP -- Loop 1.1 --

    x_trip_id := NULL; x_trip_name := NULL;

    v_return_status := NULL; v_msg_count := NULL; v_msg_data := NULL;

    FND_FILE.put_line(FND_FILE.log, 'Calling API to Pick-Release Order...'); FND_MSG_PUB.initialize;

    WSH_DELIVERIES_PUB.delivery_action ( p_api_version_number => 1.0, p_init_msg_list => fnd_api.g_true, x_return_status => v_ret

    urn_status, x_msg_count => v_msg_count, x_msg_data => v_msg

    _data, p_action_code => 'PICK-RELEASE', p_delivery_id => A_REC.delivery_id, p_delivery_name => TO_CHAR(A_REC.delivery_id), x_trip_id => x_trip_id,

    x_trip_name => x_trip_name );

    ----------------------------------------- Display Error Message if API fails----------------------------------------- IF (v_return_status FND_API.g_ret_sts_success) THEN -- If 1.1.1 --

  • 7/25/2019 Order Management API's Use

    22/47

    IF (v_msg_count > 0) THEN -- If 1.1.1.1 --

    FOR v_index in 1 .. v_msg_count LOOP -- Loop 1.1.1.1.1 --

    FND_MSG_PUB.get( p_msg_index => v_index, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || v_msg_data);

    END LOOP; -- Loop 1.1.1.1.1 --

    END IF; -- If 1.1.1.1 --

    RAISE e_exception;

    ----------------------------------------- Wait for Pick Release Concurrent ---- Request to complete --

    --------------------------------------- ELSE -- If 1.1.1 --

    COMMIT;

    FND_MSG_PUB.get( p_msg_index => 1, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); v_request_id := RTRIM(SUBSTR(v_msg_data, INSTR(v_msg_data, 'IDis', -1) + 6), '.');

    v_phase := NULL; v_status := NULL; v_dev_phase := NULL; v_dev_status := NULL; v_message := NULL;

    v_boolean := FND_CONCURRENT.wait_for_request ( v_request_id, 5, 36000, v_phase,

    v_status, v_dev_phase, v_dev_status, v_message );

    IF (v_dev_status 'NORMAL') THEN -- If 1.1.1.1 --

  • 7/25/2019 Order Management API's Use

    23/47

    FND_FILE.put_line (FND_FILE.log, 'ERROR: Pick Release request' || v_request_id || ' not completed normally'); RAISE e_exception;

    ELSE -- If 1.1.1.1 --

    FND_FILE.put_line (FND_FILE.output, 'Pick Release done successfully');

    END IF; -- If 1.1.1.1 --

    END IF; -- If 1.1.1 --

    END LOOP; -- Loop 1.1 --

    COMMIT;

    EXCEPTION -- 1 --

    WHEN e_exception THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Pick Release Order');

    ROLLBACK;

    RAISE;

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Pick Release Order :: ' || SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END; -- 1 --

    END pick_release; -- Main --

    PROCEDURE allocate_transact( p_header_id IN NUMBER ) IS

    --------------------------------------

    -- Variable Declaration ---------------------------------------- v_return_status VARCHAR2(1); v_msg_count NUMBER; v_msg_data VARCHAR2(2000); v_msg_index_out NUMBER;

    x_number_of_rows NUMBER; x_detailed_qty NUMBER; x_revision VARCHAR2(3);

  • 7/25/2019 Order Management API's Use

    24/47

    x_locator_id NUMBER; x_transfer_to_location NUMBER; x_lot_number VARCHAR2(30); x_expiration_date DATE; x_transaction_temp_id NUMBER;

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    ---------------------------------------- Cursor Declaration ---------------------------------------- CURSOR c_rec IS SELECT DISTINCT wdd.move_order_line_id FROM oe_order_headers_all ooha, oe_order_lines_all oola, wsh_delivery_details wdd

    WHERE ooha.header_id = p_header_id AND ooha.booked_flag = 'Y' AND NVL(ooha.cancelled_flag, 'N') = 'N' AND oola.header_id = ooha.header_id AND oola.org_id = ooha.org_id AND oola.flow_status_code = 'AWAITING_SHIPPING' AND wdd.source_header_id = ooha.header_id AND wdd.source_line_id = oola.line_id AND wdd.released_status IN ('S');

    BEGIN -- Main --

    ---------------------------------------- Call API to Allocate and Transact---- Move Order ---------------------------------------- BEGIN -- 1 --

    FOR a_rec IN c_rec LOOP -- Loop 1.1 --

    v_return_status := NULL; v_msg_count := NULL;

    v_msg_data := NULL;

    FND_FILE.put_line(FND_FILE.log, 'Calling API to Allocate/Transact Move Order...'); FND_MSG_PUB.initialize;

    INV_REPLENISH_DETAIL_PUB.line_details_pub ( p_line_id=> A_REC.move_order_line_id, x_number_of_rows

  • 7/25/2019 Order Management API's Use

    25/47

    => x_number_of_rows, x_detailed_qty=> x_detailed_qty, x_return_status=> v_return_status, x_msg_count=> v_msg_count, x_msg_data=> v_msg_data, x_revision=> x_revision, x_locator_id=> x_locator_id, x_transfer_to_location=> x_transfer_to_location, x_lot_number=> x_lot_number, x_expiration_date=> x_expiration_date, x_transaction_temp_id=> x_transaction_temp_id, p_transaction_header_id=> NULL, p_transaction_mode

    => NULL, p_move_order_type=> 3, p_serial_flag=> FND_API.g_false, p_plan_tasks=> FALSE, p_auto_pick_confirm=> TRUE, p_commit=> FALSE );

    ----------------------------------------- Display Error Message if API fails----------------------------------------- IF (v_return_status FND_API.g_ret_sts_success) THEN -- If 1.1.1 --

    IF (v_msg_count > 0) THEN -- If 1.1.1.1 --

    FOR v_index in 1 .. v_msg_count LOOP -- Loop 1.1.1.1.1 --

    FND_MSG_PUB.get(

    p_msg_index => v_index, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || v_msg_data);

    END LOOP; -- Loop 1.1.1.1.1 --

    END IF; -- If 1.1.1.1 --

  • 7/25/2019 Order Management API's Use

    26/47

    RAISE e_exception;

    END IF; -- If 1.1.1 --

    END LOOP; -- Loop 1.1 --

    FND_FILE.put_line (FND_FILE.output, 'Move Order Allocation and Transaction done successfully'); COMMIT;

    EXCEPTION -- 1 --

    WHEN e_exception THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Move Order Allocation andTransaction'); ROLLBACK;

    RAISE;

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Move Order Allocation andTransaction :: ' || SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END; -- 1 --

    END allocate_transact; -- Main --

    PROCEDURE ship_confirm ( p_header_id IN NUMBER ) IS

    ---------------------------------------- Variable Declaration ---------------------------------------- v_return_status VARCHAR2(1); v_msg_count NUMBER; v_msg_data VARCHAR2(2000); v_msg_index_out NUMBER;

    x_trip_id VARCHAR2(30); x_trip_name VARCHAR2(30);

    v_request_id NUMBER; v_boolean BOOLEAN; v_phase VARCHAR2(20); v_status VARCHAR2(20); v_dev_phase VARCHAR2(20); v_dev_status VARCHAR2(20);

  • 7/25/2019 Order Management API's Use

    27/47

    v_message VARCHAR2(200);

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    ---------------------------------------- Cursor Declaration ---------------------------------------- CURSOR c_rec IS SELECT DISTINCT wda.delivery_id FROM oe_order_headers_all ooha, oe_order_lines_all oola, wsh_delivery_details wdd, wsh_delivery_assignments wda WHERE ooha.header_id = p_header_id AND ooha.booked_flag = 'Y'

    AND NVL(ooha.cancelled_flag, 'N') = 'N' AND oola.header_id = ooha.header_id AND oola.org_id = ooha.org_id AND oola.flow_status_code = 'AWAITING_SHIPPING' AND wdd.source_header_id = ooha.header_id AND wdd.source_line_id = oola.line_id AND wdd.released_status IN ('Y') AND wda.delivery_detail_id = wdd.delivery_detail_id;

    BEGIN -- Main --

    ---------------------------------------- Call API to Ship Confirm Sales ---- Order ---------------------------------------- BEGIN -- 1 --

    FOR a_rec IN c_rec LOOP -- Loop 1.1 --

    x_trip_id := NULL; x_trip_name := NULL;

    v_return_status := NULL;

    v_msg_count := NULL; v_msg_data := NULL;

    FND_FILE.put_line(FND_FILE.log, 'Calling API to Ship-Confirm...'); FND_MSG_PUB.initialize;

    WSH_DELIVERIES_PUB.delivery_action ( p_api_version_number =>1.0, p_init_msg_list =>

  • 7/25/2019 Order Management API's Use

    28/47

    fnd_api.g_true, x_return_status =>v_return_status, x_msg_count =>v_msg_count, x_msg_data =>v_msg_data, p_action_code =>'CONFIRM', p_delivery_id =>A_REC.delivery_id, p_delivery_name =>TO_CHAR(A_REC.delivery_id), p_sc_intransit_flag =>'Y', p_sc_close_trip_flag =>'Y', p_sc_defer_interface_flag =>'N', x_trip_id =>x_trip_id, x_trip_name =>x_trip_name );

    ----------------------------------------- Display Error Message if API fails----------------------------------------- IF (v_return_status FND_API.g_ret_sts_success) THEN -- If 1.1.1 --

    IF (v_msg_count > 0) THEN -- If 1.1.1.1 --

    FOR v_index in 1 .. v_msg_count LOOP -- Loop 1.1.1.1.1 --

    FND_MSG_PUB.get( p_msg_index => v_index, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || v_msg_data);

    END LOOP; -- Loop 1.1.1.1.1 --

    END IF; -- If 1.1.1.1 --

    RAISE e_exception;

    ----------------------------------------- Wait for Interface Trip Stop ---- Concurrent Request to complete ----------------------------------------- ELSE -- If 1.1.1 --

    COMMIT; FND_MSG_PUB.get(

  • 7/25/2019 Order Management API's Use

    29/47

    p_msg_index => 1, p_encoded => 'F', p_data => v_msg_data, p_msg_index_out => v_msg_index_out ); v_request_id := RTRIM(SUBSTR(v_msg_data, INSTR(v_msg_data, 'Stop request', -1) + 13), ' has been submitted');

    v_phase := NULL; v_status := NULL; v_dev_phase := NULL; v_dev_status := NULL; v_message := NULL;

    v_boolean := FND_CONCURRENT.wait_for_request ( v_request_id, 5, 36000, v_phase, v_status, v_dev_phase, v_dev_statu

    s, v_message );

    IF (v_dev_status 'NORMAL') THEN -- If 1.1.1.1 --

    FND_FILE.put_line (FND_FILE.log, 'ERROR: Interface Trip Stop request ' || v_request_id || ' not completed normally'); RAISE e_exception;

    ELSE -- If 1.1.1.1 --

    FND_FILE.put_line (FND_FILE.output, 'Ship Confirm done successfully');

    END IF; -- If 1.1.1.1 --

    END IF; -- If 1.1.1 --

    END LOOP; -- Loop 1.1 --

    COMMIT;

    EXCEPTION -- 1 --

    WHEN e_exception THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Ship Confirm Order'); ROLLBACK;

    RAISE;

    WHEN OTHERS THEN

  • 7/25/2019 Order Management API's Use

    30/47

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Ship Confirm Order :: ' || SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END; -- 1 --

    END ship_confirm; -- Main --

    PROCEDURE submit_commercial_invoice ( p_header_id IN NUMBER, v_request_id OUT NUMBER ) IS

    ---------------------------------------- Variable Declaration ----------------------------------------

    v_set_layout_option BOOLEAN; v_boolean BOOLEAN; v_phase VARCHAR2(20); v_status VARCHAR2(20); v_dev_phase VARCHAR2(20); v_dev_status VARCHAR2(20); v_message VARCHAR2(200);

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    BEGIN -- Main --

    FND_FILE.put_line(FND_FILE.log, 'Submit Concurrent Request ''XXORT ALAMEDACommercial Invoice''');

    ------------------------------------------- Set Template for Concurrent Request ------------------------------------------- v_set_layout_option := FND_REQUEST.add_layout ( template_appl_name =>

    'XXORT', template_code =>'XXORT_ALAMEDA_COMM_INVOICE', template_language =>'en', template_territory =>'US', output_format =>'PDF' );

  • 7/25/2019 Order Management API's Use

    31/47

    IF (NOT v_set_layout_option) THEN -- 1.1 --

    FND_FILE.put_line(FND_FILE.log, 'ERROR: Failed to set template for concurrent request ''XXORT ALAMEDA Commercial Invoice'''); RAISE e_exception;

    ------------------------------------------- Submit Concurrent Request 'XXORT ---- ALAMEDA Commercial Invoice' ------------------------------------------- ELSE -- 1.1 --

    v_request_id := 0; v_request_id := FND_REQUEST.submit_request ( 'XXORT', 'XXORT_ALAMEDA_COMM_INVOICE', NULL, NULL, FALSE, p_header_id

    );

    COMMIT;

    IF (v_request_id = 0) THEN -- If 1.1.1 --

    FND_FILE.put_line(FND_FILE.log, 'ERROR: Failed to submit concurrentrequest ''XXORT ALAMEDA Commercial Invoice'''); RAISE e_exception;

    --------------------------------------

    -- Wait for the Concurrent request ---- and sub-requests to complete ---------------------------------------- ELSE -- If 1.1.1 --

    v_phase := NULL; v_status := NULL; v_dev_phase := NULL; v_dev_status := NULL; v_message := NULL;

    v_boolean := FND_CONCURRENT.wait_for_request ( v_request_id,

    5, 36000, v_phase, v_status, v_dev_phase, v_dev_status, v_message );

    IF (v_dev_status 'NORMAL')

  • 7/25/2019 Order Management API's Use

    32/47

    THEN -- If 1.1.1.1 --

    FND_FILE.put_line (FND_FILE.log, 'ERROR: ''XXORT ALAMEDA Commercial Invoice'' request ' || v_request_id || ' not completed normally'); RAISE e_exception;

    ELSE -- If 1.1.1.1 --

    FND_FILE.put_line (FND_FILE.output, '''XXORT ALAMEDA Commercial Invoice'' request ' || v_request_id || ' completed normally');

    END IF; -- If 1.1.1.1 --

    END IF; -- If 1.1.1 --

    END IF; -- If 1.1 --

    COMMIT;

    EXCEPTION -- Main --

    WHEN e_exception THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Submit Concurrent Request ''XXORT ALAMEDA Commercial Invoice'''); ROLLBACK;

    RAISE;

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Submit Concurrent Request ''XXORT ALAMEDA Commercial Invoice'' :: ' || SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END submit_commercial_invoice; -- Main --

    PROCEDURE submit_mailer ( p_request_id IN NUMBER ) IS

    ---------------------------------------- Variable Declaration ---------------------------------------- v_set_layout_option BOOLEAN; v_request_id NUMBER; v_boolean BOOLEAN; v_phase VARCHAR2(20); v_status VARCHAR2(20); v_dev_phase VARCHAR2(20); v_dev_status VARCHAR2(20);

  • 7/25/2019 Order Management API's Use

    33/47

    v_message VARCHAR2(200);

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    BEGIN -- Main --

    FND_FILE.put_line(FND_FILE.log, 'Submit Mailer Request');

    ------------------------------------------- Submit Mailer Request 'XXORT ALAMEDA---- Commercial Invoice Mailer' ------------------------------------------- v_request_id := 0; v_request_id := FND_REQUEST.submit_request ( 'XXORT', 'xxort_comm_invoice_send_mail', NULL,

    NULL, FALSE, p_request_id );

    COMMIT;

    IF (v_request_id = 0) THEN -- If 1 --

    FND_FILE.put_line(FND_FILE.log, 'ERROR: Failed to submit Mailer request'); RAISE e_exception;

    ---------------------------------------- Wait for the Concurrent request ---- and sub-requests to complete ---------------------------------------- ELSE -- If 1 --

    v_phase := NULL; v_status := NULL; v_dev_phase := NULL; v_dev_status := NULL; v_message := NULL;

    v_boolean := FND_CONCURRENT.wait_for_request ( v_request_id, 5, 36000, v_phase, v_status, v_dev_phase, v_dev_status, v_message

  • 7/25/2019 Order Management API's Use

    34/47

    );

    IF (v_dev_status 'NORMAL') THEN -- If 1.1 --

    FND_FILE.put_line (FND_FILE.log, 'ERROR: Mailer request ' || v_request_id || ' not completed normally'); RAISE e_exception;

    ELSE -- If 1.1 --

    FND_FILE.put_line (FND_FILE.output, 'Mailer request ' || v_request_id || ' completed normally');

    END IF; -- If 1.1 --

    END IF; -- If 1 --

    COMMIT;

    EXCEPTION -- Main --

    WHEN e_exception THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Submit Mailer'); ROLLBACK;

    RAISE;

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Submit Mailer :: ' || SUBSTR(SQLERRM, 1, 300)); ROLLBACK;

    RAISE;

    END submit_mailer; -- Main --

    PROCEDURE main ( o_errbuf OUT VARCHAR2, o_retcode OUT NUMBER ) IS

    ---------------------------------------- Variable Declaration ---------------------------------------- v_count NUMBER; v_process_flag VARCHAR2(1); v_request_id NUMBER; v_header_id NUMBER; v_order_number OE_ORDER_HEADERS_ALL.order_number%TYPE;

  • 7/25/2019 Order Management API's Use

    35/47

    ---------------------------------------- Exception Declaration ---------------------------------------- e_exception EXCEPTION;

    ---------------------------------------- Cursor Declaration ---------------------------------------- CURSOR c_rec IS SELECT DISTINCT cust_po_number, DECODE( xaos.process_flag, 'N', '0', xaos.process_flag ) Process_Flag FROM xxort_alameda_orders_stg xaos WHERE NVL(xaos.process_flag, 'P') NOT IN ('9', 'X', 'P')

    AND xaos.cust_type = 'I' AND EXISTS ( SELECT 'Y' FROM hr_operating_units

    hou, oe_transaction_types_tl

    ottt, oe_transaction_types_all

    otta, oe_order_headers_all

    ooha

    WHERE hou.name= 'Stryker US Mahwah Ortho OU'

    AND ottt.name= 'US ORTHO INTL SHIP + BILL ORDR'

    AND ottt.language= USERENV('LANG')

    AND otta.transaction_type_id= ottt.transaction_type_id

    AND otta.org_id= hou.organization_id

    AND ooha.cust_po_number= xaos.cust_po_number

    AND ooha.org_id= hou.organization_id

    AND ooha.order_type_id= otta.transaction_type_id

    AND NVL(ooha.cancelled_flag, 'N') = 'N' AND NVL(ooha.open_flag, 'Y')

    = 'Y' );

  • 7/25/2019 Order Management API's Use

    36/47

    CURSOR c_so_qty_rec ( p_header_id IN NUMBER ) IS SELECT msib.segment1 Item_Number, SUM(oola.ordered_quantity) Quantity FROM oe_order_lines_all oola, mtl_system_items_b msib WHERE oola.header_id = p_header_id AND msib.inventory_item_id = oola.inventory_item_id AND msib.organization_id = oola.ship_from_org_id GROUP BY msib.segment1;

    CURSOR c_lot_code_rec( p_cust_po_number IN VARCHAR2 ) IS SELECT msib.inventory_item_id, xaos.lot_code,

    xaos.item_number FROM xxort_alameda_orders_stg xaos, mtl_system_items_b msib, org_organization_definitions ood WHERE xaos.cust_po_number = p_cust_po_number AND xaos.cust_type = 'I' AND xaos.process_flag NOT IN ('9', 'X', 'P') AND ood.organization_code = 'D01' AND msib.segment1 = xaos.item_number AND msib.organization_id = ood.organization_id;

    BEGIN -- Main --

    ------------------------------------------- Program Output Header ------------------------------------------- FND_FILE.put_line(FND_FILE.output, '======================================================================================================'); FND_FILE.put_line(FND_FILE.output, '== XXORT ALAMEDA Process Sales Orders =='); FND_FILE.put_line(FND_FILE.output, '======================================================================================================');

    FND_FILE.put_line(FND_FILE.output, ' '); FND_FILE.put_line(FND_FILE.output, ' ');

    FOR a_rec IN c_rec LOOP -- Loop 1 --

    v_process_flag := '0'; FND_FILE.put_line(FND_FILE.output, 'ALAMEDA Customer PO Number: ' || A_REC.cust_po_number);

  • 7/25/2019 Order Management API's Use

    37/47

    BEGIN -- 1 .1 --

    ------------------------------------------- Validate Customer PO Number ------------------------------------------- BEGIN -- 1.1.1 --

    IF (A_REC.cust_po_number IS NULL) THEN -- If 1.1.1.1 --

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Customer PO Numberis null'); RAISE e_exception;

    END IF; -- If 1.1.1.1 --

    END; -- 1.1.1 --

    ------------------------------------------- Validate that all lines have been ---- successfully p

    v_count FROM xxort_alameda_orders_stg xaos WHERE xaos.cust_po_number = A_REC.cust_po_number AND NVL(xaos.process_flag, 'N') IN ('N', 'E');

    IF (v_count > 0) THEN -- If 1.1.2.1 --

    FND_FILE.put_line(FND_FILE.output, 'ERROR: All the lines of the ALAMEDA Order are not successfully processed by ''XXORT Alameda Inventory Transactions Program''');

    RAISE e_exception;

    END IF; -- If 1.1.2.1 --

    END; -- 1.1.2 --*/

    ------------------------------------------- Check if multiple orders exist, no ---- sales Order exist ------------------------------------------- BEGIN -- 1.1.3 --

    v_header_id := NULL; v_order_number := NULL;

    SELECT ooha.header_id, ooha.order_number INTO v_header_id, v_order_number FROM

  • 7/25/2019 Order Management API's Use

    38/47

    hr_operating_units hou, oe_transaction_types_tl ottt, oe_transaction_types_all otta, oe_order_headers_all ooha WHERE hou.name = 'Stryker US Mahwah Ortho OU' AND ottt.name = 'US ORTHO INTL SHIP + BILL ORDR' AND ottt.language = USERENV('LANG') AND otta.transaction_type_id = ottt.transaction_type_id AND otta.org_id = hou.organization_id AND ooha.cust_po_number = A_REC.cust_po_number AND ooha.org_id = hou.organization_id AND ooha.order_type_id = otta.transaction_type_id;

    FND_FILE.put_line(FND_FILE.output, 'Sales Order Number: ' || v_order_number);

    EXCEPTION -- 1.1.3 --

    WHEN NO_DATA_FOUND THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Sales Order doesn''t exist for ALAMEDA Customer PO Number'); RAISE;

    WHEN TOO_MANY_ROWS THEN

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Multiple Open SalesOrder exists for ALAMEDA Customer PO Number'); RAISE;

    WHEN OTHERS THEN

    RAISE;

    END; -- 1.1.3 --

    ------------------------------------------- Validate if Sales Order have extra ---- Inventory Item than ALAMEDA Order ------------------------------------------- BEGIN -- 1.1.4 --

    v_count := NULL;

    SELECT COUNT(*) INTO v_count FROM oe_order_lines_all oola WHERE oola.header_id = v_header_id AND NOT EXISTS (

  • 7/25/2019 Order Management API's Use

    39/47

    SELECT 'Y' FROM xxort_alameda_orders_stg xaos, mtl_system_items_b msib WHERE xaos.cust_po_number = A_REC.cust_po_number AND xaos.cust_type = 'I' AND xaos.process_flag NOT IN ('9', 'X', 'P') AND msib.organization_id = oola.ship_from_org_id AND msib.segment1 = xaos.item_number AND msib.inventory_item_id = oola.inventory_item_id );

    IF (v_count > 0) THEN -- If 1.1.4.1 --

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Sales Order has extra Inventory Items than ALAMEDA Order');

    RAISE e_exception;

    END IF; -- If 1.1.4.1 --

    END; -- 1.1.4 --

    ------------------------------------------- Validate if ALAMEDA Order has extra ---- Inventory Items than Sales Order ------------------------------------------- BEGIN -- 1.1.5 --

    v_count := NULL;

    SELECT COUNT(*) INTO v_count FROM xxort_alameda_orders_stg xaos WHERE xaos.cust_po_number = A_REC.cust_po_number AND xaos.cust_type = 'I' AND xaos.process_flag NOT IN ('9', 'X', 'P') AND NOT EXISTS (

    SELECT 'Y' FROM oe_order_lines_all oola, mtl_system_items_b msib WHERE oola.header_id = v_header_id AND msib.organization_id = oola.ship_from_org_id

  • 7/25/2019 Order Management API's Use

    40/47

    AND msib.inventory_item_id = oola.inventory_item_id AND msib.segment1 = xaos.item_number );

    IF (v_count > 0) THEN -- If 1.1.5.1 --

    FND_FILE.put_line(FND_FILE.output, 'ERROR: ALAMEDA Order has extra Inventory Items than Sales Order'); RAISE e_exception;

    END IF; -- If 1.1.5.1 --

    END; -- 1.1.5 --

    ------------------------------------------- Validate if ALAMEDA Order Item Qty ---- and Sales Order Item Qty is same ------------------------------------------- BEGIN -- 1.1.6 --

    FOR a_so_qty_rec IN c_so_qty_rec(v_header_id) LOOP -- Loop 1.1.6.1 --

    v_count := NULL;

    SELECT COUNT(*) - A_SO_QTY_REC.quantity INTO v_count FROM xxort_alameda_orders_stg xaos WHERE

    xaos.cust_po_number = A_REC.cust_po_number AND xaos. INTO v_count FROM xxort_alameda_orders_stg xaos WHERE xaos.cust_po_number = A_REC.cust_po_number AND xaos.cust_type = 'I' AND xaos.process_flag NOT IN ('9', 'X', 'P') AND xaos.item_number = A_SO_QTY_REC.item_number;

    IF (v_count 0) THEN -- If 1.1.6.1.1 --

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Item ''' || A_SO_QTY_REC.item_number || ''' has different quantities in ALAMEDA Order and SalesOrder'); RAISE e_exception;

    END IF; -- If 1.1.6.1.1 --

    END LOOP; -- Loop 1.1.6.1 --

  • 7/25/2019 Order Management API's Use

    41/47

    END; -- 1.1.6 --

    ------------------------------------------- Validate Lot Codes ------------------------------------------- BEGIN -- 1.1.7 --

    v_count := NULL;

    SELECT ( SELECT COUNT(*) FROM xxort_alameda_orders_stg xaos, mtl_system_items_b msib, mtl_lot_numbers mln WHERE xaos.cust_po_number = A_REC.cust_po_number AND xaos.cust_type = 'I' AND xaos.process_flag NOT IN ('9', 'X', 'P') AND xaos.lot_code IS NOT NULL AND msib.segment1 = xaos.item_number

    AND msib.organization_id = 84 AND mln.organization_id = msib.organization_id AND mln.inventory_item_id = msib.inventory_item_id AND mln.lot_number = xaos.lot_code AND NVL( mln.expiration_date, (SYSDATE + 1) ) > TRUNC(SYSDATE) ) - ( SELECT COUNT(*)

    FROM xxort_alameda_orders_stg xaos1 WHERE xaos1.cust_po_number = A_REC.cust_po_number AND xaos1.cust_type = 'I' AND xaos1.process_flag NOT IN ('9', 'X', 'P') AND xaos1.lot_code IS NOT NULL ) INTO v_count FROM dual;

    IF (v_count 0) THEN -- If 1.1.7.1 --

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Some/All Lot Numbers are invalid'); RAISE e_exception;

    END IF; -- If 1.1.7.1 --

    END; -- 1.1.7 --

  • 7/25/2019 Order Management API's Use

    42/47

  • 7/25/2019 Order Management API's Use

    43/47

    FND_FILE.put_line(FND_FILE.log, ' '); FND_FILE.put_line(FND_FILE.log, ' '); FND_FILE.put_line(FND_FILE.log, 'ALAMEDA Customer PO Number: ' ||A_REC.cust_po_number); FND_FILE.put_line(FND_FILE.log, 'Sales Order Number: ' || v_order

    _number);

    -------------------------------------------- Proc call to Update Shipment Priority-------------------------------------------- IF ( TO_NUMBER(A_REC.process_flag)

  • 7/25/2019 Order Management API's Use

    44/47

    IF ( TO_NUMBER(A_REC.process_flag)

  • 7/25/2019 Order Management API's Use

    45/47

    -------------------------------------------- Proc call to Ship-Confirm order -------------------------------------------- IF ( TO_NUMBER(A_REC.process_flag)

  • 7/25/2019 Order Management API's Use

    46/47

    v_process_flag := 'P';

    UPDATE xxort_alameda_orders_stg xaos SET xaos.process_flag = v_process_flag WHERE xaos.cust_po_number = A_REC.cust_po_number AND xaos.cust_type = 'I' AND xaos.process_flag NOT IN ('9', 'X', 'P');

    EXCEPTION -- 1.1.6 --

    WHEN OTHERS THEN

    v_process_flag := 'X';

    FND_FILE.put_line(FND_FILE.output, 'ERROR: Updating Process_Flag of staging table'); RAISE e_exception;

    END; -- 1.1.10 --

    EXCEPTION -- 1.1 --

    WHEN e_exception THEN

    o_retcode := 1;

    -------------------------------------------- Update process Flag of staging table ---- to 'E' for failed record -------------------------------------------- UPDATE

    xxort_alameda_orders_stg xaos SET xaos.process_flag = v_process_flag WHERE xaos.cust_po_number = A_REC.cust_po_number AND xaos.cust_type = 'I' AND xaos.process_flag NOT IN ('9', 'X', 'P');

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || SUBSTR(SQLERRM, 1, 300));

    o_retcode := 1;

    -------------------------------------------- Update process Flag of staging table ---- to 'E' for failed record -------------------------------------------- UPDATE xxort_alameda_orders_stg xaos SET xaos.process_flag = v_process_flag

  • 7/25/2019 Order Management API's Use

    47/47

    WHERE xaos.cust_po_number = A_REC.cust_po_number AND xaos.cust_type = 'I' AND xaos.process_flag NOT IN ('9', 'X', 'P');

    END; -- 1.1 --

    COMMIT;

    END LOOP; -- Loop 1 --

    EXCEPTION -- Main --

    WHEN OTHERS THEN

    FND_FILE.put_line(FND_FILE.log, 'ERROR: ' || SUBSTR(SQLERRM, 1, 300)); o_retcode := 1;

    END main; -- Main --

    END XXORT_ALAMEDA_PROCESS_SO_PKG;/