Sunday, November 23, 2014

Update Sales Order Price list and Add required Modifier to Line level using standard API

Below anonymous block will update Sales order Price list and add 
Modifier (as per Business Requirement ) in Order Management.
(Note: Change values as per your requirement also ON DBMS Output window to see DBMS Output message.)



DECLARE  
  l_api_version_number NUMBER := 1;  
  l_return_status      VARCHAR2(2000);  
  l_msg_count          NUMBER;  
  l_msg_data           VARCHAR2(2000);  
  -- PARAMETERS  
  l_debug_level NUMBER := 5;   -- OM DEBUG LEVEL (MAX 5)  
  l_org         NUMBER := 194; -- OPERATING UNIT  
  l_no_orders   NUMBER := 1;   -- NO OF ORDERS  
  -- INPUT VARIABLES FOR PROCESS_ORDER API  
  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;  
  -- OUT VARIABLES FOR PROCESS_ORDER API  
  l_header_rec_out oe_order_pub.header_rec_type;  
  l_header_val_rec_out oe_order_pub.header_val_rec_type;  
  l_header_adj_tbl_out oe_order_pub.header_adj_tbl_type;  
  l_header_adj_val_tbl_out oe_order_pub.header_adj_val_tbl_type;  
  l_header_price_att_tbl_out oe_order_pub.header_price_att_tbl_type;  
  l_header_adj_att_tbl_out oe_order_pub.header_adj_att_tbl_type;  
  l_header_adj_assoc_tbl_out oe_order_pub.header_adj_assoc_tbl_type;  
  l_header_scredit_tbl_out oe_order_pub.header_scredit_tbl_type;  
  l_header_scredit_val_tbl_out oe_order_pub.header_scredit_val_tbl_type;  
  l_line_tbl_out oe_order_pub.line_tbl_type;  
  l_line_val_tbl_out oe_order_pub.line_val_tbl_type;  
  l_line_adj_tbl_out oe_order_pub.line_adj_tbl_type;  
  l_line_adj_val_tbl_out oe_order_pub.line_adj_val_tbl_type;  
  l_line_price_att_tbl_out oe_order_pub.line_price_att_tbl_type;  
  l_line_adj_att_tbl_out oe_order_pub.line_adj_att_tbl_type;  
  l_line_adj_assoc_tbl_out oe_order_pub.line_adj_assoc_tbl_type;  
  l_line_scredit_tbl_out oe_order_pub.line_scredit_tbl_type;  
  l_line_scredit_val_tbl_out oe_order_pub.line_scredit_val_tbl_type;  
  l_lot_serial_tbl_out oe_order_pub.lot_serial_tbl_type;  
  l_lot_serial_val_tbl_out oe_order_pub.lot_serial_val_tbl_type;  
  l_action_request_tbl_out oe_order_pub.request_tbl_type; 
  lt_line_adj_tbl OE_ORDER_PUB.Line_Adj_Tbl_Type;  
  l_msg_index  NUMBER;  
  l_data       VARCHAR2(2000);  
  l_loop_count NUMBER;  
  l_debug_file VARCHAR2(200);  
