0% found this document useful (0 votes)
555 views

Sales Order API Code

This document contains code for a wrapper API that simplifies calling an order processing API. It includes procedures for processing an order, creating an order header, and preparing order lines in memory before submitting them. The wrapper handles initializing data structures and calling the underlying API to process orders.

Uploaded by

Prem Bandi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
555 views

Sales Order API Code

This document contains code for a wrapper API that simplifies calling an order processing API. It includes procedures for processing an order, creating an order header, and preparing order lines in memory before submitting them. The wrapper handles initializing data structures and calling the underlying API to process orders.

Uploaded by

Prem Bandi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 19

I have a wrapper API that I prepared for my development staff.

It does all the basic functions and is much simpler to call from actual code. It should serve as a good example, I hope. FYI, I had to rip out some stuff that I did want to / am not entitled to share, so I'm not 100% the version I am posting is completely runnable. - Matt [email protected] CREATE OR REPLACE PACKAGE BODY tempus_sales_order_api AS ----------------------------------------------------------------------- PROCESS_ORDER_API (PRIVATE) --- Calls the process order API. ---------------------------------------------------------------------PROCEDURE process_order_api ( p_header_rec IN OUT oe_order_pub.header_rec_type, p_line_tbl IN OUT oe_order_pub.line_tbl_type, p_action_request_tbl IN OUT oe_order_pub.request_tbl_type, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_header_val_rec oe_order_pub.header_val_rec_type; l_header_adj_tbl oe_order_pub.header_adj_tbl_type; l_header_adj_val_tbl oe_order_pub.header_adj_val_tbl_type; l_header_price_att_tbl oe_order_pub.header_price_att_tbl_type; l_header_adj_att_tbl oe_order_pub.header_adj_att_tbl_type; l_header_adj_assoc_tbl oe_order_pub.header_adj_assoc_tbl_type; l_header_scredit_tbl oe_order_pub.header_scredit_tbl_type; l_header_scredit_val_tbl oe_order_pub.header_scredit_val_tbl_type; l_line_val_tbl oe_order_pub.line_val_tbl_type; l_line_adj_tbl oe_order_pub.line_adj_tbl_type; l_line_adj_val_tbl oe_order_pub.line_adj_val_tbl_type; l_line_price_att_tbl oe_order_pub.line_price_att_tbl_type; l_line_adj_att_tbl oe_order_pub.line_adj_att_tbl_type; l_line_adj_assoc_tbl oe_order_pub.line_adj_assoc_tbl_type; l_line_scredit_tbl oe_order_pub.line_scredit_tbl_type; l_line_scredit_val_tbl oe_order_pub.line_scredit_val_tbl_type; l_lot_serial_tbl oe_order_pub.lot_serial_tbl_type; l_lot_serial_val_tbl oe_order_pub.lot_serial_val_tbl_type; BEGIN oe_order_pub.process_order (p_api_version_number => 1.0, p_init_msg_list => fnd_api.g_true, p_return_values => fnd_api.g_false, p_action_commit => fnd_api.g_false, x_return_status => x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data, p_header_rec => p_header_rec,

p_line_tbl p_line_tbl, p_action_request_tbl p_action_request_tbl, x_header_rec p_header_rec, x_header_val_rec l_header_val_rec, x_header_adj_tbl l_header_adj_tbl, x_header_adj_val_tbl l_header_adj_val_tbl, x_header_price_att_tbl l_header_price_att_tbl, x_header_adj_att_tbl l_header_adj_att_tbl, x_header_adj_assoc_tbl l_header_adj_assoc_tbl, x_header_scredit_tbl l_header_scredit_tbl, x_header_scredit_val_tbl l_header_scredit_val_tbl, x_line_tbl p_line_tbl, x_line_val_tbl l_line_val_tbl, x_line_adj_tbl l_line_adj_tbl, x_line_adj_val_tbl l_line_adj_val_tbl, x_line_price_att_tbl l_line_price_att_tbl, x_line_adj_att_tbl l_line_adj_att_tbl, x_line_adj_assoc_tbl l_line_adj_assoc_tbl, x_line_scredit_tbl l_line_scredit_tbl, x_line_scredit_val_tbl l_line_scredit_val_tbl, x_lot_serial_tbl l_lot_serial_tbl, x_lot_serial_val_tbl l_lot_serial_val_tbl, x_action_request_tbl p_action_request_tbl); END process_order_api;

=> => => => => => => => => => => => => => => => => => => => => => =>

