You are on page 1of 18

11i Order Management

Process Order Application Programming Interface


(API)

An Oracle White Paper


May 2003
11i Order Management
Process Order Application Programming Interface
(API)

ABSTRACT

The purpose of this white paper is to assist users to understand the basic concepts of the
Process Order API and how this API can be used to manipulate Order Management Sales
Order Data.

The Process Order API is a PL/SQL packaged procedure used to manipulate 11i Oracle
Applications Sales Order data without having to use the application user interface. By
doing so, the user will not be directly updating the Oracle specific tables. The APIs that
can be called by users are called public APIs, which inserts the data in the tables after
performing the required validations. The API also will populate the referenced tables, if
any.

While the API package contains many procedures to insert, modify, or delete application
data, the API is not executed on its own. The API must be called, or executed, by other
pl/sql modules, by a direct SQL*Plus call.

SCOPE & APPLICATION

This document is intended for Order Management Support Engineers, Functional


Consultants and others who desire to use the Process Order API for manipulating sales
order data.

Most importantly, the user will be able to create, update, delete and book a sales order
using the Process Order API provided in this document.

This document also assists in generating the debug files, which help in troubleshooting
error messages.
Process Order API – Salient Features

In Oracle Applications, the APIs normally reside in the following directory path:

$PRODUCT_TOP/11.5.0/PATCH/SQL

Use the command, strings –a <filename>| grep “Header” to get the package version.

You can run either of the following sql statements in sqlplus to get the required source
file name:

select name, text from all_source


where name = 'api_name'
and text like '%Header:%'
and owner = 'APPS';

select text from all_source


where name like '%api_name%';

The first sql will give only the header details while second one gives the text.

The Process Order API can be used to create, update or delete sales orders in Order
Management. Basically, data manipulation ( insert, update and delete) can be done on all
the sales order business object entities and attributes.

The sales order business object consists of the following entities:

Entity Table Name


Order Header OE_ORDER_HEADERS_ALL
Order Price Adjustments OE_PRICE_ADJUSTMENTS
Order Sales Credits OE_SALES_CREDITS
Order Line OE_ORDER_LINES_ALL
Order Pricing Attributes OE_ORDER_PRICE_ATTRIBS
Order Adjustment Attributes OE_PRICE_ADJ_ATTRIBS
Order Adjustment Associations OE_PRICE_ADJ_ASSOCS
Line Sales Credits OE_SALES_CREDITS
Line Price Adjustments OE_PRICE_ADJUSTMENTS
Line Pricing Attributes OE_ORDER_PRICE_ATTRIBS
Line Adjustment Attributes OE_PRICE_ADJ_ATTRIBS
Line Adjustment Associations OE_PRICE_ADJ_ASSOCS
Lot Serial Numbers OE_LOT_SERIAL_NUMBERS
In addition to creating, updating or deleting sales orders, there are also certain action
requests like booking, applying holds and attachments, which can be done using the
Process Order API.

Some of the important features in the process order API are:

User can pass to the API, either the id or the name and the values will be internally
determined. For example, user can pass the customer_id or the customer name or both. If
both were passed, then the identifier would take preference. In case of errors, messages
would be written to the OM message stack.

Pricing can be done by using the calculate_price_flag to Yes. The list price would be
fetched along with the all the adjustments and charges. If set to No, API does not get the
list price and the calculate_price_flag is set to freeze price. If the calculate_price_flag is
not included in the API, then the calculate_price_flag is set to partial. Users can then
query the order in the sales order form and price the order line.

PL/SQL Block to call the Process Order API

The process order API can be called by a pl/sql block, which can be executed in sqlplus.
This section describes and helps to understand how the pl/sql block can be written.

First, specify the variables in the declare section on the block.

l_header_rec oe_order_pub.Header_Rec_Type;
l_line_tbl oe_order_pub.Line_Tbl_Type;

The variable, l_header_rec is declared as a record datatype referring


to Header_Rec_Type in the package, oe_order_pub.

p_api_version_number NUMBER :=1.0;

The API version number needs to be initialized as version 1.0 and this
would get validated by the API. The process order API will not proceed
if the version number is other than 1.0

x_return_status VARCHAR2(1);

Returns FND_API.G_RET_STS_STATUS (success), FND_API.G_RET_STS_ERROR


(error) or FND_API.G_RET_STS_UNEXP_ERROR (unexpected error).