BEGIN  
  -- INITIALIZATION REQUIRED FOR R12  
  mo_global.set_policy_context ('S', l_org);  
  mo_global.init('ONT');  
  -- INITIALIZE DEBUG INFO  
  IF (l_debug_level > 0) THEN  
    l_debug_file   := OE_DEBUG_PUB.Set_Debug_Mode('FILE');  
    oe_debug_pub.initialize;  
    oe_debug_pub.setdebuglevel(l_debug_level);  
    Oe_Msg_Pub.initialize;  
  END IF;  
  -- INITIALIZE ENVIRONMENT  
  fnd_global.apps_initialize (user_id => 2106, resp_id => 50663, resp_appl_id => 660);  
  -- INITIALIZE HEADER RECORD  
  l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;  
  -- POPULATE REQUIRED ATTRIBUTES  
  l_header_rec.operation               := OE_GLOBALS.G_OPR_UPDATE;
 l_header_rec.header_id := 71477;
   
    -- Indexation Applicability  
  -- INITIALIZE ACTION REQUEST RECORD  
  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;
  -- INITIALIZE LINE RECORD  
  l_line_tbl(1)                   := OE_ORDER_PUB.G_MISS_LINE_REC;  
  l_line_tbl(1).operation         := OE_GLOBALS.G_OPR_UPDATE; -- Mandatory Operation to Pass 
  l_line_tbl(1).line_id := 240148;
  -- INITIALIZE PRICE ADJUSTMENT RECORD
  lt_line_adj_tbl(1)                     := OE_ORDER_PUB.G_MISS_LINE_ADJ_REC;
  lt_line_adj_tbl(1).operation           := OE_GLOBALS.G_OPR_CREATE;
  lt_line_adj_tbl(1).applied_flag       := 'Y';  
  lt_line_adj_tbl(1).line_index         := 1;
  lt_line_adj_tbl(1).list_header_id     := 6007;  -- Need To change as per business requirement
  lt_line_adj_tbl(1).list_line_id       := 6007;  -- Need To change as per business requirement  
  lt_line_adj_tbl(1).header_id     := 71477;
  lt_line_adj_tbl(1).line_id       := 240148;
  lt_line_adj_tbl(1).updated_flag       := 'Y';
  lt_line_adj_tbl(1).automatic_flag     := 'Y';
  lt_line_adj_tbl(1).operand             := 20;
  lt_line_adj_tbl(1).arithmetic_operator := 'AMT';
    
  FOR i IN 1..l_no_orders  
  LOOP -- BEGIN LOOP  
    -- CALLTO PROCESS ORDER API  
    oe_order_pub.process_order( p_org_id => l_org, 
                                p_operating_unit => NULL, 
                                p_api_version_number => l_api_version_number, 
                                p_header_rec => l_header_rec, 
                                p_line_tbl => l_line_tbl, 
                                p_action_request_tbl => l_action_request_tbl, 
p_line_adj_tbl => lt_line_adj_tbl,
-- OUT variables  
                                x_header_rec => l_header_rec_out, 
                                x_header_val_rec => l_header_val_rec_out, 
                                x_header_adj_tbl => l_header_adj_tbl_out, 
                                x_header_adj_val_tbl => l_header_adj_val_tbl_out, 
                                x_header_price_att_tbl => l_header_price_att_tbl_out, 
                                x_header_adj_att_tbl => l_header_adj_att_tbl_out, 
                                x_header_adj_assoc_tbl => l_header_adj_assoc_tbl_out, 
                                x_header_scredit_tbl => l_header_scredit_tbl_out, 
                                x_header_scredit_val_tbl => l_header_scredit_val_tbl_out, 
                                x_line_tbl => l_line_tbl_out, 
                                x_line_val_tbl => l_line_val_tbl_out, 
                                x_line_adj_tbl => l_line_adj_tbl_out, 
                                x_line_adj_val_tbl => l_line_adj_val_tbl_out, 
                                x_line_price_att_tbl => l_line_price_att_tbl_out, 
                                x_line_adj_att_tbl => l_line_adj_att_tbl_out, 
                                x_line_adj_assoc_tbl => l_line_adj_assoc_tbl_out, 
                                x_line_scredit_tbl => l_line_scredit_tbl_out, 
                                x_line_scredit_val_tbl => l_line_scredit_val_tbl_out, 
                                x_lot_serial_tbl => l_lot_serial_tbl_out, 
                                x_lot_serial_val_tbl => l_lot_serial_val_tbl_out, 
                                x_action_request_tbl => l_action_request_tbl_out, 
                                x_return_status =>  l_return_status, 
                                x_msg_count => l_msg_count, 
                                x_msg_data => l_msg_data);  
    -- CHECK RETURN STATUS  
    IF l_return_status  = FND_API.G_RET_STS_SUCCESS THEN  
      IF (l_debug_level > 0) THEN  
        DBMS_OUTPUT.PUT_LINE('Sales Order Successfully Created');  
      END IF;  
      COMMIT;  
    ELSE  
      IF (l_debug_level > 0) THEN  
        DBMS_OUTPUT.PUT_LINE('Failed to Create Sales Order');  
      END IF;  
      ROLLBACK;  
    END IF;  
  END LOOP;   
  -- DISPLAY ERROR MSGS  
  IF (l_debug_level > 0) THEN  
    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_data ,p_msg_index_out => l_msg_index);  
      DBMS_OUTPUT.PUT_LINE('message is:' ||l_data);  
      DBMS_OUTPUT.PUT_LINE('message index is:' ||l_msg_index);  
    END LOOP;  
  END IF;     