----------------------------------------------------------------------- CREATE_HEADER --- Creates a sales order or RMA header with the given parameters ---------------------------------------------------------------------PROCEDURE create_header ( p_order_type_id oe_order_headers.order_type_id%TYPE, p_sold_to_org_id oe_order_headers.sold_to_org_id%TYPE, p_invoice_to_org_id oe_order_headers.invoice_to_org_id%TYPE DEFAULT fnd_api.g_miss_num,

p_ship_to_org_id oe_order_headers.ship_to_org_id%TYPE DEFAULT fnd_api.g_miss_num, p_cust_po_number oe_order_headers.cust_po_number%TYPE DEFAULT fnd_api.g_miss_char, p_shipping_method_code oe_order_headers.shipping_method_code%TYPE DEFAULT fnd_api.g_miss_char, p_ship_from_org_id oe_order_headers.ship_from_org_id%TYPE DEFAULT fnd_api.g_miss_num, p_demand_class oe_order_headers.demand_class_code%TYPE DEFAULT fnd_api.g_miss_char, p_order_number oe_order_headers.order_number%TYPE DEFAULT fnd_api.g_miss_num, p_flow_status_code oe_order_headers.flow_status_code%TYPE DEFAULT fnd_api.g_miss_char, p_order_source_id oe_order_headers.order_source_id%TYPE DEFAULT fnd_api.g_miss_num, x_header_rec OUT oe_order_pub.header_rec_type, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_header_rec oe_order_pub.header_rec_type; BEGIN -- Setup process order API -- Initialize blank header l_header_rec := oe_order_pub.g_miss_header_rec; l_header_rec.operation := oe_globals.g_opr_create; -- Required attributes l_header_rec.order_type_id := p_order_type_id; l_header_rec.order_number := p_order_number; l_header_rec.sold_to_org_id := p_sold_to_org_id; -- Other attributes l_header_rec.invoice_to_org_id := p_invoice_to_org_id; l_header_rec.ship_to_org_id := p_ship_to_org_id; l_header_rec.cust_po_number := p_cust_po_number; l_header_rec.shipping_method_code := p_shipping_method_code; l_header_rec.ship_from_org_id := p_ship_from_org_id; l_header_rec.demand_class_code := p_demand_class; l_header_rec.order_source_id := p_order_source_id; -- Call process order api process_order_api (p_header_rec p_line_tbl oe_order_pub.g_miss_line_tbl, p_action_request_tbl oe_order_pub.g_miss_request_tbl, x_return_status x_msg_count x_msg_data x_header_rec := l_header_rec; END create_header; => l_header_rec, => => => x_return_status, => x_msg_count, => x_msg_data);

----------------------------------------------------------------------- PREPARE_LINE --- Creates a sales order or RMA line with the given parameters in -- memory only. The line is not submitted to the API. --- NOTE: It is the responsibility of the caller to ensure that all -- prepared lines are for the same order header.

---------------------------------------------------------------------PROCEDURE prepare_line ( p_order_header_id oe_order_headers.header_id%TYPE, p_ordered_item_id oe_order_lines.ordered_item_id%TYPE, p_quantity oe_order_lines.ordered_quantity%TYPE, p_quantity_uom oe_order_lines.order_quantity_uom%TYPE DEFAULT 'EA', p_ship_from_org_id oe_order_lines.ship_from_org_id%TYPE DEFAULT fnd_api.g_miss_num, p_bin_location oe_order_lines_all_dfv.bin_location%TYPE DEFAULT fnd_api.g_miss_char, p_schedule_manually_flag oe_order_lines_all_dfv.schedule_manually%TYPE DEFAULT 'N', p_xelus_sourcing_override oe_order_lines_all_dfv.xelus_sourcing_override%TYPE DEFAULT fnd_api.g_miss_char, p_cust_po_line_number oe_order_lines_all.customer_line_number%TYPE DEFAULT fnd_api.g_miss_char, p_cust_po_shipment_number oe_order_lines_all.customer_shipment_number%TYPE DEFAULT fnd_api.g_miss_char, p_rma_invoice_line_id NUMBER DEFAULT fnd_api.g_miss_num, p_rma_comments oe_order_lines_all.service_txn_comments%TYPE DEFAULT fnd_api.g_miss_char, p_request_date oe_order_lines_all.request_date%TYPE DEFAULT fnd_api.g_miss_date, p_return_reason_code oe_order_lines_all.return_reason_code%TYPE DEFAULT fnd_api.g_miss_char) IS l_header_rec oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec; l_line_rec oe_order_pub.line_rec_type := oe_order_pub.g_miss_line_rec; l_stmt NUMBER; BEGIN l_stmt := 10; l_line_rec.operation := oe_globals.g_opr_create; -- Set attributes l_line_rec.header_id := p_order_header_id; l_line_rec.inventory_item_id := p_ordered_item_id; l_line_rec.ordered_item_id := p_ordered_item_id; l_line_rec.ordered_quantity := p_quantity; l_stmt := 11; l_line_rec.order_quantity_uom := p_quantity_uom; l_stmt := 12; l_line_rec.ship_from_org_id := p_ship_from_org_id; l_stmt := 13; IF p_schedule_manually_flag != fnd_api.g_miss_char THEN IF verp_fnd_utility_pkg.get_dff_segment_attribute ('OE_ORDER_LINES_ALL', 'SCHEDULE_MANUALLY', 'PARTS') != 'ATTRIBUTE14' THEN -- DFF definitions have changed from what this program was designed to expect! We must return an error! raise_application_error (-20001, 'Setup error! The PARTS context DFF for Order Lines must have ATTRIBUTE14 reserved for the schedule manually flag.');

END IF; l_line_rec.attribute14 := p_schedule_manually_flag; END IF; l_stmt := 15; IF p_bin_location != fnd_api.g_miss_char THEN IF verp_fnd_utility_pkg.get_dff_segment_attribute ('OE_ORDER_LINES_ALL', 'BIN_LOCATION', 'PARTS') != 'ATTRIBUTE15' THEN -- DFF definitions have changed from what this program was designed to expect! We must return an error! raise_application_error (-20001, 'Setup error! The PARTS context DFF for Order Lines must have ATTRIBUTE15 reserved for the bin location.'); END IF; l_line_rec.attribute15 := p_bin_location; -- TODO Do dynamically in case attribute number changes END IF; l_stmt := 16; IF p_xelus_sourcing_override != fnd_api.g_miss_char THEN IF verp_fnd_utility_pkg.get_dff_segment_attribute ('OE_ORDER_LINES_ALL', 'XELUS_SOURCING_OVERRIDE', 'PARTS') != 'ATTRIBUTE17' THEN -- DFF definitions have changed from what this program was designed to expect! We must return an error! raise_application_error (-20001, 'Setup error! The PARTS context DFF for Order Lines must have ATTRIBUTE17 reserved for the Xelus override flag.'); END IF; l_line_rec.attribute17 := p_xelus_sourcing_override; -- TODO Do dynamically in case attribute number changes END IF; l_stmt := 17; l_line_rec.customer_line_number := p_cust_po_line_number; l_stmt := 18; l_line_rec.customer_shipment_number := p_cust_po_shipment_number; l_stmt := 19; l_line_rec.request_date := p_request_date; l_stmt := 19.1; l_line_rec.return_reason_code := p_return_reason_code; l_stmt := 19.2; IF p_rma_comments != fnd_api.g_miss_char THEN IF verp_fnd_utility_pkg.get_dff_segment_attribute ('OE_ORDER_LINES_ALL', 'COMMENTS', 'PARTS') != 'ATTRIBUTE18' THEN -- DFF definitions have changed from what this program was designed to expect! We must return an error! raise_application_error (-20001, 'Setup error! The PARTS context DFF for Order Lines must have ATTRIBUTE18 reserved for comments.');

END IF; l_line_rec.attribute18 := p_rma_comments; END IF; l_stmt := 19.3; -- Setup information for referenced RMA IF p_rma_invoice_line_id IS NOT NULL AND p_rma_invoice_line_id != fnd_api.g_miss_num THEN -- An RMA reference invoice line was given l_line_rec.return_context := 'INVOICE'; BEGIN SELECT customer_trx_id INTO l_line_rec.return_attribute1 FROM ra_customer_trx_lines rctl WHERE rctl.customer_trx_line_id = p_rma_invoice_line_id; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error (-20001, 'Invoice line ID ' || p_rma_invoice_line_id || ' does not exist'); END; l_line_rec.return_attribute2 := p_rma_invoice_line_id; END IF; l_stmt := 20; -- DEBUG / TEST -- If line quantity is 4 or 13, change the line so it will be rejected by Oracle -IF p_quantity IN (4,13) THEN -l_line_rec.inventory_item_id := -99999; -END IF; -- END DEBUG/TEST -- Add line to memory tempus_sales_order_api_state.g_line_tbl (tempus_sales_order_api_state.g_line_tbl.COUNT + 1) := l_line_rec; EXCEPTION WHEN OTHERS THEN raise_application_error (-20001, 'Unexpected error in tempus_sales_order_api.prepare_line, stmt ' || l_stmt || ': ' || SQLERRM); END prepare_line; ----------------------------------------------------------------------- SUBMIT_LINES --- Submits all lines from memory to the process order API ---------------------------------------------------------------------PROCEDURE submit_lines ( x_line_tbl OUT oe_order_pub.line_tbl_type, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_stmt NUMBER; l_header_rec oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec;

BEGIN -- Call process order api l_stmt := 20; process_order_api (p_header_rec => l_header_rec, p_line_tbl => tempus_sales_order_api_state.g_line_tbl, p_action_request_tbl => oe_order_pub.g_miss_request_tbl, x_return_status => x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data); -- Pass the resulting lines back to the caller l_stmt := 30; x_line_tbl := tempus_sales_order_api_state.g_line_tbl; -- Clear lines from memory after they're submitted. l_stmt := 40; tempus_sales_order_api_state.g_line_tbl := oe_order_pub.g_miss_line_tbl; EXCEPTION WHEN OTHERS THEN oe_msg_pub.add_text ('Unexpected error in tempus_sales_order_api.create_line, stmt ' || l_stmt || ': ' || SQLERRM); x_msg_count := NVL (x_msg_count, 0) + 1; x_return_status := fnd_api.g_ret_sts_unexp_error; END submit_lines; ----------------------------------------------------------------------- CREATE_LINE --- Creates a sales order or RMA line with the given parameters ---------------------------------------------------------------------PROCEDURE create_line ( p_order_header_id oe_order_headers.header_id%TYPE, p_ordered_item_id oe_order_lines.ordered_item_id%TYPE, p_quantity oe_order_lines.ordered_quantity%TYPE, p_quantity_uom oe_order_lines.order_quantity_uom%TYPE DEFAULT 'EA', p_ship_from_org_id oe_order_lines.ship_from_org_id%TYPE DEFAULT fnd_api.g_miss_num, p_bin_location oe_order_lines_all_dfv.bin_location%TYPE DEFAULT fnd_api.g_miss_char, p_schedule_manually_flag oe_order_lines_all_dfv.schedule_manually%TYPE DEFAULT 'N', p_xelus_sourcing_override oe_order_lines_all_dfv.xelus_sourcing_override%TYPE DEFAULT fnd_api.g_miss_char, p_cust_po_line_number oe_order_lines_all.customer_line_number%TYPE DEFAULT fnd_api.g_miss_char, p_cust_po_shipment_number oe_order_lines_all.customer_shipment_number%TYPE DEFAULT fnd_api.g_miss_char, p_rma_invoice_line_id NUMBER DEFAULT fnd_api.g_miss_num, p_rma_comments oe_order_lines_all.service_txn_comments%TYPE DEFAULT

fnd_api.g_miss_char, p_request_date oe_order_lines_all.request_date%TYPE DEFAULT fnd_api.g_miss_date, p_return_reason_code oe_order_lines_all.return_reason_code%TYPE DEFAULT fnd_api.g_miss_char, x_line_rec OUT oe_order_pub.line_rec_type, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_header_rec oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec; l_line_tbl oe_order_pub.line_tbl_type; l_stmt NUMBER; BEGIN -- Prepare the line BEGIN prepare_line (p_order_header_id => p_order_header_id, p_ordered_item_id => p_ordered_item_id, p_quantity => p_quantity, p_quantity_uom => p_quantity_uom, p_ship_from_org_id => p_ship_from_org_id, p_bin_location => p_bin_location, p_schedule_manually_flag => p_schedule_manually_flag, p_xelus_sourcing_override => p_xelus_sourcing_override, p_cust_po_line_number => p_cust_po_line_number, p_cust_po_shipment_number => p_cust_po_shipment_number, p_rma_invoice_line_id => p_rma_invoice_line_id, p_rma_comments => p_rma_comments, p_request_date => p_request_date, p_return_reason_code => p_return_reason_code); EXCEPTION WHEN OTHERS THEN oe_msg_pub.add_text ('Invoice line ID ' || p_rma_invoice_line_id || ' does not exist'); x_msg_count := NVL (x_msg_count, 0) + 1; x_return_status := fnd_api.g_ret_sts_error; RETURN; END; DECLARE l_lines_tbl oe_order_pub.line_tbl_type; BEGIN submit_lines (x_line_tbl => l_lines_tbl, x_return_status => x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data); x_line_rec := l_lines_tbl (1); END; EXCEPTION WHEN OTHERS THEN oe_msg_pub.add_text ('Unexpected error in

tempus_sales_order_api.create_line, stmt ' || l_stmt || ': ' || SQLERRM); x_msg_count := NVL (x_msg_count, 0) + 1; x_return_status := fnd_api.g_ret_sts_unexp_error; END create_line; ----------------------------------------------------------------------- BOOK_ORDER --- Books a sales order or RMA ---------------------------------------------------------------------PROCEDURE book_order ( p_order_header_id oe_order_headers.header_id%TYPE, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_header_rec oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec; l_line_tbl oe_order_pub.line_tbl_type; l_action_request_tbl oe_order_pub.request_tbl_type := oe_order_pub.g_miss_request_tbl; BEGIN l_action_request_tbl (1) := oe_order_pub.g_miss_request_rec; l_action_request_tbl (1).request_type := oe_globals.g_book_order; l_action_request_tbl (1).entity_code := oe_globals.g_entity_header; l_action_request_tbl (1).entity_id := p_order_header_id; -- Call process order api process_order_api (p_header_rec => l_header_rec, p_line_tbl => l_line_tbl, p_action_request_tbl => l_action_request_tbl, x_return_status => x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data); IF x_return_status = fnd_api.g_ret_sts_success THEN -- The true return status is the status from the action request x_return_status := l_action_request_tbl (1).return_status; END IF; END book_order; ----------------------------------------------------------------------- APPLY_HOLD --- Applies a hold to a sales order header or line ---------------------------------------------------------------------PROCEDURE apply_hold ( p_order_header_id oe_order_headers.header_id%TYPE := NULL, p_order_line_id oe_order_lines.line_id%TYPE := NULL, p_hold_name oe_hold_definitions.NAME%TYPE, p_hold_comment VARCHAR2 DEFAULT NULL, p_hold_until_date DATE DEFAULT NULL, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_header_rec oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec; l_line_tbl oe_order_pub.line_tbl_type;

l_action_request_tbl oe_order_pub.request_tbl_type := oe_order_pub.g_miss_request_tbl; BEGIN IF p_order_header_id IS NULL AND p_order_line_id IS NULL THEN raise_application_error (-20001, 'APPLY_HOLD API requires at least a header ID or a line ID.'); END IF; l_action_request_tbl (1) := oe_order_pub.g_miss_request_rec; l_action_request_tbl (1).request_type := oe_globals.g_apply_hold; IF p_order_line_id IS NOT NULL THEN -- Release line level hold l_action_request_tbl (1).entity_code := oe_globals.g_entity_line; l_action_request_tbl (1).entity_id := p_order_line_id; ELSE -- Release header level hold l_action_request_tbl (1).entity_code := oe_globals.g_entity_header; l_action_request_tbl (1).entity_id := p_order_header_id; END IF; BEGIN -- Get the hold ID SELECT ohd.hold_id INTO l_action_request_tbl (1).param1 FROM oe_hold_definitions ohd WHERE ohd.name = p_hold_name; EXCEPTION WHEN no_data_found THEN raise_application_error(-20001,'Hold name ' || p_hold_name || ' is not defined.'); END; l_action_request_tbl(1).param2 := 'O'; -- Order hold (i.e., hold affects only an particular order or line) l_action_request_tbl(1).param3 := 'O'; -- Order hold (i.e., hold affects only an particular order or line) l_action_request_tbl(1).param4 := p_hold_comment; l_action_request_tbl(1).date_param1 := p_hold_until_date; -- Call process order api process_order_api (p_header_rec p_line_tbl p_action_request_tbl l_action_request_tbl, x_return_status x_msg_count x_msg_data => l_header_rec, => l_line_tbl, => => x_return_status, => x_msg_count, => x_msg_data);

IF x_return_status = fnd_api.g_ret_sts_success THEN -- The true return status is the status from the action request x_return_status := l_action_request_tbl (1).return_status; END IF; END apply_hold;

----------------------------------------------------------------------- RELEASE_HOLD --- Releases a sales order or line hold ---------------------------------------------------------------------PROCEDURE release_hold ( p_order_header_id oe_order_headers.header_id%TYPE := NULL, p_order_line_id oe_order_lines.line_id%TYPE := NULL, p_hold_name oe_hold_definitions.NAME%TYPE, p_release_reason oe_hold_releases.release_reason_code%TYPE := 'MANUAL_RELEASE_MARGIN_HOLD', p_release_comment oe_hold_releases.release_comment%TYPE, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_header_rec oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec; l_line_tbl oe_order_pub.line_tbl_type; l_action_request_tbl oe_order_pub.request_tbl_type := oe_order_pub.g_miss_request_tbl; BEGIN IF p_order_header_id IS NULL AND p_order_line_id IS NULL THEN raise_application_error (-20001, 'RELEASE_HOLD API requires at least a header ID or a line ID.'); END IF; l_action_request_tbl (1) := oe_order_pub.g_miss_request_rec; l_action_request_tbl (1).request_type := oe_globals.g_release_hold; IF p_order_line_id IS NOT NULL THEN -- Release line level hold l_action_request_tbl (1).entity_code := oe_globals.g_entity_line; l_action_request_tbl (1).entity_id := p_order_line_id; ELSE -- Release header level hold l_action_request_tbl (1).entity_code := oe_globals.g_entity_header; l_action_request_tbl (1).entity_id := p_order_header_id; END IF; -- Get the hold ID, hold entity code, and hold entity id BEGIN SELECT ohs.hold_id, ohs.hold_entity_code, ohs.hold_entity_id INTO l_action_request_tbl (1).param1, l_action_request_tbl (1).param2, l_action_request_tbl (1).param3 FROM oe_order_holds ooh, oe_hold_sources ohs, oe_hold_definitions ohd WHERE ooh.released_flag = 'N' AND ohs.hold_source_id = ooh.hold_source_id AND ohd.hold_id = ohs.hold_id AND ohd.NAME = p_hold_name AND ( ooh.header_id = p_order_header_id

AND

OR p_order_header_id IS NULL) ooh.line_id = p_order_line_id OR ( p_order_line_id IS NULL AND ooh.line_id IS NULL));

EXCEPTION WHEN NO_DATA_FOUND THEN -- The specified hold does not exist x_return_status := fnd_api.g_ret_sts_error; x_msg_count := 1; IF p_order_line_id IS NOT NULL THEN x_msg_data := 'Hold ' || p_hold_name || ' is not applied to order line ID ' || p_order_line_id; ELSE x_msg_data := 'Hold ' || p_hold_name || ' is not applied to order header ID ' || NVL (TO_CHAR (p_order_header_id), 'Missing'); END IF; RETURN; END; -- Validate reason code BEGIN SELECT lookup_code INTO l_action_request_tbl (1).param4 FROM fnd_lookup_values WHERE lookup_type = 'RELEASE_REASON' AND lookup_code = p_release_reason; EXCEPTION WHEN NO_DATA_FOUND THEN -- The release reason is invalid raise_application_error (-20001, '''' || p_release_reason || ''' is not a valid hold release reason in the RELEASE_REASON lookup type'); END; l_action_request_tbl (1).param5 := p_release_comment; -- Call process order api process_order_api (p_header_rec => l_header_rec, p_line_tbl => l_line_tbl, p_action_request_tbl => l_action_request_tbl, x_return_status => x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data); IF x_return_status = fnd_api.g_ret_sts_success THEN -- The true return status is the status from the action request x_return_status := l_action_request_tbl (1).return_status; END IF; END release_hold; ----------------------------------------------------------------------- CANCEL_ORDER --- Cancels a sales order or RMA ---------------------------------------------------------------------PROCEDURE cancel_order (

p_order_header_id oe_order_headers.header_id%TYPE, p_change_reason_code VARCHAR2, p_change_comments VARCHAR2, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_header_rec oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec; l_stmt NUMBER; BEGIN l_stmt := 10; l_header_rec.operation := oe_globals.g_opr_update; l_header_rec.header_id := p_order_header_id; l_header_rec.cancelled_flag := 'Y'; l_header_rec.change_reason := p_change_reason_code; l_header_rec.change_comments := p_change_comments; -- Call process order api l_stmt := 20; process_order_api (p_header_rec => l_header_rec, p_line_tbl => oe_order_pub.g_miss_line_tbl, p_action_request_tbl => oe_order_pub.g_miss_request_tbl, x_return_status => x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data); l_stmt := 30; EXCEPTION WHEN OTHERS THEN oe_msg_pub.add_text ('Unexpected error in tempus_sales_order_api.cancel_order, stmt ' || l_stmt || ': ' || SQLERRM); x_msg_count := NVL (x_msg_count, 0) + 1; x_return_status := fnd_api.g_ret_sts_unexp_error; END; ----------------------------------------------------------------------- UPDATE_LINE_QUANTITY --- Updates (or cancels) a quantity on a sales order line ---------------------------------------------------------------------PROCEDURE update_line_quantity ( p_order_line_id oe_order_lines.line_id%TYPE, p_quantity NUMBER, p_change_reason_code VARCHAR2, p_change_comments VARCHAR2, x_line_rec OUT oe_order_pub.line_rec_type, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_header_rec oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec; l_line_tbl oe_order_pub.line_tbl_type; l_stmt NUMBER; BEGIN -- Setup process order API l_stmt := 10; -- Initialize blank line l_line_tbl := oe_order_pub.g_miss_line_tbl; l_line_tbl (1) := oe_order_pub.g_miss_line_rec;

l_line_tbl (1).operation := oe_globals.g_opr_update; -- Set attributes l_line_tbl (1).line_id := p_order_line_id; l_line_tbl (1).ordered_quantity := p_quantity; l_line_tbl (1).change_reason := p_change_reason_code; l_line_tbl (1).change_comments := p_change_comments; -- Call process order api l_stmt := 20; process_order_api (p_header_rec => l_header_rec, p_line_tbl => l_line_tbl, p_action_request_tbl => oe_order_pub.g_miss_request_tbl, x_return_status => x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data); l_stmt := 30; x_line_rec := l_line_tbl (1); EXCEPTION WHEN OTHERS THEN oe_msg_pub.add_text ('Unexpected error in tempus_sales_order_api.update_line_quantity, stmt ' || l_stmt || ': ' || SQLERRM); x_msg_count := NVL (x_msg_count, 0) + 1; x_return_status := fnd_api.g_ret_sts_unexp_error; END update_line_quantity; ----------------------------------------------------------------------- REPRICE_LINE --- Triggers a line to reprice by setting its pricing date to SYSDATE ---------------------------------------------------------------------PROCEDURE reprice_line ( p_order_line_id oe_order_lines.line_id%TYPE, x_return_status OUT VARCHAR2, x_msg_count OUT NUMBER, x_msg_data OUT VARCHAR2) IS l_header_rec oe_order_pub.header_rec_type := oe_order_pub.g_miss_header_rec; l_line_tbl oe_order_pub.line_tbl_type; l_stmt NUMBER; BEGIN -- Setup process order API l_stmt := 10; -- Initialize blank line l_line_tbl := oe_order_pub.g_miss_line_tbl; l_line_tbl (1) := oe_order_pub.g_miss_line_rec; l_line_tbl (1).operation := oe_globals.g_opr_update; -- Set attributes l_line_tbl (1).line_id := p_order_line_id; l_line_tbl (1).pricing_date := SYSDATE; -- Call process order api l_stmt := 20; process_order_api (p_header_rec => l_header_rec, p_line_tbl => l_line_tbl, p_action_request_tbl => oe_order_pub.g_miss_request_tbl, x_return_status => x_return_status, x_msg_count => x_msg_count, x_msg_data => x_msg_data); EXCEPTION

WHEN OTHERS THEN oe_msg_pub.add_text ('Unexpected error in tempus_sales_order_api.reprice_line, stmt ' || l_stmt || ': ' || SQLERRM); x_msg_count := NVL (x_msg_count, 0) + 1; x_return_status := fnd_api.g_ret_sts_unexp_error; END reprice_line; ----------------------------------------------------------------------- REPRICE_LINE_WF --- Reprices a line from Workflow, by setting the line's -- pricing date to SYSDATE ---------------------------------------------------------------------PROCEDURE reprice_line_wf ( itemtype IN VARCHAR2, itemkey IN VARCHAR2, actid IN NUMBER, funcmode IN VARCHAR2, resultout OUT VARCHAR2) IS l_return_status VARCHAR2 (1); l_msg_count NUMBER; l_msg_data VARCHAR2 (4000); l_error_message VARCHAR2 (4000); BEGIN reprice_line (p_order_line_id => TO_NUMBER (itemkey), x_return_status => l_return_status, x_msg_count => l_msg_count, x_msg_data => l_msg_data); IF l_return_status != IF l_msg_count > 0 l_error_message p_encoded => 'F'); ELSE l_error_message END IF; fnd_api.g_ret_sts_success THEN THEN := oe_msg_pub.get (p_msg_index => 1, := 'Reason unknown';

l_error_message := 'Failed to reprice line ID ' || itemkey || ': ' || l_error_message; raise_application_error (-20001, l_error_message); END IF; END reprice_line_wf; ----------------------------------------------------------------------- GET_ORDER_TYPE_ID --- Returns the order type id to use on a sales order, given the order -- type name ---------------------------------------------------------------------FUNCTION get_order_type_id ( p_order_type_name oe_transaction_types.NAME%TYPE) RETURN oe_order_headers.order_type_id%TYPE IS x_order_type_id oe_order_headers.order_type_id%TYPE; BEGIN IF p_order_type_name IS NULL THEN RETURN NULL; END IF; SELECT transaction_type_id

INTO x_order_type_id FROM oe_transaction_types WHERE NAME = p_order_type_name; RETURN x_order_type_id; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error (-20001, 'Order type ' || p_order_type_name || ' is not defined.'); END; ----------------------------------------------------------------------- GET_SOLD_TO_ORG_ID --- Returns the sold-to org id to use on a sales order, given the customer number ---------------------------------------------------------------------FUNCTION get_sold_to_org_id ( p_customer_number hz_cust_accounts.account_number%TYPE) RETURN oe_order_headers.sold_to_org_id%TYPE IS x_sold_to_org_id oe_order_headers.sold_to_org_id%TYPE; BEGIN IF p_customer_number IS NULL THEN RETURN NULL; END IF; SELECT INTO FROM WHERE hca.cust_account_id x_sold_to_org_id hz_cust_accounts hca hca.account_number = p_customer_number;

RETURN x_sold_to_org_id; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error (-20001, 'Customer number ' || p_customer_number || ' is not defined.'); END get_sold_to_org_id; ----------------------------------------------------------------------- GET_INVOICE_TO_ORG_ID --- Returns the invoice-to org id to use on a sales order, given the customer number ---------------------------------------------------------------------FUNCTION get_invoice_to_org_id ( p_customer_number hz_cust_accounts.account_number%TYPE) RETURN oe_order_headers.invoice_to_org_id%TYPE IS x_invoice_to_org_id oe_order_headers.invoice_to_org_id%TYPE; BEGIN IF p_customer_number IS NULL THEN RETURN NULL; END IF; SELECT hcsu.site_use_id INTO x_invoice_to_org_id FROM hz_cust_site_uses hcsu, hz_cust_acct_sites hcas, hz_cust_accounts hca WHERE hcas.cust_account_id = hca.cust_account_id AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id

AND AND AND AND AND

hcas.status = 'A' hcsu.status = 'A' hcsu.site_use_code = 'BILL_TO' hcsu.primary_flag = 'Y' hca.account_number = p_customer_number;

RETURN x_invoice_to_org_id; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error (-20001, 'Customer number ' || p_customer_number || ' is not defined or has no active bill to site.'); END get_invoice_to_org_id; ----------------------------------------------------------------------- GET_SHIP_TO_ORG_ID --- Returns the ship-to org id to use on a sales order, given the customer number ---------------------------------------------------------------------FUNCTION get_ship_to_org_id ( p_customer_number hz_cust_accounts.account_number%TYPE) RETURN oe_order_headers.ship_to_org_id%TYPE IS x_ship_to_org_id oe_order_headers.ship_to_org_id%TYPE; BEGIN IF p_customer_number IS NULL THEN RETURN NULL; END IF; SELECT hcsu.site_use_id INTO x_ship_to_org_id FROM hz_cust_site_uses hcsu, hz_cust_acct_sites hcas, hz_cust_accounts hca WHERE hcas.cust_account_id = hca.cust_account_id AND hcsu.cust_acct_site_id = hcas.cust_acct_site_id AND hcas.status = 'A' AND hcsu.status = 'A' AND hcsu.site_use_code = 'SHIP_TO' AND hcsu.primary_flag = 'Y' AND hca.account_number = p_customer_number; RETURN x_ship_to_org_id; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error (-20001, 'Customer number ' || p_customer_number || ' is not defined or has no active ship to site.'); END get_ship_to_org_id; ----------------------------------------------------------------------- GET_SHIP_FROM_ORG_ID --- Returns the ship-from org id to use on a sales order, given the org code ---------------------------------------------------------------------FUNCTION get_ship_from_org_id ( p_organization_code mtl_parameters.organization_code%TYPE) RETURN oe_order_headers.ship_from_org_id%TYPE IS x_ship_from_org_id oe_order_headers.ship_from_org_id%TYPE;

BEGIN IF p_organization_code IS NULL THEN RETURN NULL; END IF; SELECT INTO FROM WHERE organization_id x_ship_from_org_id mtl_parameters organization_code = p_organization_code;

RETURN x_ship_from_org_id; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error (-20001, 'Organization code ' || p_organization_code || ' is not defined.'); END get_ship_from_org_id; ----------------------------------------------------------------------- GET_DEMAND_CLASS_CODE --- Returns the demand class code to use on a sales order, given the demand -- class name ---------------------------------------------------------------------FUNCTION get_demand_class_code ( p_demand_class_name fnd_lookup_values.meaning%TYPE) RETURN oe_order_headers.demand_class_code%TYPE IS x_demand_class_code oe_order_headers.demand_class_code%TYPE; BEGIN IF p_demand_class_name IS NULL THEN RETURN NULL; END IF; SELECT INTO FROM WHERE AND lookup_code x_demand_class_code fnd_lookup_values lookup_type = 'DEMAND_CLASS' meaning = p_demand_class_name;

RETURN x_demand_class_code; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error (-20001, 'Demand class ' || p_demand_class_name || ' is not defined.'); END; ----------------------------------------------------------------------- GET_ITEM_ID --- Returns the item id to use on a sales order, given the item number ---------------------------------------------------------------------FUNCTION get_item_id ( p_item_number mtl_system_items.segment1%TYPE) RETURN oe_order_lines.ordered_item_id%TYPE IS x_item_id mtl_system_items.segment1%TYPE; BEGIN IF p_item_number IS NULL THEN RETURN NULL; END IF;

SELECT INTO FROM WHERE AND

inventory_item_id x_item_id mtl_system_items organization_id = (SELECT organization_id FROM mtl_parameters WHERE organization_code = 'SOA') segment1 = p_item_number;

RETURN x_item_id; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error (-20001, 'Item number ' || p_item_number || ' is not defined.'); END; ----------------------------------------------------------------------- GET_SHIP_METHOD_CODE --- Returns the ship method code to use on a sales order, given the ship -- method meaning ---------------------------------------------------------------------FUNCTION get_ship_method_code ( p_ship_method_meaning wsh_carrier_services.ship_method_meaning%TYPE) RETURN oe_order_headers.shipping_method_code%TYPE IS x_shipping_method_code oe_order_headers.shipping_method_code%TYPE; BEGIN IF p_ship_method_meaning IS NULL THEN RETURN NULL; END IF; SELECT wcs.ship_method_code INTO x_shipping_method_code FROM wsh_carrier_services wcs, wsh_carriers wc, fnd_lookup_values flv WHERE wc.carrier_id = wcs.carrier_id AND wc.freight_code = 'SOA_GENERIC' AND flv.lookup_type = 'WSH_SERVICE_LEVELS' AND flv.lookup_code = wcs.service_level AND wcs.enabled_flag = 'Y' AND wcs.ship_method_meaning = p_ship_method_meaning; RETURN x_shipping_method_code; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error (-20001, 'Shipping method meaning ' || p_ship_method_meaning || ' is not defined.'); END; END tempus_sales_order_api; /

You might also like