p_header_rec oe_order_pub.Header_Rec_Type
:= oe_order_pub.G_MISS_HEADER_REC;
p_old_header_rec oe_order_pub.Header_Rec_Type
:= oe_order_pub.G_MISS_HEADER_REC;

The parameter, p_header_rec is declared with the datatype as Header_Rec_Type in


oe_order_pub. It is initialized to the value returned by the function,
G_MISS_HEADER_REC. This is done so that the parameter does not contain a null
value. Further, it is pertinent to note that there is also a parameter, p_old_header_rec that
is used for retaining the old value in case the API is updating a record. The API would
compare the old and new values in the respective parameters and then update the tables if
the values are different.

x_header_val_rec Oe_Order_Pub.Header_Val_Rec_Type;
x_Header_Adj_tbl Oe_Order_Pub.Header_Adj_Tbl_Type;
. . . (etc)

These are variables, which will hold the value that is returned by the
API.

BEGIN section of the pl/sql block contains the following statements.

dbms_output.enable(1000000);

Sets the buffer size as specified so that all the messages are written
to the debug file.

fnd_global.apps_initialize(4096,21623,660);

Need to pass in user_id, responsibility_id, and application_id here, as


the system would need to information while setting the who columns for
updating the data in the tables. Also required to set the
organization/operating unit context for the system has to see the data
in views.

oe_debug_pub.SetDebugLevel(5)

Sets the debug level to 5. This is the maximum debug level in the sense
that all messages would be written to the debug file.

l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;

This is the header record and is intialized to missing. Initially,


there would not be a header_id generated for the record and hence it is
set to missing. Once the header_id id generated by the API, the
l_header_rec will take the value of the header_id.

l_header_rec.order_type_id := 1437;
l_header_rec.sold_to_org_id := 1000;
The order type and customer(sold_to_org_id) are required attributes and
must be specified.

l_header_rec.ship_to_org_id := 1001;
l_header_rec.ship_from_org_id := 207;
l_header_rec.orig_sys_document_ref := 'TEST9';
l_header_rec.price_list_id := 1000;

These are the other attributes that can be specified.

l_header_rec.operation := OE_GLOBALS.G_OPR_CREATE;

The above statement indicates to the process order API that a new
header has to be created.

l_line_tbl(1) := OE_ORDER_PUB.G_MISS_LINE_REC;

Initializing the line record to missing as we have done earlier for the
header record.

l_line_tbl(1).inventory_item_id := 149;
l_line_tbl(1).ordered_quantity := 1;
l_line_tbl(1).orig_sys_document_ref := 'TEST9';
l_line_tbl(1).orig_sys_line_ref := 'TEST9-1';
l_line_tbl(1).calculate_price_flag := 'N';
l_line_tbl(1).line_type_id := 1427;

All the above belong to the first line record as it is indicated by (1)
in l_line_tbl(1). For the second record, it will be l_line_tbl(2).

l_line_tbl(1).operation := OE_GLOBALS.G_OPR_CREATE;

Indicates that this is a create operation for the line record.

l_line_tbl(1).operation := OE_GLOBALS.G_OPR_UPDATE;

Indicates that this is an update operation for the line record.


l_line_tbl(1).operation := OE_GLOBALS.G_OPR_DELETE;

Indicates that this is a delete operation for the line record.

All lines in the table l_line_tbl must belong to the same order.

l_action_request_tbl(1).request_type := oe_globals.g_book_order;
l_action_request_tbl(1).entity_code := oe_globals.g_entity_header;

The above action request indicates to the process order that the order
has to be booked. User need not specifically indicate the header_id if
the order has to be booked while creation or updation. Otherwise, if it
is separate action, then the header_id has to be provided. The action
request statements can be commented out if you do not require the order
to be booked.