END;

Add Short text Attachment to Standard Sales Order on Both Header and line level using API

Below anonymous block will Add Attachment to Sales order header level in Order Management.
(Note:
a ) Change values as per your requirement also ON DBMS Output window to see DBMS Output message.
b) Similarly you Can add attachment on On Line level wit suitable changes in Add_Attachment API. )


DECLARE
  l_rowid rowid;
  l_attached_document_id NUMBER;
  l_document_id          NUMBER;
  l_document_id1         NUMBER;
  l_media_id             NUMBER;
  l_file_id              NUMBER;
  l_category_id          NUMBER                     :=1000881; --1000728; -- Invoice Internal
  l_pk1_value fnd_attached_documents.pk1_value%TYPE := '5';
  l_description fnd_documents_tl.description%TYPE   := 'WHT_Detail';
 -- l_filename fnd_documents_tl.file_name%TYPE        := 'b1.jpg.bmp';
  l_seq_num NUMBER;
  l_blob BLOB;
  l_bfile bfile;
  l_byte          NUMBER;
  l_return_status VARCHAR2(2000);
  l_msg_count     NUMBER(10);
  l_msg_data      VARCHAR2(1000);
  l_debug_file VARCHAR2(200);  
  l_debug_level NUMBER := 5;   -- OM DEBUG LEVEL (MAX 5)  
  l_org         NUMBER := 194; -- OPERATING UNIT 
BEGIN
-- INITIALIZATION REQUIRED FOR R12  
  mo_global.set_policy_context ('S', l_org);  
  mo_global.init('ONT'); 
  -- INITIALIZE DEBUG INFO  
  IF (l_debug_level > 0) THEN  
    l_debug_file   := OE_DEBUG_PUB.Set_Debug_Mode('FILE');  
    oe_debug_pub.initialize;  
    oe_debug_pub.setdebuglevel(l_debug_level);  
    Oe_Msg_Pub.initialize;  
  END IF;  

  -- INITIALIZE ENVIRONMENT  
  fnd_global.apps_initialize (user_id => 2106, resp_id => 50663, resp_appl_id => 660);  
mo_global.set_policy_context ('S', 194);  
--- context done ------------

dbms_output.put_line('Before Calling the API to Create_Short_Text_Document' );
Oe_Fnd_Attachments_Pub.Create_Short_Text_Document
(
p_api_version => 1.0,
p_document_text => 'PRPTEST NEW ORDER RECORD',
p_document_category =>l_category_id,
p_document_description =>'PRPTEST NEW desc',--l_doc_description,
p_language =>'AMERICAN',
p_security_type =>4,
p_security_id => NULL,
p_publish_flag =>'Y',
p_usage_type => 'O',
p_start_date_active => SYSDATE,
p_end_date_active => SYSDATE,
p_commit => 'Y',
x_document_id =>l_document_id,
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data
);

IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
dbms_output.put_line('success:');
COMMIT;
ELSIF l_return_status IS NULL THEN
DBMS_OUTPUT.PUT_LINE('Status is null');
ELSE
DBMS_OUTPUT.PUT_LINE('failure:'|| l_msg_data ||'v_msg_count'||l_msg_count);
FOR i IN 1 .. l_msg_count
     LOOP
        l_msg_data := oe_msg_pub.get( p_msg_index => i, p_encoded => 'F');
        dbms_output.put_line( i|| ') '|| l_msg_data);
     END LOOP;    
ROLLBACK;
END IF;
dbms_output.put_line('Before Calling the API to Add_Attachment' );
OE_FND_ATTACHMENTS_PUB.Add_Attachment
(
p_api_version     =>1.0,
p_entity_name     =>'OE_ORDER_HEADERS',
p_pk1_value =>l_pk1_value,
p_document_id     =>l_document_id,               
x_attachment_id =>l_document_id1,
x_return_status =>l_return_status,
x_msg_count =>l_msg_count, 
x_msg_data =>l_msg_data
);
IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
dbms_output.put_line('success:');
COMMIT;
ELSIF l_return_status IS NULL THEN
DBMS_OUTPUT.PUT_LINE('Status is null');
ELSE
DBMS_OUTPUT.PUT_LINE('failure:'|| l_msg_data ||'v_msg_count'||l_msg_count);
FOR i IN 1 .. l_msg_count
     LOOP
        l_msg_data := oe_msg_pub.get( p_msg_index => i, p_encoded => 'F');
        dbms_output.put_line( i|| ') '|| l_msg_data);
     END LOOP;
    
ROLLBACK;
END IF;

END XXVIS5_PROC;

Add Hold to standard Sales Order Using hod API

Below anonymous block will Add hold to existing Sales order in Order Management.
(Note: Change values as per your requirement also On DBMS Output window to see DBMS Output message)


DECLARE

v_return_status    VARCHAR2(30);
v_msg_data         VARCHAR2(4000);
v_msg_count        NUMBER;
v_hold_source_rec  OE_HOLDS_PVT.HOLD_SOURCE_REC_TYPE;
v_hold_id          NUMBER       DEFAULT 2032;
v_hold_entity_code VARCHAR2(10) DEFAULT 'O';
v_header_id        NUMBER       DEFAULT 5;
l_debug_file VARCHAR2(200);
l_debug_level NUMBER := 5;   -- OM DEBUG LEVEL (MAX 5)
  l_org         NUMBER := 194; -- OPERATING UNIT
BEGIN

-- INITIALIZATION REQUIRED FOR R12
  mo_global.set_policy_context ('S', l_org);
  mo_global.init('ONT');

  -- INITIALIZE DEBUG INFO
  IF (l_debug_level > 0) THEN
    l_debug_file   := OE_DEBUG_PUB.Set_Debug_Mode('FILE');
    oe_debug_pub.initialize;
    oe_debug_pub.setdebuglevel(l_debug_level);
    Oe_Msg_Pub.initialize;
  END IF;

  -- INITIALIZE ENVIRONMENT
  fnd_global.apps_initialize (user_id => 2106, resp_id => 50663, resp_appl_id => 660);
mo_global.set_policy_context ('S', 194);
--- context done ------------

v_hold_source_rec                  := OE_HOLDS_PVT.G_MISS_HOLD_SOURCE_REC;
v_hold_source_rec.hold_id          := v_hold_id;
v_hold_source_rec.hold_entity_code := v_hold_entity_code;
v_hold_source_rec.hold_entity_id   := v_header_id;
v_hold_source_rec.header_id        := v_header_id;
v_return_status                    := NULL;
v_msg_data                         := NULL;
v_msg_count                        := NULL;

dbms_output.put_line('Calling the API to Apply hold' );

OE_HOLDS_PUB.APPLY_HOLDS (
                       p_api_version     => 1.0,
                       p_init_msg_list   => FND_API.G_TRUE,
                       p_commit          => FND_API.G_FALSE,
                       p_hold_source_rec => v_hold_source_rec,
                       x_return_status   => v_return_status,
                       x_msg_count       => v_msg_count,
                       x_msg_data        => v_msg_data
                         );


IF v_return_status = FND_API.G_RET_STS_SUCCESS THEN
dbms_output.put_line('success:');
COMMIT;
ELSIF v_return_status IS NULL THEN
DBMS_OUTPUT.PUT_LINE('Status is null');
ELSE
DBMS_OUTPUT.PUT_LINE('failure:'|| v_msg_data ||'v_msg_count'||v_msg_count);

FOR i IN 1 .. v_msg_count
     LOOP
        v_msg_data := oe_msg_pub.get( p_msg_index => i, p_encoded => 'F');
        dbms_output.put_line( i|| ') '|| v_msg_data);
     END LOOP;
 
ROLLBACK;
END IF;

EXCEPTION
WHEN OTHERS THEN
 DBMS_OUTPUT.PUT_LINE('Error : '||SQLCODE||'---'||SQLERRM);
END;

Create Standard Sales Order using API

Below anonymous block will create Sales order in Order Management.
(Note: Change values as per your requirement also On DBMS Output window to see DBMS Output message)