oe_order_pub.process_order(………

Call is made to the process order API with the required IN and OUT
parameters.

FOR i IN 1 .. l_msg_count LOOP


Oe_Msg_Pub.get( p_msg_index => i ,p_encoded => Fnd_Api.G_FALSE
,p_data => l_msg_data
,p_msg_index_out => l_msg_index_out);
DBMS_OUTPUT.PUT_LINE('message is: ' || l_msg_data);
DBMS_OUTPUT.PUT_LINE('message index is: ' || l_msg_index_out);
END LOOP;

The purpose of the above statement is to collect the messages that have
been generated by the process order API when it had run and then
display them accordingly.

The number of messages is stored in l_msg_count. Each time the process


order encounters a message, it increases the count in x_msg_count and
then is finally passed to l_msg_count. The Oe_Msg_Pub gets the messages
as per the message index.

if l_return_status = FND_API.G_RET_STS_SUCCESS then


dbms_output.put_line('Header_id is ' || l_header_rec.header_id);
else
dbms_output.put_line('Failed');
end if;

If the process order is successful, it prints the header_id, otherwise


it indicates that the process order has failed.
ANNEXURE - I

Creating a Sales Order using the Process Order API

Run the following pl/sql block in sqlplus in vision database and ensure that the procedure
executes successfully.

For debugging purposes, the debug level has been set to 5 in the following pl/sql block
through the statement, “oe_debug_pub.SetDebugLevel(5)”. This means that all OM
debug messages would get written to the OM debug file. The pl/sql block also prints out
the location where the debug file was written to and the user can retrieve the debug file
from this location for analysis. This is achieved by placing the following statement after
the call to the process order: dbms_output.put_line('OM Debug file:'
||oe_debug_pub.G_DIR||'/'||oe_debug_pub.G_FILE);

--- Start of script -------


DECLARE
l_header_rec oe_order_pub.Header_Rec_Type;
l_line_tbl oe_order_pub.Line_Tbl_Type;
l_action_request_tbl oe_order_pub.Request_Tbl_Type;

l_header_adj_tbl oe_order_pub.Header_Adj_Tbl_Type;
l_line_adj_tbl oe_order_pub.line_adj_tbl_Type;
l_header_scr_tbl oe_order_pub.Header_Scredit_Tbl_Type;
l_line_scredit_tbl oe_order_pub.Line_Scredit_Tbl_Type;

l_return_status varchar2(1000);
l_msg_count number;
l_msg_data varchar2(1000);

p_api_version_number NUMBER :=1.0;


p_init_msg_list VARCHAR2(10) := FND_API.G_FALSE;
p_return_values VARCHAR2(10) := FND_API.G_FALSE;
p_action_commit VARCHAR2(10) := FND_API.G_FALSE;
x_return_status VARCHAR2(1);
x_msg_count NUMBER;
x_msg_data VARCHAR2(100);
p_header_rec oe_order_pub.Header_Rec_Type
:= oe_order_pub.G_MISS_HEADER_REC;
p_old_header_rec oe_order_pub.Header_Rec_Type
:= oe_order_pub.G_MISS_HEADER_REC;
p_header_val_rec oe_order_pub.Header_Val_Rec_Type
:= oe_order_pub.G_MISS_HEADER_VAL_REC;
p_old_header_val_rec oe_order_pub.Header_Val_Rec_Type
:= oe_order_pub.G_MISS_HEADER_VAL_REC;
p_Header_Adj_tbl oe_order_pub.Header_Adj_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_ADJ_TBL;
p_old_Header_Adj_tbl oe_order_pub.Header_Adj_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_ADJ_TBL;
p_Header_Adj_val_tbl oe_order_pub.Header_Adj_Val_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_ADJ_VAL_TBL;
p_old_Header_Adj_val_tbl oe_order_pub.Header_Adj_Val_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_ADJ_VAL_TBL;
p_Header_price_Att_tbl oe_order_pub.Header_Price_Att_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_PRICE_ATT_TBL;
p_old_Header_Price_Att_tbl oe_order_pub.Header_Price_Att_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_PRICE_ATT_TBL;
p_Header_Adj_Att_tbl oe_order_pub.Header_Adj_Att_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_ADJ_ATT_TBL;
p_old_Header_Adj_Att_tbl oe_order_pub.Header_Adj_Att_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_ADJ_ATT_TBL;
p_Header_Adj_Assoc_tbl oe_order_pub.Header_Adj_Assoc_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_ADJ_ASSOC_TBL;
p_old_Header_Adj_Assoc_tbl oe_order_pub.Header_Adj_Assoc_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_ADJ_ASSOC_TBL;
p_Header_Scredit_tbl oe_order_pub.Header_Scredit_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_SCREDIT_TBL;
p_old_Header_Scredit_tbl oe_order_pub.Header_Scredit_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_SCREDIT_TBL;
p_Header_Scredit_val_tbl e_order_pub.Header_Scredit_Val_Tbl_Type
:=oe_order_pub.G_MISS_HEADER_SCREDIT_VAL_TBL;
p_old_Header_Scredit_val_tbl
oe_order_pub.Header_Scredit_Val_Tbl_Type
:= oe_order_pub.G_MISS_HEADER_SCREDIT_VAL_TBL;
p_line_tbl oe_order_pub.Line_Tbl_Type
:= oe_order_pub.G_MISS_LINE_TBL;
p_old_line_tbl oe_order_pub.Line_Tbl_Type
:= oe_order_pub.G_MISS_LINE_TBL;
p_line_val_tbl oe_order_pub.Line_Val_Tbl_Type
:= oe_order_pub.G_MISS_LINE_VAL_TBL;
p_old_line_val_tbl oe_order_pub.Line_Val_Tbl_Type
:= oe_order_pub.G_MISS_LINE_VAL_TBL;
p_Line_Adj_tbl oe_order_pub.Line_Adj_Tbl_Type
:= oe_order_pub.G_MISS_LINE_ADJ_TBL;
p_old_Line_Adj_tbl oe_order_pub.Line_Adj_Tbl_Type
:= oe_order_pub.G_MISS_LINE_ADJ_TBL;
p_Line_Adj_val_tbl oe_order_pub.Line_Adj_Val_Tbl_Type
:= oe_order_pub.G_MISS_LINE_ADJ_VAL_TBL;
p_old_Line_Adj_val_tbl oe_order_pub.Line_Adj_Val_Tbl_Type
:= oe_order_pub.G_MISS_LINE_ADJ_VAL_TBL;
p_Line_price_Att_tbl oe_order_pub.Line_Price_Att_Tbl_Type
:= oe_order_pub.G_MISS_LINE_PRICE_ATT_TBL;
p_old_Line_Price_Att_tbl oe_order_pub.Line_Price_Att_Tbl_Type
:= oe_order_pub.G_MISS_LINE_PRICE_ATT_TBL;
p_Line_Adj_Att_tbl oe_order_pub.Line_Adj_Att_Tbl_Type
:= oe_order_pub.G_MISS_LINE_ADJ_ATT_TBL;
p_old_Line_Adj_Att_tbl oe_order_pub.Line_Adj_Att_Tbl_Type
:= oe_order_pub.G_MISS_LINE_ADJ_ATT_TBL;
p_Line_Adj_Assoc_tbl oe_order_pub.Line_Adj_Assoc_Tbl_Type
:= oe_order_pub.G_MISS_LINE_ADJ_ASSOC_TBL;
p_old_Line_Adj_Assoc_tbl oe_order_pub.Line_Adj_Assoc_Tbl_Type
:= oe_order_pub.G_MISS_LINE_ADJ_ASSOC_TBL;
p_Line_Scredit_tbl oe_order_pub.Line_Scredit_Tbl_Type
:= oe_order_pub.G_MISS_LINE_SCREDIT_TBL;
p_old_Line_Scredit_tbl oe_order_pub.Line_Scredit_Tbl_Type
:= oe_order_pub.G_MISS_LINE_SCREDIT_TBL;
p_Line_Scredit_val_tbl oe_order_pub.Line_Scredit_Val_Tbl_Type
:= oe_order_pub.G_MISS_LINE_SCREDIT_VAL_TBL;
p_old_Line_Scredit_val_tbl oe_order_pub.Line_Scredit_Val_Tbl_Type
:= oe_order_pub.G_MISS_LINE_SCREDIT_VAL_TBL;
p_Lot_Serial_tbl oe_order_pub.Lot_Serial_Tbl_Type
:= oe_order_pub.G_MISS_LOT_SERIAL_TBL;
p_old_Lot_Serial_tbl oe_order_pub.Lot_Serial_Tbl_Type
:= oe_order_pub.G_MISS_LOT_SERIAL_TBL;
p_Lot_Serial_val_tbl oe_order_pub.Lot_Serial_Val_Tbl_Type
:= oe_order_pub.G_MISS_LOT_SERIAL_VAL_TBL;
p_old_Lot_Serial_val_tbl oe_order_pub.Lot_Serial_Val_Tbl_Type
:= oe_order_pub.G_MISS_LOT_SERIAL_VAL_TBL;
p_action_request_tbl oe_order_pub.Request_Tbl_Type
:= oe_order_pub.G_MISS_REQUEST_TBL;
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_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_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;

X_DEBUG_FILE varchar2(100);

l_msg_index_out number(10);
BEGIN
dbms_output.enable(1000000);
fnd_global.apps_initialize(4096,21623,660); -- pass in user_id,
responsibility_id, and application_id
-------------------------------
oe_msg_pub.initialize;
oe_debug_pub.initialize;
X_DEBUG_FILE := OE_DEBUG_PUB.Set_Debug_Mode('FILE');
oe_debug_pub.SetDebugLevel(5); -- Use 5 for the most debuging output,
I warn you its a lot of data
dbms_output.put_line('START OF NEW DEBUG');
-------------------------------

-- SETTING UP THE HEADER RECORD


-- Initialize record to missing
l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;

l_header_rec.order_type_id := 1437;
l_header_rec.sold_to_org_id := 1000;
l_header_rec.ship_to_org_id := 1001;
l_header_rec.ship_from_org_id := 207;
l_header_rec.orig_sys_document_ref := 'TEST9';
l_header_rec.price_list_id := 1000;
l_header_rec.operation := OE_GLOBALS.G_OPR_CREATE;
l_header_rec.cust_po_number := 'TESTxxx';

-- First line record


-- Initialize record to missing
l_line_tbl(1) := OE_ORDER_PUB.G_MISS_LINE_REC;
l_line_tbl(1).inventory_item_id := 149;
l_line_tbl(1).ordered_quantity := 1;
l_line_tbl(1).orig_sys_document_ref := 'TEST9';
l_line_tbl(1).orig_sys_line_ref := 'TEST9-1';
l_line_tbl(1).calculate_price_flag := 'Y';
l_line_tbl(1).line_type_id := 1427;
l_line_tbl(1).operation := OE_GLOBALS.G_OPR_CREATE;
-- dbms_output.put_line('Line operation before is
'||l_line_tbl(1).operation);
-- Second line record
l_line_tbl(2) := OE_ORDER_PUB.G_MISS_LINE_REC;
l_line_tbl(2).inventory_item_id := 155;
l_line_tbl(2).ordered_quantity := 1;
l_line_tbl(2).orig_sys_document_ref := 'TEST9';
l_line_tbl(2).orig_sys_line_ref := 'TEST9-1';
l_line_tbl(2).calculate_price_flag := 'Y';
l_line_tbl(2).line_type_id := 1427;
l_line_tbl(2).operation := OE_GLOBALS.G_OPR_CREATE;

-- FIRST LINE RECORD


oe_order_pub.process_order
(
p_api_version_number => 1.0
,p_init_msg_list => fnd_api.g_false
,p_return_values => fnd_api.g_false
,p_action_commit => fnd_api.g_false
,x_return_status => l_return_status
,x_msg_count => l_msg_count
,x_msg_data => l_msg_data
,p_header_rec => l_header_rec
,p_line_tbl => l_line_tbl
,p_action_request_tbl => l_action_request_tbl
--OUT PARAMETERS
,x_header_rec => l_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_Adj_Assoc_tbl
,x_Header_Scredit_tbl => x_Header_Scredit_tbl
,x_Header_Scredit_val_tbl => x_Header_Scredit_val_tbl
,x_line_tbl => l_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_Scredit_tbl
,x_Line_Scredit_val_tbl => x_Line_Scredit_val_tbl
,x_Lot_Serial_tbl => x_Lot_Serial_tbl
,x_Lot_Serial_val_tbl => x_Lot_Serial_val_tbl
,x_action_request_tbl => l_action_request_tbl
);

dbms_output.put_line('OM Debug file: '


||oe_debug_pub.G_DIR||'/'||oe_debug_pub.G_FILE);

dbms_output.put_line('Line operation after is


'||l_line_tbl(1).operation);
dbms_output.put_line('Header_id is ' || l_header_rec.header_id);

-- Retrieve messages
FOR i IN 1 .. l_msg_count LOOP
Oe_Msg_Pub.get( p_msg_index => i ,p_encoded => Fnd_Api.G_FALSE
,p_data => l_msg_data
,p_msg_index_out => l_msg_index_out);
DBMS_OUTPUT.PUT_LINE('message is: ' || l_msg_data);
DBMS_OUTPUT.PUT_LINE('message index is: ' || l_msg_index_out);
END LOOP;

-- Check the return status


if l_return_status = FND_API.G_RET_STS_SUCCESS then
dbms_output.put_line('Header_id is ' || l_header_rec.header_id);
else
dbms_output.put_line('Failed');
end if;

end;

---End of script----------

After the above pl/sql block is executed, you should get a typical successful message as
below:

START OF NEW DEBUG


OM Debug file: /usr/tmp/l1005333.dbg
Line operation after is CREATE
Header_id is 72948
message is: This Customer's PO Number is referenced by another order
message index is: 1
Header_id is 72948

PL/SQL procedure successfully completed.


In case, the process order returns a failure, then you can expect a similar message as
below:

START OF NEW DEBUG


OM Debug file: /usr/tmp/l1005333.dbg
Line operation after is CREATE
Header_id is
9.9900000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000E+125
message is: This Customer's PO Number is referenced by another order
message index is: 1
message is: Item Validation Resulted in error(s).
message index is: 2
Failed

PL/SQL procedure successfully completed.

To troubleshoot the above message, “Item Validation Resulted in error(s)” you can look
into the OM debug file and take the corrective action.

Updating an existing sales order using the Process Order API

In the script used earlier, you would have to replace the following in the begin section of
the pl/sql block.

l_header_rec.header_id := XXXXXX;

-- action request
l_action_request_tbl(1).request_type := oe_globals.g_book_order;
l_action_request_tbl(1).entity_code := oe_globals.g_entity_header;

-- First line record


-- Initialize record to missing
l_line_tbl(1) := OE_ORDER_PUB.G_MISS_LINE_REC;
l_line_tbl(1).ordered_quantity := 2;
l_line_tbl(1).orig_sys_document_ref := 'RC9';
l_line_tbl(1).orig_sys_line_ref := 'RC9-1';
l_line_tbl(1).line_id := YYYYYY;
l_line_tbl(1).operation := OE_GLOBALS.G_OPR_UPDATE;
-- dbms_output.put_line('Line operation before is
'||l_line_tbl(1).operation);

Here we are updating the ordered quantity to 2 as well as changing the reference fields.
The action request type, oe_globals.g_book_order indicates to the process
order that the order has also to be booked. We are providing the
header_id of the order that has to be booked.
Deleting a line in an existing sales order using the Process Order API

In the begin section, the following statements are required to perform the delete
operation.

l_line_tbl(1) := OE_ORDER_PUB.G_MISS_LINE_REC;
l_line_tbl(1).line_id := XXXXX;
l_line_tbl(1).operation := OE_GLOBALS.G_OPR_DELETE;

In this case, we are assigning a line_id xxxxx of the order line that has to be deleted.

Booking a sales order using the Process Order API

Having created a sales order, now you can book it by using the following pls/sql block.
Run the given pl/sql block in sqlplus in vision database and ensure that the procedure
executes successfully.

For debugging purposes, the debug level has been set to 5 in the following pl/sql block
through the statement, “oe_debug_pub.SetDebugLevel(5)”. This means that all OM
debug messages would get written to the OM debug file. The pl/sql block also prints out
the location where the debug file was written to and the user can retrieve the debug file
from this location for analysis. This is achieved by placing the following statement after
the call to the process order: dbms_output.put_line('OM Debug file:'
||oe_debug_pub.G_DIR||'/'||oe_debug_pub.G_FILE);

---Start of Script----
DECLARE
l_header_rec oe_order_pub.Header_Rec_Type;
l_line_tbl oe_order_pub.Line_Tbl_Type;
l_action_request_tbl oe_order_pub.Request_Tbl_Type;

l_header_adj_tbl oe_order_pub.Header_Adj_Tbl_Type;
l_line_adj_tbl oe_order_pub.line_adj_tbl_Type;
l_header_scr_tbl oe_order_pub.Header_Scredit_Tbl_Type;
l_line_scredit_tbl oe_order_pub.Line_Scredit_Tbl_Type;

l_return_status varchar2(1000);
l_msg_count number;
l_msg_data varchar2(1000);

p_api_version_number NUMBER :=1.0;


p_init_msg_list VARCHAR2(10) := FND_API.G_FALSE;
p_return_values VARCHAR2(10) := FND_API.G_FALSE;
p_action_commit VARCHAR2(10) := FND_API.G_FALSE;
x_return_status VARCHAR2(1);
x_msg_count NUMBER;
x_msg_data VARCHAR2(100);

p_action_request_tbl oe_order_pub.Request_Tbl_Type
:= oe_order_pub.G_MISS_REQUEST_TBL;
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_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_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;

X_DEBUG_FILE varchar2(100);

l_msg_index_out number(10);
BEGIN
dbms_output.enable(1000000);
fnd_global.apps_initialize(4096,21623,660); -- pass in user_id,
responsibility_id, and application_id
-------------------------------
oe_msg_pub.initialize;
oe_debug_pub.initialize;
X_DEBUG_FILE := OE_DEBUG_PUB.Set_Debug_Mode('FILE');
oe_debug_pub.SetDebugLevel(5); -- Use 5 for the most debuging output,
I warn you its a lot of data
dbms_output.put_line('START OF NEW DEBUG');
-------------------------------

-- action request
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 := 49939;
oe_order_pub.process_order
(
p_api_version_number => 1.0
,p_init_msg_list => fnd_api.g_false
,p_return_values => fnd_api.g_false
,p_action_commit => fnd_api.g_false
,x_return_status => l_return_status
,x_msg_count => l_msg_count
,x_msg_data => l_msg_data
,p_action_request_tbl => l_action_request_tbl
--OUT PARAMETERS
,x_header_rec => l_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_Adj_Assoc_tbl
,x_Header_Scredit_tbl => x_Header_Scredit_tbl
,x_Header_Scredit_val_tbl => x_Header_Scredit_val_tbl
,x_line_tbl => l_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_Scredit_tbl
,x_Line_Scredit_val_tbl => x_Line_Scredit_val_tbl
,x_Lot_Serial_tbl => x_Lot_Serial_tbl
,x_Lot_Serial_val_tbl => x_Lot_Serial_val_tbl
,x_action_request_tbl => l_action_request_tbl
);

dbms_output.put_line('OM Debug file: '


||oe_debug_pub.G_DIR||'/'||oe_debug_pub.G_FILE);

FOR i IN 1 .. l_msg_count LOOP


Oe_Msg_Pub.get(
p_msg_index => i
,p_encoded => Fnd_Api.G_FALSE
,p_data => l_msg_data
,p_msg_index_out => l_msg_index_out);
DBMS_OUTPUT.PUT_LINE('message is: ' || l_msg_data);
DBMS_OUTPUT.PUT_LINE('message index is: ' || l_msg_index_out);
END LOOP;

-- Check the return status


if l_return_status = FND_API.G_RET_STS_SUCCESS then
dbms_output.put_line('Booking Success');
else
dbms_output.put_line('Booking Failed');
end if;

-- debug output
dbms_output.put_line('Debug Output');
for i in 1..OE_DEBUG_PUB.g_debug_count loop
dbms_output.put_line(OE_DEBUG_PUB.G_debug_tbl(i));
end loop;

end;
---End of Script---

Please note that we have passed the following action request to the API.

-- action request
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 := 49939;

The entity_id is the header_id of the order to be booked. This needs to be passed only
when you are booking the order and not updating or creating it. For example, if you are
updating as well as booking the order in the same call, then the header_id need not be
once again passed. The entity code is set to header since the order is always booked at the
header level.

The following are the messages that you would get on the sqlplus screen once the pl/sql
completes successfully.

START OF NEW DEBUG


OM Debug file: /usr/tmp/l1005333.dbg
message is: Order has been booked.
message index is: 1
Booking Success
Debug Output

PL/SQL procedure successfully completed.

The above shows that the order has been booked. You can look at the OM debug file, in
case of any errors which you may want to troubleshoot.

Conclusion

Process Order API is used to manipulate 11i Order Management Sales Order Application
data. Users can create, update and delete sales orders without having to enter through the
user interface. Messages are written to the debug file, which can be retrieved and
analyzed in case of errors, or if the API is not working as intended. The sample script
provided here serves as a guideline to either create your own pl/sql block to call the API
or troubleshoot a pl/sql block created by customers.
ABOUT THE AUTHOR

Rajesh Chandramohan is a Principal Support Engineer and a BDE for Order Management
at Oracle’s India Support Center, Bangalore.

White Paper: 11i Order Management Process Order Application Programming Interface (API)
Author: Rajesh Chandramohan
Contributing Authors: N/A

Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065
U.S.A.

Worldwide Inquiries:
Phone: +1.650.506.7000
Fax: +1.650.506.7200
www.oracle.com

Oracle is a registered trademark of Oracle Corporation. Various


product and service names referenced herein may be trademarks
of Oracle Corporation. All other product and service names
mentioned may be trademarks of their respective owners.

Copyright © 2003 Oracle Corporation


All rights reserved.

You might also like