DECLARE
  l_api_version_number NUMBER := 1;
  l_return_status      VARCHAR2(2000);
  l_msg_count          NUMBER;
  l_msg_data           VARCHAR2(2000);
  -- PARAMETERS
  l_debug_level NUMBER := 5;   -- OM DEBUG LEVEL (MAX 5)
  l_org         NUMBER := 194; -- OPERATING UNIT
  l_no_orders   NUMBER := 1;   -- NO OF ORDERS
  -- INPUT VARIABLES FOR PROCESS_ORDER API
  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;
  -- OUT VARIABLES FOR PROCESS_ORDER API
  l_header_rec_out oe_order_pub.header_rec_type;
  l_header_val_rec_out oe_order_pub.header_val_rec_type;
  l_header_adj_tbl_out oe_order_pub.header_adj_tbl_type;
  l_header_adj_val_tbl_out oe_order_pub.header_adj_val_tbl_type;
  l_header_price_att_tbl_out oe_order_pub.header_price_att_tbl_type;
  l_header_adj_att_tbl_out oe_order_pub.header_adj_att_tbl_type;
  l_header_adj_assoc_tbl_out oe_order_pub.header_adj_assoc_tbl_type;
  l_header_scredit_tbl_out oe_order_pub.header_scredit_tbl_type;
  l_header_scredit_val_tbl_out oe_order_pub.header_scredit_val_tbl_type;
  l_line_tbl_out oe_order_pub.line_tbl_type;
  l_line_val_tbl_out oe_order_pub.line_val_tbl_type;
  l_line_adj_tbl_out oe_order_pub.line_adj_tbl_type;
  l_line_adj_val_tbl_out oe_order_pub.line_adj_val_tbl_type;
  l_line_price_att_tbl_out oe_order_pub.line_price_att_tbl_type;
  l_line_adj_att_tbl_out oe_order_pub.line_adj_att_tbl_type;
  l_line_adj_assoc_tbl_out oe_order_pub.line_adj_assoc_tbl_type;
  l_line_scredit_tbl_out oe_order_pub.line_scredit_tbl_type;
  l_line_scredit_val_tbl_out oe_order_pub.line_scredit_val_tbl_type;
  l_lot_serial_tbl_out oe_order_pub.lot_serial_tbl_type;
  l_lot_serial_val_tbl_out oe_order_pub.lot_serial_val_tbl_type;
  l_action_request_tbl_out oe_order_pub.request_tbl_type;
  l_msg_index  NUMBER;
  l_data       VARCHAR2(2000);
  l_loop_count NUMBER;
  l_debug_file VARCHAR2(200);
BEGIN
  -- INITIALIZATION REQUIRED FOR R12
  mo_global.set_policy_context ('S', l_org);
  mo_global.init('ONT');
  -- INITIALIZE DEBUG INFO
  IF (l_debug_level > 0) THEN
    l_debug_file   := OE_DEBUG_PUB.Set_Debug_Mode('FILE');
    oe_debug_pub.initialize;
    oe_debug_pub.setdebuglevel(l_debug_level);
    Oe_Msg_Pub.initialize;
  END IF;
  -- INITIALIZE ENVIRONMENT
  fnd_global.apps_initialize (user_id => 2106, resp_id => 50663, resp_appl_id => 660);
  -- INITIALIZE HEADER RECORD
  l_header_rec := OE_ORDER_PUB.G_MISS_HEADER_REC;
  -- POPULATE REQUIRED ATTRIBUTES
  l_header_rec.operation               := OE_GLOBALS.G_OPR_CREATE;
  l_header_rec.orig_sys_document_ref   := 'OE_ORDER_HEADERS_PRPTEST';
  l_header_rec.TRANSACTIONAL_CURR_CODE := 'USD';
  l_header_rec.pricing_date            := SYSDATE;
  l_header_rec.cust_po_number          := NUll;
  l_header_rec.sold_to_org_id          := 25074;
  l_header_rec.price_list_id           := 6015;
  l_header_rec.ordered_date            := SYSDATE;
  l_header_rec.shipping_method_code    := NULL;
  l_header_rec.sold_from_org_id        := 194;
  l_header_rec.ship_from_org_id        := 174;
  l_header_rec.ship_to_org_id          := 4926;
  l_header_rec.salesrep_id             := -3;
  l_header_rec.flow_status_code        :='ENTERED';
  l_header_rec.order_type_id           := 1485;
  -- REQUIRED HEADER DFF INFORMATIONS
  l_header_rec.attribute1  :=193;        -- Entering Branch
  l_header_rec.attribute3  := 'Y';       -- Indexation applicable
  l_header_rec.attribute5  := '2.5';     -- Indexation Tolerance percentage
 l_header_rec.attribute7  := 100000045; -- Field Sales representative
  l_header_rec.attribute11 := '100';     -- Indexation Applicability
  -- INITIALIZE ACTION REQUEST RECORD
  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;
  -- INITIALIZE LINE RECORD
  l_line_tbl(1)                   := OE_ORDER_PUB.G_MISS_LINE_REC;
  l_line_tbl(1).operation         := OE_GLOBALS.G_OPR_CREATE; -- Mandatory Operation to Pass
  l_line_tbl(1).inventory_item_id := 524216;
  l_line_tbl(1).ordered_quantity  := 1;
  l_line_tbl(1).ship_from_org_id  := 174;
  l_line_tbl(1).subinventory      := NULL;
  -- REQUIRED LINE DFF INFORMATIONS
  l_line_tbl(1).attribute2  := '20.99998'; -- Gross Margin
  l_line_tbl(1).attribute3  := '101686'; -- Business Cost
  l_line_tbl(1).attribute10 := 'Y';     -- Original Cust Requested Qty
  l_line_tbl(1).attribute11 := '662.772';  -- Baseline Margin
  l_line_tbl(1).attribute16 := 'DBP';      -- Buy Price Basis
  FOR i IN 1..l_no_orders
  LOOP -- BEGIN LOOP
    -- CALLTO PROCESS ORDER API
    oe_order_pub.process_order( p_org_id => l_org,
                                p_operating_unit => NULL,
                                p_api_version_number => l_api_version_number,
                                p_header_rec => l_header_rec,
                                p_line_tbl => l_line_tbl,
                                p_action_request_tbl => l_action_request_tbl,
    -- OUT variables
                                x_header_rec => l_header_rec_out,
                                x_header_val_rec => l_header_val_rec_out,
                                x_header_adj_tbl => l_header_adj_tbl_out,
                                x_header_adj_val_tbl => l_header_adj_val_tbl_out,
                                x_header_price_att_tbl => l_header_price_att_tbl_out,
                                x_header_adj_att_tbl => l_header_adj_att_tbl_out,
                                x_header_adj_assoc_tbl => l_header_adj_assoc_tbl_out,
                                x_header_scredit_tbl => l_header_scredit_tbl_out,
                                x_header_scredit_val_tbl => l_header_scredit_val_tbl_out,
                                x_line_tbl => l_line_tbl_out,
                                x_line_val_tbl => l_line_val_tbl_out,
                                x_line_adj_tbl => l_line_adj_tbl_out,
                                x_line_adj_val_tbl => l_line_adj_val_tbl_out,
                                x_line_price_att_tbl => l_line_price_att_tbl_out,
                                x_line_adj_att_tbl => l_line_adj_att_tbl_out,
                                x_line_adj_assoc_tbl => l_line_adj_assoc_tbl_out,
                                x_line_scredit_tbl => l_line_scredit_tbl_out,
                                x_line_scredit_val_tbl => l_line_scredit_val_tbl_out,
                                x_lot_serial_tbl => l_lot_serial_tbl_out,
                                x_lot_serial_val_tbl => l_lot_serial_val_tbl_out,
                                x_action_request_tbl => l_action_request_tbl_out,
                                x_return_status =>  l_return_status,
                                x_msg_count => l_msg_count,
                                x_msg_data => l_msg_data);
    -- CHECK RETURN STATUS
    IF l_return_status  = FND_API.G_RET_STS_SUCCESS THEN
      IF (l_debug_level > 0) THEN
        DBMS_OUTPUT.PUT_LINE('Sales Order Successfully Created');
      END IF;
      COMMIT;
    ELSE
      IF (l_debug_level > 0) THEN
        DBMS_OUTPUT.PUT_LINE('Failed to Create Sales Order');
      END IF;
      ROLLBACK;
    END IF;
  END LOOP;  
  -- DISPLAY ERROR MSGS
  IF (l_debug_level > 0) THEN
    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_data ,p_msg_index_out => l_msg_index);
      DBMS_OUTPUT.PUT_LINE('message is:' ||l_data);
      DBMS_OUTPUT.PUT_LINE('message index is:' ||l_msg_index);
    END LOOP;
  END IF;    
END;