DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_ORDER_IMPORT_PVT

Source


1 PACKAGE BODY OE_ORDER_IMPORT_PVT AS
2 /* $Header: OEXVIMPB.pls 120.20.12020000.5 2013/01/16 10:18:17 sujithku ship $ */
3 
4 /* ---------------------------------------------------------------
5 --  Start of Comments
6 --  API name    OE_ORDER_IMPORT_PVT
7 --  Type        Private
8 --  Function
9 --  Pre-reqs
10 --  Parameters
11 --  Version     Current version = 1.0
12 --              Initial version = 1.0
13 --  Notes
14 --
15 --  End of Comments
16 ------------------------------------------------------------------
17 */
18 
19 /* -----------------------------------------------------------
20    Procedure: Import_Order
21    -----------------------------------------------------------
22 */
23 PROCEDURE IMPORT_ORDER(
24    p_request_id			IN NUMBER
25   ,p_order_source_id		IN NUMBER
26   ,p_orig_sys_document_ref      IN VARCHAR2
27   ,p_sold_to_org_id             IN  NUMBER
28   ,p_sold_to_org                IN  VARCHAR2
29   ,p_change_sequence      	IN VARCHAR2
30   ,p_validate_only		IN VARCHAR2
31   ,p_init_msg_list		IN VARCHAR2
32   ,p_rtrim_data                 IN VARCHAR2
33   ,p_org_id                     IN NUMBER
34   ,p_msg_count          OUT NOCOPY NUMBER
35   ,p_msg_data           OUT NOCOPY VARCHAR2
36   ,p_return_status      OUT NOCOPY VARCHAR2
37   ,p_validate_desc_flex         in varchar2 default 'Y' -- bug4343612
38 ) IS
39 
40   l_control_rec                 OE_Globals.Control_Rec_Type;
41 
42   l_header_adj_rec  		OE_Order_Pub.Header_Adj_Rec_Type;
43   l_header_scredit_rec      	OE_Order_Pub.Header_Scredit_Rec_Type;
44   l_header_payment_rec          OE_Order_Pub.Header_payment_Rec_Type;
45   l_header_price_att_rec        OE_Order_Pub.Header_Price_Att_Rec_Type;
46   l_header_adj_att_rec          OE_Order_Pub.Header_Adj_Att_Rec_Type;
47   l_header_adj_assoc_rec        OE_Order_Pub.Header_Adj_Assoc_Rec_Type;
48   l_line_rec                    OE_Order_Pub.Line_Rec_Type;
49   l_line_adj_rec                OE_Order_Pub.Line_Adj_Rec_Type;
50   l_line_price_att_rec          OE_Order_Pub.Line_Price_Att_Rec_Type;
51   l_line_adj_att_rec            OE_Order_Pub.Line_Adj_Att_Rec_Type;
52   l_line_adj_assoc_rec          OE_Order_Pub.Line_Adj_Assoc_Rec_Type;
53   l_line_scredit_rec            OE_Order_Pub.Line_Scredit_Rec_Type;
54   l_line_payment_rec            OE_Order_Pub.Line_payment_Rec_Type;
55   l_lot_serial_rec         	OE_Order_Pub.Lot_Serial_Rec_Type;
56   l_reservation_rec         	OE_Order_Pub.Reservation_Rec_Type;
57   l_action_request_rec          OE_Order_Pub.Request_Rec_Type;
58 
59   l_header_rec                  OE_Order_Pub.Header_Rec_Type;
60   l_header_adj_tbl  		OE_Order_Pub.Header_Adj_Tbl_Type;
61   l_header_price_att_tbl  	OE_Order_Pub.Header_Price_Att_Tbl_Type;
62   l_header_adj_att_tbl  	OE_Order_Pub.Header_Adj_Att_Tbl_Type;
63   l_header_adj_assoc_tbl  	OE_Order_Pub.Header_Adj_Assoc_Tbl_Type;
64   l_header_scredit_tbl      	OE_Order_Pub.Header_Scredit_Tbl_Type;
65   l_header_payment_tbl          OE_Order_Pub.Header_payment_Tbl_Type;
66   l_line_tbl                    OE_Order_Pub.Line_Tbl_Type;
67   l_line_adj_tbl                OE_Order_Pub.Line_Adj_Tbl_Type;
68   l_line_price_att_tbl  	OE_Order_Pub.Line_Price_Att_Tbl_Type;
69   l_line_adj_att_tbl  		OE_Order_Pub.Line_Adj_Att_Tbl_Type;
70   l_line_adj_assoc_tbl  	OE_Order_Pub.Line_Adj_Assoc_Tbl_Type;
71   l_line_scredit_tbl            OE_Order_Pub.Line_Scredit_Tbl_Type;
72   l_line_payment_tbl            OE_Order_Pub.Line_payment_Tbl_Type;
73   l_lot_serial_tbl         	OE_Order_Pub.Lot_Serial_Tbl_Type;
74   l_reservation_tbl         	OE_Order_Pub.Reservation_Tbl_Type;
75   l_action_request_tbl	        OE_Order_Pub.Request_Tbl_Type;
76 
77   l_header_rec_old              OE_Order_Pub.Header_Rec_Type;
78   l_header_adj_tbl_old  	OE_Order_Pub.Header_Adj_Tbl_Type;
79   l_header_price_att_tbl_old  	OE_Order_Pub.Header_Price_Att_Tbl_Type;
80   l_header_adj_att_tbl_old  	OE_Order_Pub.Header_Adj_Att_Tbl_Type;
81   l_header_adj_assoc_tbl_old  	OE_Order_Pub.Header_Adj_Assoc_Tbl_Type;
82   l_header_scredit_tbl_old      OE_Order_Pub.Header_Scredit_Tbl_Type;
83   l_header_payment_tbl_old      OE_Order_Pub.Header_payment_Tbl_Type;
84   l_line_tbl_old                OE_Order_Pub.Line_Tbl_Type;
85   l_line_adj_tbl_old            OE_Order_Pub.Line_Adj_Tbl_Type;
86   l_line_price_att_tbl_old  	OE_Order_Pub.Line_Price_Att_Tbl_Type;
87   l_line_adj_att_tbl_old 	OE_Order_Pub.Line_Adj_Att_Tbl_Type;
88   l_line_adj_assoc_tbl_old  	OE_Order_Pub.Line_Adj_Assoc_Tbl_Type;
89   l_line_scredit_tbl_old        OE_Order_Pub.Line_Scredit_Tbl_Type;
90   l_line_payment_tbl_old        OE_Order_Pub.Line_payment_Tbl_Type;
91   l_lot_serial_tbl_old     	OE_Order_Pub.Lot_Serial_Tbl_Type;
92   l_action_request_tbl_old      OE_Order_Pub.Request_Tbl_Type;
93 
94   l_header_rec_new              OE_Order_Pub.Header_Rec_Type;
95   l_header_adj_tbl_new  	OE_Order_Pub.Header_Adj_Tbl_Type;
96   l_header_price_att_tbl_new  	OE_Order_Pub.Header_Price_Att_Tbl_Type;
97   l_header_adj_att_tbl_new  	OE_Order_Pub.Header_Adj_Att_Tbl_Type;
98   l_header_adj_assoc_tbl_new  	OE_Order_Pub.Header_Adj_Assoc_Tbl_Type;
99   l_header_scredit_tbl_new      OE_Order_Pub.Header_Scredit_Tbl_Type;
100   l_header_payment_tbl_new      OE_Order_Pub.Header_payment_Tbl_Type;
101   l_line_tbl_new                OE_Order_Pub.Line_Tbl_Type;
102   l_line_adj_tbl_new            OE_Order_Pub.Line_Adj_Tbl_Type;
103   l_line_price_att_tbl_new  	OE_Order_Pub.Line_Price_Att_Tbl_Type;
104   l_line_adj_att_tbl_new 	OE_Order_Pub.Line_Adj_Att_Tbl_Type;
105   l_line_adj_assoc_tbl_new  	OE_Order_Pub.Line_Adj_Assoc_Tbl_Type;
106   l_line_scredit_tbl_new        OE_Order_Pub.Line_Scredit_Tbl_Type;
107   l_line_payment_tbl_new        OE_Order_Pub.Line_payment_Tbl_Type;
108   l_lot_serial_tbl_new     	OE_Order_Pub.Lot_Serial_Tbl_Type;
109 
110   l_header_adj_val_rec  	OE_Order_Pub.Header_Adj_Val_Rec_Type;
111   l_header_scredit_val_rec      OE_Order_Pub.Header_Scredit_Val_Rec_Type;
112   l_header_payment_val_rec      OE_Order_Pub.Header_payment_Val_Rec_Type;
113   l_line_val_rec              	OE_Order_Pub.Line_Val_Rec_Type;
114   l_line_adj_val_rec  		OE_Order_Pub.Line_Adj_Val_Rec_Type;
115   l_line_scredit_val_rec      	OE_Order_Pub.Line_Scredit_Val_Rec_Type;
116   l_line_payment_val_rec        OE_Order_Pub.Line_payment_Val_Rec_Type;
117   l_lot_serial_val_rec         	OE_Order_Pub.Lot_Serial_Val_Rec_Type;
118   l_reservation_val_rec         OE_Order_Pub.Reservation_Val_Rec_Type;
119 
120   l_header_val_rec              OE_Order_Pub.Header_Val_Rec_Type;
121   l_header_adj_val_tbl  	OE_Order_Pub.Header_Adj_Val_Tbl_Type;
122   l_header_scredit_val_tbl      OE_Order_Pub.Header_Scredit_Val_Tbl_Type;
123   l_header_payment_val_tbl      OE_Order_Pub.Header_payment_Val_Tbl_Type;
124   l_line_val_tbl              	OE_Order_Pub.Line_Val_Tbl_Type;
125   l_line_adj_val_tbl  		OE_Order_Pub.Line_Adj_Val_Tbl_Type;
126   l_line_scredit_val_tbl      	OE_Order_Pub.Line_Scredit_Val_Tbl_Type;
127   l_line_payment_val_tbl        OE_Order_Pub.Line_payment_Val_Tbl_Type;
128   l_lot_serial_val_tbl         	OE_Order_Pub.Lot_Serial_Val_Tbl_Type;
129   l_reservation_val_tbl         OE_Order_Pub.Reservation_Val_Tbl_Type;
130 
131   l_header_val_rec_old          OE_Order_Pub.Header_Val_Rec_Type;
132   l_header_adj_val_tbl_old  	OE_Order_Pub.Header_Adj_Val_Tbl_Type;
133   l_header_scredit_val_tbl_old  OE_Order_Pub.Header_Scredit_Val_Tbl_Type;
134   l_header_payment_val_tbl_old  OE_Order_Pub.Header_payment_Val_Tbl_Type;
135   l_line_val_tbl_old          	OE_Order_Pub.Line_Val_Tbl_Type;
136   l_line_adj_val_tbl_old  	OE_Order_Pub.Line_Adj_Val_Tbl_Type;
137   l_line_scredit_val_tbl_old  	OE_Order_Pub.Line_Scredit_Val_Tbl_Type;
138   l_line_payment_val_tbl_old    OE_Order_Pub.Line_payment_Val_Tbl_Type;
139   l_lot_serial_val_tbl_old     	OE_Order_Pub.Lot_Serial_Val_Tbl_Type;
140 
141   l_header_val_rec_new          OE_Order_Pub.Header_Val_Rec_Type;
142   l_header_adj_val_tbl_new  	OE_Order_Pub.Header_Adj_Val_Tbl_Type;
143   l_header_scredit_val_tbl_new  OE_Order_Pub.Header_Scredit_Val_Tbl_Type;
144   l_header_payment_val_tbl_new  OE_Order_Pub.Header_payment_Val_Tbl_Type;
145   l_line_val_tbl_new          	OE_Order_Pub.Line_Val_Tbl_Type;
146   l_line_adj_val_tbl_new  	OE_Order_Pub.Line_Adj_Val_Tbl_Type;
147   l_line_scredit_val_tbl_new  	OE_Order_Pub.Line_Scredit_Val_Tbl_Type;
148   l_line_payment_val_tbl_new    OE_Order_Pub.Line_payment_Val_Tbl_Type;
149   l_lot_serial_val_tbl_new     	OE_Order_Pub.Lot_Serial_Val_Tbl_Type;
150 
151   l_action_rec          	OE_Order_Import_Pvt.Action_Rec_Type;
152 
153   l_request_id			NUMBER 		:= p_request_id;
154   l_order_source_id		NUMBER 		:= p_order_source_id;
155   l_orig_sys_document_ref	VARCHAR2(50) 	:= p_orig_sys_document_ref;
156   l_sold_to_org_id              NUMBER          := p_sold_to_org_id;
157   l_sold_to_org                 VARCHAR2(360)   := p_sold_to_org;
158   l_change_sequence		VARCHAR2(50)	:= p_change_sequence;
159   l_org_id                      NUMBER          := p_org_id;
160   l_orig_sys_line_ref		VARCHAR2(50);
161   l_orig_sys_shipment_ref	VARCHAR2(50);
162 
163   l_order_type_id		NUMBER;
164   l_order_number		NUMBER;
165   l_line_number			NUMBER;
166   l_shipment_number		NUMBER;
167   l_header_id			NUMBER;
168   l_line_id			NUMBER;
169 
170   l_validate_only		VARCHAR2(1);
171   l_init_msg_list		VARCHAR2(1)	:= p_init_msg_list;
172   l_validation_level 		NUMBER		:= FND_API.G_VALID_LEVEL_FULL;
173   l_return_values 		VARCHAR2(1)     := FND_API.G_FALSE;
174   l_commit 			VARCHAR2(1)     := FND_API.G_FALSE;
175   l_api_service_level 		VARCHAR2(30)    := OE_GLOBALS.G_ALL_SERVICE;
176 
177   l_return_status              	VARCHAR2(1) 	:= FND_API.G_RET_STS_SUCCESS;
178   l_return_status_oi_pre        VARCHAR2(1) 	:= FND_API.G_RET_STS_SUCCESS;
179   l_return_status_oi_pst        VARCHAR2(1) 	:= FND_API.G_RET_STS_SUCCESS;
180   l_return_status_po          	VARCHAR2(1) 	:= FND_API.G_RET_STS_SUCCESS;
181   l_return_status_del_ord       VARCHAR2(1) 	:= FND_API.G_RET_STS_SUCCESS;
182   l_return_status_del_msg       VARCHAR2(1) 	:= FND_API.G_RET_STS_SUCCESS;
183   l_return_status_sav_msg       VARCHAR2(1) 	:= FND_API.G_RET_STS_SUCCESS;
184   l_return_status_upd_err       VARCHAR2(1) 	:= FND_API.G_RET_STS_SUCCESS;
185   l_return_status_book          VARCHAR2(1) 	:= FND_API.G_RET_STS_SUCCESS;
186   l_error_index_flag            VARCHAR2(1)  := 'N';
187   l_validation_org  NUMBER := OE_Sys_Parameters.VALUE('MASTER_ORGANIZATION_ID', p_org_id);
188 
189   l_header_count		NUMBER 		:= 0;
190   l_header_adj_count		NUMBER 		:= 0;
191   l_header_att_count            NUMBER          := 0;
192   l_header_scredit_count	NUMBER 		:= 0;
193   l_header_payment_count        NUMBER          := 0;
194   l_line_count		        NUMBER 		:= 0;
195   l_line_adj_count		NUMBER 		:= 0;
196   l_line_att_count              NUMBER          := 0;
197   l_line_scredit_count		NUMBER 		:= 0;
198   l_line_payment_count          NUMBER          := 0;
199   l_lot_serial_count		NUMBER 		:= 0;
200   l_reservation_count		NUMBER 		:= 0;
201   l_action_request_count        NUMBER 		:= 0;
202 
203   l_msg_index              	NUMBER := 0;
204   l_msg_context              	VARCHAR2(2000);
205   l_msg_data              	VARCHAR2(2000);
206   l_tbl_index                   Number;
207 
208   l_msg_entity_code             VARCHAR2(30);
209   l_msg_entity_ref		VARCHAR2(50);
210   l_msg_entity_id               NUMBER;
211   l_msg_header_id               NUMBER;
212   l_msg_line_id                 NUMBER;
213   l_msg_order_source_id         NUMBER;
214   l_msg_orig_sys_document_ref   VARCHAR2(50);
215   l_msg_change_sequence   	VARCHAR2(50);
216   l_msg_orig_sys_line_ref  	VARCHAR2(50);
217   l_msg_orig_sys_shipment_ref  	VARCHAR2(50);
218   l_msg_sold_to_org_id          NUMBER;
219   l_msg_sold_to_org                 VARCHAR2(360);
220   l_msg_source_document_type_id NUMBER;
221   l_msg_source_document_id      NUMBER;
222   l_msg_source_document_line_id NUMBER;
223   l_msg_attribute_code          VARCHAR2(50);
224   l_msg_constraint_id           NUMBER;
225   l_msg_process_activity        NUMBER;
226   l_msg_notification_flag       VARCHAR2(1);
227   l_msg_type                 	VARCHAR2(30);
228 
229   l_commit_flag              	VARCHAR2(1) := 'Y';
230   l_delete_flag              	VARCHAR2(1) := 'Y';
231 
232   l_api_name                    CONSTANT VARCHAR2(30) := 'Import_Order';
233 
234   l_structure  fnd_flex_key_api.structure_type;
235   l_flexfield  fnd_flex_key_api.flexfield_type;
236   l_segment_array  fnd_flex_ext.segmentarray;
237   l_n_segments  NUMBER;
238   l_segments  FND_FLEX_KEY_API.SEGMENT_LIST;
239   l_id  NUMBER;
240   failure_message      varchar2(2000);
241 
242   --{ Start of the variable declaration for the add customer
243 
244   l_header_customer_rec       OE_ORDER_IMPORT_SPECIFIC_PVT.Customer_Rec_Type;
245   l_line_customer_rec         OE_ORDER_IMPORT_SPECIFIC_PVT.Customer_Rec_Type;
246   l_line_customer_tbl         OE_ORDER_IMPORT_SPECIFIC_PVT.Customer_Tbl_Type;
247 
248   --End of the variable declaration for the add customer}
249 
250   --{ Start of the subinventory Nulling Code variable declartion
251   l_revision_code           NUMBER;
252   l_lot_code                NUMBER;
253   -- End of subinventory Nulling Code variable declartion}
254 
255   G_IMPORT_SHIPMENTS        VARCHAR2(3);
256 
257   l_order_imported          Varchar2(1);
258   l_header_cso_response_flag Varchar2(1);
259   l_cso_response_pfile      Varchar2(3);
260   l_cho_ack_send_pfile      Varchar2(3);
261   l_sold_to_org_id_tmp      NUMBER;
262 
263   l_rtrim_data              Varchar2(1) := p_rtrim_data;
264   l_status           VARCHAR2(1);  -- Added for the bug 6378240
265 
266   l_msg_data_vp   varchar2(2000); -- Added for  bug 7367433
267   l_msg_count_vp  number;  -- Added for  bug 7367433
268 
269 
270 --myerrams, Bug:4724191  l_header_id_temp	    NUMBER;		--myerrams
271 
272 
273 /* -----------------------------------------------------------
274    Headers cursor
275    -----------------------------------------------------------
276 */
277     CURSOR l_header_cursor IS
278     SELECT order_source_id
279     	 , orig_sys_document_ref
280     	 , change_sequence
281 	 , nvl(change_request_code,		FND_API.G_MISS_CHAR)
282 	 , nvl(order_source,			FND_API.G_MISS_CHAR)
283 	 , nvl(org_id,				FND_API.G_MISS_NUM)
284 	 , nvl(header_id,			FND_API.G_MISS_NUM)
285 	 , nvl(order_number,			FND_API.G_MISS_NUM)
286 	 , nvl(version_number,			FND_API.G_MISS_NUM)
287 	 , nvl(ordered_date,			FND_API.G_MISS_DATE)
288 	 , nvl(order_type_id,			FND_API.G_MISS_NUM)
289 	 , nvl(order_type,			FND_API.G_MISS_CHAR)
290 	 , nvl(price_list_id,			FND_API.G_MISS_NUM)
291 	 , nvl(price_list,			FND_API.G_MISS_CHAR)
292 	 , nvl(conversion_rate,			FND_API.G_MISS_NUM)
293 	 , nvl(conversion_rate_date,		FND_API.G_MISS_DATE)
294 	 , nvl(conversion_type_code,		FND_API.G_MISS_CHAR)
295 	 , nvl(conversion_type,			FND_API.G_MISS_CHAR)
296 	 , nvl(transactional_curr_code,		FND_API.G_MISS_CHAR)
297 	 , nvl(return_reason_code,		FND_API.G_MISS_CHAR)
298 	 , nvl(salesrep_id,			FND_API.G_MISS_NUM)
299 	 , nvl(salesrep,			FND_API.G_MISS_CHAR)
300 	 , nvl(sales_channel_code,		FND_API.G_MISS_CHAR)
301 	 , nvl(sales_channel,     		FND_API.G_MISS_CHAR)
302 	 , nvl(tax_point_code,			FND_API.G_MISS_CHAR)
303 	 , nvl(tax_point,			FND_API.G_MISS_CHAR)
304 	 , nvl(tax_exempt_flag,			FND_API.G_MISS_CHAR)
305 	 , nvl(tax_exempt_number,		FND_API.G_MISS_CHAR)
306 	 , nvl(tax_exempt_reason_code,		FND_API.G_MISS_CHAR)
307 	 , nvl(tax_exempt_reason,		FND_API.G_MISS_CHAR)
308 	 , nvl(agreement_id,			FND_API.G_MISS_NUM)
309 	 , nvl(agreement,			FND_API.G_MISS_CHAR)
310 	 , nvl(invoicing_rule_id,		FND_API.G_MISS_NUM)
311 	 , nvl(invoicing_rule,			FND_API.G_MISS_CHAR)
312 	 , nvl(accounting_rule_id,		FND_API.G_MISS_NUM)
313 	 , nvl(accounting_rule_duration,	FND_API.G_MISS_NUM)
314 	 , nvl(accounting_rule,			FND_API.G_MISS_CHAR)
315 	 , nvl(payment_term_id,			FND_API.G_MISS_NUM)
316 	 , nvl(payment_term,			FND_API.G_MISS_CHAR)
317 	 , nvl(demand_class_code,		FND_API.G_MISS_CHAR)
318 	 , nvl(shipment_priority_code,		FND_API.G_MISS_CHAR)
319 	 , nvl(shipment_priority,		FND_API.G_MISS_CHAR)
320 	 , nvl(shipping_method_code,		FND_API.G_MISS_CHAR)
321 	 , nvl(freight_carrier_code,		FND_API.G_MISS_CHAR)
322 	 , nvl(freight_terms_code,		FND_API.G_MISS_CHAR)
323 	 , nvl(freight_terms,			FND_API.G_MISS_CHAR)
324 	 , nvl(fob_point_code,			FND_API.G_MISS_CHAR)
325 	 , nvl(fob_point,			FND_API.G_MISS_CHAR)
326 	 , nvl(partial_shipments_allowed,	FND_API.G_MISS_CHAR)
327 	 , nvl(ship_tolerance_above,		FND_API.G_MISS_NUM)
328 	 , nvl(ship_tolerance_below,		FND_API.G_MISS_NUM)
329 	 , nvl(shipping_instructions,		FND_API.G_MISS_CHAR)
330 	 , nvl(packing_instructions,		FND_API.G_MISS_CHAR)
331 	 , nvl(order_date_type_code,		FND_API.G_MISS_CHAR)
332 	 , nvl(earliest_schedule_limit,		FND_API.G_MISS_NUM)
333 	 , nvl(latest_schedule_limit,		FND_API.G_MISS_NUM)
334 	 , nvl(customer_po_number,		FND_API.G_MISS_CHAR)
335 	 , nvl(customer_payment_term_id,	FND_API.G_MISS_NUM)
336 	 , nvl(customer_payment_term,		FND_API.G_MISS_CHAR)
337 	 , nvl(payment_type_code,		FND_API.G_MISS_CHAR)
338 	 , nvl(payment_amount,			FND_API.G_MISS_NUM)
339 	 , nvl(check_number,			FND_API.G_MISS_CHAR)
340 	 , nvl(credit_card_code,		FND_API.G_MISS_CHAR)
341 	 , nvl(credit_card_holder_name,		FND_API.G_MISS_CHAR)
342 	 , nvl(credit_card_number,		FND_API.G_MISS_CHAR)
343 	 , nvl(credit_card_expiration_date,	FND_API.G_MISS_DATE)
344 	 , nvl(credit_card_approval_code,	FND_API.G_MISS_CHAR)
345 	 , nvl(credit_card_approval_date,	FND_API.G_MISS_DATE)
346 	 , nvl(sold_from_org_id,		FND_API.G_MISS_NUM)
347 	 , nvl(sold_from_org,			FND_API.G_MISS_CHAR)
348 	 , nvl(sold_to_org_id,			FND_API.G_MISS_NUM)
349 	 , nvl(sold_to_org,			FND_API.G_MISS_CHAR)
350 	 , nvl(customer_number,       FND_API.G_MISS_CHAR)
351 	 , nvl(ship_from_org_id,		FND_API.G_MISS_NUM)
352 	 , nvl(ship_from_org,			FND_API.G_MISS_CHAR)
353 	 , nvl(ship_to_org_id,			FND_API.G_MISS_NUM)
354 	 , nvl(ship_to_org,			FND_API.G_MISS_CHAR)
355 	 , nvl(invoice_to_org_id,		FND_API.G_MISS_NUM)
356 	 , nvl(invoice_to_org,			FND_API.G_MISS_CHAR)
357 	 , nvl(deliver_to_org_id,		FND_API.G_MISS_NUM)
358 	 , nvl(deliver_to_org,			FND_API.G_MISS_CHAR)
359 	 , nvl(sold_to_contact_id,		FND_API.G_MISS_NUM)
360 	 , nvl(sold_to_contact,			FND_API.G_MISS_CHAR)
361 	 , nvl(ship_to_contact_id,		FND_API.G_MISS_NUM)
362 	 , nvl(ship_to_contact,			FND_API.G_MISS_CHAR)
363 	 , nvl(invoice_to_contact_id,		FND_API.G_MISS_NUM)
364 	 , nvl(invoice_to_contact,		FND_API.G_MISS_CHAR)
365 	 , nvl(deliver_to_contact_id,		FND_API.G_MISS_NUM)
366 	 , nvl(deliver_to_contact,		FND_API.G_MISS_CHAR)
367 	 , nvl(ship_to_address1,		FND_API.G_MISS_CHAR)
368 	 , nvl(ship_to_address2,		FND_API.G_MISS_CHAR)
369 	 , nvl(ship_to_address3,		FND_API.G_MISS_CHAR)
370 	 , nvl(ship_to_address4,		FND_API.G_MISS_CHAR)
371 	 , nvl(ship_to_city,		        FND_API.G_MISS_CHAR)
372 	 , nvl(ship_to_state,nvl(ship_to_province , FND_API.G_MISS_CHAR)) --bug#9395147 ,9878736
373          , nvl(ship_to_postal_code,	        FND_API.G_MISS_CHAR)
374 	 , nvl(ship_to_country,	                FND_API.G_MISS_CHAR)
375 	 , nvl(invoice_address1,		FND_API.G_MISS_CHAR)
376 	 , nvl(invoice_address2,		FND_API.G_MISS_CHAR)
377 	 , nvl(invoice_address3,		FND_API.G_MISS_CHAR)
378 	 , nvl(invoice_address4,		FND_API.G_MISS_CHAR)
379 	 , nvl(invoice_city,		        FND_API.G_MISS_CHAR)
380 	 , nvl(invoice_state,nvl(invoice_province_int , FND_API.G_MISS_CHAR)) ---bug# 9395147 ,9878736
381 	 , nvl(invoice_postal_code,	        FND_API.G_MISS_CHAR)
382 	 , nvl(invoice_country,	                FND_API.G_MISS_CHAR)
383 	 , nvl(drop_ship_flag,			FND_API.G_MISS_CHAR)
384 	 , nvl(booked_flag,			FND_API.G_MISS_CHAR)
385 --	 , nvl(closed_flag,			FND_API.G_MISS_CHAR)
386 	 , nvl(cancelled_flag,			FND_API.G_MISS_CHAR)
387 	 , nvl(context,				FND_API.G_MISS_CHAR)
388 	 , nvl(attribute1,			FND_API.G_MISS_CHAR)
389 	 , nvl(attribute2,			FND_API.G_MISS_CHAR)
390 	 , nvl(attribute3,			FND_API.G_MISS_CHAR)
391 	 , nvl(attribute4,			FND_API.G_MISS_CHAR)
392 	 , nvl(attribute5,			FND_API.G_MISS_CHAR)
393 	 , nvl(attribute6,			FND_API.G_MISS_CHAR)
394 	 , nvl(attribute7,			FND_API.G_MISS_CHAR)
395 	 , nvl(attribute8,			FND_API.G_MISS_CHAR)
396 	 , nvl(attribute9,			FND_API.G_MISS_CHAR)
397 	 , nvl(attribute10,			FND_API.G_MISS_CHAR)
398 	 , nvl(attribute11,			FND_API.G_MISS_CHAR)
399 	 , nvl(attribute12,			FND_API.G_MISS_CHAR)
400 	 , nvl(attribute13,			FND_API.G_MISS_CHAR)
401 	 , nvl(attribute14,			FND_API.G_MISS_CHAR)
402 	 , nvl(attribute15,			FND_API.G_MISS_CHAR)
403 	 , nvl(attribute16,			FND_API.G_MISS_CHAR)  -- for bug 2184255
404 	 , nvl(attribute17,			FND_API.G_MISS_CHAR)
405 	 , nvl(attribute18,			FND_API.G_MISS_CHAR)
406 	 , nvl(attribute19,			FND_API.G_MISS_CHAR)
407 	 , nvl(attribute20,			FND_API.G_MISS_CHAR)
408 	 , nvl(tp_context,			FND_API.G_MISS_CHAR)
409 	 , nvl(tp_attribute1,			FND_API.G_MISS_CHAR)
410 	 , nvl(tp_attribute2,			FND_API.G_MISS_CHAR)
411 	 , nvl(tp_attribute3,			FND_API.G_MISS_CHAR)
412 	 , nvl(tp_attribute4,			FND_API.G_MISS_CHAR)
413 	 , nvl(tp_attribute5,			FND_API.G_MISS_CHAR)
414 	 , nvl(tp_attribute6,			FND_API.G_MISS_CHAR)
415 	 , nvl(tp_attribute7,			FND_API.G_MISS_CHAR)
416 	 , nvl(tp_attribute8,			FND_API.G_MISS_CHAR)
417 	 , nvl(tp_attribute9,			FND_API.G_MISS_CHAR)
418 	 , nvl(tp_attribute10,			FND_API.G_MISS_CHAR)
419 	 , nvl(tp_attribute11,			FND_API.G_MISS_CHAR)
420 	 , nvl(tp_attribute12,			FND_API.G_MISS_CHAR)
421 	 , nvl(tp_attribute13,			FND_API.G_MISS_CHAR)
422 	 , nvl(tp_attribute14,			FND_API.G_MISS_CHAR)
423 	 , nvl(tp_attribute15,			FND_API.G_MISS_CHAR)
424 	 , nvl(global_attribute_category,	FND_API.G_MISS_CHAR)
425 	 , nvl(global_attribute1,		FND_API.G_MISS_CHAR)
426 	 , nvl(global_attribute2,		FND_API.G_MISS_CHAR)
427 	 , nvl(global_attribute3,		FND_API.G_MISS_CHAR)
428 	 , nvl(global_attribute4,		FND_API.G_MISS_CHAR)
429 	 , nvl(global_attribute5,		FND_API.G_MISS_CHAR)
430 	 , nvl(global_attribute6,		FND_API.G_MISS_CHAR)
431 	 , nvl(global_attribute7,		FND_API.G_MISS_CHAR)
432 	 , nvl(global_attribute8,		FND_API.G_MISS_CHAR)
433 	 , nvl(global_attribute9,		FND_API.G_MISS_CHAR)
434 	 , nvl(global_attribute10,		FND_API.G_MISS_CHAR)
435 	 , nvl(global_attribute11,		FND_API.G_MISS_CHAR)
436 	 , nvl(global_attribute12,		FND_API.G_MISS_CHAR)
437 	 , nvl(global_attribute13,		FND_API.G_MISS_CHAR)
438 	 , nvl(global_attribute14,		FND_API.G_MISS_CHAR)
439 	 , nvl(global_attribute15,		FND_API.G_MISS_CHAR)
440 	 , nvl(global_attribute16,		FND_API.G_MISS_CHAR)
441 	 , nvl(global_attribute17,		FND_API.G_MISS_CHAR)
442 	 , nvl(global_attribute18,		FND_API.G_MISS_CHAR)
443 	 , nvl(global_attribute19,		FND_API.G_MISS_CHAR)
444 	 , nvl(global_attribute20,		FND_API.G_MISS_CHAR)
445       , request_id
446 	 , NVL(request_date,               FND_API.G_MISS_DATE)
447 	 , nvl(operation_code,			OE_GLOBALS.G_OPR_CREATE)
448 	 , nvl(ready_flag,			'Y')
449 	 , nvl(status_flag,			'0')
450 	 , nvl(force_apply_flag,		'N')
451 	 , nvl(change_reason,			FND_API.G_MISS_CHAR)
452 	 , nvl(change_comments,			FND_API.G_MISS_CHAR)
453          , nvl(customer_preference_set_code,    FND_API.G_MISS_CHAR)
454       -- { Start add new columns to select for the Add Customer
455          , Orig_Sys_Customer_Ref
456          , Orig_Ship_Address_Ref
457          , Orig_Bill_Address_Ref
458          , Orig_Deliver_Address_Ref
459          , Sold_to_Contact_Ref
460          , Ship_to_Contact_Ref
461          , Bill_to_Contact_Ref
462          , Deliver_to_Contact_Ref
463       -- End add new columns to select for the Add Customer}
464          , Xml_Message_Id
465          , nvl(ship_to_customer,		FND_API.G_MISS_CHAR)
466          , nvl(ship_to_customer_number,		FND_API.G_MISS_CHAR)
467          , nvl(ship_to_customer_id,		FND_API.G_MISS_NUM)
468          , nvl(invoice_customer,		FND_API.G_MISS_CHAR)
469          , nvl(invoice_customer_number,		FND_API.G_MISS_CHAR)
470          , nvl(invoice_customer_id,		FND_API.G_MISS_NUM)
471          , nvl(deliver_to_customer,	FND_API.G_MISS_CHAR)
472          , nvl(deliver_to_customer_number,	FND_API.G_MISS_CHAR)
473          , nvl(deliver_to_customer_id,	        FND_API.G_MISS_NUM)
474          , xml_transaction_type_code
475          , nvl(blanket_number,	                FND_API.G_MISS_NUM)
476          , nvl(shipping_method,                 FND_API.G_MISS_CHAR)
477          -- Added pricing_date for the bug 3001346
478 	 , nvl(pricing_date,			FND_API.G_MISS_DATE)
479          , response_flag
480 	 , nvl(sold_to_site_use_id, FND_API.G_MISS_NUM)
481 	 , nvl(sold_to_location_address1, FND_API.G_MISS_CHAR)
482 	 , nvl(sold_to_location_address2, FND_API.G_MISS_CHAR)
483 	 , nvl(sold_to_location_address3, FND_API.G_MISS_CHAR)
484 	 , nvl(sold_to_location_address4, FND_API.G_MISS_CHAR)
485 	 , nvl(sold_to_location_city, FND_API.G_MISS_CHAR)
486 	 , nvl(sold_to_location_postal_code, FND_API.G_MISS_CHAR)
487 	 , nvl(sold_to_location_country, FND_API.G_MISS_CHAR)
488 	 , nvl(sold_to_location_state, FND_API.G_MISS_CHAR)
489 	 , nvl(sold_to_location_county, FND_API.G_MISS_CHAR)
490 	 , nvl(sold_to_location_province, FND_API.G_MISS_CHAR)
491          -- automatic account creation {
492          , sold_to_party_id
493          , sold_to_org_contact_id
494          , ship_to_party_id
495          , ship_to_party_site_id
496          , ship_to_party_site_use_id
497          , deliver_to_party_id
498          , deliver_to_party_site_id
499          , deliver_to_party_site_use_id
500          , invoice_to_party_id
501          , invoice_to_party_site_id
502          , invoice_to_party_site_use_id
503      -- automatic account creation }
504      -- start if additional quoting columns
505          , nvl(transaction_phase_code, FND_API.G_MISS_CHAR)
506          , nvl(expiration_date, FND_API.G_MISS_DATE)
507          , nvl(quote_number, FND_API.G_MISS_NUM)
508          , nvl(quote_date, FND_API.G_MISS_DATE)
509          , nvl(sales_document_name, FND_API.G_MISS_CHAR)
510          , nvl(user_status_code, FND_API.G_MISS_CHAR)
511      -- end of additional quoting columns
512      -- { Distributer Order related change
513          , nvl(end_customer_id,                 FND_API.G_MISS_NUM)
514          , nvl(end_customer_contact_id,         FND_API.G_MISS_NUM)
515          , nvl(end_customer_site_use_id,        FND_API.G_MISS_NUM)
516        	 , nvl(end_customer_name,		FND_API.G_MISS_CHAR) --mvijayku
517 	 , nvl(end_customer_address1,		FND_API.G_MISS_CHAR)
518 	 , nvl(end_customer_address2,		FND_API.G_MISS_CHAR)
519 	 , nvl(end_customer_address3,		FND_API.G_MISS_CHAR)
520 	 , nvl(end_customer_address4,		FND_API.G_MISS_CHAR)
521 	-- , nvl(end_customer_location,		FND_API.G_MISS_CHAR)
522 	 , nvl(end_customer_city,		        FND_API.G_MISS_CHAR)
523 	 , nvl(end_customer_state,nvl(end_customer_province , FND_API.G_MISS_CHAR)) ---bug# 9395147 ,9878736
524 	 , nvl(end_customer_postal_code,	        FND_API.G_MISS_CHAR)
525 	 , nvl(end_customer_country,	                FND_API.G_MISS_CHAR)
526 	 , nvl(end_customer_contact,			FND_API.G_MISS_CHAR)
527          , nvl(end_customer_number,		FND_API.G_MISS_CHAR)
528          , nvl(ib_owner,                        FND_API.G_MISS_CHAR)
529          , nvl(ib_current_location,             FND_API.G_MISS_CHAR)
530          , nvl(ib_installed_at_location,        FND_API.G_MISS_CHAR)
531          , nvl(ib_owner_code,                   FND_API.G_MISS_CHAR)
532          , nvl(ib_current_location_code,        FND_API.G_MISS_CHAR)
533          , nvl(ib_installed_at_location_code,   FND_API.G_MISS_CHAR)
534 	 , END_CUSTOMER_PARTY_ID
535 	 , END_CUSTOMER_ORG_CONTACT_ID
536          , END_CUSTOMER_PARTY_SITE_ID
537          , END_CUSTOMER_PARTY_SITE_USE_ID
538          , END_CUSTOMER_PARTY_NUMBER
539      -- Distributer Order related change }
540      -- for automatic account creation
541          , sold_to_party_number
542          , ship_to_party_number
543          , invoice_to_party_number
544          , deliver_to_party_number
545      -- for automatic account creation
546          , nvl(deliver_to_address1,               FND_API.G_MISS_CHAR)
547          , nvl(deliver_to_address2,               FND_API.G_MISS_CHAR)
548          , nvl(deliver_to_address3,               FND_API.G_MISS_CHAR)
549          , nvl(deliver_to_address4,               FND_API.G_MISS_CHAR)
550          , nvl(deliver_to_state ,  nvl(deliver_to_province,FND_API.G_MISS_CHAR))   ---bug# 9395147 ,9878736
551          , nvl(deliver_to_county  ,               FND_API.G_MISS_CHAR)
552          , nvl(deliver_to_country ,               FND_API.G_MISS_CHAR)
553          , nvl(deliver_to_province,               FND_API.G_MISS_CHAR)
554          , nvl(deliver_to_city    ,               FND_API.G_MISS_CHAR)
555          , nvl(deliver_to_postal_code ,           FND_API.G_MISS_CHAR)
556          , nvl(instrument_security_code,          FND_API.G_MISS_CHAR)    --R12 CVV2
557       FROM oe_headers_iface_all
558      WHERE order_source_id 			= l_order_source_id
559        AND orig_sys_document_ref 		= l_orig_sys_document_ref
560        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
561          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
562        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
563          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
564        AND nvl(  change_sequence,		FND_API.G_MISS_CHAR)
565 	 = nvl(l_change_sequence,		FND_API.G_MISS_CHAR)
566        AND nvl(org_id,                          FND_API.G_MISS_NUM)
567          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
568        AND nvl(  request_id,			FND_API.G_MISS_NUM)
569 	 = nvl(l_request_id,			FND_API.G_MISS_NUM)
570        AND nvl(error_flag,'N')			= 'N'
571        AND nvl(ready_flag,'Y')			= 'Y'
572        AND nvl(rejected_flag,'N')		= 'N'
573        AND nvl(force_apply_flag,'Y')		= 'Y'
574   FOR UPDATE NOWAIT
575   ORDER BY org_id,order_source_id, orig_sys_document_ref, change_sequence
576 ;
577 
578 
579 /* -----------------------------------------------------------
580    Header Discounts/Price adjustments cursor
581    -----------------------------------------------------------
582 */
583     CURSOR l_header_adj_cursor IS
584     SELECT nvl(orig_sys_discount_ref,	FND_API.G_MISS_CHAR)
585 	 , nvl(change_request_code,	FND_API.G_MISS_CHAR)
586 	 , nvl(list_header_id,        FND_API.G_MISS_NUM)
587 	 , nvl(list_line_id,          FND_API.G_MISS_NUM)
588 	 , nvl(discount_name,		FND_API.G_MISS_CHAR)
589 	 , nvl(percent,			FND_API.G_MISS_NUM)
590 	 , nvl(automatic_flag,		FND_API.G_MISS_CHAR)
591 	 , nvl(applied_flag,		FND_API.G_MISS_CHAR)
592 	 , nvl(operand,			FND_API.G_MISS_NUM)
593 	 , nvl(arithmetic_operator,	FND_API.G_MISS_CHAR)
594 	 , nvl(context,			FND_API.G_MISS_CHAR)
595 	 , nvl(attribute1,		FND_API.G_MISS_CHAR)
596 	 , nvl(attribute2,		FND_API.G_MISS_CHAR)
597 	 , nvl(attribute3,		FND_API.G_MISS_CHAR)
598 	 , nvl(attribute4,		FND_API.G_MISS_CHAR)
599 	 , nvl(attribute5,		FND_API.G_MISS_CHAR)
600 	 , nvl(attribute6,		FND_API.G_MISS_CHAR)
601 	 , nvl(attribute7,		FND_API.G_MISS_CHAR)
602 	 , nvl(attribute8,		FND_API.G_MISS_CHAR)
603 	 , nvl(attribute9,		FND_API.G_MISS_CHAR)
604 	 , nvl(attribute10,		FND_API.G_MISS_CHAR)
605 	 , nvl(attribute11,		FND_API.G_MISS_CHAR)
606 	 , nvl(attribute12,		FND_API.G_MISS_CHAR)
607 	 , nvl(attribute13,		FND_API.G_MISS_CHAR)
608 	 , nvl(attribute14,		FND_API.G_MISS_CHAR)
609 	 , nvl(attribute15,		FND_API.G_MISS_CHAR)
610          , request_id
611 	 , nvl(operation_code,		OE_GLOBALS.G_OPR_CREATE)
612 	 , nvl(status_flag,		FND_API.G_MISS_CHAR)
613 -- Price Adjustment related changes bug# 1220921 (Start)
614       , nvl( AC_CONTEXT,                 FND_API.G_MISS_CHAR)
615       , nvl( AC_ATTRIBUTE1,              FND_API.G_MISS_CHAR)
616       , nvl( AC_ATTRIBUTE2,              FND_API.G_MISS_CHAR)
617       , nvl( AC_ATTRIBUTE3,              FND_API.G_MISS_CHAR)
618       , nvl( AC_ATTRIBUTE4,              FND_API.G_MISS_CHAR)
619       , nvl( AC_ATTRIBUTE5,              FND_API.G_MISS_CHAR)
620       , nvl( AC_ATTRIBUTE6,              FND_API.G_MISS_CHAR)
621       , nvl( AC_ATTRIBUTE7,              FND_API.G_MISS_CHAR)
622       , nvl( AC_ATTRIBUTE8,              FND_API.G_MISS_CHAR)
623       , nvl( AC_ATTRIBUTE9,              FND_API.G_MISS_CHAR)
624       , nvl( AC_ATTRIBUTE10,             FND_API.G_MISS_CHAR)
625       , nvl( AC_ATTRIBUTE11,             FND_API.G_MISS_CHAR)
626       , nvl( AC_ATTRIBUTE12,             FND_API.G_MISS_CHAR)
627       , nvl( AC_ATTRIBUTE13,             FND_API.G_MISS_CHAR)
628       , nvl( AC_ATTRIBUTE14,             FND_API.G_MISS_CHAR)
629       , nvl( AC_ATTRIBUTE15,             FND_API.G_MISS_CHAR)
630       , nvl( LIST_NAME,                  FND_API.G_MISS_CHAR)
631       , nvl( LIST_LINE_TYPE_CODE,        FND_API.G_MISS_CHAR)
632       , nvl( LIST_LINE_NUMBER,           FND_API.G_MISS_CHAR)
633       , nvl( VERSION_NUMBER,             FND_API.G_MISS_CHAR)
634       , nvl( INVOICED_FLAG,              FND_API.G_MISS_CHAR)
635       , nvl( ESTIMATED_FLAG,             FND_API.G_MISS_CHAR)
636       , nvl( INC_IN_SALES_PERFORMANCE,   FND_API.G_MISS_CHAR)
637       , nvl( CHARGE_TYPE_CODE,           FND_API.G_MISS_CHAR)
638       , nvl( CHARGE_SUBTYPE_CODE,        FND_API.G_MISS_CHAR)
639       , nvl( CREDIT_OR_CHARGE_FLAG,      FND_API.G_MISS_CHAR)
640       , nvl( INCLUDE_ON_RETURNS_FLAG,    FND_API.G_MISS_CHAR)
641       , nvl( COST_ID,                    FND_API.G_MISS_NUM)
642       , nvl( TAX_CODE,                   FND_API.G_MISS_CHAR)
643       , nvl( PARENT_ADJUSTMENT_ID,       FND_API.G_MISS_NUM)
644       , nvl(MODIFIER_MECHANISM_TYPE_CODE,FND_API.G_MISS_CHAR)
645       , nvl( MODIFIED_FROM,              FND_API.G_MISS_CHAR)
646       , nvl( MODIFIED_TO,                FND_API.G_MISS_CHAR)
647       , nvl( UPDATED_FLAG,               FND_API.G_MISS_CHAR)
648       , nvl( UPDATE_ALLOWED,             FND_API.G_MISS_CHAR)
649       , nvl( CHANGE_REASON_CODE,         FND_API.G_MISS_CHAR)
650       , nvl( CHANGE_REASON_TEXT,         FND_API.G_MISS_CHAR)
651       , nvl( PRICING_PHASE_ID,           FND_API.G_MISS_NUM)
652       , nvl( ADJUSTED_AMOUNT,            FND_API.G_MISS_NUM)
653 -- Price Adjustment related changes bug# 1220921 (End)
654       FROM oe_price_adjs_iface_all
655      WHERE order_source_id		= l_order_source_id
656        AND orig_sys_document_ref 	= l_orig_sys_document_ref
657        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
658          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
659        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
660          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
661        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
662 	 = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
663        AND nvl(org_id,                          FND_API.G_MISS_NUM)
664          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
665        AND nvl(orig_sys_line_ref,	FND_API.G_MISS_CHAR)
666 	 = 				FND_API.G_MISS_CHAR
667        AND nvl(orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
668 	 = 				FND_API.G_MISS_CHAR
669        AND nvl(  request_id,		FND_API.G_MISS_NUM)
670 	 = nvl(l_request_id,		FND_API.G_MISS_NUM)
671   FOR UPDATE NOWAIT
672   ORDER BY orig_sys_discount_ref
673 ;
674 
675 
676 /* -----------------------------------------------------------
677    Header Price attribute cursor
678    -----------------------------------------------------------
679 */
680      CURSOR l_header_attrib_cursor IS
681      SELECT nvl(orig_sys_atts_ref,   FND_API.G_MISS_CHAR)
682           , nvl(change_request_code,     FND_API.G_MISS_CHAR)
683           ,  nvl(creation_date	, FND_API.G_MISS_DATE)
684           ,  nvl(created_by		,   FND_API.G_MISS_NUM)
685           ,  nvl(last_update_date	, FND_API.G_MISS_DATE)
686           ,  nvl(last_updated_by		,   FND_API.G_MISS_NUM)
687           ,  nvl(last_update_login	,   FND_API.G_MISS_NUM)
688           ,  nvl(program_application_id	,   FND_API.G_MISS_NUM)
689           ,  nvl(program_id		,   FND_API.G_MISS_NUM)
690           ,  nvl(program_update_date,  FND_API.G_MISS_DATE)
691           ,  nvl(request_id		,   FND_API.G_MISS_NUM)
692           ,  nvl(flex_title		,   FND_API.G_MISS_CHAR)
693           ,  nvl(pricing_context	,   FND_API.G_MISS_CHAR)
694           ,  nvl(pricing_attribute1	,   FND_API.G_MISS_CHAR)
695           ,  nvl(pricing_attribute2	,   FND_API.G_MISS_CHAR)
696           ,  nvl(pricing_attribute3	,   FND_API.G_MISS_CHAR)
697           ,  nvl(pricing_attribute4	,   FND_API.G_MISS_CHAR)
698           ,  nvl(pricing_attribute5	,   FND_API.G_MISS_CHAR)
699           ,  nvl(pricing_attribute6	,   FND_API.G_MISS_CHAR)
700           ,  nvl(pricing_attribute7	,   FND_API.G_MISS_CHAR)
701           ,  nvl(pricing_attribute8	,   FND_API.G_MISS_CHAR)
702           ,  nvl(pricing_attribute9	,   FND_API.G_MISS_CHAR)
703           ,  nvl(pricing_attribute10	,   FND_API.G_MISS_CHAR)
704           ,  nvl(pricing_attribute11	,   FND_API.G_MISS_CHAR)
705           ,  nvl(pricing_attribute12	,   FND_API.G_MISS_CHAR)
706           ,  nvl(pricing_attribute13	,   FND_API.G_MISS_CHAR)
707           ,  nvl(pricing_attribute14	,   FND_API.G_MISS_CHAR)
708           ,  nvl(pricing_attribute15	,   FND_API.G_MISS_CHAR)
709           ,  nvl(pricing_attribute16	,   FND_API.G_MISS_CHAR)
710           ,  nvl(pricing_attribute17	,   FND_API.G_MISS_CHAR)
711           ,  nvl(pricing_attribute18	,   FND_API.G_MISS_CHAR)
712           ,  nvl(pricing_attribute19	,   FND_API.G_MISS_CHAR)
713           ,  nvl(pricing_attribute20	,   FND_API.G_MISS_CHAR)
714           ,  nvl(pricing_attribute21	,   FND_API.G_MISS_CHAR)
715           ,  nvl(pricing_attribute22	,   FND_API.G_MISS_CHAR)
716           ,  nvl(pricing_attribute23	,   FND_API.G_MISS_CHAR)
717           ,  nvl(pricing_attribute24	,   FND_API.G_MISS_CHAR)
718           ,  nvl(pricing_attribute25	,   FND_API.G_MISS_CHAR)
719           ,  nvl(pricing_attribute26	,   FND_API.G_MISS_CHAR)
720           ,  nvl(pricing_attribute27	,   FND_API.G_MISS_CHAR)
721           ,  nvl(pricing_attribute28	,   FND_API.G_MISS_CHAR)
722           ,  nvl(pricing_attribute29	,   FND_API.G_MISS_CHAR)
723           ,  nvl(pricing_attribute30	,   FND_API.G_MISS_CHAR)
724           ,  nvl(pricing_attribute31	,   FND_API.G_MISS_CHAR)
725           ,  nvl(pricing_attribute32	,   FND_API.G_MISS_CHAR)
726           ,  nvl(pricing_attribute33	,   FND_API.G_MISS_CHAR)
727           ,  nvl(pricing_attribute34	,   FND_API.G_MISS_CHAR)
728           ,  nvl(pricing_attribute35	,   FND_API.G_MISS_CHAR)
729           ,  nvl(pricing_attribute36	,   FND_API.G_MISS_CHAR)
730           ,  nvl(pricing_attribute37	,   FND_API.G_MISS_CHAR)
731           ,  nvl(pricing_attribute38	,   FND_API.G_MISS_CHAR)
732           ,  nvl(pricing_attribute39	,   FND_API.G_MISS_CHAR)
733           ,  nvl(pricing_attribute40	,   FND_API.G_MISS_CHAR)
734           ,  nvl(pricing_attribute41	,   FND_API.G_MISS_CHAR)
735           ,  nvl(pricing_attribute42	,   FND_API.G_MISS_CHAR)
736           ,  nvl(pricing_attribute43	,   FND_API.G_MISS_CHAR)
737           ,  nvl(pricing_attribute44	,   FND_API.G_MISS_CHAR)
738           ,  nvl(pricing_attribute45	,   FND_API.G_MISS_CHAR)
739           ,  nvl(pricing_attribute46	,   FND_API.G_MISS_CHAR)
740           ,  nvl(pricing_attribute47	,   FND_API.G_MISS_CHAR)
741           ,  nvl(pricing_attribute48	,   FND_API.G_MISS_CHAR)
742           ,  nvl(pricing_attribute49	,   FND_API.G_MISS_CHAR)
743           ,  nvl(pricing_attribute50	,   FND_API.G_MISS_CHAR)
744           ,  nvl(pricing_attribute51	,   FND_API.G_MISS_CHAR)
745           ,  nvl(pricing_attribute52	,   FND_API.G_MISS_CHAR)
746           ,  nvl(pricing_attribute53	,   FND_API.G_MISS_CHAR)
747           ,  nvl(pricing_attribute54	,   FND_API.G_MISS_CHAR)
748           ,  nvl(pricing_attribute55	,   FND_API.G_MISS_CHAR)
749           ,  nvl(pricing_attribute56	,   FND_API.G_MISS_CHAR)
750           ,  nvl(pricing_attribute57	,   FND_API.G_MISS_CHAR)
751           ,  nvl(pricing_attribute58	,   FND_API.G_MISS_CHAR)
752           ,  nvl(pricing_attribute59	,   FND_API.G_MISS_CHAR)
753           ,  nvl(pricing_attribute60	,   FND_API.G_MISS_CHAR)
754           ,  nvl(pricing_attribute61	,   FND_API.G_MISS_CHAR)
755           ,  nvl(pricing_attribute62	,   FND_API.G_MISS_CHAR)
756           ,  nvl(pricing_attribute63	,   FND_API.G_MISS_CHAR)
757           ,  nvl(pricing_attribute64	,   FND_API.G_MISS_CHAR)
758           ,  nvl(pricing_attribute65	,   FND_API.G_MISS_CHAR)
759           ,  nvl(pricing_attribute66	,   FND_API.G_MISS_CHAR)
760           ,  nvl(pricing_attribute67	,   FND_API.G_MISS_CHAR)
761           ,  nvl(pricing_attribute68	,   FND_API.G_MISS_CHAR)
762           ,  nvl(pricing_attribute69	,   FND_API.G_MISS_CHAR)
763           ,  nvl(pricing_attribute70	,   FND_API.G_MISS_CHAR)
764           ,  nvl(pricing_attribute71	,   FND_API.G_MISS_CHAR)
765           ,  nvl(pricing_attribute72	,   FND_API.G_MISS_CHAR)
766           ,  nvl(pricing_attribute73	,   FND_API.G_MISS_CHAR)
767           ,  nvl(pricing_attribute74	,   FND_API.G_MISS_CHAR)
768           ,  nvl(pricing_attribute75	,   FND_API.G_MISS_CHAR)
769           ,  nvl(pricing_attribute76	,   FND_API.G_MISS_CHAR)
770           ,  nvl(pricing_attribute77	,   FND_API.G_MISS_CHAR)
771           ,  nvl(pricing_attribute78	,   FND_API.G_MISS_CHAR)
772           ,  nvl(pricing_attribute79	,   FND_API.G_MISS_CHAR)
773           ,  nvl(pricing_attribute80	,   FND_API.G_MISS_CHAR)
774           ,  nvl(pricing_attribute81	,   FND_API.G_MISS_CHAR)
775           ,  nvl(pricing_attribute82	,   FND_API.G_MISS_CHAR)
776           ,  nvl(pricing_attribute83	,   FND_API.G_MISS_CHAR)
777           ,  nvl(pricing_attribute84	,   FND_API.G_MISS_CHAR)
778           ,  nvl(pricing_attribute85	,   FND_API.G_MISS_CHAR)
779           ,  nvl(pricing_attribute86	,   FND_API.G_MISS_CHAR)
780           ,  nvl(pricing_attribute87	,   FND_API.G_MISS_CHAR)
781           ,  nvl(pricing_attribute88	,   FND_API.G_MISS_CHAR)
782           ,  nvl(pricing_attribute89	,   FND_API.G_MISS_CHAR)
783           ,  nvl(pricing_attribute90	,   FND_API.G_MISS_CHAR)
784           ,  nvl(pricing_attribute91	,   FND_API.G_MISS_CHAR)
785           ,  nvl(pricing_attribute92	,   FND_API.G_MISS_CHAR)
786           ,  nvl(pricing_attribute93	,   FND_API.G_MISS_CHAR)
787           ,  nvl(pricing_attribute94	,   FND_API.G_MISS_CHAR)
788           ,  nvl(pricing_attribute95	,   FND_API.G_MISS_CHAR)
789           ,  nvl(pricing_attribute96	,   FND_API.G_MISS_CHAR)
790           ,  nvl(pricing_attribute97	,   FND_API.G_MISS_CHAR)
791           ,  nvl(pricing_attribute98	,   FND_API.G_MISS_CHAR)
792           ,  nvl(pricing_attribute99	,   FND_API.G_MISS_CHAR)
793           ,  nvl(pricing_attribute100	,   FND_API.G_MISS_CHAR)
794           ,  nvl(context 		,   FND_API.G_MISS_CHAR)
795           ,  nvl(attribute1		,   FND_API.G_MISS_CHAR)
796           ,  nvl(attribute2		,   FND_API.G_MISS_CHAR)
797           ,  nvl(attribute3		,   FND_API.G_MISS_CHAR)
798           ,  nvl(attribute4		,   FND_API.G_MISS_CHAR)
799           ,  nvl(attribute5		,   FND_API.G_MISS_CHAR)
800           ,  nvl(attribute6		,   FND_API.G_MISS_CHAR)
801           ,  nvl(attribute7		,   FND_API.G_MISS_CHAR)
802           ,  nvl(attribute8		,   FND_API.G_MISS_CHAR)
803           ,  nvl(attribute9		,   FND_API.G_MISS_CHAR)
804           ,  nvl(attribute10		,   FND_API.G_MISS_CHAR)
805           ,  nvl(attribute11		,   FND_API.G_MISS_CHAR)
806           ,  nvl(attribute12		,   FND_API.G_MISS_CHAR)
807           ,  nvl(attribute13		,   FND_API.G_MISS_CHAR)
808           ,  nvl(attribute14		,   FND_API.G_MISS_CHAR)
809           ,  nvl(attribute15		,   FND_API.G_MISS_CHAR)
810           ,  nvl(operation_code         ,   OE_GLOBALS.G_OPR_CREATE)
811          FROM oe_price_atts_iface_all
812          WHERE order_source_id              = l_order_source_id
813          AND orig_sys_document_ref        = l_orig_sys_document_ref
814          AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
815            = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
816          AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
817            = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
818          AND nvl(  change_sequence,              FND_API.G_MISS_CHAR)
819            = nvl(l_change_sequence,       FND_API.G_MISS_CHAR)
820          AND nvl(org_id,                          FND_API.G_MISS_NUM)
821          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
822          AND nvl(orig_sys_line_ref,       FND_API.G_MISS_CHAR)
823            =                              FND_API.G_MISS_CHAR
824          AND nvl(orig_sys_shipment_ref,   FND_API.G_MISS_CHAR)
825            =                              FND_API.G_MISS_CHAR
826          AND nvl(  request_id,            FND_API.G_MISS_NUM)
827            = nvl(l_request_id,            FND_API.G_MISS_NUM)
828   FOR UPDATE NOWAIT
829   ORDER  by orig_sys_document_ref;
830 
831 /* -----------------------------------------------------------
832    Header Sales Credits cursor
833    -----------------------------------------------------------
834 */
835     CURSOR l_header_scredit_cursor IS
836     SELECT nvl(orig_sys_credit_ref,	FND_API.G_MISS_CHAR)
837 	 , nvl(change_request_code,	FND_API.G_MISS_CHAR)
838 	 , nvl(salesrep_id,		FND_API.G_MISS_NUM)
839 	 , nvl(salesrep	,		FND_API.G_MISS_CHAR)
840 	 , nvl(sales_credit_type_id,	FND_API.G_MISS_NUM)
841 	 , nvl(sales_credit_type,	FND_API.G_MISS_CHAR)
842 	 , nvl(percent,			FND_API.G_MISS_NUM)
843 	 , nvl(context,			FND_API.G_MISS_CHAR)
844 	 , nvl(attribute1,		FND_API.G_MISS_CHAR)
845 	 , nvl(attribute2,		FND_API.G_MISS_CHAR)
846 	 , nvl(attribute3,		FND_API.G_MISS_CHAR)
847 	 , nvl(attribute4,		FND_API.G_MISS_CHAR)
848 	 , nvl(attribute5,		FND_API.G_MISS_CHAR)
849 	 , nvl(attribute6,		FND_API.G_MISS_CHAR)
850 	 , nvl(attribute7,		FND_API.G_MISS_CHAR)
851 	 , nvl(attribute8,		FND_API.G_MISS_CHAR)
852 	 , nvl(attribute9,		FND_API.G_MISS_CHAR)
853 	 , nvl(attribute10,		FND_API.G_MISS_CHAR)
854 	 , nvl(attribute11,		FND_API.G_MISS_CHAR)
855 	 , nvl(attribute12,		FND_API.G_MISS_CHAR)
856 	 , nvl(attribute13,		FND_API.G_MISS_CHAR)
857 	 , nvl(attribute14,		FND_API.G_MISS_CHAR)
858 	 , nvl(attribute15,		FND_API.G_MISS_CHAR)
859 	 , nvl(operation_code,		OE_GLOBALS.G_OPR_CREATE)
860 	 , nvl(status_flag,		FND_API.G_MISS_CHAR)
861          , nvl(change_reason,           FND_API.G_MISS_CHAR)
862          , nvl(change_comments,         FND_API.G_MISS_CHAR)
863       FROM oe_credits_iface_all
864      WHERE order_source_id 		= l_order_source_id
865        AND orig_sys_document_ref 	= l_orig_sys_document_ref
866        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
867          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
868        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
869          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
870        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
871 	 = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
872        AND nvl(org_id,                          FND_API.G_MISS_NUM)
873          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
874        AND nvl(orig_sys_line_ref,	FND_API.G_MISS_CHAR)
875 	 = 				FND_API.G_MISS_CHAR
876        AND nvl(orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
877 	 = 				FND_API.G_MISS_CHAR
878        AND nvl(  request_id,		FND_API.G_MISS_NUM)
879 	 = nvl(l_request_id,		FND_API.G_MISS_NUM)
880   FOR UPDATE NOWAIT
881   ORDER BY orig_sys_credit_ref
882 ;
883 
884 /* -----------------------------------------------------------
885    Multiple Payments: Header payments cursor
886    -----------------------------------------------------------
887 */
888 CURSOR l_header_payment_cursor IS
889 SELECT 	   nvl(orig_sys_payment_ref,	FND_API.G_MISS_CHAR)
890 	 , nvl(change_request_code,	FND_API.G_MISS_CHAR)
891 	 , nvl(payment_type_code,	FND_API.G_MISS_CHAR)
892 	 , nvl(commitment,		FND_API.G_MISS_CHAR)
893 	 , nvl(payment_trx_id,		FND_API.G_MISS_NUM)
894 	 , nvl(payment_method,		FND_API.G_MISS_CHAR)
895 	 , nvl(receipt_method_id,	FND_API.G_MISS_NUM)
896 	 , nvl(payment_collection_event,FND_API.G_MISS_CHAR)
897 	 , nvl(payment_set_id,		FND_API.G_MISS_NUM)
898 	 , nvl(prepaid_amount,		FND_API.G_MISS_NUM)
899 	 , nvl(credit_card_number,	FND_API.G_MISS_CHAR)
900 	 , nvl(credit_card_holder_name,	FND_API.G_MISS_CHAR)
901 	 , nvl(credit_card_expiration_date,FND_API.G_MISS_DATE)
902 	 , nvl(credit_card_code,	FND_API.G_MISS_CHAR)
903 	 , nvl(credit_card_approval_code,FND_API.G_MISS_CHAR)
904 	 , nvl(credit_card_approval_date,FND_API.G_MISS_DATE)
905 	 , nvl(check_number,		FND_API.G_MISS_CHAR)--6367320
906 	 , nvl(payment_amount,		FND_API.G_MISS_NUM)
907 	 , nvl(payment_percentage,	FND_API.G_MISS_NUM)
908 	 , nvl(creation_date,		FND_API.G_MISS_DATE)
909          , nvl(created_by,		FND_API.G_MISS_NUM)
910          , nvl(last_update_date,   	FND_API.G_MISS_DATE)
911          , nvl(last_updated_by,   	FND_API.G_MISS_NUM)
912          , nvl(last_update_login,   	FND_API.G_MISS_NUM)
913          , nvl(program_application_id,  FND_API.G_MISS_NUM)
914          , nvl(program_id,   		FND_API.G_MISS_NUM)
915          , nvl(program_update_date,   	FND_API.G_MISS_DATE)
916 	 , nvl(context,			FND_API.G_MISS_CHAR)
917 	 , nvl(attribute1,		FND_API.G_MISS_CHAR)
918 	 , nvl(attribute2,		FND_API.G_MISS_CHAR)
919 	 , nvl(attribute3,		FND_API.G_MISS_CHAR)
920 	 , nvl(attribute4,		FND_API.G_MISS_CHAR)
921 	 , nvl(attribute5,		FND_API.G_MISS_CHAR)
922 	 , nvl(attribute6,		FND_API.G_MISS_CHAR)
923 	 , nvl(attribute7,		FND_API.G_MISS_CHAR)
924 	 , nvl(attribute8,		FND_API.G_MISS_CHAR)
925 	 , nvl(attribute9,		FND_API.G_MISS_CHAR)
926 	 , nvl(attribute10,		FND_API.G_MISS_CHAR)
927 	 , nvl(attribute11,		FND_API.G_MISS_CHAR)
928 	 , nvl(attribute12,		FND_API.G_MISS_CHAR)
929 	 , nvl(attribute13,		FND_API.G_MISS_CHAR)
930 	 , nvl(attribute14,		FND_API.G_MISS_CHAR)
931 	 , nvl(attribute15,		FND_API.G_MISS_CHAR)
932 	 , nvl(operation_code,		OE_GLOBALS.G_OPR_CREATE)
933 	 , nvl(status_flag,		FND_API.G_MISS_CHAR)
934 	 , nvl(payment_number,		FND_API.G_MISS_NUM)
935 	 , nvl(header_id,		FND_API.G_MISS_NUM)
936 	 , nvl(line_id,			FND_API.G_MISS_NUM)
937          , nvl(DEFER_PAYMENT_PROCESSING_FLAG, FND_API.G_MISS_CHAR) -- Added for bug 8478559
938 	 , nvl(trxn_extension_id,       FND_API.G_MISS_NUM)
939          , nvl(instrument_security_code,FND_API.G_MISS_CHAR)  --R12 CVV2
940    FROM  oe_payments_iface_all
941   WHERE  order_source_id              = l_order_source_id
942     AND  orig_sys_document_ref        = l_orig_sys_document_ref
943     AND  nvl(  change_sequence,       FND_API.G_MISS_CHAR)
944       =  nvl(l_change_sequence,       FND_API.G_MISS_CHAR)
945     AND nvl(org_id,                          FND_API.G_MISS_NUM)
946          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
947     AND  nvl(orig_sys_line_ref,       FND_API.G_MISS_CHAR)
948       =                               FND_API.G_MISS_CHAR
949     AND  nvl(orig_sys_shipment_ref,   FND_API.G_MISS_CHAR)
950       =                               FND_API.G_MISS_CHAR
951     AND  nvl(  request_id,            FND_API.G_MISS_NUM)
952       =  nvl(l_request_id,            FND_API.G_MISS_NUM)
953 FOR UPDATE NOWAIT
954 ORDER BY orig_sys_payment_ref;
955 -- end of multiple payments: header payment cursor.
956 
957 
958 /* -----------------------------------------------------------
959    Lines cursor
960    -----------------------------------------------------------
961 */
962     CURSOR l_line_cursor IS
963     SELECT nvl(order_source_id,			FND_API.G_MISS_NUM)
964     	 , nvl(orig_sys_document_ref,		FND_API.G_MISS_CHAR)
965     	 , nvl(orig_sys_line_ref,		FND_API.G_MISS_CHAR)
966 	 , nvl(orig_sys_shipment_ref,		FND_API.G_MISS_CHAR)
967 	 , nvl(change_request_code,		FND_API.G_MISS_CHAR)
968 	 , nvl(org_id,				FND_API.G_MISS_NUM)
969 	 , nvl(line_number,			FND_API.G_MISS_NUM)
970 	 , nvl(shipment_number,			FND_API.G_MISS_NUM)
971 	 , nvl(line_id,				FND_API.G_MISS_NUM)
972 	 , nvl(line_type_id,			FND_API.G_MISS_NUM)
973 	 , nvl(line_type,			FND_API.G_MISS_CHAR)
974 	 , nvl(item_type_code,			FND_API.G_MISS_CHAR)
975 	 , nvl(inventory_item_id,		FND_API.G_MISS_NUM)
976 	 , nvl(inventory_item,			FND_API.G_MISS_CHAR)
977 	 , nvl(top_model_line_ref,		FND_API.G_MISS_CHAR)
978 	 , nvl(link_to_line_ref,		FND_API.G_MISS_CHAR)
979 	 , nvl(explosion_date,			FND_API.G_MISS_DATE)
980 	 , nvl(ato_line_id,			FND_API.G_MISS_NUM)
981 	 , nvl(component_sequence_id,		FND_API.G_MISS_NUM)
982 	 , nvl(component_code,			FND_API.G_MISS_CHAR)
983 	 , nvl(sort_order,			FND_API.G_MISS_CHAR)
984 	 , nvl(model_group_number,		FND_API.G_MISS_NUM)
985 	 , nvl(option_number,			FND_API.G_MISS_NUM)
986 	 , nvl(option_flag,			'N')
987 	 , nvl(ship_model_complete_flag,	FND_API.G_MISS_CHAR)
988 	 , nvl(source_type_code,		FND_API.G_MISS_CHAR)
989 	 , nvl(schedule_status_code,		FND_API.G_MISS_CHAR)
990 	 , nvl(schedule_ship_date,		FND_API.G_MISS_DATE)
991          , nvl(late_demand_penalty_factor,      FND_API.G_MISS_NUM)
992 	 , nvl(schedule_arrival_date,		FND_API.G_MISS_DATE)
993 	 , nvl(actual_arrival_date,		FND_API.G_MISS_DATE)
994   	 , nvl(request_date,			FND_API.G_MISS_DATE)
995 	 , nvl(promise_date,			FND_API.G_MISS_DATE)
996 	 , nvl(delivery_lead_time,		FND_API.G_MISS_NUM)
997 	 , nvl(ordered_quantity,		FND_API.G_MISS_NUM)
998 	 , nvl(order_quantity_uom ,		FND_API.G_MISS_CHAR)
999 	 , nvl(shipping_quantity,		FND_API.G_MISS_NUM)
1000 	 , nvl(shipping_quantity_uom,		FND_API.G_MISS_CHAR)
1001 	 , nvl(shipped_quantity,		FND_API.G_MISS_NUM)
1002 	 , nvl(cancelled_quantity,		FND_API.G_MISS_NUM)
1003 	 , nvl(fulfilled_quantity,		FND_API.G_MISS_NUM)
1004    /* OPM variables */
1005          , nvl(ordered_quantity2,               FND_API.G_MISS_NUM)
1006          , nvl(ordered_quantity_uom2 ,          FND_API.G_MISS_CHAR)
1007          , nvl(shipping_quantity2,              FND_API.G_MISS_NUM)
1008          , nvl(shipping_quantity_uom2,          FND_API.G_MISS_CHAR)
1009          , nvl(shipped_quantity2,               FND_API.G_MISS_NUM)
1010          , nvl(cancelled_quantity2,             FND_API.G_MISS_NUM)
1011          , nvl(fulfilled_quantity2,             FND_API.G_MISS_NUM)
1012          , nvl(preferred_grade,                 FND_API.G_MISS_CHAR)
1013    /* end of OPM variables */
1014 	 , nvl(pricing_quantity,		FND_API.G_MISS_NUM)
1015 	 , nvl(pricing_quantity_uom,		FND_API.G_MISS_CHAR)
1016 	 , nvl(sold_from_org_id,		FND_API.G_MISS_NUM)
1017 	 , nvl(sold_from_org,			FND_API.G_MISS_CHAR)
1018 	 , nvl(sold_to_org_id ,			FND_API.G_MISS_NUM)
1019 	 , nvl(sold_to_org,			FND_API.G_MISS_CHAR)
1020 	 , nvl(ship_from_org_id,		FND_API.G_MISS_NUM)
1021 	 , nvl(ship_from_org,			FND_API.G_MISS_CHAR)
1022 	 , nvl(ship_to_org_id ,			FND_API.G_MISS_NUM)
1023 	 , nvl(ship_to_org,			FND_API.G_MISS_CHAR)
1024 	 , nvl(deliver_to_org_id,		FND_API.G_MISS_NUM)
1025 	 , nvl(deliver_to_org,			FND_API.G_MISS_CHAR)
1026 	 , nvl(invoice_to_org_id,		FND_API.G_MISS_NUM)
1027 	 , nvl(invoice_to_org,			FND_API.G_MISS_CHAR)
1028 	 , nvl(ship_to_address1,		FND_API.G_MISS_CHAR)
1029 	 , nvl(ship_to_address2,		FND_API.G_MISS_CHAR)
1030 	 , nvl(ship_to_address3,		FND_API.G_MISS_CHAR)
1031 	 , nvl(ship_to_address4,		FND_API.G_MISS_CHAR)
1032 	 , nvl(ship_to_city,		        FND_API.G_MISS_CHAR)
1033 	 , nvl(ship_to_state,nvl(ship_to_province ,FND_API.G_MISS_CHAR))   ---bug# 9395147 ,9878736
1034 	 , nvl(ship_to_postal_code,	        FND_API.G_MISS_CHAR)
1035 	 , nvl(ship_to_country,	                FND_API.G_MISS_CHAR)
1036 	 , nvl(ship_to_contact_id,		FND_API.G_MISS_NUM)
1037 	 , nvl(ship_to_contact,			FND_API.G_MISS_CHAR)
1038 	 , nvl(deliver_to_contact_id,		FND_API.G_MISS_NUM)
1039 	 , nvl(deliver_to_contact,		FND_API.G_MISS_CHAR)
1040 	 , nvl(invoice_to_contact_id,		FND_API.G_MISS_NUM)
1041 	 , nvl(invoice_to_contact,		FND_API.G_MISS_CHAR)
1042 	 , nvl(drop_ship_flag,		        FND_API.G_MISS_CHAR)
1043 	 , nvl(ship_tolerance_above,		FND_API.G_MISS_NUM)
1044 	 , nvl(ship_tolerance_below,		FND_API.G_MISS_NUM)
1045 	 , nvl(price_list_id,			FND_API.G_MISS_NUM)
1046 	 , nvl(price_list,			FND_API.G_MISS_CHAR)
1047 	 , nvl(pricing_date,			FND_API.G_MISS_DATE)
1048 	 , nvl(unit_list_price,			FND_API.G_MISS_NUM)
1049 	 , nvl(unit_selling_price,		FND_API.G_MISS_NUM)
1050 	 --, nvl(calculate_price_flag,		'Y')		     --commented for BUG#7304558
1051 	 , nvl(calculate_price_flag,		FND_API.G_MISS_CHAR) --added for BUG#7304558
1052 	 , nvl(ship_set_id,			FND_API.G_MISS_NUM)
1053 	 , nvl(ship_set_name,			FND_API.G_MISS_CHAR)
1054 	 , nvl(arrival_set_id,			FND_API.G_MISS_NUM)
1055 	 , nvl(arrival_set_name,		FND_API.G_MISS_CHAR)
1056 	 , nvl(fulfillment_set_id,		FND_API.G_MISS_NUM)
1057 	 , nvl(fulfillment_set_name,		FND_API.G_MISS_CHAR)
1058 	 , nvl(tax_code,			FND_API.G_MISS_CHAR)
1059 	 , nvl(tax_value,			FND_API.G_MISS_NUM)
1060 	 , nvl(tax_date,			FND_API.G_MISS_DATE)
1061 	 , nvl(tax_point_code,			FND_API.G_MISS_CHAR)
1062 	 , nvl(tax_point,			FND_API.G_MISS_CHAR)
1063 	 , nvl(tax_exempt_flag,			FND_API.G_MISS_CHAR)
1064 	 , nvl(tax_exempt_number,		FND_API.G_MISS_CHAR)
1065 	 , nvl(tax_exempt_reason_code,		FND_API.G_MISS_CHAR)
1066 	 , nvl(tax_exempt_reason,		FND_API.G_MISS_CHAR)
1067 	 , nvl(agreement_id,			FND_API.G_MISS_NUM)
1068 	 , nvl(agreement,			FND_API.G_MISS_CHAR)
1069 	 , nvl(invoicing_rule_id,		FND_API.G_MISS_NUM)
1070 	 , nvl(invoicing_rule,			FND_API.G_MISS_CHAR)
1071 	 , nvl(accounting_rule_id,		FND_API.G_MISS_NUM)
1072 	 , nvl(accounting_rule_duration,	FND_API.G_MISS_NUM)
1073 	 , nvl(accounting_rule,			FND_API.G_MISS_CHAR)
1074 	 , nvl(payment_term_id,			FND_API.G_MISS_NUM)
1075 	 , nvl(payment_term,			FND_API.G_MISS_CHAR)
1076 	 , nvl(demand_class_code,		FND_API.G_MISS_CHAR)
1077 	 , nvl(shipment_priority_code,		FND_API.G_MISS_CHAR)
1078 	 , nvl(shipment_priority,		FND_API.G_MISS_CHAR)
1079 	 , nvl(shipping_method_code,		FND_API.G_MISS_CHAR)
1080 	 , nvl(shipping_instructions,		FND_API.G_MISS_CHAR)
1081 	 , nvl(packing_instructions,		FND_API.G_MISS_CHAR)
1082 	 , nvl(freight_carrier_code,		FND_API.G_MISS_CHAR)
1083 	 , nvl(freight_terms_code,		FND_API.G_MISS_CHAR)
1084 	 , nvl(freight_terms,			FND_API.G_MISS_CHAR)
1085 	 , nvl(fob_point_code,			FND_API.G_MISS_CHAR)
1086 	 , nvl(fob_point,			FND_API.G_MISS_CHAR)
1087 	 , nvl(return_reason_code,		FND_API.G_MISS_CHAR)
1088 	 , nvl(reference_type,			FND_API.G_MISS_CHAR)
1089 	 , nvl(reference_header_id,		FND_API.G_MISS_NUM)
1090 	 , nvl(reference_line_id,		FND_API.G_MISS_NUM)
1091 	 , nvl(credit_invoice_line_id,		FND_API.G_MISS_NUM)
1092 	 , nvl(customer_po_number,		FND_API.G_MISS_CHAR)
1093           --bug#4063831:
1094           --FP:11I9-12.0CUST_PRODUCTION_SEQ_NUM IS NOT GETTING POPULATED
1095           -- DURING ORDER IMPORT
1096          , nvl(cust_production_seq_num,         FND_API.G_MISS_CHAR)
1097 	 , nvl(customer_line_number,		FND_API.G_MISS_CHAR)
1098 	 , nvl(customer_shipment_number,	FND_API.G_MISS_CHAR)
1099 	 , nvl(customer_item_id,		FND_API.G_MISS_NUM)
1100 	 , nvl(customer_item_id_type,		FND_API.G_MISS_CHAR)
1101 	 , nvl(customer_item_name,		FND_API.G_MISS_CHAR)
1102 --	 , nvl(customer_item_revision,		FND_API.G_MISS_CHAR)
1103 	 , nvl(customer_item_net_price,		FND_API.G_MISS_NUM)
1104 	 , nvl(customer_payment_term_id,	FND_API.G_MISS_NUM)
1105 	 , nvl(customer_payment_term,		FND_API.G_MISS_CHAR)
1106 	 , nvl(demand_bucket_type_code,		FND_API.G_MISS_CHAR)
1107 	 , nvl(demand_bucket_type,		FND_API.G_MISS_CHAR)
1108 	 , nvl(customer_dock_code,		FND_API.G_MISS_CHAR)
1109 	 , nvl(customer_job,			FND_API.G_MISS_CHAR)
1110 	 , nvl(customer_production_line,	FND_API.G_MISS_CHAR)
1111 	 , nvl(cust_model_serial_number,	FND_API.G_MISS_CHAR)
1112 	 , nvl(project_id,			FND_API.G_MISS_NUM)
1113 	 , nvl(project,				FND_API.G_MISS_CHAR)
1114 	 , nvl(task_id,				FND_API.G_MISS_NUM)
1115 	 , nvl(task,				FND_API.G_MISS_CHAR)
1116 	 , nvl(end_item_unit_number,		FND_API.G_MISS_CHAR)
1117 	 , nvl(item_revision,			FND_API.G_MISS_CHAR)
1118 	 , nvl(service_duration,		FND_API.G_MISS_NUM)
1119 	 , nvl(service_period,			FND_API.G_MISS_CHAR)
1120 	 , nvl(service_start_date,		FND_API.G_MISS_DATE)
1121 	 , nvl(service_end_date,		FND_API.G_MISS_DATE)
1122 	 , nvl(service_coterminate_flag,	FND_API.G_MISS_CHAR)
1123 	 , nvl(unit_selling_percent,		FND_API.G_MISS_NUM)
1124 	 , nvl(unit_list_percent,		FND_API.G_MISS_NUM)
1125 	 , nvl(unit_percent_base_price,		FND_API.G_MISS_NUM)
1126 	 , nvl(service_number,			FND_API.G_MISS_NUM)
1127 --	 , nvl(fulfilled_flag,			FND_API.G_MISS_CHAR)--ToBeAdded
1128 --	 , nvl(closed_flag,			FND_API.G_MISS_CHAR)
1129 	 , nvl(cancelled_flag,			FND_API.G_MISS_CHAR)
1130 	 , nvl(context,                         FND_API.G_MISS_CHAR)
1131 	 , nvl(attribute1,			FND_API.G_MISS_CHAR)
1132 	 , nvl(attribute2,			FND_API.G_MISS_CHAR)
1133 	 , nvl(attribute3,			FND_API.G_MISS_CHAR)
1134 	 , nvl(attribute4,			FND_API.G_MISS_CHAR)
1135 	 , nvl(attribute5,			FND_API.G_MISS_CHAR)
1136 	 , nvl(attribute6,			FND_API.G_MISS_CHAR)
1137 	 , nvl(attribute7,			FND_API.G_MISS_CHAR)
1138 	 , nvl(attribute8,			FND_API.G_MISS_CHAR)
1139 	 , nvl(attribute9,			FND_API.G_MISS_CHAR)
1140 	 , nvl(attribute10,			FND_API.G_MISS_CHAR)
1141 	 , nvl(attribute11,			FND_API.G_MISS_CHAR)
1142 	 , nvl(attribute12,			FND_API.G_MISS_CHAR)
1143 	 , nvl(attribute13,			FND_API.G_MISS_CHAR)
1144 	 , nvl(attribute14,			FND_API.G_MISS_CHAR)
1145 	 , nvl(attribute15,			FND_API.G_MISS_CHAR)
1146 	 , nvl(attribute16,			FND_API.G_MISS_CHAR)  -- for bug 2184255
1147 	 , nvl(attribute17,			FND_API.G_MISS_CHAR)
1148 	 , nvl(attribute18,			FND_API.G_MISS_CHAR)
1149 	 , nvl(attribute19,			FND_API.G_MISS_CHAR)
1150 	 , nvl(attribute20,			FND_API.G_MISS_CHAR)
1151 	 , nvl(tp_context,			FND_API.G_MISS_CHAR)
1152 	 , nvl(tp_attribute1,			FND_API.G_MISS_CHAR)
1153 	 , nvl(tp_attribute2,			FND_API.G_MISS_CHAR)
1154 	 , nvl(tp_attribute3,			FND_API.G_MISS_CHAR)
1155 	 , nvl(tp_attribute4,			FND_API.G_MISS_CHAR)
1156 	 , nvl(tp_attribute5,			FND_API.G_MISS_CHAR)
1157 	 , nvl(tp_attribute6,			FND_API.G_MISS_CHAR)
1158 	 , nvl(tp_attribute7,			FND_API.G_MISS_CHAR)
1159 	 , nvl(tp_attribute8,			FND_API.G_MISS_CHAR)
1160 	 , nvl(tp_attribute9,			FND_API.G_MISS_CHAR)
1161 	 , nvl(tp_attribute10,			FND_API.G_MISS_CHAR)
1162 	 , nvl(tp_attribute11,			FND_API.G_MISS_CHAR)
1163 	 , nvl(tp_attribute12,			FND_API.G_MISS_CHAR)
1164 	 , nvl(tp_attribute13,			FND_API.G_MISS_CHAR)
1165 	 , nvl(tp_attribute14,			FND_API.G_MISS_CHAR)
1166 	 , nvl(tp_attribute15,			FND_API.G_MISS_CHAR)
1167 	 , nvl(industry_context,		FND_API.G_MISS_CHAR)
1168 	 , nvl(industry_attribute1,		FND_API.G_MISS_CHAR)
1169 	 , nvl(industry_attribute2,		FND_API.G_MISS_CHAR)
1170 	 , nvl(industry_attribute3,		FND_API.G_MISS_CHAR)
1171 	 , nvl(industry_attribute4,		FND_API.G_MISS_CHAR)
1172 	 , nvl(industry_attribute5,		FND_API.G_MISS_CHAR)
1173 	 , nvl(industry_attribute6,		FND_API.G_MISS_CHAR)
1174 	 , nvl(industry_attribute7,		FND_API.G_MISS_CHAR)
1175 	 , nvl(industry_attribute8,		FND_API.G_MISS_CHAR)
1176 	 , nvl(industry_attribute9,		FND_API.G_MISS_CHAR)
1177 	 , nvl(industry_attribute10,		FND_API.G_MISS_CHAR)
1178 	 , nvl(industry_attribute11,		FND_API.G_MISS_CHAR)
1179 	 , nvl(industry_attribute12,		FND_API.G_MISS_CHAR)
1180 	 , nvl(industry_attribute13,		FND_API.G_MISS_CHAR)
1181 	 , nvl(industry_attribute14,		FND_API.G_MISS_CHAR)
1182 	 , nvl(industry_attribute15,		FND_API.G_MISS_CHAR)
1183 	 , nvl(industry_attribute16,		FND_API.G_MISS_CHAR)
1184 	 , nvl(industry_attribute17,		FND_API.G_MISS_CHAR)
1185 	 , nvl(industry_attribute18,		FND_API.G_MISS_CHAR)
1186 	 , nvl(industry_attribute19,		FND_API.G_MISS_CHAR)
1187 	 , nvl(industry_attribute20,		FND_API.G_MISS_CHAR)
1188 	 , nvl(industry_attribute21,		FND_API.G_MISS_CHAR)
1189 	 , nvl(industry_attribute22,		FND_API.G_MISS_CHAR)
1190 	 , nvl(industry_attribute23,		FND_API.G_MISS_CHAR)
1191 	 , nvl(industry_attribute24,		FND_API.G_MISS_CHAR)
1192 	 , nvl(industry_attribute25,		FND_API.G_MISS_CHAR)
1193 	 , nvl(industry_attribute26,		FND_API.G_MISS_CHAR)
1194 	 , nvl(industry_attribute27,		FND_API.G_MISS_CHAR)
1195 	 , nvl(industry_attribute28,		FND_API.G_MISS_CHAR)
1196 	 , nvl(industry_attribute29,		FND_API.G_MISS_CHAR)
1197 	 , nvl(industry_attribute30,		FND_API.G_MISS_CHAR)
1198 	 , nvl(pricing_context,			FND_API.G_MISS_CHAR)
1199 	 , nvl(pricing_attribute1,		FND_API.G_MISS_CHAR)
1200 	 , nvl(pricing_attribute2,		FND_API.G_MISS_CHAR)
1201 	 , nvl(pricing_attribute3,		FND_API.G_MISS_CHAR)
1202 	 , nvl(pricing_attribute4,		FND_API.G_MISS_CHAR)
1203 	 , nvl(pricing_attribute5,		FND_API.G_MISS_CHAR)
1204 	 , nvl(pricing_attribute6,		FND_API.G_MISS_CHAR)
1205 	 , nvl(pricing_attribute7,		FND_API.G_MISS_CHAR)
1206 	 , nvl(pricing_attribute8,		FND_API.G_MISS_CHAR)
1207 	 , nvl(pricing_attribute9,		FND_API.G_MISS_CHAR)
1208 	 , nvl(pricing_attribute10,		FND_API.G_MISS_CHAR)
1209 	 , nvl(global_attribute_category,	FND_API.G_MISS_CHAR)
1210 	 , nvl(global_attribute1,		FND_API.G_MISS_CHAR)
1211 	 , nvl(global_attribute2,		FND_API.G_MISS_CHAR)
1212 	 , nvl(global_attribute3,		FND_API.G_MISS_CHAR)
1213 	 , nvl(global_attribute4,		FND_API.G_MISS_CHAR)
1214 	 , nvl(global_attribute5,		FND_API.G_MISS_CHAR)
1215 	 , nvl(global_attribute6,		FND_API.G_MISS_CHAR)
1216 	 , nvl(global_attribute7,		FND_API.G_MISS_CHAR)
1217 	 , nvl(global_attribute8,		FND_API.G_MISS_CHAR)
1218 	 , nvl(global_attribute9,		FND_API.G_MISS_CHAR)
1219 	 , nvl(global_attribute10,		FND_API.G_MISS_CHAR)
1220 	 , nvl(global_attribute11,		FND_API.G_MISS_CHAR)
1221 	 , nvl(global_attribute12,		FND_API.G_MISS_CHAR)
1222 	 , nvl(global_attribute13,		FND_API.G_MISS_CHAR)
1223 	 , nvl(global_attribute14,		FND_API.G_MISS_CHAR)
1224 	 , nvl(global_attribute15,		FND_API.G_MISS_CHAR)
1225 	 , nvl(global_attribute16,		FND_API.G_MISS_CHAR)
1226 	 , nvl(global_attribute17,		FND_API.G_MISS_CHAR)
1227 	 , nvl(global_attribute18,		FND_API.G_MISS_CHAR)
1228 	 , nvl(global_attribute19,		FND_API.G_MISS_CHAR)
1229 	 , nvl(global_attribute20,		FND_API.G_MISS_CHAR)
1230 	 , nvl(return_context,                  FND_API.G_MISS_CHAR)
1231 	 , nvl(return_attribute1,		FND_API.G_MISS_CHAR)
1232 	 , nvl(return_attribute2,		FND_API.G_MISS_CHAR)
1233 	 , nvl(return_attribute3,		FND_API.G_MISS_CHAR)
1234 	 , nvl(return_attribute4,		FND_API.G_MISS_CHAR)
1235 	 , nvl(return_attribute5,		FND_API.G_MISS_CHAR)
1236 	 , nvl(return_attribute6,		FND_API.G_MISS_CHAR)
1237 	 , nvl(return_attribute7,		FND_API.G_MISS_CHAR)
1238 	 , nvl(return_attribute8,		FND_API.G_MISS_CHAR)
1239 	 , nvl(return_attribute9,		FND_API.G_MISS_CHAR)
1240 	 , nvl(return_attribute10,		FND_API.G_MISS_CHAR)
1241 	 , nvl(return_attribute11,		FND_API.G_MISS_CHAR)
1242 	 , nvl(return_attribute12,		FND_API.G_MISS_CHAR)
1243 	 , nvl(return_attribute13,		FND_API.G_MISS_CHAR)
1244 	 , nvl(return_attribute14,		FND_API.G_MISS_CHAR)
1245 	 , nvl(return_attribute15,		FND_API.G_MISS_CHAR)
1246          , request_id
1247 	 , nvl(operation_code,			OE_GLOBALS.G_OPR_CREATE)
1248 	 , nvl(status_flag,		        FND_API.G_MISS_CHAR)
1249 	 , nvl(change_reason,			FND_API.G_MISS_CHAR)
1250 	 , nvl(change_comments,			FND_API.G_MISS_CHAR)
1251 	 , nvl(service_txn_reason_code,	        FND_API.G_MISS_CHAR)
1252 	 , nvl(service_txn_comments,		FND_API.G_MISS_CHAR)
1253 	 , nvl(service_reference_type_code,     FND_API.G_MISS_CHAR)
1254 	 , nvl(service_reference_order,	        FND_API.G_MISS_CHAR)
1255 	 , nvl(service_reference_line,	        FND_API.G_MISS_CHAR)
1256 	 , nvl(service_reference_system,	FND_API.G_MISS_CHAR)
1257 	 , INVENTORY_ITEM_SEGMENT_1
1258 	 , INVENTORY_ITEM_SEGMENT_2
1259 	 , INVENTORY_ITEM_SEGMENT_3
1260 	 , INVENTORY_ITEM_SEGMENT_4
1261 	 , INVENTORY_ITEM_SEGMENT_5
1262 	 , INVENTORY_ITEM_SEGMENT_6
1263 	 , INVENTORY_ITEM_SEGMENT_7
1264 	 , INVENTORY_ITEM_SEGMENT_8
1265 	 , INVENTORY_ITEM_SEGMENT_9
1266 	 , INVENTORY_ITEM_SEGMENT_10
1267 	 , INVENTORY_ITEM_SEGMENT_11
1268 	 , INVENTORY_ITEM_SEGMENT_12
1269 	 , INVENTORY_ITEM_SEGMENT_13
1270 	 , INVENTORY_ITEM_SEGMENT_14
1271 	 , INVENTORY_ITEM_SEGMENT_15
1272 	 , INVENTORY_ITEM_SEGMENT_16
1273 	 , INVENTORY_ITEM_SEGMENT_17
1274 	 , INVENTORY_ITEM_SEGMENT_18
1275 	 , INVENTORY_ITEM_SEGMENT_19
1276 	 , INVENTORY_ITEM_SEGMENT_20
1277 	 , nvl(commitment,		       FND_API.G_MISS_CHAR)
1278 	 , nvl(commitment_id,		       FND_API.G_MISS_NUM)
1279 -- aksingh subinventory
1280       , nvl(subinventory,                      FND_API.G_MISS_CHAR)
1281       ,nvl(salesrep,                           FND_API.G_MISS_CHAR)
1282       ,nvl(salesrep_id,                        FND_API.G_MISS_NUM)
1283       , nvl(earliest_acceptable_date,          FND_API.G_MISS_DATE)
1284       , nvl(latest_acceptable_date,            FND_API.G_MISS_DATE)
1285       , split_from_line_ref --bsadri
1286       , split_from_shipment_ref
1287 	 , nvl(invoice_to_address1,	       FND_API.G_MISS_CHAR)
1288 	 , nvl(invoice_to_address2,	       FND_API.G_MISS_CHAR)
1289 	 , nvl(invoice_to_address3,	       FND_API.G_MISS_CHAR)
1290 	 , nvl(invoice_to_address4,	       FND_API.G_MISS_CHAR)
1291 	 , nvl(invoice_to_city,		       FND_API.G_MISS_CHAR)
1292 	 , nvl(invoice_to_state,nvl(invoice_to_province ,FND_API.G_MISS_CHAR))   ----bug# 9395147 ,9878736
1293 	 , nvl(invoice_to_postal_code,	       FND_API.G_MISS_CHAR)
1294 	 , nvl(invoice_to_country,	       FND_API.G_MISS_CHAR)
1295       -- { Start add new columns to select for the Add Customer
1296          , Orig_Ship_Address_Ref
1297          , Orig_Bill_Address_Ref
1298          , Orig_Deliver_Address_Ref
1299          , Ship_to_Contact_Ref
1300          , Bill_to_Contact_Ref
1301          , Deliver_to_Contact_Ref
1302       -- End add new columns to select for the Add Customer}
1303          , nvl(Config_Header_Id,               FND_API.G_MISS_NUM)
1304          , nvl(Config_Rev_Nbr,                 FND_API.G_MISS_NUM)
1305          , nvl(Configuration_ID,               FND_API.G_MISS_NUM)
1306          , nvl(ship_to_customer_name,	       FND_API.G_MISS_CHAR)
1307          , nvl(ship_to_customer_number,	       FND_API.G_MISS_CHAR)
1308          , nvl(ship_to_customer_id,	       FND_API.G_MISS_NUM)
1309          , nvl(invoice_to_customer_name,       FND_API.G_MISS_CHAR)
1310          , nvl(invoice_to_customer_number,     FND_API.G_MISS_CHAR)
1311          , nvl(invoice_to_customer_id,	       FND_API.G_MISS_NUM)
1312          , nvl(deliver_to_customer_name,       FND_API.G_MISS_CHAR)
1313          , nvl(deliver_to_customer_number,     FND_API.G_MISS_CHAR)
1314          , nvl(deliver_to_customer_id,	       FND_API.G_MISS_NUM)
1315          , nvl(user_item_description,	       FND_API.G_MISS_CHAR)
1316          , override_atp_date_code
1317          , xml_transaction_type_code
1318          , nvl(blanket_number,	               FND_API.G_MISS_NUM)
1319          , nvl(blanket_line_number,	       FND_API.G_MISS_NUM)
1320          , nvl(shipping_method, FND_API.G_MISS_CHAR)
1321          , nvl(change_sequence, FND_API.G_MISS_CHAR)
1322          -- automatic account creation {
1323         , ship_to_party_id
1324         , ship_to_party_site_id
1325         , ship_to_party_site_use_id
1326         , deliver_to_party_id
1327         , deliver_to_party_site_id
1328         , deliver_to_party_site_use_id
1329         , invoice_to_party_id
1330         , invoice_to_party_site_id
1331         , invoice_to_party_site_use_id
1332        -- automatic account creation }
1333      -- { Distributer Order related change
1334          , nvl(end_customer_id,                 FND_API.G_MISS_NUM)
1335          , nvl(end_customer_contact_id,         FND_API.G_MISS_NUM)
1336          , nvl(end_customer_site_use_id,        FND_API.G_MISS_NUM)
1337       , nvl(end_customer_name,		FND_API.G_MISS_CHAR) --mvijayku
1338          , nvl(end_customer_address1,		FND_API.G_MISS_CHAR)
1339 	 , nvl(end_customer_address2,		FND_API.G_MISS_CHAR)
1340 	 , nvl(end_customer_address3,		FND_API.G_MISS_CHAR)
1341 	 , nvl(end_customer_address4,		FND_API.G_MISS_CHAR)
1342 --	 	 , nvl(end_customer_location,		FND_API.G_MISS_CHAR)
1343 	 , nvl(end_customer_city,		        FND_API.G_MISS_CHAR)
1344 	 , nvl(end_customer_state,nvl(end_customer_province ,FND_API.G_MISS_CHAR))  ---bug#9395147 ,9878736
1345 	 , nvl(end_customer_postal_code,	        FND_API.G_MISS_CHAR)
1346 	 , nvl(end_customer_country,	                FND_API.G_MISS_CHAR)
1347 	 , nvl(end_customer_contact,			FND_API.G_MISS_CHAR)
1348          , nvl(end_customer_number,		FND_API.G_MISS_CHAR)
1349          , nvl(ib_owner,                        FND_API.G_MISS_CHAR)
1350          , nvl(ib_current_location,             FND_API.G_MISS_CHAR)
1351          , nvl(ib_installed_at_location,        FND_API.G_MISS_CHAR)
1352          , nvl(ib_owner_code,                   FND_API.G_MISS_CHAR)
1353          , nvl(ib_current_location_code,        FND_API.G_MISS_CHAR)
1354          , nvl(ib_installed_at_location_code,   FND_API.G_MISS_CHAR)
1355 	 , END_CUSTOMER_PARTY_ID
1356 	 , END_CUSTOMER_ORG_CONTACT_ID
1357          , END_CUSTOMER_PARTY_SITE_ID
1358          , END_CUSTOMER_PARTY_SITE_USE_ID
1359          , END_CUSTOMER_PARTY_NUMBER
1360      -- Distributer Order related change }
1361      -- for automatic account creation
1362          , ship_to_party_number
1363          , invoice_to_party_number
1364          , deliver_to_party_number
1365      -- for automatic account creation
1366          , nvl(deliver_to_address1,               FND_API.G_MISS_CHAR)
1367          , nvl(deliver_to_address2,               FND_API.G_MISS_CHAR)
1368          , nvl(deliver_to_address3,               FND_API.G_MISS_CHAR)
1369          , nvl(deliver_to_address4,               FND_API.G_MISS_CHAR)
1370          , nvl(deliver_to_state,nvl(deliver_to_province,FND_API.G_MISS_CHAR))  ---bug#9395147 ,9878736
1371          , nvl(deliver_to_county,               FND_API.G_MISS_CHAR)
1372          , nvl(deliver_to_country,                FND_API.G_MISS_CHAR)
1373          , nvl(deliver_to_province,               FND_API.G_MISS_CHAR)
1374          , nvl(deliver_to_city,                   FND_API.G_MISS_CHAR)
1375          , nvl(deliver_to_postal_code,            FND_API.G_MISS_CHAR)
1376 	 , nvl(planning_priority,                 FND_API.G_MISS_NUM)  --Bug#6924881
1377 	 --sol_ord_er #16014165
1378 		 , nvl(SERVICE_BILL_PROFILE_ID ,FND_API.G_MISS_NUM)
1379 		 , nvl(SERVICE_COV_TEMPLATE_ID,FND_API.G_MISS_NUM)
1380 		 , nvl(SERVICE_SUBS_TEMPLATE_ID,FND_API.G_MISS_NUM)
1381 		 , nvl(SERVICE_BILL_OPTION_CODE,FND_API.G_MISS_CHAR)
1382 		 , nvl(SERVICE_BILLING_PROFILE,FND_API.G_MISS_CHAR)
1383 		 , nvl(SERVICE_COVERAGE_TEMPLATE,FND_API.G_MISS_CHAR)
1384 		 , nvl(SERVICE_SUBSCRIPTION_TEMPLATE,FND_API.G_MISS_CHAR)
1385 		 , nvl(SUBSCRIPTION_ENABLE_FLAG,FND_API.G_MISS_CHAR)
1386 		   --sol_ord_er #16014165 end
1387       FROM oe_lines_iface_all
1388      WHERE order_source_id		       = l_order_source_id
1389        AND orig_sys_document_ref 	       = l_orig_sys_document_ref
1390        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
1391          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
1392        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
1393          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
1394        AND nvl(  change_sequence,	       FND_API.G_MISS_CHAR)
1395 	 = nvl(l_change_sequence,	       FND_API.G_MISS_CHAR)
1396        AND nvl(org_id,                          FND_API.G_MISS_NUM)
1397          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
1398        AND nvl(  request_id,		       FND_API.G_MISS_NUM)
1399 	 = nvl(l_request_id,		       FND_API.G_MISS_NUM)
1400        AND nvl(rejected_flag,'N')	       = 'N'
1401   FOR UPDATE NOWAIT
1402   ORDER BY operation_code desc, orig_sys_line_ref asc, orig_sys_shipment_ref asc
1403 ;
1404 
1405 
1406 /* -----------------------------------------------------------
1407    Line Discounts/Price adjustments cursor
1408    -----------------------------------------------------------
1409 */
1410     CURSOR l_line_adj_cursor IS
1411     SELECT nvl(orig_sys_discount_ref,	FND_API.G_MISS_CHAR)
1412 	 , nvl(change_request_code,	FND_API.G_MISS_CHAR)
1413 	 , nvl(list_header_id,        FND_API.G_MISS_NUM)
1414 	 , nvl(list_line_id,          FND_API.G_MISS_NUM)
1415 	 , nvl(discount_name,		FND_API.G_MISS_CHAR)
1416 	 , nvl(percent,			FND_API.G_MISS_NUM)
1417 	 , nvl(automatic_flag,		FND_API.G_MISS_CHAR)
1418 	 , nvl(applied_flag,		FND_API.G_MISS_CHAR)
1419 	 , nvl(operand,			FND_API.G_MISS_NUM)
1420 	 , nvl(arithmetic_operator,	FND_API.G_MISS_CHAR)
1421 	 , nvl(context,			FND_API.G_MISS_CHAR)
1422 	 , nvl(attribute1,		FND_API.G_MISS_CHAR)
1423 	 , nvl(attribute2,		FND_API.G_MISS_CHAR)
1424 	 , nvl(attribute3,		FND_API.G_MISS_CHAR)
1425 	 , nvl(attribute4,		FND_API.G_MISS_CHAR)
1426 	 , nvl(attribute5,		FND_API.G_MISS_CHAR)
1427 	 , nvl(attribute6,		FND_API.G_MISS_CHAR)
1428 	 , nvl(attribute7,		FND_API.G_MISS_CHAR)
1429 	 , nvl(attribute8,		FND_API.G_MISS_CHAR)
1430 	 , nvl(attribute9,		FND_API.G_MISS_CHAR)
1431 	 , nvl(attribute10,		FND_API.G_MISS_CHAR)
1432 	 , nvl(attribute11,		FND_API.G_MISS_CHAR)
1433 	 , nvl(attribute12,		FND_API.G_MISS_CHAR)
1434 	 , nvl(attribute13,		FND_API.G_MISS_CHAR)
1435 	 , nvl(attribute14,		FND_API.G_MISS_CHAR)
1436 	 , nvl(attribute15,		FND_API.G_MISS_CHAR)
1437          , request_id
1438 	 , nvl(operation_code,		OE_GLOBALS.G_OPR_CREATE)
1439 	 , nvl(status_flag,		FND_API.G_MISS_CHAR)
1440 -- Price Adjustment related changes bug# 1220921 (Start)
1441       , nvl( AC_CONTEXT,                 FND_API.G_MISS_CHAR)
1442       , nvl( AC_ATTRIBUTE1,              FND_API.G_MISS_CHAR)
1443       , nvl( AC_ATTRIBUTE2,              FND_API.G_MISS_CHAR)
1444       , nvl( AC_ATTRIBUTE3,              FND_API.G_MISS_CHAR)
1445       , nvl( AC_ATTRIBUTE4,              FND_API.G_MISS_CHAR)
1446       , nvl( AC_ATTRIBUTE5,              FND_API.G_MISS_CHAR)
1447       , nvl( AC_ATTRIBUTE6,              FND_API.G_MISS_CHAR)
1448       , nvl( AC_ATTRIBUTE7,              FND_API.G_MISS_CHAR)
1449       , nvl( AC_ATTRIBUTE8,              FND_API.G_MISS_CHAR)
1450       , nvl( AC_ATTRIBUTE9,              FND_API.G_MISS_CHAR)
1451       , nvl( AC_ATTRIBUTE10,             FND_API.G_MISS_CHAR)
1452       , nvl( AC_ATTRIBUTE11,             FND_API.G_MISS_CHAR)
1453       , nvl( AC_ATTRIBUTE12,             FND_API.G_MISS_CHAR)
1454       , nvl( AC_ATTRIBUTE13,             FND_API.G_MISS_CHAR)
1455       , nvl( AC_ATTRIBUTE14,             FND_API.G_MISS_CHAR)
1456       , nvl( AC_ATTRIBUTE15,             FND_API.G_MISS_CHAR)
1457       , nvl( LIST_NAME,                  FND_API.G_MISS_CHAR)
1458       , nvl( LIST_LINE_TYPE_CODE,        FND_API.G_MISS_CHAR)
1459       , nvl( LIST_LINE_NUMBER,           FND_API.G_MISS_CHAR)
1460       , nvl( VERSION_NUMBER,             FND_API.G_MISS_CHAR)
1461       , nvl( INVOICED_FLAG,              FND_API.G_MISS_CHAR)
1462       , nvl( ESTIMATED_FLAG,             FND_API.G_MISS_CHAR)
1463       , nvl( INC_IN_SALES_PERFORMANCE,   FND_API.G_MISS_CHAR)
1464       , nvl( CHARGE_TYPE_CODE,           FND_API.G_MISS_CHAR)
1465       , nvl( CHARGE_SUBTYPE_CODE,        FND_API.G_MISS_CHAR)
1466       , nvl( CREDIT_OR_CHARGE_FLAG,      FND_API.G_MISS_CHAR)
1467       , nvl( INCLUDE_ON_RETURNS_FLAG,    FND_API.G_MISS_CHAR)
1468       , nvl( COST_ID,                    FND_API.G_MISS_NUM)
1469       , nvl( TAX_CODE,                   FND_API.G_MISS_CHAR)
1470       , nvl( PARENT_ADJUSTMENT_ID,       FND_API.G_MISS_NUM)
1471       , nvl(MODIFIER_MECHANISM_TYPE_CODE,FND_API.G_MISS_CHAR)
1472       , nvl( MODIFIED_FROM,              FND_API.G_MISS_CHAR)
1473       , nvl( MODIFIED_TO,                FND_API.G_MISS_CHAR)
1474       , nvl( UPDATED_FLAG,               FND_API.G_MISS_CHAR)
1475       , nvl( UPDATE_ALLOWED,             FND_API.G_MISS_CHAR)
1476       , nvl( CHANGE_REASON_CODE,         FND_API.G_MISS_CHAR)
1477       , nvl( CHANGE_REASON_TEXT,         FND_API.G_MISS_CHAR)
1478       , nvl( PRICING_PHASE_ID,           FND_API.G_MISS_NUM)
1479       , nvl( ADJUSTED_AMOUNT,            FND_API.G_MISS_NUM)
1480 -- Price Adjustment related changes bug# 1220921 (End)
1481       FROM oe_price_adjs_iface_all
1482      WHERE order_source_id		= l_order_source_id
1483        AND orig_sys_document_ref 	= l_orig_sys_document_ref
1484        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
1485          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
1486        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
1487          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
1488        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
1489 	 = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
1490        AND nvl(org_id,                          FND_API.G_MISS_NUM)
1491          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
1492        AND orig_sys_line_ref 		= l_orig_sys_line_ref
1493        AND nvl(  orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1494 	 = nvl(l_orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1495        AND nvl(  request_id,		FND_API.G_MISS_NUM)
1496 	 = nvl(l_request_id,		FND_API.G_MISS_NUM)
1497   FOR UPDATE NOWAIT
1498   ORDER BY orig_sys_discount_ref
1499 ;
1500 
1501 
1502 /* -----------------------------------------------------------
1503    Line Price attribute cursor
1504    -----------------------------------------------------------
1505 */
1506 
1507          CURSOR l_Line_attrib_cursor IS
1508          SELECT nvl(creation_date	,   FND_API.G_MISS_DATE)
1509           ,  nvl(created_by	        ,   FND_API.G_MISS_NUM)
1510           ,  nvl(last_update_date	,   FND_API.G_MISS_DATE)
1511           ,  nvl(last_updated_by	,   FND_API.G_MISS_NUM)
1512           ,  nvl(last_update_login	,   FND_API.G_MISS_NUM)
1513           ,  nvl(program_application_id	,   FND_API.G_MISS_NUM)
1514           ,  nvl(program_id		,   FND_API.G_MISS_NUM)
1515           ,  nvl(program_update_date    ,   FND_API.G_MISS_DATE)
1516           ,  nvl(request_id		,   FND_API.G_MISS_NUM)
1517           ,  nvl(flex_title		,   FND_API.G_MISS_CHAR)
1518           ,  nvl(pricing_context	,   FND_API.G_MISS_CHAR)
1519           ,  nvl(pricing_attribute1	,   FND_API.G_MISS_CHAR)
1520           ,  nvl(pricing_attribute2	,   FND_API.G_MISS_CHAR)
1521           ,  nvl(pricing_attribute3	,   FND_API.G_MISS_CHAR)
1522           ,  nvl(pricing_attribute4	,   FND_API.G_MISS_CHAR)
1523           ,  nvl(pricing_attribute5	,   FND_API.G_MISS_CHAR)
1524           ,  nvl(pricing_attribute6	,   FND_API.G_MISS_CHAR)
1525           ,  nvl(pricing_attribute7	,   FND_API.G_MISS_CHAR)
1526           ,  nvl(pricing_attribute8	,   FND_API.G_MISS_CHAR)
1527           ,  nvl(pricing_attribute9	,   FND_API.G_MISS_CHAR)
1528           ,  nvl(pricing_attribute10	,   FND_API.G_MISS_CHAR)
1529           ,  nvl(pricing_attribute11	,   FND_API.G_MISS_CHAR)
1530           ,  nvl(pricing_attribute12	,   FND_API.G_MISS_CHAR)
1531           ,  nvl(pricing_attribute13	,   FND_API.G_MISS_CHAR)
1532           ,  nvl(pricing_attribute14	,   FND_API.G_MISS_CHAR)
1533           ,  nvl(pricing_attribute15	,   FND_API.G_MISS_CHAR)
1534           ,  nvl(pricing_attribute16	,   FND_API.G_MISS_CHAR)
1535           ,  nvl(pricing_attribute17	,   FND_API.G_MISS_CHAR)
1536           ,  nvl(pricing_attribute18	,   FND_API.G_MISS_CHAR)
1537           ,  nvl(pricing_attribute19	,   FND_API.G_MISS_CHAR)
1538           ,  nvl(pricing_attribute20	,   FND_API.G_MISS_CHAR)
1539           ,  nvl(pricing_attribute21	,   FND_API.G_MISS_CHAR)
1540           ,  nvl(pricing_attribute22	,   FND_API.G_MISS_CHAR)
1541           ,  nvl(pricing_attribute23	,   FND_API.G_MISS_CHAR)
1542           ,  nvl(pricing_attribute24	,   FND_API.G_MISS_CHAR)
1543           ,  nvl(pricing_attribute25	,   FND_API.G_MISS_CHAR)
1544           ,  nvl(pricing_attribute26	,   FND_API.G_MISS_CHAR)
1545           ,  nvl(pricing_attribute27	,   FND_API.G_MISS_CHAR)
1546           ,  nvl(pricing_attribute28	,   FND_API.G_MISS_CHAR)
1547           ,  nvl(pricing_attribute29	,   FND_API.G_MISS_CHAR)
1548           ,  nvl(pricing_attribute30	,   FND_API.G_MISS_CHAR)
1549           ,  nvl(pricing_attribute31	,   FND_API.G_MISS_CHAR)
1550           ,  nvl(pricing_attribute32	,   FND_API.G_MISS_CHAR)
1551           ,  nvl(pricing_attribute33	,   FND_API.G_MISS_CHAR)
1552           ,  nvl(pricing_attribute34	,   FND_API.G_MISS_CHAR)
1553           ,  nvl(pricing_attribute35	,   FND_API.G_MISS_CHAR)
1554           ,  nvl(pricing_attribute36	,   FND_API.G_MISS_CHAR)
1555           ,  nvl(pricing_attribute37	,   FND_API.G_MISS_CHAR)
1556           ,  nvl(pricing_attribute38	,   FND_API.G_MISS_CHAR)
1557           ,  nvl(pricing_attribute39	,   FND_API.G_MISS_CHAR)
1558           ,  nvl(pricing_attribute40	,   FND_API.G_MISS_CHAR)
1559           ,  nvl(pricing_attribute41	,   FND_API.G_MISS_CHAR)
1560           ,  nvl(pricing_attribute42	,   FND_API.G_MISS_CHAR)
1561           ,  nvl(pricing_attribute43	,   FND_API.G_MISS_CHAR)
1562           ,  nvl(pricing_attribute44	,   FND_API.G_MISS_CHAR)
1563           ,  nvl(pricing_attribute45	,   FND_API.G_MISS_CHAR)
1564           ,  nvl(pricing_attribute46	,   FND_API.G_MISS_CHAR)
1565           ,  nvl(pricing_attribute47	,   FND_API.G_MISS_CHAR)
1566           ,  nvl(pricing_attribute48	,   FND_API.G_MISS_CHAR)
1567           ,  nvl(pricing_attribute49	,   FND_API.G_MISS_CHAR)
1568           ,  nvl(pricing_attribute50	,   FND_API.G_MISS_CHAR)
1569           ,  nvl(pricing_attribute51	,   FND_API.G_MISS_CHAR)
1570           ,  nvl(pricing_attribute52	,   FND_API.G_MISS_CHAR)
1571           ,  nvl(pricing_attribute53	,   FND_API.G_MISS_CHAR)
1572           ,  nvl(pricing_attribute54	,   FND_API.G_MISS_CHAR)
1573           ,  nvl(pricing_attribute55	,   FND_API.G_MISS_CHAR)
1574           ,  nvl(pricing_attribute56	,   FND_API.G_MISS_CHAR)
1575           ,  nvl(pricing_attribute57	,   FND_API.G_MISS_CHAR)
1576           ,  nvl(pricing_attribute58	,   FND_API.G_MISS_CHAR)
1577           ,  nvl(pricing_attribute59	,   FND_API.G_MISS_CHAR)
1578           ,  nvl(pricing_attribute60	,   FND_API.G_MISS_CHAR)
1579           ,  nvl(pricing_attribute61	,   FND_API.G_MISS_CHAR)
1580           ,  nvl(pricing_attribute62	,   FND_API.G_MISS_CHAR)
1581           ,  nvl(pricing_attribute63	,   FND_API.G_MISS_CHAR)
1582           ,  nvl(pricing_attribute64	,   FND_API.G_MISS_CHAR)
1583           ,  nvl(pricing_attribute65	,   FND_API.G_MISS_CHAR)
1584           ,  nvl(pricing_attribute66	,   FND_API.G_MISS_CHAR)
1585           ,  nvl(pricing_attribute67	,   FND_API.G_MISS_CHAR)
1586           ,  nvl(pricing_attribute68	,   FND_API.G_MISS_CHAR)
1587           ,  nvl(pricing_attribute69	,   FND_API.G_MISS_CHAR)
1588           ,  nvl(pricing_attribute70	,   FND_API.G_MISS_CHAR)
1589           ,  nvl(pricing_attribute71	,   FND_API.G_MISS_CHAR)
1590           ,  nvl(pricing_attribute72	,   FND_API.G_MISS_CHAR)
1591           ,  nvl(pricing_attribute73	,   FND_API.G_MISS_CHAR)
1592           ,  nvl(pricing_attribute74	,   FND_API.G_MISS_CHAR)
1593           ,  nvl(pricing_attribute75	,   FND_API.G_MISS_CHAR)
1594           ,  nvl(pricing_attribute76	,   FND_API.G_MISS_CHAR)
1595           ,  nvl(pricing_attribute77	,   FND_API.G_MISS_CHAR)
1596           ,  nvl(pricing_attribute78	,   FND_API.G_MISS_CHAR)
1597           ,  nvl(pricing_attribute79	,   FND_API.G_MISS_CHAR)
1598           ,  nvl(pricing_attribute80	,   FND_API.G_MISS_CHAR)
1599           ,  nvl(pricing_attribute81	,   FND_API.G_MISS_CHAR)
1600           ,  nvl(pricing_attribute82	,   FND_API.G_MISS_CHAR)
1601           ,  nvl(pricing_attribute83	,   FND_API.G_MISS_CHAR)
1602           ,  nvl(pricing_attribute84	,   FND_API.G_MISS_CHAR)
1603           ,  nvl(pricing_attribute85	,   FND_API.G_MISS_CHAR)
1604           ,  nvl(pricing_attribute86	,   FND_API.G_MISS_CHAR)
1605           ,  nvl(pricing_attribute87	,   FND_API.G_MISS_CHAR)
1606           ,  nvl(pricing_attribute88	,   FND_API.G_MISS_CHAR)
1607           ,  nvl(pricing_attribute89	,   FND_API.G_MISS_CHAR)
1608           ,  nvl(pricing_attribute90	,   FND_API.G_MISS_CHAR)
1609           ,  nvl(pricing_attribute91	,   FND_API.G_MISS_CHAR)
1610           ,  nvl(pricing_attribute92	,   FND_API.G_MISS_CHAR)
1611           ,  nvl(pricing_attribute93	,   FND_API.G_MISS_CHAR)
1612           ,  nvl(pricing_attribute94	,   FND_API.G_MISS_CHAR)
1613           ,  nvl(pricing_attribute95	,   FND_API.G_MISS_CHAR)
1614           ,  nvl(pricing_attribute96	,   FND_API.G_MISS_CHAR)
1615           ,  nvl(pricing_attribute97	,   FND_API.G_MISS_CHAR)
1616           ,  nvl(pricing_attribute98	,   FND_API.G_MISS_CHAR)
1617           ,  nvl(pricing_attribute99	,   FND_API.G_MISS_CHAR)
1618           ,  nvl(pricing_attribute100	,   FND_API.G_MISS_CHAR)
1619           ,  nvl(context 		,   FND_API.G_MISS_CHAR)
1620           ,  nvl(attribute1		,   FND_API.G_MISS_CHAR)
1621           ,  nvl(attribute2		,   FND_API.G_MISS_CHAR)
1622           ,  nvl(attribute3		,   FND_API.G_MISS_CHAR)
1623           ,  nvl(attribute4		,   FND_API.G_MISS_CHAR)
1624           ,  nvl(attribute5		,   FND_API.G_MISS_CHAR)
1625           ,  nvl(attribute6		,   FND_API.G_MISS_CHAR)
1626           ,  nvl(attribute7		,   FND_API.G_MISS_CHAR)
1627           ,  nvl(attribute8		,   FND_API.G_MISS_CHAR)
1628           ,  nvl(attribute9		,   FND_API.G_MISS_CHAR)
1629           ,  nvl(attribute10		,   FND_API.G_MISS_CHAR)
1630           ,  nvl(attribute11		,   FND_API.G_MISS_CHAR)
1631           ,  nvl(attribute12		,   FND_API.G_MISS_CHAR)
1632           ,  nvl(attribute13		,   FND_API.G_MISS_CHAR)
1633           ,  nvl(attribute14		,   FND_API.G_MISS_CHAR)
1634           ,  nvl(attribute15		,   FND_API.G_MISS_CHAR)
1635           ,  nvl(operation_code        ,   OE_GLOBALS.G_OPR_CREATE)
1636           FROM  oe_price_atts_iface_all
1637           WHERE order_source_id           = l_order_source_id
1638          AND orig_sys_document_ref        = l_orig_sys_document_ref
1639          AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
1640            = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
1641          AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
1642            = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
1643          AND nvl(  change_sequence,       FND_API.G_MISS_CHAR)
1644            = nvl(l_change_sequence,       FND_API.G_MISS_CHAR)
1645          AND nvl(org_id,                          FND_API.G_MISS_NUM)
1646          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
1647          AND orig_sys_line_ref            = l_orig_sys_line_ref
1648          AND nvl(  orig_sys_shipment_ref, FND_API.G_MISS_CHAR)
1649            = nvl(l_orig_sys_shipment_ref, FND_API.G_MISS_CHAR)
1650          AND nvl(  request_id,            FND_API.G_MISS_NUM)
1651            = nvl(l_request_id,            FND_API.G_MISS_NUM)
1652   FOR UPDATE NOWAIT
1653   ORDER by orig_sys_line_ref;
1654 
1655 /* -----------------------------------------------------------
1656    Line Sales Credits cursor
1657    -----------------------------------------------------------
1658 */
1659     CURSOR l_line_scredit_cursor IS
1660     SELECT nvl(orig_sys_credit_ref,	FND_API.G_MISS_CHAR)
1661 	 , nvl(change_request_code,	FND_API.G_MISS_CHAR)
1662 	 , nvl(salesrep_id,		FND_API.G_MISS_NUM)
1663 	 , nvl(salesrep	,		FND_API.G_MISS_CHAR)
1664 	 , nvl(sales_credit_type_id,	FND_API.G_MISS_NUM)
1665 	 , nvl(sales_credit_type,	FND_API.G_MISS_CHAR)
1666 	 , nvl(percent,			FND_API.G_MISS_NUM)
1667 	 , nvl(context,			FND_API.G_MISS_CHAR)
1668 	 , nvl(attribute1,		FND_API.G_MISS_CHAR)
1669 	 , nvl(attribute2,		FND_API.G_MISS_CHAR)
1670 	 , nvl(attribute3,		FND_API.G_MISS_CHAR)
1671 	 , nvl(attribute4,		FND_API.G_MISS_CHAR)
1672 	 , nvl(attribute5,		FND_API.G_MISS_CHAR)
1673 	 , nvl(attribute6,		FND_API.G_MISS_CHAR)
1674 	 , nvl(attribute7,		FND_API.G_MISS_CHAR)
1675 	 , nvl(attribute8,		FND_API.G_MISS_CHAR)
1676 	 , nvl(attribute9,		FND_API.G_MISS_CHAR)
1677 	 , nvl(attribute10,		FND_API.G_MISS_CHAR)
1678 	 , nvl(attribute11,		FND_API.G_MISS_CHAR)
1679 	 , nvl(attribute12,		FND_API.G_MISS_CHAR)
1680 	 , nvl(attribute13,		FND_API.G_MISS_CHAR)
1681 	 , nvl(attribute14,		FND_API.G_MISS_CHAR)
1682 	 , nvl(attribute15,		FND_API.G_MISS_CHAR)
1683 	 , nvl(operation_code,		OE_GLOBALS.G_OPR_CREATE)
1684 	 , nvl(status_flag,		FND_API.G_MISS_CHAR)
1685          , nvl(change_reason,           FND_API.G_MISS_CHAR)
1686          , nvl(change_comments,         FND_API.G_MISS_CHAR)
1687       FROM oe_credits_iface_all
1688      WHERE order_source_id		= l_order_source_id
1689        AND orig_sys_document_ref 	= l_orig_sys_document_ref
1690        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
1691          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
1692        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
1693          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
1694        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
1695 	 = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
1696        AND nvl(org_id,                          FND_API.G_MISS_NUM)
1697          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
1698        AND orig_sys_line_ref 		= l_orig_sys_line_ref
1699        AND nvl(  orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1700 	 = nvl(l_orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1701        AND nvl(  request_id,		FND_API.G_MISS_NUM)
1702 	 = nvl(l_request_id,		FND_API.G_MISS_NUM)
1703   FOR UPDATE NOWAIT
1704   ORDER BY orig_sys_credit_ref
1705 ;
1706 
1707 /* -----------------------------------------------------------
1708    Multiple Payments: Line payments cursor
1709    -----------------------------------------------------------
1710 */
1711 CURSOR l_line_payment_cursor IS
1712 SELECT 	   nvl(orig_sys_payment_ref,	FND_API.G_MISS_CHAR)
1713 	 , nvl(change_request_code,	FND_API.G_MISS_CHAR)
1714 	 , nvl(payment_type_code,	FND_API.G_MISS_CHAR)
1715 	 , nvl(commitment,		FND_API.G_MISS_CHAR)
1716 	 , nvl(payment_trx_id,		FND_API.G_MISS_NUM)
1717 	 , nvl(payment_method,		FND_API.G_MISS_CHAR)
1718 	 , nvl(receipt_method_id,	FND_API.G_MISS_NUM)
1719 	 , nvl(payment_collection_event,FND_API.G_MISS_CHAR)
1720 	 , nvl(payment_set_id,		FND_API.G_MISS_NUM)
1721 	 , nvl(prepaid_amount,		FND_API.G_MISS_NUM)
1722 	 , nvl(credit_card_number,	FND_API.G_MISS_CHAR)
1723 	 , nvl(credit_card_holder_name,	FND_API.G_MISS_CHAR)
1724 	 , nvl(credit_card_expiration_date,FND_API.G_MISS_DATE)
1725 	 , nvl(credit_card_code,	FND_API.G_MISS_CHAR)
1726 	 , nvl(credit_card_approval_code,FND_API.G_MISS_CHAR)
1727 	 , nvl(credit_card_approval_date,FND_API.G_MISS_DATE)
1728 	 , nvl(check_number,		FND_API.G_MISS_CHAR)--6367320
1729 	 , nvl(payment_amount,		FND_API.G_MISS_NUM)
1730 	 , nvl(payment_percentage,	FND_API.G_MISS_NUM)
1731 	 , nvl(creation_date,		FND_API.G_MISS_DATE)
1732          , nvl(created_by,		FND_API.G_MISS_NUM)
1733          , nvl(last_update_date,   	FND_API.G_MISS_DATE)
1734          , nvl(last_updated_by,   	FND_API.G_MISS_NUM)
1735          , nvl(last_update_login,   	FND_API.G_MISS_NUM)
1736          , nvl(program_application_id,  FND_API.G_MISS_NUM)
1737          , nvl(program_id,   		FND_API.G_MISS_NUM)
1738          , nvl(program_update_date,   	FND_API.G_MISS_DATE)
1739 	 , nvl(context,			FND_API.G_MISS_CHAR)
1740 	 , nvl(attribute1,		FND_API.G_MISS_CHAR)
1741 	 , nvl(attribute2,		FND_API.G_MISS_CHAR)
1742 	 , nvl(attribute3,		FND_API.G_MISS_CHAR)
1743 	 , nvl(attribute4,		FND_API.G_MISS_CHAR)
1744 	 , nvl(attribute5,		FND_API.G_MISS_CHAR)
1745 	 , nvl(attribute6,		FND_API.G_MISS_CHAR)
1746 	 , nvl(attribute7,		FND_API.G_MISS_CHAR)
1747 	 , nvl(attribute8,		FND_API.G_MISS_CHAR)
1748 	 , nvl(attribute9,		FND_API.G_MISS_CHAR)
1749 	 , nvl(attribute10,		FND_API.G_MISS_CHAR)
1750 	 , nvl(attribute11,		FND_API.G_MISS_CHAR)
1751 	 , nvl(attribute12,		FND_API.G_MISS_CHAR)
1752 	 , nvl(attribute13,		FND_API.G_MISS_CHAR)
1753 	 , nvl(attribute14,		FND_API.G_MISS_CHAR)
1754 	 , nvl(attribute15,		FND_API.G_MISS_CHAR)
1755 	 , nvl(operation_code,		OE_GLOBALS.G_OPR_CREATE)
1756 	 , nvl(status_flag,		FND_API.G_MISS_CHAR)
1757 	 , nvl(payment_number,		FND_API.G_MISS_NUM)
1758 	 , nvl(header_id,		FND_API.G_MISS_NUM)
1759 	 , nvl(line_id,			FND_API.G_MISS_NUM)
1760          , nvl(DEFER_PAYMENT_PROCESSING_FLAG, FND_API.G_MISS_CHAR) -- Added for bug 8478559
1761 	 , nvl(trxn_extension_id,	FND_API.G_MISS_NUM)
1762          , nvl(instrument_security_code,FND_API.G_MISS_CHAR)  --R12 CVV2
1763    FROM  oe_payments_iface_all
1764   WHERE  order_source_id              = l_order_source_id
1765     AND  orig_sys_document_ref        = l_orig_sys_document_ref
1766     AND  nvl(  change_sequence,       FND_API.G_MISS_CHAR)
1767       =  nvl(l_change_sequence,       FND_API.G_MISS_CHAR)
1768     AND nvl(org_id,                          FND_API.G_MISS_NUM)
1769          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
1770     AND  orig_sys_line_ref 		= l_orig_sys_line_ref
1771     AND  nvl(  orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1772       =  nvl(l_orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1773     AND  nvl(  request_id,            FND_API.G_MISS_NUM)
1774       =  nvl(l_request_id,            FND_API.G_MISS_NUM)
1775 FOR UPDATE NOWAIT
1776 ORDER BY orig_sys_payment_ref;
1777 -- end of multiple payments: line payment cursor.
1778 
1779 /* -----------------------------------------------------------
1780    Line Lot Serials cursor
1781    -----------------------------------------------------------
1782 */
1783     CURSOR l_lot_serial_cursor IS
1784     SELECT nvl(orig_sys_lotserial_ref,	FND_API.G_MISS_CHAR)
1785 	 , nvl(change_request_code,	FND_API.G_MISS_CHAR)
1786 	 , nvl(lot_number,		FND_API.G_MISS_CHAR)
1787    --      , nvl(sublot_number,		FND_API.G_MISS_CHAR) -- OPM 3322359 INVCONV
1788 	 , nvl(from_serial_number,	FND_API.G_MISS_CHAR)
1789 	 , nvl(to_serial_number,	FND_API.G_MISS_CHAR)
1790 	 , nvl(quantity,		FND_API.G_MISS_NUM)
1791 	 , nvl(quantity2,		FND_API.G_MISS_NUM) -- OPM 3322359
1792 	 , nvl(context,			FND_API.G_MISS_CHAR)
1793 	 , nvl(attribute1,		FND_API.G_MISS_CHAR)
1794 	 , nvl(attribute2,		FND_API.G_MISS_CHAR)
1795 	 , nvl(attribute3,		FND_API.G_MISS_CHAR)
1796 	 , nvl(attribute4,		FND_API.G_MISS_CHAR)
1797 	 , nvl(attribute5,		FND_API.G_MISS_CHAR)
1798 	 , nvl(attribute6,		FND_API.G_MISS_CHAR)
1799 	 , nvl(attribute7,		FND_API.G_MISS_CHAR)
1800 	 , nvl(attribute8,		FND_API.G_MISS_CHAR)
1801 	 , nvl(attribute9,		FND_API.G_MISS_CHAR)
1802 	 , nvl(attribute10,		FND_API.G_MISS_CHAR)
1803 	 , nvl(attribute11,		FND_API.G_MISS_CHAR)
1804 	 , nvl(attribute12,		FND_API.G_MISS_CHAR)
1805 	 , nvl(attribute13,		FND_API.G_MISS_CHAR)
1806 	 , nvl(attribute14,		FND_API.G_MISS_CHAR)
1807 	 , nvl(attribute15,		FND_API.G_MISS_CHAR)
1808 	 , nvl(operation_code,		OE_GLOBALS.G_OPR_CREATE)
1809 	 , nvl(status_flag,		FND_API.G_MISS_CHAR)
1810       FROM oe_lotserials_iface_all
1811      WHERE order_source_id 		= l_order_source_id
1812        AND orig_sys_document_ref 	= l_orig_sys_document_ref
1813        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
1814          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
1815        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
1816          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
1817        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
1818 	 = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
1819        AND nvl(org_id,                          FND_API.G_MISS_NUM)
1820          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
1821        AND orig_sys_line_ref 		= l_orig_sys_line_ref
1822        AND nvl(  orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1823 	 = nvl(l_orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1824        AND nvl(  request_id,		FND_API.G_MISS_NUM)
1825 	 = nvl(l_request_id,		FND_API.G_MISS_NUM)
1826   FOR UPDATE NOWAIT
1827   ORDER BY orig_sys_lotserial_ref
1828 ;
1829 
1830 
1831 /* -----------------------------------------------------------
1832    Line Reservations cursor
1833    -----------------------------------------------------------
1834 */
1835     CURSOR l_reservation_cursor IS
1836     SELECT orig_sys_reservation_ref
1837 	 , revision
1838 	 , lot_number_id
1839 	 , lot_number
1840 	 , subinventory_id
1841 	 , subinventory_code
1842 	 , locator_id
1843 	 , quantity
1844 	 , quantity2 -- INVCONV
1845 	 , attribute_category
1846 	 , attribute1
1847 	 , attribute2
1848 	 , attribute3
1849 	 , attribute4
1850 	 , attribute5
1851 	 , attribute6
1852 	 , attribute7
1853 	 , attribute8
1854 	 , attribute9
1855 	 , attribute10
1856 	 , attribute11
1857 	 , attribute12
1858 	 , attribute13
1859 	 , attribute14
1860 	 , attribute15
1861 	 , nvl(operation_code,		OE_GLOBALS.G_OPR_CREATE)
1862       FROM oe_reservtns_iface_all
1863      WHERE order_source_id 		= l_order_source_id
1864        AND orig_sys_document_ref 	= l_orig_sys_document_ref
1865        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
1866          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
1867        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
1868          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
1869        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
1870 	 = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
1871        AND nvl(org_id,                          FND_API.G_MISS_NUM)
1872          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
1873        AND orig_sys_line_ref 		= l_orig_sys_line_ref
1874        AND nvl(  orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1875 	 = nvl(l_orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1876        AND nvl(  request_id,		FND_API.G_MISS_NUM)
1877 	 = nvl(l_request_id,		FND_API.G_MISS_NUM)
1878   FOR UPDATE NOWAIT
1879   ORDER BY orig_sys_reservation_ref
1880 ;
1881 
1882 
1883 /* -----------------------------------------------------------
1884    Action Requests cursor
1885    -----------------------------------------------------------
1886 */
1887     CURSOR l_action_request_header_cursor IS
1888     SELECT nvl(orig_sys_line_ref,	FND_API.G_MISS_CHAR)
1889          , nvl(orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1890 	 , hold_id
1891 	 , hold_type_code
1892 	 , hold_type_id
1893 	 , hold_until_date
1894 	 , release_reason_code
1895 	 , comments
1896 	 , context
1897 	 , attribute1
1898 	 , attribute2
1899 	 , attribute3
1900 	 , attribute4
1901 	 , attribute5
1902 	 , attribute6
1903 	 , attribute7
1904 	 , attribute8
1905 	 , attribute9
1906 	 , attribute10
1907 	 , attribute11
1908 	 , attribute12
1909 	 , attribute13
1910 	 , attribute14
1911 	 , attribute15
1912 	 , operation_code
1913 	 , error_flag
1914 	 , status_flag
1915 	 , interface_status
1916 --myerrams, start, added the following fields to the cursor for Customer Acceptance
1917 	 , char_param1
1918 	 , char_param2
1919 	 , char_param3
1920 	 , char_param4
1921 	 , char_param5
1922 	 , date_param1
1923 	 , date_param2
1924 	 , date_param3
1925 	 , date_param4
1926 	 , date_param5
1927 --myerrams, end
1928       FROM oe_actions_iface_all
1929      WHERE order_source_id 		= l_order_source_id
1930        AND orig_sys_document_ref 	= l_orig_sys_document_ref
1931        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
1932          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
1933        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
1934          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
1935        AND nvl(org_id,                          FND_API.G_MISS_NUM)
1936          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
1937        AND nvl(orig_sys_line_ref,       FND_API.G_MISS_CHAR)
1938          =                              FND_API.G_MISS_CHAR
1939        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
1940 	 = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
1941        AND nvl(  request_id,		FND_API.G_MISS_NUM)
1942 	 = nvl(l_request_id,		FND_API.G_MISS_NUM)
1943   FOR UPDATE NOWAIT
1944 ;
1945 /*bsadri the actions at line level has to have its own cursor so
1946   we can pass the line_index to it at the main loop.like other lines*/
1947 
1948     CURSOR l_action_request_line_cursor IS
1949     SELECT nvl(orig_sys_line_ref,	FND_API.G_MISS_CHAR)
1950          , nvl(orig_sys_shipment_ref,	FND_API.G_MISS_CHAR)
1951 	 , hold_id
1952 	 , hold_type_code
1953 	 , hold_type_id
1954 	 , hold_until_date
1955 	 , release_reason_code
1956 	 , comments
1957 	 , context
1958 	 , attribute1
1959 	 , attribute2
1960 	 , attribute3
1961 	 , attribute4
1962 	 , attribute5
1963 	 , attribute6
1964 	 , attribute7
1965 	 , attribute8
1966 	 , attribute9
1967 	 , attribute10
1968 	 , attribute11
1969 	 , attribute12
1970 	 , attribute13
1971 	 , attribute14
1972 	 , attribute15
1973 	 , operation_code
1974          , fulfillment_set_name
1975 	 , error_flag
1976 	 , status_flag
1977 	 , interface_status
1978 --myerrams, start, added the following fields to the cursor for Customer Acceptance
1979 	 , char_param1
1980 	 , char_param2
1981 	 , char_param3
1982 	 , char_param4
1983 	 , char_param5
1984 	 , date_param1
1985 	 , date_param2
1986 	 , date_param3
1987 	 , date_param4
1988 	 , date_param5
1989 --myerrams, end
1990       FROM oe_actions_iface_all
1991      WHERE order_source_id 		= l_order_source_id
1992        AND orig_sys_document_ref 	= l_orig_sys_document_ref
1993        AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
1994          = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
1995        AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
1996          = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
1997        AND orig_sys_line_ref            = l_orig_sys_line_ref
1998        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
1999 	 = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
2000        AND nvl(org_id,                          FND_API.G_MISS_NUM)
2001          = nvl(l_org_id,                        FND_API.G_MISS_NUM)
2002        AND nvl(  request_id,		FND_API.G_MISS_NUM)
2003 	 = nvl(l_request_id,		FND_API.G_MISS_NUM)
2004   FOR UPDATE NOWAIT
2005 ;
2006 
2007 
2008 --
2009 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
2010 --
2011 BEGIN
2012 
2013 
2014 /* -----------------------------------------------------------
2015    Initialize messages
2016    -----------------------------------------------------------
2017 */
2018    IF p_init_msg_list = FND_API.G_TRUE THEN
2019       IF l_debug_level  > 0 THEN
2020           oe_debug_pub.add(  'BEFORE INITIALIZING MESSAGES LIST' ) ;
2021       END IF;
2022       OE_MSG_PUB.Initialize;
2023    END IF;
2024 
2025 /* -----------------------------------------------------------
2026    Set message context
2027    -----------------------------------------------------------
2028 */
2029   IF l_debug_level  > 0 THEN
2030       oe_debug_pub.add(  'BEFORE SETTING MESSAGE CONTEXT' ) ;
2031       oe_debug_pub.add('trim data = '||l_rtrim_data);
2032   END IF;
2033 
2034   OE_MSG_PUB.set_msg_context(
2035 		p_entity_code                => 'HEADER'
2036          ,p_entity_ref                 => null
2037 	    ,p_entity_id                  => null
2038 	    ,p_header_id                  => null
2039 	    ,p_line_id                    => null
2040 	    ,p_order_source_id            => l_order_source_id
2041 	    ,p_orig_sys_document_ref      => l_orig_sys_document_ref
2042 	    ,p_change_sequence            => l_change_sequence
2043 	    ,p_orig_sys_document_line_ref => null
2044 	    ,p_orig_sys_shipment_ref      => null
2045 	    ,p_source_document_type_id    => null
2046 	    ,p_source_document_id         => null
2047 	    ,p_source_document_line_id    => null
2048 	    ,p_attribute_code             => null
2049 	    ,p_constraint_id              => null
2050 	    );
2051 
2052 /* -----------------------------------------------------------
2053    Initialization
2054    -----------------------------------------------------------
2055 */
2056    IF l_debug_level  > 0 THEN
2057        oe_debug_pub.add(  'BEFORE INITIALIZATION' ) ;
2058    END IF;
2059   begin
2060     select DECODE(p_validate_only,'Y','T','N','F',p_validate_only)
2061     into   l_validate_only
2062     from   dual;
2063   exception
2064     when others then
2065       l_validate_only := 'T';
2066   end;
2067   l_header_rec 	     := OE_Order_Pub.G_MISS_HEADER_REC;
2068   l_header_rec_old 		:= OE_Order_Pub.G_MISS_HEADER_REC;
2069   l_header_rec_new 		:= OE_Order_Pub.G_MISS_HEADER_REC;
2070   l_header_adj_rec 		:= OE_Order_Pub.G_MISS_HEADER_ADJ_REC;
2071   l_header_adj_tbl 		:= OE_Order_Pub.G_MISS_HEADER_ADJ_TBL;
2072   l_header_adj_tbl_old 		:= OE_Order_Pub.G_MISS_HEADER_ADJ_TBL;
2073   l_header_adj_tbl_new 		:= OE_Order_Pub.G_MISS_HEADER_ADJ_TBL;
2074   l_header_scredit_rec 		:= OE_Order_Pub.G_MISS_HEADER_SCREDIT_REC;
2075   l_header_scredit_tbl 		:= OE_Order_Pub.G_MISS_HEADER_SCREDIT_TBL;
2076   l_header_scredit_tbl_old 	:= OE_Order_Pub.G_MISS_HEADER_SCREDIT_TBL;
2077   l_header_scredit_tbl_new 	:= OE_Order_Pub.G_MISS_HEADER_SCREDIT_TBL;
2078   l_header_payment_rec          := OE_Order_Pub.G_MISS_HEADER_payment_REC;
2079   l_header_payment_tbl          := OE_Order_Pub.G_MISS_HEADER_payment_TBL;
2080   l_header_payment_tbl_old      := OE_Order_Pub.G_MISS_HEADER_payment_TBL;
2081   l_header_payment_tbl_new      := OE_Order_Pub.G_MISS_HEADER_payment_TBL;
2082 
2083   /* 1433292   */
2084   l_header_price_att_rec        := OE_Order_Pub.G_MISS_HEADER_PRICE_ATT_REC;
2085   l_header_price_att_tbl        := OE_Order_Pub.G_MISS_HEADER_PRICE_ATT_TBL;
2086   l_header_price_att_tbl_old    := OE_Order_Pub.G_MISS_HEADER_PRICE_ATT_TBL;
2087   l_header_price_att_tbl_new    := OE_Order_Pub.G_MISS_HEADER_PRICE_ATT_TBL;
2088   l_header_adj_att_rec          := OE_Order_Pub.G_MISS_HEADER_ADJ_ATT_REC;
2089   l_header_adj_att_tbl          := OE_Order_Pub.G_MISS_HEADER_ADJ_ATT_TBL;
2090   l_header_adj_att_tbl_old      := OE_Order_Pub.G_MISS_HEADER_ADJ_ATT_TBL;
2091   l_header_adj_att_tbl_new      := OE_Order_Pub.G_MISS_HEADER_ADJ_ATT_TBL;
2092   l_header_adj_assoc_rec        := OE_Order_Pub.G_MISS_HEADER_ADJ_ASSOC_REC;
2093   l_header_adj_assoc_tbl        := OE_Order_Pub.G_MISS_HEADER_ADJ_ASSOC_TBL;
2094   l_header_adj_assoc_tbl_old    := OE_Order_Pub.G_MISS_HEADER_ADJ_ASSOC_TBL;
2095   l_header_adj_assoc_tbl_new    := OE_Order_Pub.G_MISS_HEADER_ADJ_ASSOC_TBL;
2096 
2097   l_header_val_rec 		:= OE_Order_Pub.G_MISS_HEADER_VAL_REC;
2098   l_header_val_rec_old 		:= OE_Order_Pub.G_MISS_HEADER_VAL_REC;
2099   l_header_val_rec_new 		:= OE_Order_Pub.G_MISS_HEADER_VAL_REC;
2100   l_header_adj_val_rec 		:= OE_Order_Pub.G_MISS_HEADER_ADJ_VAL_REC;
2101   l_header_adj_val_tbl 		:= OE_Order_Pub.G_MISS_HEADER_ADJ_VAL_TBL;
2102   l_header_adj_val_tbl_old 	:= OE_Order_Pub.G_MISS_HEADER_ADJ_VAL_TBL;
2103   l_header_adj_val_tbl_new 	:= OE_Order_Pub.G_MISS_HEADER_ADJ_VAL_TBL;
2104   l_header_scredit_val_rec 	:= OE_Order_Pub.G_MISS_HEADER_SCREDIT_VAL_REC;
2105   l_header_scredit_val_tbl 	:= OE_Order_Pub.G_MISS_HEADER_SCREDIT_VAL_TBL;
2106   l_header_scredit_val_tbl_old 	:= OE_Order_Pub.G_MISS_HEADER_SCREDIT_VAL_TBL;
2107   l_header_scredit_val_tbl_new 	:= OE_Order_Pub.G_MISS_HEADER_SCREDIT_VAL_TBL;
2108   l_header_payment_val_rec      := OE_Order_Pub.G_MISS_HEADER_payment_VAL_REC;
2109   l_header_payment_val_tbl      := OE_Order_Pub.G_MISS_HEADER_payment_VAL_TBL;
2110   l_header_payment_val_tbl_old  := OE_Order_Pub.G_MISS_HEADER_payment_VAL_TBL;
2111   l_header_payment_val_tbl_new  := OE_Order_Pub.G_MISS_HEADER_payment_VAL_TBL;
2112 
2113   l_line_rec 			:= OE_Order_Pub.G_MISS_LINE_REC;
2114   l_line_tbl 			:= OE_Order_Pub.G_MISS_LINE_TBL;
2115   l_line_tbl_old 		:= OE_Order_Pub.G_MISS_LINE_TBL;
2116   l_line_tbl_new 		:= OE_Order_Pub.G_MISS_LINE_TBL;
2117   l_line_adj_rec 		:= OE_Order_Pub.G_MISS_LINE_ADJ_REC;
2118   l_line_adj_tbl 		:= OE_Order_Pub.G_MISS_LINE_ADJ_TBL;
2119   l_line_adj_tbl_old 		:= OE_Order_Pub.G_MISS_LINE_ADJ_TBL;
2120   l_line_adj_tbl_new 		:= OE_Order_Pub.G_MISS_LINE_ADJ_TBL;
2121   l_line_scredit_rec 		:= OE_Order_Pub.G_MISS_LINE_SCREDIT_REC;
2122   l_line_scredit_tbl 		:= OE_Order_Pub.G_MISS_LINE_SCREDIT_TBL;
2123   l_line_scredit_tbl_old 	:= OE_Order_Pub.G_MISS_LINE_SCREDIT_TBL;
2124   l_line_scredit_tbl_new 	:= OE_Order_Pub.G_MISS_LINE_SCREDIT_TBL;
2125   l_line_payment_rec            := OE_Order_Pub.G_MISS_LINE_payment_REC;
2126   l_line_payment_tbl            := OE_Order_Pub.G_MISS_LINE_payment_TBL;
2127   l_line_payment_tbl_old        := OE_Order_Pub.G_MISS_LINE_payment_TBL;
2128   l_line_payment_tbl_new        := OE_Order_Pub.G_MISS_LINE_payment_TBL;
2129   l_reservation_rec 		:= OE_Order_Pub.G_MISS_RESERVATION_REC;
2130   l_reservation_tbl 		:= OE_Order_Pub.G_MISS_RESERVATION_TBL;
2131   /* 1433292 */
2132   l_line_price_att_rec        := OE_Order_Pub.G_MISS_LINE_PRICE_ATT_REC;
2133   l_line_price_att_tbl        := OE_Order_Pub.G_MISS_LINE_PRICE_ATT_TBL;
2134   l_line_price_att_tbl_old    := OE_Order_Pub.G_MISS_LINE_PRICE_ATT_TBL;
2135   l_line_price_att_tbl_new    := OE_Order_Pub.G_MISS_LINE_PRICE_ATT_TBL;
2136   l_line_adj_att_rec          := OE_Order_Pub.G_MISS_LINE_ADJ_ATT_REC;
2137   l_line_adj_att_tbl          := OE_Order_Pub.G_MISS_LINE_ADJ_ATT_TBL;
2138   l_line_adj_att_tbl_old      := OE_Order_Pub.G_MISS_LINE_ADJ_ATT_TBL;
2139   l_line_adj_att_tbl_new      := OE_Order_Pub.G_MISS_LINE_ADJ_ATT_TBL;
2140   l_line_adj_assoc_rec        := OE_Order_Pub.G_MISS_LINE_ADJ_ASSOC_REC;
2141   l_line_adj_assoc_tbl        := OE_Order_Pub.G_MISS_LINE_ADJ_ASSOC_TBL;
2142   l_line_adj_assoc_tbl_old    := OE_Order_Pub.G_MISS_LINE_ADJ_ASSOC_TBL;
2143   l_line_adj_assoc_tbl_new    := OE_Order_Pub.G_MISS_LINE_ADJ_ASSOC_TBL;
2144 
2145   l_line_val_rec 		:= OE_Order_Pub.G_MISS_LINE_VAL_REC;
2146   l_line_val_tbl 		:= OE_Order_Pub.G_MISS_LINE_VAL_TBL;
2147   l_line_val_tbl_old 		:= OE_Order_Pub.G_MISS_LINE_VAL_TBL;
2148   l_line_val_tbl_new 		:= OE_Order_Pub.G_MISS_LINE_VAL_TBL;
2149   l_line_adj_val_rec 		:= OE_Order_Pub.G_MISS_LINE_ADJ_VAL_REC;
2150   l_line_adj_val_tbl 		:= OE_Order_Pub.G_MISS_LINE_ADJ_VAL_TBL;
2151   l_line_adj_val_tbl_old 	:= OE_Order_Pub.G_MISS_LINE_ADJ_VAL_TBL;
2152   l_line_adj_val_tbl_new 	:= OE_Order_Pub.G_MISS_LINE_ADJ_VAL_TBL;
2153   l_line_scredit_val_rec 	:= OE_Order_Pub.G_MISS_LINE_SCREDIT_VAL_REC;
2154   l_line_scredit_val_tbl 	:= OE_Order_Pub.G_MISS_LINE_SCREDIT_VAL_TBL;
2155   l_line_scredit_val_tbl_old 	:= OE_Order_Pub.G_MISS_LINE_SCREDIT_VAL_TBL;
2156   l_line_scredit_val_tbl_new 	:= OE_Order_Pub.G_MISS_LINE_SCREDIT_VAL_TBL;
2157   l_line_payment_val_rec        := OE_Order_Pub.G_MISS_LINE_payment_VAL_REC;
2158   l_line_payment_val_tbl        := OE_Order_Pub.G_MISS_LINE_payment_VAL_TBL;
2159   l_line_payment_val_tbl_old    := OE_Order_Pub.G_MISS_LINE_payment_VAL_TBL;
2160   l_line_payment_val_tbl_new    := OE_Order_Pub.G_MISS_LINE_payment_VAL_TBL;
2161   l_reservation_val_rec 	:= OE_Order_Pub.G_MISS_RESERVATION_VAL_REC;
2162   l_reservation_val_tbl 	:= OE_Order_Pub.G_MISS_RESERVATION_VAL_TBL;
2163 
2164   l_lot_serial_rec 		:= OE_Order_Pub.G_MISS_LOT_SERIAL_REC;
2165   l_lot_serial_tbl 		:= OE_Order_Pub.G_MISS_LOT_SERIAL_TBL;
2166   l_lot_serial_tbl_old 		:= OE_Order_Pub.G_MISS_LOT_SERIAL_TBL;
2167   l_lot_serial_tbl_new 		:= OE_Order_Pub.G_MISS_LOT_SERIAL_TBL;
2168 
2169   l_action_request_rec 		:= OE_Order_Pub.G_MISS_REQUEST_REC;
2170   l_action_request_tbl 		:= OE_Order_Pub.G_MISS_REQUEST_TBL;
2171   l_action_request_tbl_old 	:= OE_Order_Pub.G_MISS_REQUEST_TBL;
2172 
2173   p_return_status		:= FND_API.G_RET_STS_SUCCESS; -- Success
2174 
2175   fnd_profile.get('ONT_IMP_MULTIPLE_SHIPMENTS', G_IMPORT_SHIPMENTS);
2176   G_IMPORT_SHIPMENTS := nvl(G_IMPORT_SHIPMENTS, 'NO');
2177 
2178   FND_PROFILE.GET('ONT_3A7_RESPONSE_REQUIRED', l_cso_response_pfile);
2179   l_cso_response_pfile := nvl(l_cso_response_pfile, 'N');
2180 
2181   FND_PROFILE.GET('ONT_3A8_RESPONSE_ACK', l_cho_ack_send_pfile);
2182   l_cho_ack_send_pfile := nvl(l_cho_ack_send_pfile, 'N');
2183 
2184 /* -----------------------------------------------------------
2185    Headers
2186    -----------------------------------------------------------
2187 */
2188    IF l_debug_level  > 0 THEN
2189        oe_debug_pub.add(  'BEFORE HEADERS LOOP' ) ;
2190    END IF;
2191 
2192   l_header_count := 0;
2193 
2194   OPEN l_header_cursor;
2195   --LOOP
2196      FETCH l_header_cursor
2197       INTO l_header_rec.order_source_id
2198 	 , l_header_rec.orig_sys_document_ref
2199 	 , l_header_rec.change_sequence
2200 	 , l_header_rec.change_request_code
2201 	 , l_header_val_rec.order_source
2202 	 , l_header_rec.org_id
2203 	 , l_header_rec.header_id
2204 	 , l_header_rec.order_number
2205 	 , l_header_rec.version_number
2206 	 , l_header_rec.ordered_date
2207 	 , l_header_rec.order_type_id
2208 	 , l_header_val_rec.order_type
2209 	 , l_header_rec.price_list_id
2210 	 , l_header_val_rec.price_list
2211 	 , l_header_rec.conversion_rate
2212 	 , l_header_rec.conversion_rate_date
2213 	 , l_header_rec.conversion_type_code
2214 	 , l_header_val_rec.conversion_type
2215 	 , l_header_rec.transactional_curr_code
2216 	 , l_header_rec.return_reason_code
2217 	 , l_header_rec.salesrep_id
2218 	 , l_header_val_rec.salesrep
2219 	 , l_header_rec.sales_channel_code
2220 	 , l_header_val_rec.sales_channel
2221 	 , l_header_rec.tax_point_code
2222 	 , l_header_val_rec.tax_point
2223 	 , l_header_rec.tax_exempt_flag
2224 	 , l_header_rec.tax_exempt_number
2225 	 , l_header_rec.tax_exempt_reason_code
2226 	 , l_header_val_rec.tax_exempt_reason
2227 	 , l_header_rec.agreement_id
2228 	 , l_header_val_rec.agreement
2229 	 , l_header_rec.invoicing_rule_id
2230 	 , l_header_val_rec.invoicing_rule
2231 	 , l_header_rec.accounting_rule_id
2232 	 , l_header_rec.accounting_rule_duration
2233 	 , l_header_val_rec.accounting_rule
2234 	 , l_header_rec.payment_term_id
2235 	 , l_header_val_rec.payment_term
2236 	 , l_header_rec.demand_class_code
2237 	 , l_header_rec.shipment_priority_code
2238 	 , l_header_val_rec.shipment_priority
2239 	 , l_header_rec.shipping_method_code
2240 	 , l_header_rec.freight_carrier_code
2241 	 , l_header_rec.freight_terms_code
2242 	 , l_header_val_rec.freight_terms
2243 	 , l_header_rec.fob_point_code
2244 	 , l_header_val_rec.fob_point
2245 	 , l_header_rec.partial_shipments_allowed
2246 	 , l_header_rec.ship_tolerance_above
2247 	 , l_header_rec.ship_tolerance_below
2248 	 , l_header_rec.shipping_instructions
2249 	 , l_header_rec.packing_instructions
2250   	 , l_header_rec.order_date_type_code
2251   	 , l_header_rec.earliest_schedule_limit
2252   	 , l_header_rec.latest_schedule_limit
2253 	 , l_header_rec.cust_po_number
2254 	 , l_header_rec.customer_payment_term_id
2255 	 , l_header_val_rec.customer_payment_term
2256 	 , l_header_rec.payment_type_code
2257 	 , l_header_rec.payment_amount
2258 	 , l_header_rec.check_number
2259 	 , l_header_rec.credit_card_code
2260 	 , l_header_rec.credit_card_holder_name
2261 	 , l_header_rec.credit_card_number
2262 	 , l_header_rec.credit_card_expiration_date
2263 	 , l_header_rec.credit_card_approval_code
2264 	 , l_header_rec.credit_card_approval_date
2265 	 , l_header_rec.sold_from_org_id
2266 	 , l_header_val_rec.sold_from_org
2267 	 , l_header_rec.sold_to_org_id
2268 	 , l_header_val_rec.sold_to_org
2269 	 , l_header_val_rec.customer_number
2270 	 , l_header_rec.ship_from_org_id
2271 	 , l_header_val_rec.ship_from_org
2272 	 , l_header_rec.ship_to_org_id
2273 	 , l_header_val_rec.ship_to_org
2274 	 , l_header_rec.invoice_to_org_id
2275 	 , l_header_val_rec.invoice_to_org
2276 	 , l_header_rec.deliver_to_org_id
2277 	 , l_header_val_rec.deliver_to_org
2278 	 , l_header_rec.sold_to_contact_id
2279 	 , l_header_val_rec.sold_to_contact
2280 	 , l_header_rec.ship_to_contact_id
2281 	 , l_header_val_rec.ship_to_contact
2282 	 , l_header_rec.invoice_to_contact_id
2283 	 , l_header_val_rec.invoice_to_contact
2284 	 , l_header_rec.deliver_to_contact_id
2285 	 , l_header_val_rec.deliver_to_contact
2286 	 , l_header_val_rec.ship_to_address1
2287 	 , l_header_val_rec.ship_to_address2
2288 	 , l_header_val_rec.ship_to_address3
2289 	 , l_header_val_rec.ship_to_address4
2290 	 , l_header_val_rec.ship_to_city
2291 	 , l_header_val_rec.ship_to_state
2292 	 , l_header_val_rec.ship_to_zip
2293 	 , l_header_val_rec.ship_to_country
2294 	 , l_header_val_rec.invoice_to_address1
2295 	 , l_header_val_rec.invoice_to_address2
2296 	 , l_header_val_rec.invoice_to_address3
2297 	 , l_header_val_rec.invoice_to_address4
2298 	 , l_header_val_rec.invoice_to_city
2299 	 , l_header_val_rec.invoice_to_state
2300 	 , l_header_val_rec.invoice_to_zip
2301 	 , l_header_val_rec.invoice_to_country
2302 	 , l_header_rec.drop_ship_flag
2303 	 , l_header_rec.booked_flag
2304 --	 , l_header_rec.closed_flag
2305 	 , l_header_rec.cancelled_flag
2306 	 , l_header_rec.context
2307 	 , l_header_rec.attribute1
2308 	 , l_header_rec.attribute2
2309 	 , l_header_rec.attribute3
2310 	 , l_header_rec.attribute4
2311 	 , l_header_rec.attribute5
2312 	 , l_header_rec.attribute6
2313 	 , l_header_rec.attribute7
2314 	 , l_header_rec.attribute8
2315 	 , l_header_rec.attribute9
2316 	 , l_header_rec.attribute10
2317 	 , l_header_rec.attribute11
2318 	 , l_header_rec.attribute12
2319 	 , l_header_rec.attribute13
2320 	 , l_header_rec.attribute14
2321 	 , l_header_rec.attribute15
2322 	 , l_header_rec.attribute16  -- For bug 2184255
2323 	 , l_header_rec.attribute17
2324 	 , l_header_rec.attribute18
2325 	 , l_header_rec.attribute19
2326 	 , l_header_rec.attribute20
2327 	 , l_header_rec.tp_context
2328 	 , l_header_rec.tp_attribute1
2329 	 , l_header_rec.tp_attribute2
2330 	 , l_header_rec.tp_attribute3
2331 	 , l_header_rec.tp_attribute4
2332 	 , l_header_rec.tp_attribute5
2333 	 , l_header_rec.tp_attribute6
2334 	 , l_header_rec.tp_attribute7
2335 	 , l_header_rec.tp_attribute8
2336 	 , l_header_rec.tp_attribute9
2337 	 , l_header_rec.tp_attribute10
2338 	 , l_header_rec.tp_attribute11
2339 	 , l_header_rec.tp_attribute12
2340 	 , l_header_rec.tp_attribute13
2341 	 , l_header_rec.tp_attribute14
2342 	 , l_header_rec.tp_attribute15
2343 	 , l_header_rec.global_attribute_category
2344 	 , l_header_rec.global_attribute1
2345 	 , l_header_rec.global_attribute2
2346 	 , l_header_rec.global_attribute3
2347 	 , l_header_rec.global_attribute4
2348 	 , l_header_rec.global_attribute5
2349 	 , l_header_rec.global_attribute6
2350 	 , l_header_rec.global_attribute7
2351 	 , l_header_rec.global_attribute8
2352 	 , l_header_rec.global_attribute9
2353 	 , l_header_rec.global_attribute10
2354 	 , l_header_rec.global_attribute11
2355 	 , l_header_rec.global_attribute12
2356 	 , l_header_rec.global_attribute13
2357 	 , l_header_rec.global_attribute14
2358 	 , l_header_rec.global_attribute15
2359 	 , l_header_rec.global_attribute16
2360 	 , l_header_rec.global_attribute17
2361 	 , l_header_rec.global_attribute18
2362 	 , l_header_rec.global_attribute19
2363 	 , l_header_rec.global_attribute20
2364       , l_header_rec.request_id
2365 	 , l_header_rec.request_date
2366 	 , l_header_rec.operation
2367 	 , l_header_rec.ready_flag
2368 	 , l_header_rec.status_flag
2369 	 , l_header_rec.force_apply_flag
2370 	 , l_header_rec.change_reason
2371 	 , l_header_rec.change_comments
2372          , l_header_rec.customer_preference_set_code
2373       -- { Start add new columns to select for the Add Customer
2374          , l_header_customer_rec.Orig_Sys_Customer_Ref
2375          , l_header_customer_rec.Orig_Ship_Address_Ref
2376          , l_header_customer_rec.Orig_Bill_Address_Ref
2377          , l_header_customer_rec.Orig_Deliver_Address_Ref
2378          , l_header_customer_rec.Sold_to_Contact_Ref
2379          , l_header_customer_rec.Ship_to_Contact_Ref
2380          , l_header_customer_rec.Bill_to_Contact_Ref
2381          , l_header_customer_rec.Deliver_to_Contact_Ref
2382       -- End add new columns to select for the Add Customer}
2383          , l_header_rec.xml_message_id
2384          , l_header_val_rec.ship_to_customer_name_oi
2385          , l_header_val_rec.ship_to_customer_number_oi
2386          , l_header_rec.ship_to_customer_id
2387          , l_header_val_rec.invoice_to_customer_name_oi
2388          , l_header_val_rec.invoice_to_customer_number_oi
2389          , l_header_rec.invoice_to_customer_id
2390          , l_header_val_rec.deliver_to_customer_name_oi
2391          , l_header_val_rec.deliver_to_customer_number_oi
2392          , l_header_rec.deliver_to_customer_id
2393          , l_header_rec.xml_transaction_type_code
2394          , l_header_rec.blanket_number
2395          , l_header_val_rec.shipping_method
2396          -- Added pricing_date for the bug 3001346
2397 	 , l_header_rec.pricing_date
2398          , l_header_cso_response_flag
2399 	 , l_header_rec.sold_to_site_use_id
2400 	 , l_header_val_rec.sold_to_location_address1
2401 	 , l_header_val_rec.sold_to_location_address2
2402 	 , l_header_val_rec.sold_to_location_address3
2403 	 , l_header_val_rec.sold_to_location_address4
2404 	 , l_header_val_rec.sold_to_location_city
2405 	 , l_header_val_rec.sold_to_location_postal
2406 	 , l_header_val_rec.sold_to_location_country
2407 	 , l_header_val_rec.sold_to_location_state
2408 	 , l_header_val_rec.sold_to_location_county
2409 	 , l_header_val_rec.sold_to_location_province
2410          -- automatic account creation {
2411         , l_header_rec.sold_to_party_id
2412         , l_header_rec.sold_to_org_contact_id
2413         , l_header_rec.ship_to_party_id
2414         , l_header_rec.ship_to_party_site_id
2415         , l_header_rec.ship_to_party_site_use_id
2416         , l_header_rec.deliver_to_party_id
2417         , l_header_rec.deliver_to_party_site_id
2418         , l_header_rec.deliver_to_party_site_use_id
2419         , l_header_rec.invoice_to_party_id
2420         , l_header_rec.invoice_to_party_site_id
2421         , l_header_rec.invoice_to_party_site_use_id
2422          -- automatic account creation }
2423          -- start of additional quoting columns
2424         , l_header_rec.transaction_phase_code
2425         , l_header_rec.expiration_date
2426         , l_header_rec.quote_number
2427         , l_header_rec.quote_date
2428         , l_header_rec.sales_document_name
2429         , l_header_rec.user_status_code
2430          -- end of additional quoting columns
2431      -- { Distributer Order related change
2432         , l_header_rec.end_customer_id
2433         , l_header_rec.end_customer_contact_id
2434         , l_header_rec.end_customer_site_use_id
2435         ,l_header_val_rec.end_customer_name  --mvijayku
2436 	 , l_header_val_rec.end_customer_site_address1
2437 	 , l_header_val_rec.end_customer_site_address2
2438 	 , l_header_val_rec.end_customer_site_address3
2439 	 , l_header_val_rec.end_customer_site_address4
2440 --	   , l_header_val_rec.end_customer_site_location
2441 	 , l_header_val_rec.end_customer_site_city
2442 	 , l_header_val_rec.end_customer_site_state
2443 	 , l_header_val_rec.end_customer_site_postal_code
2444 	 , l_header_val_rec.end_customer_site_country
2445 	 , l_header_val_rec.end_customer_contact
2446          , l_header_val_rec.end_customer_number
2447         , l_header_val_rec.ib_owner_dsp
2448         , l_header_val_rec.ib_current_location_dsp
2449         , l_header_val_rec.ib_installed_at_location_dsp
2450         , l_header_rec.ib_owner
2451         , l_header_rec.ib_current_location
2452         , l_header_rec.ib_installed_at_location
2453         , l_header_rec.END_CUSTOMER_PARTY_ID
2454 	 ,l_header_rec.END_CUSTOMER_ORG_CONTACT_ID
2455          ,l_header_rec.END_CUSTOMER_PARTY_SITE_ID
2456          ,l_header_rec.END_CUSTOMER_PARTY_SITE_USE_ID
2457          ,l_header_rec.END_CUSTOMER_PARTY_NUMBER
2458      -- Distributer Order related change }
2459      -- Automatic Account Creation
2460         , l_header_rec.sold_to_party_number
2461         , l_header_rec.ship_to_party_number
2462         , l_header_rec.invoice_to_party_number
2463         , l_header_rec.deliver_to_party_number
2464      -- Automatic Account Creation
2465          , l_header_val_rec.deliver_to_address1
2466          , l_header_val_rec.deliver_to_address2
2467          , l_header_val_rec.deliver_to_address3
2468          , l_header_val_rec.deliver_to_address4
2469          , l_header_val_rec.deliver_to_state
2470          , l_header_val_rec.deliver_to_county
2471          , l_header_val_rec.deliver_to_country
2472          , l_header_val_rec.deliver_to_province
2473          , l_header_val_rec.deliver_to_city
2474          , l_header_val_rec.deliver_to_zip
2475          , l_header_rec.instrument_security_code  --R12 CVV2
2476 ;
2477       --EXIT WHEN l_header_cursor%NOTFOUND;
2478 
2479       l_header_count := l_header_count + 1;
2480 
2481       l_order_source_id 	:= l_header_rec.order_source_id;
2482       l_orig_sys_document_ref 	:= l_header_rec.orig_sys_document_ref;
2483       l_sold_to_org_id          := l_header_rec.sold_to_org_id;
2484       l_sold_to_org             := l_header_val_rec.sold_to_org;
2485       l_change_sequence 	:= l_header_rec.change_sequence;
2486 
2487       IF l_header_rec.operation  = 'INSERT' THEN
2488          l_header_rec.operation := 'CREATE';
2489       END IF;
2490 
2491       IF l_debug_level  > 0 THEN
2492           oe_debug_pub.add(  'ORDER SOURCE ID: ' || L_ORDER_SOURCE_ID ) ;
2493 
2494           oe_debug_pub.add(  'ORIG SYS REFERENCE: '|| L_ORIG_SYS_DOCUMENT_REF ) ;
2495 	  oe_debug_pub.add(  'SOLD_TO_ORG passed in: ' || P_SOLD_TO_ORG ) ;
2496 	  oe_debug_pub.add(  'SOLD_TO_ORG_ID passed in: ' || P_SOLD_TO_ORG_ID ) ;
2497 	  oe_debug_pub.add(  'SOLD_TO_ORG: from record' || L_SOLD_TO_ORG ) ;
2498 	  oe_debug_pub.add(  'SOLD_TO_ORG_ID: from record' || L_SOLD_TO_ORG_ID ) ;
2499 
2500           oe_debug_pub.add(  'CHANGE SEQUENCE: ' || L_CHANGE_SEQUENCE ) ;
2501           oe_debug_pub.add('sarita: booked flag: '|| l_header_rec.booked_flag);
2502 
2503 
2504       END IF;
2505 
2506 
2507 
2508  IF OE_CODE_CONTROL.GET_CODE_RELEASE_LEVEL >= '110510' THEN
2509 
2510 /*    If l_sold_to_org_id is null attempt to populate it based on
2511           l_sold_to_org.
2512 
2513 */
2514       -- bug 3392678
2515       OE_GLOBALS.G_XML_TXN_CODE := NULL;
2516       IF l_header_rec.order_source_id = OE_Acknowledgment_Pub.G_XML_ORDER_SOURCE_ID
2517          AND nvl(l_header_rec.xml_transaction_type_code, FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR THEN
2518          OE_GLOBALS.G_XML_TXN_CODE := l_header_rec.xml_transaction_type_code;
2519          IF l_debug_level  > 0 THEN
2520             oe_debug_pub.add(  'SET GLOBAL TXN CODE TO '||OE_GLOBALS.G_XML_TXN_CODE ) ;
2521          END IF;
2522       END IF;
2523 
2524       IF l_header_rec.order_source_id NOT IN (OE_Acknowledgment_Pub.G_XML_ORDER_SOURCE_ID,
2525                                               OE_Globals.G_ORDER_SOURCE_EDI)
2526          AND l_header_rec.xml_message_id IS NULL THEN
2527          SELECT oe_xml_message_seq_s.nextval
2528            INTO l_header_rec.xml_message_id
2529            FROM DUAL;
2530       END IF;
2531 
2532      if l_sold_to_org_id = FND_API.G_MISS_NUM then
2533         IF l_debug_level  > 0 THEN
2534           oe_debug_pub.add(  'header level sold to org id is g_miss_num, so it was not populated' ) ;
2535         END IF;
2536 
2537       if (l_sold_to_org IS NOT NULL) AND
2538          (l_sold_to_org <> FND_API.G_MISS_CHAR) THEN
2539 
2540         IF l_debug_level  > 0 THEN
2541           oe_debug_pub.add(  'sold to org is populated:' || l_sold_to_org) ;
2542         END IF;
2543 
2544          l_sold_to_org_id_tmp   := OE_VALUE_TO_ID.sold_to_org(
2545 					    p_sold_to_org => l_sold_to_org,
2546 					    p_customer_number => null);
2547 
2548          if (l_sold_to_org_id_tmp <> FND_API.G_MISS_NUM) AND
2549             (l_sold_to_org_id_tmp IS NOT NULL) THEN
2550             IF l_debug_level  > 0 THEN
2551             oe_debug_pub.add(  'returned value for sold_to_org_id was ' || l_sold_to_org_id_tmp) ;
2552             END IF;
2553           l_header_rec.sold_to_org_id := l_sold_to_org_id_tmp;
2554          end if;
2555 
2556        end if;
2557 
2558      end if;
2559 END IF;  -- code control check
2560 
2561 
2562 /* -----------------------------------------------------------
2563    Header Discounts/Price adjustments
2564    -----------------------------------------------------------
2565 */
2566 
2567    IF l_debug_level  > 0 THEN
2568        oe_debug_pub.add(  'BEFORE HEADER ADJUSTMENTS LOOP' ) ;
2569    END IF;
2570 
2571   l_header_adj_count := 0;
2572 
2573   OPEN l_header_adj_cursor;
2574   LOOP
2575      FETCH l_header_adj_cursor
2576       INTO l_header_adj_rec.orig_sys_discount_ref
2577 	 , l_header_adj_rec.change_request_code
2578 	 , l_header_adj_rec.list_header_id	-- changed from discount_id
2579 	 , l_header_adj_rec.list_line_id	-- changed from discount_line_id
2580 	 , l_header_adj_val_rec.discount
2581 	 , l_header_adj_rec.percent
2582 	 , l_header_adj_rec.automatic_flag
2583 	 , l_header_adj_rec.applied_flag
2584 	 , l_header_adj_rec.operand
2585 	 , l_header_adj_rec.arithmetic_operator
2586 	 , l_header_adj_rec.context
2587 	 , l_header_adj_rec.attribute1
2588 	 , l_header_adj_rec.attribute2
2589 	 , l_header_adj_rec.attribute3
2590 	 , l_header_adj_rec.attribute4
2591 	 , l_header_adj_rec.attribute5
2592 	 , l_header_adj_rec.attribute6
2593 	 , l_header_adj_rec.attribute7
2594 	 , l_header_adj_rec.attribute8
2595 	 , l_header_adj_rec.attribute9
2596 	 , l_header_adj_rec.attribute10
2597 	 , l_header_adj_rec.attribute11
2598 	 , l_header_adj_rec.attribute12
2599 	 , l_header_adj_rec.attribute13
2600 	 , l_header_adj_rec.attribute14
2601 	 , l_header_adj_rec.attribute15
2602          , l_header_adj_rec.request_id
2603 	 , l_header_adj_rec.operation
2604 	 , l_header_adj_rec.status_flag
2605 -- Price Adjustment related changes bug# 1220921 (Start)
2606       , l_header_adj_rec.AC_CONTEXT
2607       , l_header_adj_rec.AC_ATTRIBUTE1
2608       , l_header_adj_rec.AC_ATTRIBUTE2
2609       , l_header_adj_rec.AC_ATTRIBUTE3
2610       , l_header_adj_rec.AC_ATTRIBUTE4
2611       , l_header_adj_rec.AC_ATTRIBUTE5
2612       , l_header_adj_rec.AC_ATTRIBUTE6
2613       , l_header_adj_rec.AC_ATTRIBUTE7
2614       , l_header_adj_rec.AC_ATTRIBUTE8
2615       , l_header_adj_rec.AC_ATTRIBUTE9
2616       , l_header_adj_rec.AC_ATTRIBUTE10
2617       , l_header_adj_rec.AC_ATTRIBUTE11
2618       , l_header_adj_rec.AC_ATTRIBUTE12
2619       , l_header_adj_rec.AC_ATTRIBUTE13
2620       , l_header_adj_rec.AC_ATTRIBUTE14
2621       , l_header_adj_rec.AC_ATTRIBUTE15
2622       , l_header_adj_val_rec.LIST_NAME
2623       , l_header_adj_rec.LIST_LINE_TYPE_CODE
2624       , l_header_adj_rec.LIST_LINE_NO
2625       , l_header_adj_val_rec.VERSION_NO
2626       , l_header_adj_rec.INVOICED_FLAG
2627       , l_header_adj_rec.ESTIMATED_FLAG
2628       , l_header_adj_rec.INC_IN_SALES_PERFORMANCE
2629       , l_header_adj_rec.CHARGE_TYPE_CODE
2630       , l_header_adj_rec.CHARGE_SUBTYPE_CODE
2631       , l_header_adj_rec.CREDIT_OR_CHARGE_FLAG
2632       , l_header_adj_rec.INCLUDE_ON_RETURNS_FLAG
2633       , l_header_adj_rec.COST_ID
2634       , l_header_adj_rec.TAX_CODE
2635       , l_header_adj_rec.PARENT_ADJUSTMENT_ID
2636       , l_header_adj_rec.MODIFIER_MECHANISM_TYPE_CODE
2637       , l_header_adj_rec.MODIFIED_FROM
2638       , l_header_adj_rec.MODIFIED_TO
2639       , l_header_adj_rec.UPDATED_FLAG
2640       , l_header_adj_rec.UPDATE_ALLOWED
2641       , l_header_adj_rec.CHANGE_REASON_CODE
2642       , l_header_adj_rec.CHANGE_REASON_TEXT
2643       , l_header_adj_rec.PRICING_PHASE_ID
2644       , l_header_adj_rec.ADJUSTED_AMOUNT
2645 -- Price Adjustment related changes bug# 1220921 (End)
2646 ;
2647       EXIT WHEN l_header_adj_cursor%NOTFOUND;
2648 
2649       IF l_header_adj_rec.operation  = 'INSERT' THEN
2650          l_header_adj_rec.operation := 'CREATE';
2651       END IF;
2652 
2653       IF(l_header_adj_count > 0) THEN
2654         IF(l_header_adj_rec.orig_sys_discount_ref = l_header_adj_tbl(l_header_adj_count).orig_sys_discount_ref) THEN
2655           --duplicate
2656           p_return_status := FND_API.G_RET_STS_ERROR;
2657           l_validate_only := FND_API.G_TRUE;
2658           IF l_debug_level  > 0 THEN
2659               oe_debug_pub.add(  'YOU ARE ENTERING A DUPLICATE ORIG_SYS_DISCOUNT_REF FOR THE SAME ORDER' ) ;
2660           END IF;
2661 
2662           FND_MESSAGE.SET_NAME('ONT','OE_OI_DUPLICATE_REF');
2663           FND_MESSAGE.SET_TOKEN('DUPLICATE_REF','orig_sys_discount_ref');
2664           OE_MSG_PUB.Add;
2665 
2666         END IF;
2667       END IF;
2668 
2669       l_header_adj_count := l_header_adj_count + 1;
2670       l_header_adj_tbl     (l_header_adj_count) := l_header_adj_rec;
2671       l_header_adj_val_tbl (l_header_adj_count) := l_header_adj_val_rec;
2672 
2673 		IF l_debug_level  > 0 THEN
2674 		    oe_debug_pub.add(  'HEADER ADJ REF ( '||L_HEADER_ADJ_COUNT||' ) : '|| L_HEADER_ADJ_TBL ( L_HEADER_ADJ_COUNT ) .ORIG_SYS_DISCOUNT_REF ) ;
2675 		END IF;
2676 
2677   END LOOP;
2678   CLOSE l_header_adj_cursor;
2679 
2680 
2681 /* -----------------------------------------------------------
2682    Header Price Attribs
2683    -----------------------------------------------------------
2684 */
2685    IF l_debug_level  > 0 THEN
2686        oe_debug_pub.add(  'BEFORE HEADER ATTRIBS LOOP' ) ;
2687    END IF;
2688 
2689   l_header_att_count := 0;
2690 
2691   OPEN l_header_attrib_cursor;
2692  LOOP
2693   FETCH l_header_attrib_cursor
2694   INTO l_header_price_att_rec.orig_sys_atts_ref
2695     , l_header_price_att_rec.change_request_code
2696     , l_header_price_att_rec.creation_date
2697     , l_header_price_att_rec.created_by
2698     , l_header_price_att_rec.last_update_date
2699     , l_header_price_att_rec.last_updated_by
2700     , l_header_price_att_rec.last_update_login
2701     , l_header_price_att_rec.program_application_id
2702     , l_header_price_att_rec.program_id
2703     , l_header_price_att_rec.program_update_date
2704     , l_header_price_att_rec.request_id
2705     , l_header_price_att_rec.flex_title
2706     , l_header_price_att_rec.pricing_context
2707     , l_header_price_att_rec.pricing_attribute1
2708     , l_header_price_att_rec.pricing_attribute2
2709     , l_header_price_att_rec.pricing_attribute3
2710     , l_header_price_att_rec.pricing_attribute4
2711     , l_header_price_att_rec.pricing_attribute5
2712     , l_header_price_att_rec.pricing_attribute6
2713     , l_header_price_att_rec.pricing_attribute7
2714     , l_header_price_att_rec.pricing_attribute8
2715     , l_header_price_att_rec.pricing_attribute9
2716     , l_header_price_att_rec.pricing_attribute10
2717     , l_header_price_att_rec.pricing_attribute11
2718     , l_header_price_att_rec.pricing_attribute12
2719     , l_header_price_att_rec.pricing_attribute13
2720     , l_header_price_att_rec.pricing_attribute14
2721     , l_header_price_att_rec.pricing_attribute15
2722     , l_header_price_att_rec.pricing_attribute16
2723     , l_header_price_att_rec.pricing_attribute17
2724     , l_header_price_att_rec.pricing_attribute18
2725     , l_header_price_att_rec.pricing_attribute19
2726     , l_header_price_att_rec.pricing_attribute20
2727     , l_header_price_att_rec.pricing_attribute21
2728     , l_header_price_att_rec.pricing_attribute22
2729     , l_header_price_att_rec.pricing_attribute23
2730     , l_header_price_att_rec.pricing_attribute24
2731     , l_header_price_att_rec.pricing_attribute25
2732     , l_header_price_att_rec.pricing_attribute26
2733     , l_header_price_att_rec.pricing_attribute27
2734     , l_header_price_att_rec.pricing_attribute28
2735     , l_header_price_att_rec.pricing_attribute29
2736     , l_header_price_att_rec.pricing_attribute30
2737     , l_header_price_att_rec.pricing_attribute31
2738     , l_header_price_att_rec.pricing_attribute32
2739     , l_header_price_att_rec.pricing_attribute33
2740     , l_header_price_att_rec.pricing_attribute34
2741     , l_header_price_att_rec.pricing_attribute35
2742     , l_header_price_att_rec.pricing_attribute36
2743     , l_header_price_att_rec.pricing_attribute37
2744     , l_header_price_att_rec.pricing_attribute38
2745     , l_header_price_att_rec.pricing_attribute39
2746     , l_header_price_att_rec.pricing_attribute40
2747     , l_header_price_att_rec.pricing_attribute41
2748     , l_header_price_att_rec.pricing_attribute42
2749     , l_header_price_att_rec.pricing_attribute43
2750     , l_header_price_att_rec.pricing_attribute44
2751     , l_header_price_att_rec.pricing_attribute45
2752     , l_header_price_att_rec.pricing_attribute46
2753     , l_header_price_att_rec.pricing_attribute47
2754     , l_header_price_att_rec.pricing_attribute48
2755     , l_header_price_att_rec.pricing_attribute49
2756     , l_header_price_att_rec.pricing_attribute50
2757     , l_header_price_att_rec.pricing_attribute51
2758     , l_header_price_att_rec.pricing_attribute52
2759     , l_header_price_att_rec.pricing_attribute53
2760     , l_header_price_att_rec.pricing_attribute54
2761     , l_header_price_att_rec.pricing_attribute55
2762     , l_header_price_att_rec.pricing_attribute56
2763     , l_header_price_att_rec.pricing_attribute57
2764     , l_header_price_att_rec.pricing_attribute58
2765     , l_header_price_att_rec.pricing_attribute59
2766     , l_header_price_att_rec.pricing_attribute60
2767     , l_header_price_att_rec.pricing_attribute61
2768     , l_header_price_att_rec.pricing_attribute62
2769     , l_header_price_att_rec.pricing_attribute63
2770     , l_header_price_att_rec.pricing_attribute64
2771     , l_header_price_att_rec.pricing_attribute65
2772     , l_header_price_att_rec.pricing_attribute66
2773     , l_header_price_att_rec.pricing_attribute67
2774     , l_header_price_att_rec.pricing_attribute68
2775     , l_header_price_att_rec.pricing_attribute69
2776     , l_header_price_att_rec.pricing_attribute70
2777     , l_header_price_att_rec.pricing_attribute71
2778     , l_header_price_att_rec.pricing_attribute72
2779     , l_header_price_att_rec.pricing_attribute73
2780     , l_header_price_att_rec.pricing_attribute74
2781     , l_header_price_att_rec.pricing_attribute75
2782     , l_header_price_att_rec.pricing_attribute76
2783     , l_header_price_att_rec.pricing_attribute77
2784     , l_header_price_att_rec.pricing_attribute78
2785     , l_header_price_att_rec.pricing_attribute79
2786     , l_header_price_att_rec.pricing_attribute80
2787     , l_header_price_att_rec.pricing_attribute81
2788     , l_header_price_att_rec.pricing_attribute82
2789     , l_header_price_att_rec.pricing_attribute83
2790     , l_header_price_att_rec.pricing_attribute84
2791     , l_header_price_att_rec.pricing_attribute85
2792     , l_header_price_att_rec.pricing_attribute86
2793     , l_header_price_att_rec.pricing_attribute87
2794     , l_header_price_att_rec.pricing_attribute88
2795     , l_header_price_att_rec.pricing_attribute89
2796     , l_header_price_att_rec.pricing_attribute90
2797     , l_header_price_att_rec.pricing_attribute91
2798     , l_header_price_att_rec.pricing_attribute92
2799     , l_header_price_att_rec.pricing_attribute93
2800     , l_header_price_att_rec.pricing_attribute94
2801     , l_header_price_att_rec.pricing_attribute95
2802     , l_header_price_att_rec.pricing_attribute96
2803     , l_header_price_att_rec.pricing_attribute97
2804     , l_header_price_att_rec.pricing_attribute98
2805     , l_header_price_att_rec.pricing_attribute99
2806     , l_header_price_att_rec.pricing_attribute100
2807     , l_header_price_att_rec.context
2808     , l_header_price_att_rec.attribute1
2809     , l_header_price_att_rec.attribute2
2810     , l_header_price_att_rec.attribute3
2811     , l_header_price_att_rec.attribute4
2812     , l_header_price_att_rec.attribute5
2813     , l_header_price_att_rec.attribute6
2814     , l_header_price_att_rec.attribute7
2815     , l_header_price_att_rec.attribute8
2816     , l_header_price_att_rec.attribute9
2817     , l_header_price_att_rec.attribute10
2818     , l_header_price_att_rec.attribute11
2819     , l_header_price_att_rec.attribute12
2820     , l_header_price_att_rec.attribute13
2821     , l_header_price_att_rec.attribute14
2822     , l_header_price_att_rec.attribute15
2823     , l_header_price_att_rec.operation;
2824 
2825     EXIT WHEN l_header_attrib_cursor%NOTFOUND;
2826 
2827     IF( l_header_price_att_rec.operation = 'INSERT') THEN
2828        l_header_price_att_rec.operation := 'CREATE';
2829     END IF;
2830     l_header_price_att_rec.flex_title := 'QP_ATTR_DEFNS_QUALIFIER'; --bug#5679839
2831  IF( l_header_att_count > 0 ) THEN
2832    IF (l_header_price_att_rec.orig_sys_atts_ref =l_header_price_att_tbl(l_header_att_count).orig_sys_atts_ref) THEN
2833      -- duplicate
2834      p_return_status := FND_API.G_RET_STS_ERROR;
2835      l_validate_only := FND_API.G_TRUE;
2836      IF l_debug_level  > 0 THEN
2837         oe_debug_pub.add(  'YOU ARE ENTERING A DUPLICATE ORIG_SYS_ATTS_REF FOR THE SAME ORDER' ) ;
2838      END IF;
2839           FND_MESSAGE.SET_NAME('ONT','OE_OI_DUPLICATE_REF');
2840           FND_MESSAGE.SET_TOKEN('DUPLICATE_REF','orig_sys_ats_ref');
2841           OE_MSG_PUB.Add;
2842    END IF;
2843   END IF;
2844   l_header_att_count := l_header_att_count +1;
2845   l_header_price_att_tbl(l_header_att_count) := l_header_price_att_rec;
2846 
2847 END LOOP;
2848 
2849 CLOSE l_header_attrib_cursor;
2850 
2851 /* -----------------------------------------------------------
2852    Header Sales Credits
2853    -----------------------------------------------------------
2854 */
2855    IF l_debug_level  > 0 THEN
2856        oe_debug_pub.add(  'BEFORE HEADER SALES CREDITS LOOP' ) ;
2857    END IF;
2858 
2859   l_header_scredit_count := 0;
2860 
2861   OPEN l_header_scredit_cursor;
2862   LOOP
2863      FETCH l_header_scredit_cursor
2864       INTO l_header_scredit_rec.orig_sys_credit_ref
2865 	 , l_header_scredit_rec.change_request_code
2866 	 , l_header_scredit_rec.salesrep_id
2867 	 , l_header_scredit_val_rec.salesrep
2868 	 , l_header_scredit_rec.sales_credit_type_id
2869 	 , l_header_scredit_val_rec.sales_credit_type
2870 	 , l_header_scredit_rec.percent
2871 	 , l_header_scredit_rec.context
2872 	 , l_header_scredit_rec.attribute1
2873 	 , l_header_scredit_rec.attribute2
2874 	 , l_header_scredit_rec.attribute3
2875 	 , l_header_scredit_rec.attribute4
2876 	 , l_header_scredit_rec.attribute5
2877 	 , l_header_scredit_rec.attribute6
2878 	 , l_header_scredit_rec.attribute7
2879 	 , l_header_scredit_rec.attribute8
2880 	 , l_header_scredit_rec.attribute9
2881 	 , l_header_scredit_rec.attribute10
2882 	 , l_header_scredit_rec.attribute11
2883 	 , l_header_scredit_rec.attribute12
2884 	 , l_header_scredit_rec.attribute13
2885 	 , l_header_scredit_rec.attribute14
2886 	 , l_header_scredit_rec.attribute15
2887 	 , l_header_scredit_rec.operation
2888 	 , l_header_scredit_rec.status_flag
2889          , l_header_scredit_rec.change_reason
2890          , l_header_scredit_rec.change_comments
2891 ;
2892       EXIT WHEN l_header_scredit_cursor%NOTFOUND;
2893 
2894       IF l_header_scredit_rec.operation  = 'INSERT' THEN
2895          l_header_scredit_rec.operation := 'CREATE';
2896       END IF;
2897 
2898       IF(l_header_scredit_count > 0) THEN
2899         IF(l_header_scredit_rec.orig_sys_credit_ref = l_header_scredit_tbl(l_header_scredit_count).orig_sys_credit_ref) THEN
2900           --duplicate
2901           p_return_status := FND_API.G_RET_STS_ERROR;
2902           l_validate_only := FND_API.G_TRUE;
2903           IF l_debug_level  > 0 THEN
2904               oe_debug_pub.add(  'YOU ARE ENTERING A DUPLICATE ORIG_SYS_CREDIT_REF FORTHE SAME ORDER' ) ;
2905           END IF;
2906           FND_MESSAGE.SET_NAME('ONT','OE_OI_DUPLICATE_REF');
2907           FND_MESSAGE.SET_TOKEN('DUPLICATE_REF','orig_sys_credit_ref');
2908           OE_MSG_PUB.Add;
2909         END IF;
2910       END IF;
2911 
2912       l_header_scredit_count := l_header_scredit_count + 1;
2913       l_header_scredit_tbl     (l_header_scredit_count) := l_header_scredit_rec;
2914       l_header_scredit_val_tbl (l_header_scredit_count) := l_header_scredit_val_rec;
2915 
2916       	IF l_debug_level  > 0 THEN
2917       	    oe_debug_pub.add(  'HEADER SALESCREDIT ( '|| L_HEADER_SCREDIT_COUNT||' ) : '|| L_HEADER_SCREDIT_TBL ( L_HEADER_SCREDIT_COUNT ) .ORIG_SYS_CREDIT_REF ) ;
2918       	END IF;
2919 
2920   END LOOP;
2921   CLOSE l_header_scredit_cursor;
2922 
2923 /* -----------------------------------------------------------
2924    Multiple Payments: Header PAYMENTs
2925    -----------------------------------------------------------
2926 */
2927    IF l_debug_level  > 0 THEN
2928        oe_debug_pub.add(  'BEFORE HEADER PAYMENTS LOOP' ) ;
2929    END IF;
2930 
2931   l_header_payment_count := 0;
2932 
2933   OPEN l_header_payment_cursor;
2934   LOOP
2935      FETCH l_header_payment_cursor
2936      INTO  l_header_payment_rec.orig_sys_payment_ref
2937 	 , l_header_payment_rec.change_request_code
2938 	 , l_header_payment_rec.payment_type_code
2939 	 , l_header_payment_val_rec.commitment
2940 	 , l_header_payment_rec.payment_trx_id
2941 	 , l_header_payment_val_rec.receipt_method
2942 	 , l_header_payment_rec.receipt_method_id
2943 	 , l_header_payment_rec.payment_collection_event
2944 	 , l_header_payment_rec.payment_set_id
2945 	 , l_header_payment_rec.prepaid_amount
2946 	 , l_header_payment_rec.credit_card_number
2947 	 , l_header_payment_rec.credit_card_holder_name
2948 	 , l_header_payment_rec.credit_card_expiration_date
2949 	 , l_header_payment_rec.credit_card_code
2950 	 , l_header_payment_rec.credit_card_approval_code
2951 	 , l_header_payment_rec.credit_card_approval_date
2952 	 , l_header_payment_rec.check_number
2953 	 , l_header_payment_rec.payment_amount
2954 	 , l_header_payment_val_rec.payment_percentage
2955 	 , l_header_payment_rec.creation_date
2956          , l_header_payment_rec.created_by
2957          , l_header_payment_rec.last_update_date
2958          , l_header_payment_rec.last_updated_by
2959          , l_header_payment_rec.last_update_login
2960          , l_header_payment_rec.program_application_id
2961          , l_header_payment_rec.program_id
2962          , l_header_payment_rec.program_update_date
2963 	 , l_header_payment_rec.context
2964 	 , l_header_payment_rec.attribute1
2965 	 , l_header_payment_rec.attribute2
2966 	 , l_header_payment_rec.attribute3
2967 	 , l_header_payment_rec.attribute4
2968 	 , l_header_payment_rec.attribute5
2969 	 , l_header_payment_rec.attribute6
2970 	 , l_header_payment_rec.attribute7
2971 	 , l_header_payment_rec.attribute8
2972 	 , l_header_payment_rec.attribute9
2973 	 , l_header_payment_rec.attribute10
2974 	 , l_header_payment_rec.attribute11
2975 	 , l_header_payment_rec.attribute12
2976 	 , l_header_payment_rec.attribute13
2977 	 , l_header_payment_rec.attribute14
2978 	 , l_header_payment_rec.attribute15
2979 	 , l_header_payment_rec.operation
2980 	 , l_header_payment_rec.status_flag
2981 	 , l_header_payment_rec.payment_number
2982 	 , l_header_payment_rec.header_id
2983 	 , l_header_payment_rec.line_id
2984          , l_header_payment_rec.DEFER_PAYMENT_PROCESSING_FLAG -- Added for bug 8478559
2985 	 , l_header_payment_rec.trxn_extension_id
2986          , l_header_payment_rec.instrument_security_code  --R12 CVV2
2987 ;
2988       EXIT WHEN l_header_payment_cursor%NOTFOUND;
2989 
2990       IF l_header_payment_rec.operation  = 'INSERT' THEN
2991          l_header_payment_rec.operation := 'CREATE';
2992       END IF;
2993 
2994       IF l_header_payment_rec.operation = 'CREATE' THEN
2995       -- set it to miss num, so payment number will be generated internally.
2996          l_header_payment_rec.payment_number :=  FND_API.G_MISS_NUM;
2997       END IF;
2998 
2999       IF(l_header_payment_count > 0) THEN
3000         IF(l_header_payment_rec.orig_sys_payment_ref = l_header_payment_tbl(l_header_payment_count).orig_sys_payment_ref) THEN
3001           --duplicate
3002 
3003           l_validate_only := FND_API.G_TRUE;
3004           IF l_debug_level  > 0 THEN
3005               oe_debug_pub.add(  'YOU ARE ENTERING A DUPLICATE ORIG_SYS_payment_REF FORTHE SAME ORDER' ) ;
3006           END IF;
3007           FND_MESSAGE.SET_NAME('ONT','OE_OI_DUPLICATE_REF');
3008           FND_MESSAGE.SET_TOKEN('DUPLICATE_REF','orig_sys_payment_ref');
3009           OE_MSG_PUB.Add;
3010 
3011         END IF;
3012       END IF;
3013 
3014       l_header_payment_count := l_header_payment_count + 1;
3015       l_header_payment_tbl     (l_header_payment_count) := l_header_payment_rec;
3016       l_header_payment_val_tbl (l_header_payment_count) := l_header_payment_val_rec;
3017 
3018       	IF l_debug_level  > 0 THEN
3019       	    oe_debug_pub.add(  'HEADER PAYMENT ( '|| L_HEADER_PAYMENT_COUNT||' ) : '|| L_HEADER_payment_TBL ( L_HEADER_payment_COUNT ) .ORIG_SYS_payment_REF ) ;
3020       	END IF;
3021 
3022 
3023   END LOOP;
3024   CLOSE l_header_payment_cursor;
3025 -- end of multiple payments: fetching header payment.
3026 
3027 /* myerrams, Bug:4724191
3028 --myerrams, start
3029 select header_id into l_header_id_temp
3030 	from oe_order_headers_all
3031 	where orig_sys_document_ref = l_orig_sys_document_ref;
3032 --myerrams, end
3033 */
3034 
3035   l_action_request_count := 0;
3036   OPEN l_action_request_header_cursor;
3037   LOOP
3038      FETCH l_action_request_header_cursor
3039       INTO l_action_rec.orig_sys_line_ref
3040          , l_action_rec.orig_sys_shipment_ref
3041 	 , l_action_rec.hold_id
3042 	 , l_action_rec.hold_type_code
3043 	 , l_action_rec.hold_type_id
3044 	 , l_action_rec.hold_until_date
3045 	 , l_action_rec.release_reason_code
3046 	 , l_action_rec.comments
3047 	 , l_action_rec.context
3048 	 , l_action_rec.attribute1
3049 	 , l_action_rec.attribute2
3050 	 , l_action_rec.attribute3
3051 	 , l_action_rec.attribute4
3052 	 , l_action_rec.attribute5
3053 	 , l_action_rec.attribute6
3054 	 , l_action_rec.attribute7
3055 	 , l_action_rec.attribute8
3056 	 , l_action_rec.attribute9
3057 	 , l_action_rec.attribute10
3058 	 , l_action_rec.attribute11
3059 	 , l_action_rec.attribute12
3060 	 , l_action_rec.attribute13
3061 	 , l_action_rec.attribute14
3062 	 , l_action_rec.attribute15
3063 	 , l_action_rec.operation_code
3064 	 , l_action_rec.error_flag
3065 	 , l_action_rec.status_flag
3066 	 , l_action_rec.interface_status
3067 --myerrams,start, modified the fetch statement to fetch newly introduced
3068 --fields in oe_actions_interface for Customer Acceptance
3069 	 , l_action_rec.char_param1
3070 	 , l_action_rec.char_param2
3071 	 , l_action_rec.char_param3
3072 	 , l_action_rec.char_param4
3073 	 , l_action_rec.char_param5
3074 	 , l_action_rec.date_param1
3075 	 , l_action_rec.date_param2
3076 	 , l_action_rec.date_param3
3077 	 , l_action_rec.date_param4
3078 	 , l_action_rec.date_param5
3079 --myerrams, end
3080 ;
3081       EXIT WHEN l_action_request_header_cursor%NOTFOUND;
3082       l_action_request_rec.request_type := l_action_rec.operation_code;
3083 
3084       l_action_request_rec.entity_code := OE_Globals.G_ENTITY_HEADER;
3085       --l_action_request_rec.entity_id   := l_header_rec_new.header_id;
3086 
3087       IF l_debug_level  > 0 THEN
3088           oe_debug_pub.add(  'ACTION CODE: '|| L_ACTION_REQUEST_REC.REQUEST_TYPE , 1 ) ;
3089 
3090           oe_debug_pub.add(  'ENTITY CODE: '|| L_ACTION_REQUEST_REC.ENTITY_CODE , 1 ) ;
3091 
3092           oe_debug_pub.add(  'ENTITY ID : '|| L_ACTION_REQUEST_REC.ENTITY_ID , 1 ) ;
3093       END IF;
3094 
3095       IF l_action_rec.operation_code = OE_Globals.G_APPLY_HOLD THEN
3096 	 l_action_request_rec.param1  := l_action_rec.hold_id;
3097 	 l_action_request_rec.param2  := nvl(l_action_rec.hold_type_code,'O');
3098 	 l_action_request_rec.param3  := nvl(l_action_rec.hold_type_id,
3099 					     l_action_request_rec.entity_id);
3100 	 l_action_request_rec.param4  := l_action_rec.comments;
3101 	 l_action_request_rec.date_param1  := l_action_rec.hold_until_date;
3102 	 l_action_request_rec.param10 := l_action_rec.context;
3103 	 l_action_request_rec.param11 := l_action_rec.attribute1;
3104 	 l_action_request_rec.param12 := l_action_rec.attribute2;
3105 	 l_action_request_rec.param13 := l_action_rec.attribute3;
3106 	 l_action_request_rec.param14 := l_action_rec.attribute4;
3107 	 l_action_request_rec.param15 := l_action_rec.attribute5;
3108 	 l_action_request_rec.param16 := l_action_rec.attribute6;
3109 	 l_action_request_rec.param17 := l_action_rec.attribute7;
3110 	 l_action_request_rec.param18 := l_action_rec.attribute8;
3111 	 l_action_request_rec.param19 := l_action_rec.attribute9;
3112 	 l_action_request_rec.param20 := l_action_rec.attribute10;
3113 	 l_action_request_rec.param21 := l_action_rec.attribute11;
3114 	 l_action_request_rec.param22 := l_action_rec.attribute12;
3115 	 l_action_request_rec.param23 := l_action_rec.attribute13;
3116 	 l_action_request_rec.param24 := l_action_rec.attribute14;
3117 	 l_action_request_rec.param25 := l_action_rec.attribute15;
3118 
3119       IF l_debug_level  > 0 THEN
3120           oe_debug_pub.add(  'PARAM1/HOLD_ID: ' || L_ACTION_REQUEST_REC.PARAM1 , 1 ) ;
3121 
3122           oe_debug_pub.add(  'PARAM2/HOLD_ENT_CD: '|| L_ACTION_REQUEST_REC.PARAM2 , 1 ) ;
3123 
3124           oe_debug_pub.add(  'PARAM3/HOLD_ENT_ID: '|| L_ACTION_REQUEST_REC.PARAM3 , 1 ) ;
3125 
3126           oe_debug_pub.add(  'PARAM4/HOLD_CMNTS: ' || L_ACTION_REQUEST_REC.PARAM4 , 1 ) ;
3127       END IF;
3128 
3129       ELSIF l_action_rec.operation_code = OE_Globals.G_RELEASE_HOLD THEN
3130 	 l_action_request_rec.param1  := l_action_rec.hold_id;
3131 	 l_action_request_rec.param2  := nvl(l_action_rec.hold_type_code,'O');
3132 	 l_action_request_rec.param3  := nvl(l_action_rec.hold_type_id,
3133 					     l_action_request_rec.entity_id);
3134 	 l_action_request_rec.param4  := l_action_rec.release_reason_code;
3135 	 l_action_request_rec.param5  := l_action_rec.comments;
3136 
3137       IF l_debug_level  > 0 THEN
3138           oe_debug_pub.add(  'PARAM1/HOLD_ID: ' || L_ACTION_REQUEST_REC.PARAM1 , 1 ) ;
3139 
3140           oe_debug_pub.add(  'PARAM2/HOLD_ENT_CD: '|| L_ACTION_REQUEST_REC.PARAM2 , 1 ) ;
3141 
3142           oe_debug_pub.add(  'PARAM3/HOLD_ENT_ID: '|| L_ACTION_REQUEST_REC.PARAM3 , 1 ) ;
3143 
3144           oe_debug_pub.add(  'PARAM4/REL_REASON: ' || L_ACTION_REQUEST_REC.PARAM4 , 1 ) ;
3145 
3146           oe_debug_pub.add(  'PARAM5/REL_COMMNTS: '|| L_ACTION_REQUEST_REC.PARAM5 , 1 ) ;
3147       END IF;
3148 
3149 --myerrams, introduced the following check for Customer Acceptance.
3150       ELSIF l_action_rec.operation_code = OE_Globals.G_ACCEPT_FULFILLMENT  OR l_action_rec.operation_code = OE_Globals.G_REJECT_FULFILLMENT THEN
3151          IF (OE_SYS_PARAMETERS.VALUE('ENABLE_FULFILLMENT_ACCEPTANCE',p_org_id) = 'Y')
3152 	 THEN
3153         -- Customer Comments
3154 	 l_action_request_rec.param1  := l_action_rec.char_param1;
3155         -- Customer Signature
3156 	 l_action_request_rec.param2  := l_action_rec.char_param2;
3157         -- Reference Document
3158 	 l_action_request_rec.param3  := l_action_rec.char_param3;
3159         -- Implicit Acceptance Flag
3160 	 l_action_request_rec.param4  := l_action_rec.char_param4;
3161 --myerrams, Bug:4724191	 l_action_request_rec.param5  := l_header_id_temp;
3162         -- Customer Signature Date
3163 	 l_action_request_rec.date_param1  := l_action_rec.date_param1;
3164          ELSE
3165 --display a message saying Customer Acceptance is not enabled
3166 	       FND_MESSAGE.Set_Name('ONT', 'ONT_CUST_ACC_DISABLED');
3167 	       OE_MSG_PUB.add;
3168 	 END IF;
3169 
3170       IF l_debug_level  > 0 THEN
3171           oe_debug_pub.add(  'PARAM2/CUSTOMER_COMMENTS: ' || L_ACTION_REQUEST_REC.PARAM2 , 1 ) ;
3172 
3173           oe_debug_pub.add(  'PARAM3/CUSTOMER_SIGNATURE: '|| L_ACTION_REQUEST_REC.PARAM3 , 1 ) ;
3174 
3175           oe_debug_pub.add(  'PARAM4/REFERENCE_DOCUMENT: '|| L_ACTION_REQUEST_REC.PARAM4 , 1 ) ;
3176 
3177           oe_debug_pub.add(  'PARAM5/IMPLICIT ACCEPTANCE FLAG: ' || L_ACTION_REQUEST_REC.PARAM5 , 1 ) ;
3178 
3179           oe_debug_pub.add(  'DATE_PARAM1/SIGNATURE_DATE: '|| L_ACTION_REQUEST_REC.DATE_PARAM1 , 1 ) ;
3180       END IF;
3181 --myerrams, end
3182       END IF;
3183 
3184       l_action_request_count := l_action_request_count+1;
3185       l_action_request_tbl(l_action_request_count) := l_action_request_rec;
3186 
3187   END LOOP;
3188   CLOSE l_action_request_header_cursor;
3189 
3190 /* -----------------------------------------------------------
3191    Lines
3192    -----------------------------------------------------------
3193 */
3194    IF l_debug_level  > 0 THEN
3195        oe_debug_pub.add(  'BEFORE LINES LOOP' ) ;
3196    END IF;
3197 
3198   l_line_count := 0;
3199 
3200   OPEN l_line_cursor;
3201   LOOP
3202      FETCH l_line_cursor
3203       INTO l_line_rec.order_source_id
3204          , l_line_rec.orig_sys_document_ref
3205          , l_line_rec.orig_sys_line_ref
3206 	 , l_line_rec.orig_sys_shipment_ref
3207 	 , l_line_rec.change_request_code
3208 	 , l_line_rec.org_id
3209 	 , l_line_rec.line_number
3210 	 , l_line_rec.shipment_number
3211 	 , l_line_rec.line_id
3212 	 , l_line_rec.line_type_id
3213 	 , l_line_val_rec.line_type
3214 	 , l_line_rec.item_type_code
3215 	 , l_line_rec.inventory_item_id
3216 	 , l_line_val_rec.inventory_item
3217 	 , l_line_rec.top_model_line_ref
3218 	 , l_line_rec.link_to_line_ref
3219 	 , l_line_rec.explosion_date
3220 	 , l_line_rec.ato_line_id
3221 	 , l_line_rec.component_sequence_id
3222 	 , l_line_rec.component_code
3223 	 , l_line_rec.sort_order
3224 	 , l_line_rec.model_group_number
3225 	 , l_line_rec.option_number
3226 	 , l_line_rec.option_flag
3227 	 , l_line_rec.ship_model_complete_flag
3228 	 , l_line_rec.source_type_code
3229 	 , l_line_rec.schedule_status_code
3230 	 , l_line_rec.schedule_ship_date
3231          , l_line_rec.late_demand_penalty_factor
3232 	 , l_line_rec.schedule_arrival_date
3233 	 , l_line_rec.actual_arrival_date
3234   	 , l_line_rec.request_date
3235 	 , l_line_rec.promise_date
3236 	 , l_line_rec.delivery_lead_time
3237 	 , l_line_rec.ordered_quantity
3238 	 , l_line_rec.order_quantity_uom
3239 	 , l_line_rec.shipping_quantity
3240 	 , l_line_rec.shipping_quantity_uom
3241 	 , l_line_rec.shipped_quantity
3242 	 , l_line_rec.cancelled_quantity
3243 	 , l_line_rec.fulfilled_quantity
3244    /* OPM variables */
3245          , l_line_rec.ordered_quantity2
3246          , l_line_rec.ordered_quantity_uom2
3247          , l_line_rec.shipping_quantity2
3248          , l_line_rec.shipping_quantity_uom2
3249          , l_line_rec.shipped_quantity2
3250          , l_line_rec.cancelled_quantity2
3251          , l_line_rec.fulfilled_quantity2
3252          , l_line_rec.preferred_grade
3253    /* end OPM variables */
3254 	 , l_line_rec.pricing_quantity
3255 	 , l_line_rec.pricing_quantity_uom
3256 	 , l_line_rec.sold_from_org_id
3257 	 , l_line_val_rec.sold_from_org
3258 	 , l_line_rec.sold_to_org_id
3259 	 , l_line_val_rec.sold_to_org
3260 	 , l_line_rec.ship_from_org_id
3261 	 , l_line_val_rec.ship_from_org
3262 	 , l_line_rec.ship_to_org_id
3263 	 , l_line_val_rec.ship_to_org
3264 	 , l_line_rec.deliver_to_org_id
3265 	 , l_line_val_rec.deliver_to_org
3266 	 , l_line_rec.invoice_to_org_id
3267 	 , l_line_val_rec.invoice_to_org
3268 	 , l_line_val_rec.ship_to_address1
3269 	 , l_line_val_rec.ship_to_address2
3270 	 , l_line_val_rec.ship_to_address3
3271 	 , l_line_val_rec.ship_to_address4
3272 	 , l_line_val_rec.ship_to_city
3273 	 , l_line_val_rec.ship_to_state
3274 	 , l_line_val_rec.ship_to_zip
3275 	 , l_line_val_rec.ship_to_country
3276 	 , l_line_rec.ship_to_contact_id
3277 	 , l_line_val_rec.ship_to_contact
3278 	 , l_line_rec.deliver_to_contact_id
3279 	 , l_line_val_rec.deliver_to_contact
3280 	 , l_line_rec.invoice_to_contact_id
3281 	 , l_line_val_rec.invoice_to_contact
3282 	 , l_line_rec.drop_ship_flag
3283 	 , l_line_rec.ship_tolerance_above
3284 	 , l_line_rec.ship_tolerance_below
3285 	 , l_line_rec.price_list_id
3286 	 , l_line_val_rec.price_list
3287 	 , l_line_rec.pricing_date
3288 	 , l_line_rec.unit_list_price
3289 	 , l_line_rec.unit_selling_price
3290 	 , l_line_rec.calculate_price_flag
3291 	 , l_line_rec.ship_set_id
3292 	 , l_line_rec.ship_set
3293 	 , l_line_rec.arrival_set_id
3294 	 , l_line_rec.arrival_set
3295 	 , l_line_rec.fulfillment_set_id
3296 	 , l_line_rec.fulfillment_set
3297 	 , l_line_rec.tax_code
3298 	 , l_line_rec.tax_value
3299 	 , l_line_rec.tax_date
3300 	 , l_line_rec.tax_point_code
3301 	 , l_line_val_rec.tax_point
3302 	 , l_line_rec.tax_exempt_flag
3303 	 , l_line_rec.tax_exempt_number
3304 	 , l_line_rec.tax_exempt_reason_code
3305 	 , l_line_val_rec.tax_exempt_reason
3306 	 , l_line_rec.agreement_id
3307 	 , l_line_val_rec.agreement
3308 	 , l_line_rec.invoicing_rule_id
3309 	 , l_line_val_rec.invoicing_rule
3310 	 , l_line_rec.accounting_rule_id
3311 	 , l_line_rec.accounting_rule_duration
3312 	 , l_line_val_rec.accounting_rule
3313 	 , l_line_rec.payment_term_id
3314 	 , l_line_val_rec.payment_term
3315 	 , l_line_rec.demand_class_code
3316 	 , l_line_rec.shipment_priority_code
3317 	 , l_line_val_rec.shipment_priority
3318 	 , l_line_rec.shipping_method_code
3319 	 , l_line_rec.shipping_instructions
3320 	 , l_line_rec.packing_instructions
3321 	 , l_line_rec.freight_carrier_code
3322 	 , l_line_rec.freight_terms_code
3323 	 , l_line_val_rec.freight_terms
3324 	 , l_line_rec.fob_point_code
3325 	 , l_line_val_rec.fob_point
3326 	 , l_line_rec.return_reason_code
3327 	 , l_line_rec.reference_type
3328 	 , l_line_rec.reference_header_id
3329 	 , l_line_rec.reference_line_id
3330 	 , l_line_rec.credit_invoice_line_id
3331 	 , l_line_rec.cust_po_number
3332           --bug#4063831:
3333           --FP:11I9-12.0CUST_PRODUCTION_SEQ_NUM IS NOT GETTING POPULATED
3334           -- DURING ORDER IMPORT
3335          , l_line_rec.cust_production_seq_num
3336 	 , l_line_rec.customer_line_number
3337 	 , l_line_rec.customer_shipment_number
3338 	 , l_line_rec.ordered_item_id
3339 	 , l_line_rec.item_identifier_type
3340 	 , l_line_rec.ordered_item
3341 --	 , l_line_rec.customer_item_revision
3342 	 , l_line_rec.customer_item_net_price
3343 	 , l_line_rec.customer_payment_term_id
3344 	 , l_line_val_rec.customer_payment_term
3345 	 , l_line_rec.demand_bucket_type_code
3346 	 , l_line_val_rec.demand_bucket_type
3347 	 , l_line_rec.customer_dock_code
3348 	 , l_line_rec.customer_job
3349 	 , l_line_rec.customer_production_line
3350 	 , l_line_rec.cust_model_serial_number
3351 	 , l_line_rec.project_id
3352 	 , l_line_val_rec.project
3353 	 , l_line_rec.task_id
3354 	 , l_line_val_rec.task
3355 	 , l_line_rec.end_item_unit_number
3356 	 , l_line_rec.item_revision
3357 	 , l_line_rec.service_duration
3358 	 , l_line_rec.service_period
3359 	 , l_line_rec.service_start_date
3360 	 , l_line_rec.service_end_date
3361 	 , l_line_rec.service_coterminate_flag
3362 	 , l_line_rec.unit_selling_percent
3363 	 , l_line_rec.unit_list_percent
3364 	 , l_line_rec.unit_percent_base_price
3365 	 , l_line_rec.service_number
3366 --	 , l_line_rec.fulfilled_flag	 -- To be added in Process Order
3367 --	 , l_line_rec.closed_flag
3368 	 , l_line_rec.cancelled_flag
3369 	 , l_line_rec.context
3370 	 , l_line_rec.attribute1
3371 	 , l_line_rec.attribute2
3372 	 , l_line_rec.attribute3
3373 	 , l_line_rec.attribute4
3374 	 , l_line_rec.attribute5
3375 	 , l_line_rec.attribute6
3376 	 , l_line_rec.attribute7
3377 	 , l_line_rec.attribute8
3378 	 , l_line_rec.attribute9
3379 	 , l_line_rec.attribute10
3380 	 , l_line_rec.attribute11
3381 	 , l_line_rec.attribute12
3382 	 , l_line_rec.attribute13
3383 	 , l_line_rec.attribute14
3384 	 , l_line_rec.attribute15
3385 	 , l_line_rec.attribute16  -- For bug 2184255
3386 	 , l_line_rec.attribute17
3387 	 , l_line_rec.attribute18
3388 	 , l_line_rec.attribute19
3389 	 , l_line_rec.attribute20
3390 	 , l_line_rec.tp_context
3391 	 , l_line_rec.tp_attribute1
3392 	 , l_line_rec.tp_attribute2
3393 	 , l_line_rec.tp_attribute3
3394 	 , l_line_rec.tp_attribute4
3395 	 , l_line_rec.tp_attribute5
3396 	 , l_line_rec.tp_attribute6
3397 	 , l_line_rec.tp_attribute7
3398 	 , l_line_rec.tp_attribute8
3399 	 , l_line_rec.tp_attribute9
3400 	 , l_line_rec.tp_attribute10
3401 	 , l_line_rec.tp_attribute11
3402 	 , l_line_rec.tp_attribute12
3403 	 , l_line_rec.tp_attribute13
3404 	 , l_line_rec.tp_attribute14
3405 	 , l_line_rec.tp_attribute15
3406 	 , l_line_rec.industry_context
3407 	 , l_line_rec.industry_attribute1
3408 	 , l_line_rec.industry_attribute2
3409 	 , l_line_rec.industry_attribute3
3410 	 , l_line_rec.industry_attribute4
3411 	 , l_line_rec.industry_attribute5
3412 	 , l_line_rec.industry_attribute6
3413 	 , l_line_rec.industry_attribute7
3414 	 , l_line_rec.industry_attribute8
3415 	 , l_line_rec.industry_attribute9
3416 	 , l_line_rec.industry_attribute10
3417 	 , l_line_rec.industry_attribute11
3418 	 , l_line_rec.industry_attribute12
3419 	 , l_line_rec.industry_attribute13
3420 	 , l_line_rec.industry_attribute14
3421 	 , l_line_rec.industry_attribute15
3422 	 , l_line_rec.industry_attribute16
3423 	 , l_line_rec.industry_attribute17
3424 	 , l_line_rec.industry_attribute18
3425 	 , l_line_rec.industry_attribute19
3426 	 , l_line_rec.industry_attribute20
3427 	 , l_line_rec.industry_attribute21
3428 	 , l_line_rec.industry_attribute22
3429 	 , l_line_rec.industry_attribute23
3430 	 , l_line_rec.industry_attribute24
3431 	 , l_line_rec.industry_attribute25
3432 	 , l_line_rec.industry_attribute26
3433 	 , l_line_rec.industry_attribute27
3434 	 , l_line_rec.industry_attribute28
3435 	 , l_line_rec.industry_attribute29
3436 	 , l_line_rec.industry_attribute30
3437 	 , l_line_rec.pricing_context
3438 	 , l_line_rec.pricing_attribute1
3439 	 , l_line_rec.pricing_attribute2
3440 	 , l_line_rec.pricing_attribute3
3441 	 , l_line_rec.pricing_attribute4
3442 	 , l_line_rec.pricing_attribute5
3443 	 , l_line_rec.pricing_attribute6
3444 	 , l_line_rec.pricing_attribute7
3445 	 , l_line_rec.pricing_attribute8
3446 	 , l_line_rec.pricing_attribute9
3447 	 , l_line_rec.pricing_attribute10
3448 	 , l_line_rec.global_attribute_category
3449 	 , l_line_rec.global_attribute1
3450 	 , l_line_rec.global_attribute2
3451 	 , l_line_rec.global_attribute3
3452 	 , l_line_rec.global_attribute4
3453 	 , l_line_rec.global_attribute5
3454 	 , l_line_rec.global_attribute6
3455 	 , l_line_rec.global_attribute7
3456 	 , l_line_rec.global_attribute8
3457 	 , l_line_rec.global_attribute9
3458 	 , l_line_rec.global_attribute10
3459 	 , l_line_rec.global_attribute11
3460 	 , l_line_rec.global_attribute12
3461 	 , l_line_rec.global_attribute13
3462 	 , l_line_rec.global_attribute14
3463 	 , l_line_rec.global_attribute15
3464 	 , l_line_rec.global_attribute16
3465 	 , l_line_rec.global_attribute17
3466 	 , l_line_rec.global_attribute18
3467 	 , l_line_rec.global_attribute19
3468 	 , l_line_rec.global_attribute20
3469 	 , l_line_rec.return_context
3470 	 , l_line_rec.return_attribute1
3471 	 , l_line_rec.return_attribute2
3472 	 , l_line_rec.return_attribute3
3473 	 , l_line_rec.return_attribute4
3474 	 , l_line_rec.return_attribute5
3475 	 , l_line_rec.return_attribute6
3476 	 , l_line_rec.return_attribute7
3477 	 , l_line_rec.return_attribute8
3478 	 , l_line_rec.return_attribute9
3479 	 , l_line_rec.return_attribute10
3480 	 , l_line_rec.return_attribute11
3481 	 , l_line_rec.return_attribute12
3482 	 , l_line_rec.return_attribute13
3483 	 , l_line_rec.return_attribute14
3484 	 , l_line_rec.return_attribute15
3485       , l_line_rec.request_id
3486 	 , l_line_rec.operation
3487 	 , l_line_rec.status_flag
3488 	 , l_line_rec.change_reason
3489 	 , l_line_rec.change_comments
3490 	 , l_line_rec.service_txn_reason_code
3491 	 , l_line_rec.service_txn_comments
3492 	 , l_line_rec.service_reference_type_code
3493 	 , l_line_rec.service_reference_order
3494 	 , l_line_rec.service_reference_line
3495 	 , l_line_rec.service_reference_system
3496 	 , l_segment_array(1)
3497 	 , l_segment_array(2)
3498 	 , l_segment_array(3)
3499 	 , l_segment_array(4)
3500 	 , l_segment_array(5)
3501 	 , l_segment_array(6)
3502 	 , l_segment_array(7)
3503 	 , l_segment_array(8)
3504 	 , l_segment_array(9)
3505 	 , l_segment_array(10)
3506 	 , l_segment_array(11)
3507 	 , l_segment_array(12)
3508 	 , l_segment_array(13)
3509 	 , l_segment_array(14)
3510 	 , l_segment_array(15)
3511 	 , l_segment_array(16)
3512 	 , l_segment_array(17)
3513 	 , l_segment_array(18)
3514 	 , l_segment_array(19)
3515 	 , l_segment_array(20)
3516          , l_line_val_rec.commitment
3517          , l_line_rec.commitment_id
3518 -- aksingh subinventory
3519          , l_line_rec.subinventory
3520          ,l_line_val_rec.salesrep
3521          ,l_line_rec.salesrep_id
3522          ,l_line_rec.earliest_acceptable_date
3523          ,l_line_rec.latest_acceptable_date
3524          , l_line_rec.split_from_line_ref
3525          , l_line_rec.split_from_shipment_ref
3526          ,l_line_val_rec.invoice_to_address1
3527          ,l_line_val_rec.invoice_to_address2
3528          ,l_line_val_rec.invoice_to_address3
3529          ,l_line_val_rec.invoice_to_address4
3530 	 ,l_line_val_rec.invoice_to_city
3531 	 ,l_line_val_rec.invoice_to_state
3532 	 ,l_line_val_rec.invoice_to_zip
3533 	 ,l_line_val_rec.invoice_to_country
3534       -- { Start add new columns to select for the Add Customer
3535          , l_line_customer_rec.Orig_Ship_Address_Ref
3536          , l_line_customer_rec.Orig_Bill_Address_Ref
3537          , l_line_customer_rec.Orig_Deliver_Address_Ref
3538          , l_line_customer_rec.Ship_to_Contact_Ref
3539          , l_line_customer_rec.Bill_to_Contact_Ref
3540          , l_line_customer_rec.Deliver_to_Contact_Ref
3541       -- End add new columns to select for the Add Customer}
3542          , l_line_rec.Config_Header_Id
3543          , l_line_rec.Config_Rev_Nbr
3544          , l_line_rec.Configuration_Id
3545          , l_line_val_rec.ship_to_customer_name_oi
3546          , l_line_val_rec.ship_to_customer_number_oi
3547          , l_line_rec.ship_to_customer_id
3548          , l_line_val_rec.invoice_to_customer_name_oi
3549          , l_line_val_rec.invoice_to_customer_number_oi
3550          , l_line_rec.invoice_to_customer_id
3551          , l_line_val_rec.deliver_to_customer_name_oi
3552          , l_line_val_rec.deliver_to_customer_number_oi
3553          , l_line_rec.deliver_to_customer_id
3554          , l_line_rec.user_item_description
3555          , l_line_rec.override_atp_date_code
3556          , l_line_rec.xml_transaction_type_code
3557          , l_line_rec.blanket_number
3558          , l_line_rec.blanket_line_number
3559          , l_line_val_rec.shipping_method
3560          , l_line_rec.change_sequence
3561 	-- automatic account creation {
3562         , l_line_rec.ship_to_party_id
3563         , l_line_rec.ship_to_party_site_id
3564         , l_line_rec.ship_to_party_site_use_id
3565         , l_line_rec.deliver_to_party_id
3566         , l_line_rec.deliver_to_party_site_id
3567         , l_line_rec.deliver_to_party_site_use_id
3568         , l_line_rec.invoice_to_party_id
3569         , l_line_rec.invoice_to_party_site_id
3570         , l_line_rec.invoice_to_party_site_use_id
3571 	-- automatic account creation }
3572      -- { Distributer Order related change
3573         , l_line_rec.end_customer_id
3574         , l_line_rec.end_customer_contact_id
3575         , l_line_rec.end_customer_site_use_id
3576         ,l_line_val_rec.end_customer_name  --mvijayku
3577           , l_line_val_rec.end_customer_site_address1
3578 	 , l_line_val_rec.end_customer_site_address2
3579 	 , l_line_val_rec.end_customer_site_address3
3580 	 , l_line_val_rec.end_customer_site_address4
3581 --	   , l_line_val_rec.end_customer_site_location
3582 	 , l_line_val_rec.end_customer_site_city
3583 	 , l_line_val_rec.end_customer_site_state
3584 	 , l_line_val_rec.end_customer_site_postal_code
3585 	 , l_line_val_rec.end_customer_site_country
3586 	, l_line_val_rec.end_customer_contact
3587          , l_line_val_rec.end_customer_number
3588         , l_line_val_rec.ib_owner_dsp
3589         , l_line_val_rec.ib_current_location_dsp
3590         , l_line_val_rec.ib_installed_at_location_dsp
3591         , l_line_rec.ib_owner
3592         , l_line_rec.ib_current_location
3593         , l_line_rec.ib_installed_at_location
3594         , l_line_rec.END_CUSTOMER_PARTY_ID
3595 	 ,l_line_rec.END_CUSTOMER_ORG_CONTACT_ID
3596          ,l_line_rec.END_CUSTOMER_PARTY_SITE_ID
3597          ,l_line_rec.END_CUSTOMER_PARTY_SITE_USE_ID
3598          ,l_line_rec.END_CUSTOMER_PARTY_NUMBER
3599      -- Distributer Order related change }
3600      -- Automatic Account Creation
3601         , l_line_rec.ship_to_party_number
3602         , l_line_rec.invoice_to_party_number
3603         , l_line_rec.deliver_to_party_number
3604      -- Automatic Account Creation
3605          , l_line_val_rec.deliver_to_address1
3606          , l_line_val_rec.deliver_to_address2
3607          , l_line_val_rec.deliver_to_address3
3608          , l_line_val_rec.deliver_to_address4
3609          , l_line_val_rec.deliver_to_state
3610          , l_line_val_rec.deliver_to_county
3611          , l_line_val_rec.deliver_to_country
3612          , l_line_val_rec.deliver_to_province
3613          , l_line_val_rec.deliver_to_city
3614          , l_line_val_rec.deliver_to_zip
3615 	 , l_line_rec.planning_priority           --Bug#6924881
3616 	 --sol_ord_er #16014165
3617 	     , l_line_rec.service_bill_profile_id
3618 		 , l_line_rec.service_cov_template_id
3619 		 , l_line_rec.service_subs_template_id
3620 		 , l_line_rec.service_bill_option_code
3621 		 , l_line_val_rec.service_bill_profile
3622 		 , l_line_val_rec.service_cov_template
3623 		 , l_line_val_rec.service_subs_template
3624 		 , l_line_rec.subscription_enable_flag
3625 	 --sol_ord_er #16014165
3626 ;
3627       EXIT WHEN l_line_cursor%NOTFOUND;
3628 
3629     IF l_line_rec.operation  = 'INSERT' THEN
3630        l_line_rec.operation := 'CREATE';
3631     END IF;
3632 	-- sol_ord_er #16014165 start
3633 	 /* System Parameter "OM: Subscription Item Line Behavior" needs to be honored only from UI */
3634 	 		If l_line_rec.operation = OE_GLOBALS.G_OPR_CREATE
3635 			   AND NVL(l_line_rec.subscription_enable_flag,FND_API.G_MISS_CHAR) = FND_API.G_MISS_CHAR THEN
3636 					l_line_rec.subscription_enable_flag := 'N';
3637 			End If;
3638 	 -- sol_ord_er #16014165 end
3639 
3640     --added for BUG#7304558
3641 
3642          IF l_line_rec.operation = 'CREATE' THEN
3643          	IF l_line_rec.calculate_price_flag IS NULL or l_line_rec.calculate_price_flag = FND_API.G_MISS_CHAR THEN
3644          		l_line_rec.calculate_price_flag := 'Y';
3645          	end if;
3646          ELSE
3647          BEGIN
3648          IF l_debug_level  > 0 THEN
3649     	oe_debug_pub.add(  'OPERATION CODE :'||l_line_rec.operation, 5);
3650     	oe_debug_pub.add(  'CALCULATE PRICE FLAG'||l_line_rec.calculate_price_flag, 5) ;
3651     	oe_debug_pub.add(  'UNIT SELLING PRICE'||l_line_rec.unit_selling_price, 5) ;
3652     	oe_debug_pub.add(  'UNIT LIST PRICE'||l_line_rec.unit_list_price, 5) ;
3653     	oe_debug_pub.add(  'ORIG_SYS_SHIPMENT_REF'||l_line_rec.orig_sys_shipment_ref, 5) ;
3654          END IF;
3655          IF l_line_rec.orig_sys_shipment_ref IS NULL or l_line_rec.orig_sys_shipment_ref = FND_API.G_MISS_CHAR then
3656          	IF l_line_rec.calculate_price_flag IS NULL or l_line_rec.calculate_price_flag = FND_API.G_MISS_CHAR then
3657          		--populate calculate_price_flag from lines table
3658          		SELECT calculate_price_flag
3659     		INTO   l_line_rec.calculate_price_flag
3660     		FROM   OE_ORDER_LINES_ALL
3661     		WHERE  orig_sys_document_ref = l_line_rec.orig_sys_document_ref
3662     		AND    orig_sys_line_ref = l_line_rec.orig_sys_line_ref;
3663 
3664     		IF l_debug_level  > 0 THEN
3665     		oe_debug_pub.add(  'CALCULATE PRICE FLAG'||l_line_rec.calculate_price_flag, 5) ;
3666          		END IF;
3667 
3668          		if l_line_rec.calculate_price_flag in ('P', 'N') then
3669 
3670          			if (l_line_rec.unit_selling_price is null or l_line_rec.unit_selling_price = FND_API.G_MISS_NUM)
3671          			   AND (l_line_rec.unit_list_price is null or l_line_rec.unit_list_price = FND_API.G_MISS_NUM)
3672          			THEN
3673          				SELECT unit_selling_price,unit_list_price
3674     				INTO   l_line_rec.unit_selling_price,l_line_rec.unit_list_price
3675     				FROM   OE_ORDER_LINES_ALL
3676     				WHERE  orig_sys_document_ref = l_line_rec.orig_sys_document_ref
3677     				AND    orig_sys_line_ref = l_line_rec.orig_sys_line_ref;
3678 
3679     				IF l_debug_level  > 0 THEN
3680     				oe_debug_pub.add(  'UNIT SELLING PRICE/UNIT LIST PRICE'||l_line_rec.unit_selling_price||'/'||l_line_rec.unit_list_price, 5);
3681     				END IF;
3682 
3683          			end if;
3684 
3685          		end if;
3686          --//added to handle the case when user will populate CPF
3687          	ELSIF l_line_rec.calculate_price_flag in ('P', 'N') then
3688 
3689     		if (l_line_rec.unit_selling_price is null or l_line_rec.unit_selling_price = FND_API.G_MISS_NUM)
3690     		    AND (l_line_rec.unit_list_price is null or l_line_rec.unit_list_price = FND_API.G_MISS_NUM)
3691     		THEN
3692     			SELECT unit_selling_price,unit_list_price
3693     			INTO   l_line_rec.unit_selling_price,l_line_rec.unit_list_price
3694     			FROM   OE_ORDER_LINES_ALL
3695     			WHERE  orig_sys_document_ref = l_line_rec.orig_sys_document_ref
3696     			AND    orig_sys_line_ref = l_line_rec.orig_sys_line_ref;
3697 
3698     			IF l_debug_level  > 0 THEN
3699     			oe_debug_pub.add(  'UNIT SELLING PRICE/UNIT LIST PRICE'||l_line_rec.unit_selling_price||'/'||l_line_rec.unit_list_price, 5);
3700     			END IF;
3701          	       end if;
3702          --//added to handle the case when user will populate CPF
3703          	END IF;
3704          ELSE --if orig_sys_shipment_ref is populated(split line case)
3705            	  IF l_line_rec.calculate_price_flag IS NULL or l_line_rec.calculate_price_flag = FND_API.G_MISS_CHAR then
3706     	   --populate calculate_price_flag from lines table
3707     		SELECT calculate_price_flag
3708     		INTO   l_line_rec.calculate_price_flag
3709     		FROM   OE_ORDER_LINES_ALL
3710     		WHERE  orig_sys_document_ref = l_line_rec.orig_sys_document_ref
3711     		AND    orig_sys_line_ref = l_line_rec.orig_sys_line_ref
3712     		AND    orig_sys_shipment_ref = l_line_rec.orig_sys_shipment_ref;
3713 
3714     		IF l_debug_level  > 0 THEN
3715     		oe_debug_pub.add(  'CALCULATE PRICE FLAG'||l_line_rec.calculate_price_flag, 5) ;
3716     		END IF;
3717 
3718     		if l_line_rec.calculate_price_flag in ('P', 'N') then
3719 
3720     			if (l_line_rec.unit_selling_price is null or l_line_rec.unit_selling_price = FND_API.G_MISS_NUM)
3721     			   AND (l_line_rec.unit_list_price is null or l_line_rec.unit_list_price = FND_API.G_MISS_NUM)
3722     			THEN
3723     				SELECT unit_selling_price,unit_list_price
3724     				INTO   l_line_rec.unit_selling_price,l_line_rec.unit_list_price
3725     				FROM   OE_ORDER_LINES_ALL
3726     				WHERE  orig_sys_document_ref = l_line_rec.orig_sys_document_ref
3727     				AND    orig_sys_line_ref = l_line_rec.orig_sys_line_ref
3728     				AND    orig_sys_shipment_ref = l_line_rec.orig_sys_shipment_ref;
3729 
3730     				IF l_debug_level  > 0 THEN
3731     				oe_debug_pub.add(  'UNIT SELLING PRICE/UNIT LIST PRICE'||l_line_rec.unit_selling_price||'/'||l_line_rec.unit_list_price, 5);
3732     				END IF;
3733 
3734     			end if;
3735 
3736     		end if;
3737          --//added to handle the case when user will populate CPF
3738     	ELSIF l_line_rec.calculate_price_flag in ('P', 'N') then
3739 
3740     		if (l_line_rec.unit_selling_price is null or l_line_rec.unit_selling_price = FND_API.G_MISS_NUM)
3741     		    AND (l_line_rec.unit_list_price is null or l_line_rec.unit_list_price = FND_API.G_MISS_NUM)
3742     		THEN
3743     			SELECT unit_selling_price,unit_list_price
3744     			INTO   l_line_rec.unit_selling_price,l_line_rec.unit_list_price
3745     			FROM   OE_ORDER_LINES_ALL
3746     			WHERE  orig_sys_document_ref = l_line_rec.orig_sys_document_ref
3747     			AND    orig_sys_line_ref = l_line_rec.orig_sys_line_ref
3748     			AND    orig_sys_shipment_ref = l_line_rec.orig_sys_shipment_ref;
3749 
3750     			IF l_debug_level  > 0 THEN
3751     			oe_debug_pub.add(  'UNIT SELLING PRICE/UNIT LIST PRICE'||l_line_rec.unit_selling_price||'/'||l_line_rec.unit_list_price, 5);
3752     			END IF;
3753 
3754     	       end if;
3755          --//added to handle the case when user will populate CPF
3756          	END IF;
3757          END IF; --end of orig_sys_shipment_ref check
3758     	EXCEPTION
3759     	WHEN NO_DATA_FOUND THEN
3760     	IF l_debug_level  > 0 THEN
3761     		oe_debug_pub.add(  'CALCULATE_PRICE_FLAG/UNIT SELLING PRICE/UNIT LIST PRICE NOT FOUND', 5) ;
3762     	END IF;
3763     	WHEN TOO_MANY_ROWS THEN
3764     	IF l_debug_level  > 0 THEN
3765     		oe_debug_pub.add(  'TOO MANY ROWS ERROR: '||SQLERRM) ;
3766     	END IF;
3767     	WHEN OTHERS THEN
3768     	IF l_debug_level  > 0 THEN
3769     		oe_debug_pub.add(  'UNEXPECTED ERROR: '||SQLERRM ) ;
3770     	END IF;
3771     	END;
3772         END IF;
3773 
3774        --added for BUG#7304558
3775 
3776 /* if missing, get line level sold to org id from header
3777  this is necessary for the case where the sold_to_org
3778  was populated and the header-level sold_to_org_id was derived
3779  */
3780 
3781 
3782      if l_line_rec.sold_to_org_id = FND_API.G_MISS_NUM then
3783         IF l_debug_level  > 0 THEN
3784           oe_debug_pub.add(  'line level sold to org id is g_miss_num, so it was not populated.  defaulting to header level sold to org id' ) ;
3785         END IF;
3786         l_line_rec.sold_to_org_id := l_header_rec.sold_to_org_id;
3787      end if;
3788 
3789 
3790 
3791     IF(l_line_count > 0) THEN
3792      IF OE_CODE_CONTROL.GET_CODE_RELEASE_LEVEL >= '110508' THEN
3793       IF (l_line_rec.orig_sys_line_ref = l_line_tbl(l_line_count).orig_sys_line_ref) AND
3794          (l_line_rec.orig_sys_shipment_ref = l_line_tbl(l_line_count).orig_sys_shipment_ref) AND
3795          (G_IMPORT_SHIPMENTS = 'YES') THEN
3796         --duplicate
3797         p_return_status := FND_API.G_RET_STS_ERROR;
3798         l_validate_only := FND_API.G_TRUE;
3799         IF l_debug_level  > 0 THEN
3800             oe_debug_pub.add(  'YOU ARE ENTERING EITHER A DUPLICATE ORIG_SYS_LINE_REF OR ORIG_SYS_SHIPMENT_REF FOR THE SAME ORDER' ) ;
3801         END IF;
3802         FND_MESSAGE.SET_NAME('ONT','OE_OI_DUPLICATE_REF');
3803         FND_MESSAGE.SET_TOKEN('DUPLICATE_REF','orig_sys_line_ref and orig_sys_shipment_ref');
3804         OE_MSG_PUB.Add;
3805       ELSIF
3806         (l_line_rec.orig_sys_line_ref = l_line_tbl(l_line_count).orig_sys_line_ref) AND
3807         (G_IMPORT_SHIPMENTS = 'NO') THEN
3808         p_return_status := FND_API.G_RET_STS_ERROR;
3809         l_validate_only := FND_API.G_TRUE;
3810         IF l_debug_level  > 0 THEN
3811             oe_debug_pub.add(  'YOU ARE ENTERING A DUPLICATE ORIG_SYS_LINE_REF FOR THE SAME ORDER' ) ;
3812         END IF;
3813         FND_MESSAGE.SET_NAME('ONT','OE_OI_DUPLICATE_REF');
3814         FND_MESSAGE.SET_TOKEN('DUPLICATE_REF','orig_sys_line_ref');
3815         OE_MSG_PUB.Add;
3816       END IF;
3817      ELSIF
3818        OE_CODE_CONTROL.GET_CODE_RELEASE_LEVEL < '110508' THEN
3819        IF (l_line_rec.orig_sys_line_ref = l_line_tbl(l_line_count).orig_sys_line_ref) THEN
3820          p_return_status := FND_API.G_RET_STS_ERROR;
3821          l_validate_only := FND_API.G_TRUE;
3822          IF l_debug_level  > 0 THEN
3823              oe_debug_pub.add(  'YOU ARE ENTERING A DUPLICATE ORIG_SYS_LINE_REF FOR THESAME ORDER' ) ;
3824          END IF;
3825          FND_MESSAGE.SET_NAME('ONT','OE_OI_DUPLICATE_REF');
3826          FND_MESSAGE.SET_TOKEN('DUPLICATE_REF','orig_sys_line_ref');
3827          OE_MSG_PUB.Add;
3828        END IF;
3829      END IF;
3830     END IF;
3831 
3832      -- BUG 1282873
3833     IF OE_CODE_CONTROL.GET_CODE_RELEASE_LEVEL < '110509' THEN
3834     -- do not allow the override atp flag before Pack I
3835        l_line_rec.override_atp_date_code := NULL;
3836     END IF;
3837 
3838     IF OE_CODE_CONTROL.GET_CODE_RELEASE_LEVEL >= '110510' THEN
3839        IF l_line_rec.order_source_id = OE_Acknowledgment_Pub.G_XML_ORDER_SOURCE_ID
3840           AND l_line_rec.xml_transaction_type_code = OE_Acknowledgment_Pub.G_TRANSACTION_CHO THEN
3841           l_line_rec.cso_response_flag := l_header_cso_response_flag;
3842           IF l_debug_level  > 0 THEN
3843              oe_debug_pub.add(  'Populated line response flag with :' ||  l_header_cso_response_flag
3844                                 || 'for line ref : ' || l_line_rec.orig_sys_line_ref);
3845           END IF;
3846        END IF;
3847     END IF;
3848 
3849     l_line_count := l_line_count + 1;
3850     if l_line_rec.service_reference_order = FND_API.G_MISS_CHAR then
3851     IF l_debug_level  > 0 THEN
3852         oe_debug_pub.add(  'L_LINE_REC.SERVICE_REFERENCE_ORDER ' || ASCII ( L_LINE_REC.SERVICE_REFERENCE_ORDER ) ) ;
3853     END IF;
3854     end if;
3855     if l_line_val_rec.sold_to_org = FND_API.G_MISS_CHAR then
3856     IF l_debug_level  > 0 THEN
3857         oe_debug_pub.add(  'L_LINE_VAL_REC.SOLD_TO_ORG ' || ASCII ( L_LINE_VAL_REC.SOLD_TO_ORG ) ) ;
3858     END IF;
3859     end if;
3860 
3861     --populate l_line_rec.inventory_item_id with ccid if any of the
3862     --segments are passed instead of inventory_item_id
3863     IF l_line_rec.inventory_item_id = FND_API.G_MISS_NUM AND
3864 	 ((l_segment_array(1) IS NOT NULL) OR
3865 	  (l_segment_array(2) IS NOT NULL) OR
3866 	  (l_segment_array(3) IS NOT NULL) OR
3867 	  (l_segment_array(4) IS NOT NULL) OR
3868 	  (l_segment_array(5) IS NOT NULL) OR
3869 	  (l_segment_array(6) IS NOT NULL) OR
3870 	  (l_segment_array(7) IS NOT NULL) OR
3871 	  (l_segment_array(8) IS NOT NULL) OR
3872 	  (l_segment_array(9) IS NOT NULL) OR
3873 	  (l_segment_array(10) IS NOT NULL) OR
3874 	  (l_segment_array(11) IS NOT NULL) OR
3875 	  (l_segment_array(12) IS NOT NULL) OR
3876 	  (l_segment_array(13) IS NOT NULL) OR
3877 	  (l_segment_array(14) IS NOT NULL) OR
3878 	  (l_segment_array(15) IS NOT NULL) OR
3879 	  (l_segment_array(16) IS NOT NULL) OR
3880 	  (l_segment_array(17) IS NOT NULL) OR
3881 	  (l_segment_array(18) IS NOT NULL) OR
3882 	  (l_segment_array(19) IS NOT NULL) OR
3883 	  (l_segment_array(20) IS NOT NULL)) THEN
3884       IF l_debug_level  > 0 THEN
3885           oe_debug_pub.add(  'INSIDE GET CCID ROUTINE' ) ;
3886       END IF;
3887 	 FND_FLEX_KEY_API.SET_SESSION_MODE('customer_data');
3888 	 IF l_debug_level  > 0 THEN
3889 	     oe_debug_pub.add(  'AFTER CALL TO SET SESSION' ) ;
3890 	 END IF;
3891 	 l_flexfield := FND_FLEX_KEY_API.FIND_FLEXFIELD('INV', 'MSTK');
3892 	 IF l_debug_level  > 0 THEN
3893 	     oe_debug_pub.add(  'AFTER FIND FLEXFIELD' ) ;
3894 	 END IF;
3895 	 l_structure.structure_number := 101;
3896 	 FND_FLEX_KEY_API.GET_SEGMENTS(l_flexfield, l_structure, TRUE, l_n_segments, l_segments);
3897       IF l_debug_level  > 0 THEN
3898           oe_debug_pub.add(  'SEGMENTS ENABLED = '||L_N_SEGMENTS ) ;
3899 
3900 	     oe_debug_pub.add(  'ORG_ID = '||L_LINE_REC.ORG_ID ) ;
3901 
3902 	     oe_debug_pub.add(  'VALIDATION_ORG_ID = '||L_VALIDATION_ORG ) ;
3903 
3904 	     oe_debug_pub.add(  'ARRAY1 = '||L_SEGMENT_ARRAY ( 1 ) ) ;
3905 	 END IF;
3906 	 IF FND_FLEX_EXT.GET_COMBINATION_ID('INV', 'MSTK', 101, SYSDATE, l_n_segments, l_segment_array, l_id, l_validation_org) THEN
3907 	   l_line_rec.inventory_item_id := l_id;
3908       IF l_debug_level  > 0 THEN
3909           oe_debug_pub.add(  'GET CCID = '||L_LINE_REC.INVENTORY_ITEM_ID ) ;
3910       END IF;
3911 	 ELSE
3912 	   IF l_debug_level  > 0 THEN
3913 	       oe_debug_pub.add(  'ERROR IN GETTING CCID' ) ;
3914 	   END IF;
3915 	   failure_message := fnd_flex_ext.get_message;
3916 	   OE_MSG_PUB.Add_TEXT(failure_message);
3917            p_return_status := FND_API.G_RET_STS_ERROR;
3918 	   l_validate_only := FND_API.G_TRUE;
3919 	   IF l_debug_level  > 0 THEN
3920 	       oe_debug_pub.add('failure message = ' || substr ( failure_message , 1 , 50 ) ) ;
3921 	       oe_debug_pub.add('failure message = ' || substr ( failure_message , 51 , 50 ) ) ;
3922 	       oe_debug_pub.add('failure message = ' || substr ( failure_message , 101 , 50 ) ) ;
3923 	   END IF;
3924       END IF;
3925 
3926   ELSIF l_line_rec.inventory_item_id <> FND_API.G_MISS_NUM AND
3927 	 ((l_segment_array(1) IS NOT NULL) OR
3928 	  (l_segment_array(2) IS NOT NULL) OR
3929 	  (l_segment_array(3) IS NOT NULL) OR
3930 	  (l_segment_array(4) IS NOT NULL) OR
3931 	  (l_segment_array(5) IS NOT NULL) OR
3932 	  (l_segment_array(6) IS NOT NULL) OR
3933 	  (l_segment_array(7) IS NOT NULL) OR
3934 	  (l_segment_array(8) IS NOT NULL) OR
3935 	  (l_segment_array(9) IS NOT NULL) OR
3936 	  (l_segment_array(10) IS NOT NULL) OR
3937 	  (l_segment_array(11) IS NOT NULL) OR
3938 	  (l_segment_array(12) IS NOT NULL) OR
3939 	  (l_segment_array(13) IS NOT NULL) OR
3940 	  (l_segment_array(14) IS NOT NULL) OR
3941 	  (l_segment_array(15) IS NOT NULL) OR
3942 	  (l_segment_array(16) IS NOT NULL) OR
3943 	  (l_segment_array(17) IS NOT NULL) OR
3944 	  (l_segment_array(18) IS NOT NULL) OR
3945 	  (l_segment_array(19) IS NOT NULL) OR
3946 	  (l_segment_array(20) IS NOT NULL)) THEN
3947      IF l_debug_level  > 0 THEN
3948          oe_debug_pub.add(  'INSIDE ROUTINE WHERE BOTH ID AND SEG ARE POPULATED' ) ;
3949      END IF;
3950      l_line_rec.inventory_item_id := FND_API.G_MISS_NUM;
3951   	FND_MESSAGE.SET_NAME('ONT','OE_OIM_INVALID_ITEM_ID');
3952   	FND_MESSAGE.SET_TOKEN('ORDER_NO', l_orig_sys_document_ref);
3953   	FND_MESSAGE.SET_TOKEN('ORDER_SOURCE', l_order_source_id);
3954      OE_MSG_PUB.Add;
3955   	p_return_status := FND_API.G_RET_STS_ERROR;
3956 	l_validate_only := FND_API.G_TRUE;
3957 	IF l_debug_level  > 0 THEN
3958 	    oe_debug_pub.add(  'CANNOT IMPORT ORDER AS BOTH INVENTORY_ITEM_ID AND INVENTORY_ITEM_SEGMENTS ARE POPULATED' ) ;
3959 
3960 	    oe_debug_pub.add(  'ORDER NO: '||L_ORIG_SYS_DOCUMENT_REF ) ;
3961 
3962 	    oe_debug_pub.add(  'ORDER SOURCE: '||L_ORDER_SOURCE_ID ) ;
3963 	END IF;
3964 
3965   END IF;
3966 
3967   -- { Start of fix for bug 2664600
3968   --  Following code is commented out as the process order no longer error
3969   --  out if the subinventory is present and it is not able to reserve
3970   --  because of some error. To check the code here take out the previous version
3971 
3972   -- { Start of the fix to NULL out the subinventory information if
3973   --   the item has lower level of details defined in mtl_system_items_b
3974   --   This is required as PO is now not going to send the reservation
3975   --   record and process order fails, for the mention condition. This
3976   --   Code will NULL out the subinventory, so the process order does
3977   --   not fail, and order import behaves in the same way(order imported
3978   --   even if the reservations fails).
3979   --   Fixed Bug# 2049995
3980 
3981   -- End of the subinventory related change}
3982   -- End of fix for bug 2664600 }
3983 
3984 
3985     l_line_rec.service_reference_order :=
3986       nvl(l_line_rec.service_reference_order, FND_API.G_MISS_CHAR);
3987     l_line_rec.service_reference_line :=
3988       nvl(l_line_rec.service_reference_line, FND_API.G_MISS_CHAR);
3989 
3990       -- Ignore the fulfilment_set name populated on the lines interface
3991       -- table if the operation is update
3992 
3993       IF l_line_rec.operation = 'UPDATE' AND
3994          ((l_line_rec.fulfillment_set IS NOT NULL AND
3995             l_line_rec.fulfillment_set <> FND_API.G_MISS_CHAR) OR
3996               (l_line_rec.fulfillment_set_id IS NOT NULL AND
3997                  l_line_rec.fulfillment_set_id <> FND_API.G_MISS_NUM)) AND
3998          OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' THEN
3999          oe_debug_pub.add('Ignoring : '|| l_line_rec.fulfillment_set, 1 ) ;
4000          l_line_rec.fulfillment_set    := NULL;
4001          l_line_rec.fulfillment_set_id := NULL;
4002          FND_MESSAGE.Set_Name('ONT','ONT_FULSET_NAME_IGNORED');
4003          OE_MSG_PUB.Add;
4004       END IF;
4005 
4006 
4007 
4008   -- Assign record to line table
4009     l_line_tbl    (l_line_count) := l_line_rec;
4010     l_line_val_tbl(l_line_count) := l_line_val_rec;
4011 
4012     --{ Start of the Add customer
4013     l_line_customer_tbl(l_line_count) := l_line_customer_rec;
4014     --End of the Add customer}
4015 
4016     if l_line_val_tbl(l_line_count).sold_to_org = FND_API.G_MISS_CHAR then
4017     IF l_debug_level  > 0 THEN
4018         oe_debug_pub.add(  'L_LINE_TBL.SERVICE_REFERENCE_ORDER ' || ASCII ( L_LINE_TBL ( L_LINE_COUNT ) .SERVICE_REFERENCE_ORDER ) ) ;
4019 
4020         oe_debug_pub.add(  'L_LINE_VAL_TBL.SOLD_TO_ORG ' || ASCII ( L_LINE_VAL_TBL ( L_LINE_COUNT ) .SOLD_TO_ORG ) ) ;
4021     END IF;
4022     end if;
4023 
4024     l_orig_sys_line_ref     := l_line_rec.orig_sys_line_ref;
4025     l_orig_sys_shipment_ref := l_line_rec.orig_sys_shipment_ref;
4026 
4027 	                 IF l_debug_level  > 0 THEN
4028 	                     oe_debug_pub.add(  'ORIG SYS LINE REF ( '||L_LINE_COUNT||' ) : '|| L_LINE_TBL ( L_LINE_COUNT ) .ORIG_SYS_LINE_REF ) ;
4029 
4030 			     oe_debug_pub.add(  'ORIG SYS SHIPMENT REF ( '||L_LINE_COUNT||' ) : '|| L_LINE_TBL ( L_LINE_COUNT ) .ORIG_SYS_SHIPMENT_REF ) ;
4031 
4032 /* -----------------------------------------------------------
4033    Line Discounts/Price adjustments
4034    -----------------------------------------------------------
4035 */
4036        oe_debug_pub.add(  'BEFORE LINE ADJUSTMENTS LOOP' ) ;
4037    END IF;
4038 
4039   OPEN l_line_adj_cursor;
4040   LOOP
4041      FETCH l_line_adj_cursor
4042       INTO l_line_adj_rec.orig_sys_discount_ref
4043 	 , l_line_adj_rec.change_request_code
4044 	 , l_line_adj_rec.list_header_id	-- changed from discount_id
4045 	 , l_line_adj_rec.list_line_id		-- changed from discount_line_id
4046 	 , l_line_adj_val_rec.discount
4047 	 , l_line_adj_rec.percent
4048 	 , l_line_adj_rec.automatic_flag
4049 	 , l_line_adj_rec.applied_flag
4050 	 , l_line_adj_rec.operand
4051 	 , l_line_adj_rec.arithmetic_operator
4052 	 , l_line_adj_rec.context
4053 	 , l_line_adj_rec.attribute1
4054 	 , l_line_adj_rec.attribute2
4055 	 , l_line_adj_rec.attribute3
4056 	 , l_line_adj_rec.attribute4
4057 	 , l_line_adj_rec.attribute5
4058 	 , l_line_adj_rec.attribute6
4059 	 , l_line_adj_rec.attribute7
4060 	 , l_line_adj_rec.attribute8
4061 	 , l_line_adj_rec.attribute9
4062 	 , l_line_adj_rec.attribute10
4063 	 , l_line_adj_rec.attribute11
4064 	 , l_line_adj_rec.attribute12
4065 	 , l_line_adj_rec.attribute13
4066 	 , l_line_adj_rec.attribute14
4067 	 , l_line_adj_rec.attribute15
4068 	 , l_line_adj_rec.request_id
4069 	 , l_line_adj_rec.operation
4070 	 , l_line_adj_rec.status_flag
4071 -- Price Adjustment related changes bug# 1220921 (Start)
4072       , l_line_adj_rec.AC_CONTEXT
4073       , l_line_adj_rec.AC_ATTRIBUTE1
4074       , l_line_adj_rec.AC_ATTRIBUTE2
4075       , l_line_adj_rec.AC_ATTRIBUTE3
4076       , l_line_adj_rec.AC_ATTRIBUTE4
4077       , l_line_adj_rec.AC_ATTRIBUTE5
4078       , l_line_adj_rec.AC_ATTRIBUTE6
4079       , l_line_adj_rec.AC_ATTRIBUTE7
4080       , l_line_adj_rec.AC_ATTRIBUTE8
4081       , l_line_adj_rec.AC_ATTRIBUTE9
4082       , l_line_adj_rec.AC_ATTRIBUTE10
4083       , l_line_adj_rec.AC_ATTRIBUTE11
4084       , l_line_adj_rec.AC_ATTRIBUTE12
4085       , l_line_adj_rec.AC_ATTRIBUTE13
4086       , l_line_adj_rec.AC_ATTRIBUTE14
4087       , l_line_adj_rec.AC_ATTRIBUTE15
4088       , l_line_adj_val_rec.LIST_NAME
4089       , l_line_adj_rec.LIST_LINE_TYPE_CODE
4090       , l_line_adj_rec.LIST_LINE_NO
4091       , l_line_adj_val_rec.VERSION_NO
4092       , l_line_adj_rec.INVOICED_FLAG
4093       , l_line_adj_rec.ESTIMATED_FLAG
4094       , l_line_adj_rec.INC_IN_SALES_PERFORMANCE
4095       , l_line_adj_rec.CHARGE_TYPE_CODE
4096       , l_line_adj_rec.CHARGE_SUBTYPE_CODE
4097       , l_line_adj_rec.CREDIT_OR_CHARGE_FLAG
4098       , l_line_adj_rec.INCLUDE_ON_RETURNS_FLAG
4099       , l_line_adj_rec.COST_ID
4100       , l_line_adj_rec.TAX_CODE
4101       , l_line_adj_rec.PARENT_ADJUSTMENT_ID
4102       , l_line_adj_rec.MODIFIER_MECHANISM_TYPE_CODE
4103       , l_line_adj_rec.MODIFIED_FROM
4104       , l_line_adj_rec.MODIFIED_TO
4105       , l_line_adj_rec.UPDATED_FLAG
4106       , l_line_adj_rec.UPDATE_ALLOWED
4107       , l_line_adj_rec.CHANGE_REASON_CODE
4108       , l_line_adj_rec.CHANGE_REASON_TEXT
4109       , l_line_adj_rec.PRICING_PHASE_ID
4110       , l_line_adj_rec.ADJUSTED_AMOUNT
4111 -- Price Adjustment related changes bug# 1220921 (End)
4112 ;
4113       EXIT WHEN l_line_adj_cursor%NOTFOUND;
4114 
4115       l_line_adj_rec.line_index := l_line_count;
4116 
4117       IF l_line_adj_rec.operation  = 'INSERT' THEN
4118          l_line_adj_rec.operation := 'CREATE';
4119       END IF;
4120 
4121       l_line_adj_count := l_line_adj_count + 1;
4122       l_line_adj_tbl     (l_line_adj_count) := l_line_adj_rec;
4123       l_line_adj_val_tbl (l_line_adj_count) := l_line_adj_val_rec;
4124 
4125 		IF l_debug_level  > 0 THEN
4126 		    oe_debug_pub.add(  'LINE ADJUSTMENT REF ( '||L_LINE_ADJ_COUNT||' ) : '|| L_LINE_ADJ_TBL ( L_LINE_ADJ_COUNT ) .ORIG_SYS_DISCOUNT_REF ) ;
4127 		END IF;
4128 
4129   END LOOP;
4130   CLOSE l_line_adj_cursor;
4131 
4132 
4133 /* -----------------------------------------------------------
4134    Line Price attribs
4135    -----------------------------------------------------------
4136 */
4137    IF l_debug_level  > 0 THEN
4138        oe_debug_pub.add(  'BEFORE LINE ATTRIBS LOOP' ) ;
4139    END IF;
4140 
4141   OPEN l_line_attrib_cursor;
4142   LOOP
4143      FETCH l_line_attrib_cursor
4144      INTO l_line_price_att_rec.creation_date
4145     , l_line_price_att_rec.created_by
4146     , l_line_price_att_rec.last_update_date
4147     , l_line_price_att_rec.last_updated_by
4148     , l_line_price_att_rec.last_update_login
4149     , l_line_price_att_rec.program_application_id
4150     , l_line_price_att_rec.program_id
4151     , l_line_price_att_rec.program_update_date
4152     , l_line_price_att_rec.request_id
4153     , l_line_price_att_rec.flex_title
4154     , l_line_price_att_rec.pricing_context
4155     , l_line_price_att_rec.pricing_attribute1
4156     , l_line_price_att_rec.pricing_attribute2
4157     , l_line_price_att_rec.pricing_attribute3
4158     , l_line_price_att_rec.pricing_attribute4
4159     , l_line_price_att_rec.pricing_attribute5
4160     , l_line_price_att_rec.pricing_attribute6
4161     , l_line_price_att_rec.pricing_attribute7
4162     , l_line_price_att_rec.pricing_attribute8
4163     , l_line_price_att_rec.pricing_attribute9
4164     , l_line_price_att_rec.pricing_attribute10
4165     , l_line_price_att_rec.pricing_attribute11
4166     , l_line_price_att_rec.pricing_attribute12
4167     , l_line_price_att_rec.pricing_attribute13
4168     , l_line_price_att_rec.pricing_attribute14
4169     , l_line_price_att_rec.pricing_attribute15
4170     , l_line_price_att_rec.pricing_attribute16
4171     , l_line_price_att_rec.pricing_attribute17
4172     , l_line_price_att_rec.pricing_attribute18
4173     , l_line_price_att_rec.pricing_attribute19
4174     , l_line_price_att_rec.pricing_attribute20
4175     , l_line_price_att_rec.pricing_attribute21
4176     , l_line_price_att_rec.pricing_attribute22
4177     , l_line_price_att_rec.pricing_attribute23
4178     , l_line_price_att_rec.pricing_attribute24
4179     , l_line_price_att_rec.pricing_attribute25
4180     , l_line_price_att_rec.pricing_attribute26
4181     , l_line_price_att_rec.pricing_attribute27
4182     , l_line_price_att_rec.pricing_attribute28
4183     , l_line_price_att_rec.pricing_attribute29
4184     , l_line_price_att_rec.pricing_attribute30
4185     , l_line_price_att_rec.pricing_attribute31
4186     , l_line_price_att_rec.pricing_attribute32
4187     , l_line_price_att_rec.pricing_attribute33
4188     , l_line_price_att_rec.pricing_attribute34
4189     , l_line_price_att_rec.pricing_attribute35
4190     , l_line_price_att_rec.pricing_attribute36
4191     , l_line_price_att_rec.pricing_attribute37
4192     , l_line_price_att_rec.pricing_attribute38
4193     , l_line_price_att_rec.pricing_attribute39
4194     , l_line_price_att_rec.pricing_attribute40
4195     , l_line_price_att_rec.pricing_attribute41
4196     , l_line_price_att_rec.pricing_attribute42
4197     , l_line_price_att_rec.pricing_attribute43
4198     , l_line_price_att_rec.pricing_attribute44
4199     , l_line_price_att_rec.pricing_attribute45
4200     , l_line_price_att_rec.pricing_attribute46
4201     , l_line_price_att_rec.pricing_attribute47
4202     , l_line_price_att_rec.pricing_attribute48
4203     , l_line_price_att_rec.pricing_attribute49
4204     , l_line_price_att_rec.pricing_attribute50
4205     , l_line_price_att_rec.pricing_attribute51
4206     , l_line_price_att_rec.pricing_attribute52
4207     , l_line_price_att_rec.pricing_attribute53
4208     , l_line_price_att_rec.pricing_attribute54
4209     , l_line_price_att_rec.pricing_attribute55
4210     , l_line_price_att_rec.pricing_attribute56
4211     , l_line_price_att_rec.pricing_attribute57
4212     , l_line_price_att_rec.pricing_attribute58
4213     , l_line_price_att_rec.pricing_attribute59
4214     , l_line_price_att_rec.pricing_attribute60
4215     , l_line_price_att_rec.pricing_attribute61
4216     , l_line_price_att_rec.pricing_attribute62
4217     , l_line_price_att_rec.pricing_attribute63
4218     , l_line_price_att_rec.pricing_attribute64
4219     , l_line_price_att_rec.pricing_attribute65
4220     , l_line_price_att_rec.pricing_attribute66
4221     , l_line_price_att_rec.pricing_attribute67
4222     , l_line_price_att_rec.pricing_attribute68
4223     , l_line_price_att_rec.pricing_attribute69
4224     , l_line_price_att_rec.pricing_attribute70
4225     , l_line_price_att_rec.pricing_attribute71
4226     , l_line_price_att_rec.pricing_attribute72
4227     , l_line_price_att_rec.pricing_attribute73
4228     , l_line_price_att_rec.pricing_attribute74
4229     , l_line_price_att_rec.pricing_attribute75
4230     , l_line_price_att_rec.pricing_attribute76
4231     , l_line_price_att_rec.pricing_attribute77
4232     , l_line_price_att_rec.pricing_attribute78
4233     , l_line_price_att_rec.pricing_attribute79
4234     , l_line_price_att_rec.pricing_attribute80
4235     , l_line_price_att_rec.pricing_attribute81
4236     , l_line_price_att_rec.pricing_attribute82
4237     , l_line_price_att_rec.pricing_attribute83
4238     , l_line_price_att_rec.pricing_attribute84
4239     , l_line_price_att_rec.pricing_attribute85
4240     , l_line_price_att_rec.pricing_attribute86
4241     , l_line_price_att_rec.pricing_attribute87
4242     , l_line_price_att_rec.pricing_attribute88
4243     , l_line_price_att_rec.pricing_attribute89
4244     , l_line_price_att_rec.pricing_attribute90
4245     , l_line_price_att_rec.pricing_attribute91
4246     , l_line_price_att_rec.pricing_attribute92
4247     , l_line_price_att_rec.pricing_attribute93
4248     , l_line_price_att_rec.pricing_attribute94
4249     , l_line_price_att_rec.pricing_attribute95
4250     , l_line_price_att_rec.pricing_attribute96
4251     , l_line_price_att_rec.pricing_attribute97
4252     , l_line_price_att_rec.pricing_attribute98
4253     , l_line_price_att_rec.pricing_attribute99
4254     , l_line_price_att_rec.pricing_attribute100
4255     , l_line_price_att_rec.context
4256     , l_line_price_att_rec.attribute1
4257     , l_line_price_att_rec.attribute2
4258     , l_line_price_att_rec.attribute3
4259     , l_line_price_att_rec.attribute4
4260     , l_line_price_att_rec.attribute5
4261     , l_line_price_att_rec.attribute6
4262     , l_line_price_att_rec.attribute7
4263     , l_line_price_att_rec.attribute8
4264     , l_line_price_att_rec.attribute9
4265     , l_line_price_att_rec.attribute10
4266     , l_line_price_att_rec.attribute11
4267     , l_line_price_att_rec.attribute12
4268     , l_line_price_att_rec.attribute13
4269     , l_line_price_att_rec.attribute14
4270     , l_line_price_att_rec.attribute15
4271     , l_line_price_att_rec.operation;
4272 
4273    EXIT WHEN l_line_attrib_cursor%NOTFOUND;
4274     l_line_price_att_rec.line_index := l_line_count;
4275 
4276     IF l_line_price_att_rec.operation = 'INSERT' THEN
4277       l_line_price_att_rec.operation  := 'CREATE';
4278     END IF;
4279     --bug#5679839
4280    IF l_line_price_att_rec.flex_title = 'QP_ATTR_DEFNS_PRICING' or
4281       l_line_price_att_rec.flex_title = 'QP_ATTR_DEFNS_QUALIFIER' THEN
4282       null;
4283    ELSE
4284       l_line_price_att_rec.flex_title := 'QP_ATTR_DEFNS_PRICING';
4285    END IF;
4286    --bug#5679839
4287 /*
4288     IF  ( l_line_att_count > 0) THEN
4289      IF(l_line_price_att_rec.orig_sys_line_ref = l_line_price_att_tbl(l_line_att_count).orig_sys_line_ref) AND
4290        (l_line_rec.orig_sys_line_ref = l_line_tbl(l_line_count).orig_sys_line_ref )  THEN
4291        --duplicate
4292        p_return_status := FND_API.G_RET_STS_ERROR;
4293        l_validate_only := FND_API.G_TRUE;
4294        oe_debug_pub.add('You are entering a duplicate orig_sys_att_refat the line level for the same order');
4295        FND_MESSAGE.SET_NAME('ONT','OE_OI_DUPLICATE_REF');
4296        FND_MESSAGE.SET_TOKEN('DUPLICATE_REF','orig_sys_price_att_ref');
4297        OE_MSG_PUB.Add;
4298      END IF;
4299     END IF;
4300 */
4301         l_line_att_count := l_line_att_count+1;
4302         l_line_price_att_tbl (l_line_att_count):=l_line_price_att_rec;
4303 --      oe_debug_pub.add('Line Price ATT ('||l_line_att_count||'):'||l_line_price_att_tbl(l_line_att_count).orig_sys_line_ref);
4304 
4305 END LOOP;
4306   CLOSE l_line_attrib_cursor;
4307 
4308 /* -----------------------------------------------------------
4309    Line Sales Credits
4310    -----------------------------------------------------------
4311 */
4312    IF l_debug_level  > 0 THEN
4313        oe_debug_pub.add(  'BEFORE LINE SALES CREDITS LOOP' ) ;
4314    END IF;
4315 
4316   OPEN l_line_scredit_cursor;
4317   LOOP
4318      FETCH l_line_scredit_cursor
4319       INTO l_line_scredit_rec.orig_sys_credit_ref
4320 	 , l_line_scredit_rec.change_request_code
4321 	 , l_line_scredit_rec.salesrep_id
4322 	 , l_line_scredit_val_rec.salesrep
4323 	 , l_line_scredit_rec.sales_credit_type_id
4324 	 , l_line_scredit_val_rec.sales_credit_type
4325 	 , l_line_scredit_rec.percent
4326 	 , l_line_scredit_rec.context
4327 	 , l_line_scredit_rec.attribute1
4328 	 , l_line_scredit_rec.attribute2
4329 	 , l_line_scredit_rec.attribute3
4330 	 , l_line_scredit_rec.attribute4
4331 	 , l_line_scredit_rec.attribute5
4332 	 , l_line_scredit_rec.attribute6
4333 	 , l_line_scredit_rec.attribute7
4334 	 , l_line_scredit_rec.attribute8
4335 	 , l_line_scredit_rec.attribute9
4336 	 , l_line_scredit_rec.attribute10
4337 	 , l_line_scredit_rec.attribute11
4338 	 , l_line_scredit_rec.attribute12
4339 	 , l_line_scredit_rec.attribute13
4340 	 , l_line_scredit_rec.attribute14
4341 	 , l_line_scredit_rec.attribute15
4342 	 , l_line_scredit_rec.operation
4343 	 , l_line_scredit_rec.status_flag
4344          , l_line_scredit_rec.change_reason
4345          , l_line_scredit_rec.change_comments
4346 ;
4347       EXIT WHEN l_line_scredit_cursor%NOTFOUND;
4348 
4349       l_line_scredit_rec.line_index := l_line_count;
4350 
4351       IF l_line_scredit_rec.operation  = 'INSERT' THEN
4352          l_line_scredit_rec.operation := 'CREATE';
4353       END IF;
4354 
4355       l_line_scredit_count := l_line_scredit_count + 1;
4356       l_line_scredit_tbl     (l_line_scredit_count) := l_line_scredit_rec;
4357       l_line_scredit_val_tbl (l_line_scredit_count) := l_line_scredit_val_rec;
4358 
4359 		IF l_debug_level  > 0 THEN
4360 		    oe_debug_pub.add(  'LINE SALESCREDITS REF ( '||L_LINE_SCREDIT_COUNT||' ) : '|| L_LINE_SCREDIT_TBL ( L_LINE_SCREDIT_COUNT ) .ORIG_SYS_CREDIT_REF ) ;
4361 		END IF;
4362 
4363   END LOOP;
4364   CLOSE l_line_scredit_cursor;
4365 
4366 
4367 /* -----------------------------------------------------------
4368    Multiple Payments: Line Payments
4369    -----------------------------------------------------------
4370 */
4371    IF l_debug_level  > 0 THEN
4372        oe_debug_pub.add(  'BEFORE LINE PAYMENTS LOOP' ) ;
4373    END IF;
4374 
4375    --l_line_payment_count := 0;     Commented for the Bug3419970
4376 
4377   OPEN l_line_payment_cursor;
4378   LOOP
4379      FETCH l_line_payment_cursor
4380      INTO  l_line_payment_rec.orig_sys_payment_ref
4381 	 , l_line_payment_rec.change_request_code
4382 	 , l_line_payment_rec.payment_type_code
4383 	 , l_line_payment_val_rec.commitment
4384 	 , l_line_payment_rec.payment_trx_id
4385 	 , l_line_payment_val_rec.receipt_method
4386 	 , l_line_payment_rec.receipt_method_id
4387 	 , l_line_payment_rec.payment_collection_event
4388 	 , l_line_payment_rec.payment_set_id
4389 	 , l_line_payment_rec.prepaid_amount
4390 	 , l_line_payment_rec.credit_card_number
4391 	 , l_line_payment_rec.credit_card_holder_name
4392 	 , l_line_payment_rec.credit_card_expiration_date
4393 	 , l_line_payment_rec.credit_card_code
4394 	 , l_line_payment_rec.credit_card_approval_code
4395 	 , l_line_payment_rec.credit_card_approval_date
4396 	 , l_line_payment_rec.check_number
4397 	 , l_line_payment_rec.payment_amount
4398 	 , l_line_payment_val_rec.payment_percentage
4399 	 , l_line_payment_rec.creation_date
4400          , l_line_payment_rec.created_by
4401          , l_line_payment_rec.last_update_date
4402          , l_line_payment_rec.last_updated_by
4403          , l_line_payment_rec.last_update_login
4404          , l_line_payment_rec.program_application_id
4405          , l_line_payment_rec.program_id
4406          , l_line_payment_rec.program_update_date
4407 	 , l_line_payment_rec.context
4408 	 , l_line_payment_rec.attribute1
4409 	 , l_line_payment_rec.attribute2
4410 	 , l_line_payment_rec.attribute3
4411 	 , l_line_payment_rec.attribute4
4412 	 , l_line_payment_rec.attribute5
4413 	 , l_line_payment_rec.attribute6
4414 	 , l_line_payment_rec.attribute7
4415 	 , l_line_payment_rec.attribute8
4416 	 , l_line_payment_rec.attribute9
4417 	 , l_line_payment_rec.attribute10
4418 	 , l_line_payment_rec.attribute11
4419 	 , l_line_payment_rec.attribute12
4420 	 , l_line_payment_rec.attribute13
4421 	 , l_line_payment_rec.attribute14
4422 	 , l_line_payment_rec.attribute15
4423 	 , l_line_payment_rec.operation
4424 	 , l_line_payment_rec.status_flag
4425 	 , l_line_payment_rec.payment_number
4426 	 , l_line_payment_rec.header_id
4427 	 , l_line_payment_rec.line_id
4428          , l_line_payment_rec.DEFER_PAYMENT_PROCESSING_FLAG -- Added for bug 8478559
4429 	 , l_line_payment_rec.trxn_extension_id
4430          , l_line_payment_rec.instrument_security_code  --R12 CVV2
4431 ;
4432       EXIT WHEN l_line_payment_cursor%NOTFOUND;
4433 
4434       l_line_payment_rec.line_index := l_line_count;
4435 
4436       IF l_line_payment_rec.operation  = 'INSERT' THEN
4437          l_line_payment_rec.operation := 'CREATE';
4438       END IF;
4439 
4440       IF l_line_payment_rec.operation = 'CREATE' THEN
4441       -- set it to miss num, so payment number will be generated internally.
4442          l_line_payment_rec.payment_number :=  FND_API.G_MISS_NUM;
4443       END IF;
4444 
4445       l_line_payment_count := l_line_payment_count + 1;
4446       l_line_payment_tbl     (l_line_payment_count) := l_line_payment_rec;
4447       l_line_payment_val_tbl (l_line_payment_count) := l_line_payment_val_rec;
4448 
4449 		IF l_debug_level  > 0 THEN
4450 		    oe_debug_pub.add(  'LINE PAYMENT REF ( '||L_LINE_payment_COUNT||' ) : '|| L_LINE_payment_TBL ( L_LINE_payment_COUNT ) .ORIG_SYS_PAYMENT_REF ) ;
4451 		END IF;
4452 
4453   END LOOP;
4454   CLOSE l_line_payment_cursor;
4455 -- end of multiple payments: fetching line payments.
4456 
4457 /* -----------------------------------------------------------
4458    Line Lot Serials
4459    -----------------------------------------------------------
4460 */
4461    IF l_debug_level  > 0 THEN
4462        oe_debug_pub.add(  'BEFORE LINE LOT SERIALS LOOP' ) ;
4463    END IF;
4464 
4465   OPEN l_lot_serial_cursor;
4466   LOOP
4467      FETCH l_lot_serial_cursor
4468       INTO l_lot_serial_rec.orig_sys_lotserial_ref
4469 	 , l_lot_serial_rec.change_request_code
4470 	 , l_lot_serial_rec.lot_number
4471 --	 , l_lot_serial_rec.sublot_number -- OPM 3322359 INVCONV
4472 	 , l_lot_serial_rec.from_serial_number
4473 	 , l_lot_serial_rec.to_serial_number
4474 	 , l_lot_serial_rec.quantity
4475 	 , l_lot_serial_rec.quantity2 -- OPM 3322359
4476 	 , l_lot_serial_rec.context
4477 	 , l_lot_serial_rec.attribute1
4478 	 , l_lot_serial_rec.attribute2
4479 	 , l_lot_serial_rec.attribute3
4480 	 , l_lot_serial_rec.attribute4
4481 	 , l_lot_serial_rec.attribute5
4482 	 , l_lot_serial_rec.attribute6
4483 	 , l_lot_serial_rec.attribute7
4484 	 , l_lot_serial_rec.attribute8
4485 	 , l_lot_serial_rec.attribute9
4486 	 , l_lot_serial_rec.attribute10
4487 	 , l_lot_serial_rec.attribute11
4488 	 , l_lot_serial_rec.attribute12
4489 	 , l_lot_serial_rec.attribute13
4490 	 , l_lot_serial_rec.attribute14
4491 	 , l_lot_serial_rec.attribute15
4492 	 , l_lot_serial_rec.operation
4493 	 , l_lot_serial_rec.status_flag
4494 ;
4495       EXIT WHEN l_lot_serial_cursor%NOTFOUND;
4496 
4497       l_lot_serial_rec.line_index := l_line_count;
4498 
4499       IF l_lot_serial_rec.operation  = 'INSERT' THEN
4500          l_lot_serial_rec.operation := 'CREATE';
4501       END IF;
4502 
4503       l_lot_serial_count := l_lot_serial_count + 1;
4504       l_lot_serial_tbl (l_lot_serial_count) := l_lot_serial_rec;
4505 
4506 	        IF l_debug_level  > 0 THEN
4507 	            oe_debug_pub.add(  'LINE LOT SERIAL REF ( '||L_LOT_SERIAL_COUNT||' ) : '|| L_LOT_SERIAL_TBL ( L_LOT_SERIAL_COUNT ) .ORIG_SYS_LOTSERIAL_REF ) ;
4508 	        END IF;
4509 
4510   END LOOP;
4511   CLOSE l_lot_serial_cursor;
4512 
4513 
4514 /* -----------------------------------------------------------
4515    Line Reservation Details
4516    -----------------------------------------------------------
4517 */
4518    IF l_debug_level  > 0 THEN
4519        oe_debug_pub.add(  'BEFORE LINE RESERVATIONS LOOP' ) ;
4520    END IF;
4521 
4522   OPEN l_reservation_cursor;
4523   LOOP
4524      FETCH l_reservation_cursor
4525       INTO l_reservation_rec.orig_sys_reservation_ref
4526 	 , l_reservation_rec.revision
4527 	 , l_reservation_rec.lot_number_id
4528 	 , l_reservation_val_rec.lot_number
4529 	 , l_reservation_rec.subinventory_id
4530 	 , l_reservation_val_rec.subinventory_code
4531 	 , l_reservation_rec.locator_id
4532 	 , l_reservation_rec.quantity
4533 	 , l_reservation_rec.quantity2 -- INVCONV
4534 	 , l_reservation_rec.attribute_category
4535 	 , l_reservation_rec.attribute1
4536 	 , l_reservation_rec.attribute2
4537 	 , l_reservation_rec.attribute3
4538 	 , l_reservation_rec.attribute4
4539 	 , l_reservation_rec.attribute5
4540 	 , l_reservation_rec.attribute6
4541 	 , l_reservation_rec.attribute7
4542 	 , l_reservation_rec.attribute8
4543 	 , l_reservation_rec.attribute9
4544 	 , l_reservation_rec.attribute10
4545 	 , l_reservation_rec.attribute11
4546 	 , l_reservation_rec.attribute12
4547 	 , l_reservation_rec.attribute13
4548 	 , l_reservation_rec.attribute14
4549 	 , l_reservation_rec.attribute15
4550 	 , l_reservation_rec.operation
4551 ;
4552       EXIT WHEN l_reservation_cursor%NOTFOUND;
4553 
4554       l_reservation_rec.line_index := l_line_count;
4555 
4556       IF l_reservation_rec.operation  = 'INSERT' THEN
4557          l_reservation_rec.operation := 'CREATE';
4558       END IF;
4559 
4560       l_reservation_count := l_reservation_count + 1;
4561       l_reservation_tbl     (l_reservation_count) := l_reservation_rec;
4562       l_reservation_val_tbl (l_reservation_count) := l_reservation_val_rec;
4563 
4564         IF l_debug_level  > 0 THEN
4565             oe_debug_pub.add(  'LINE RESERVATION REF ( '||L_RESERVATION_COUNT||' ) : '|| L_RESERVATION_TBL ( L_RESERVATION_COUNT ) .ORIG_SYS_RESERVATION_REF ) ;
4566         END IF;
4567 
4568   END LOOP;
4569   CLOSE l_reservation_cursor;
4570 
4571 --bsadri
4572   --l_action_request_count := 0;
4573 
4574   OPEN l_action_request_line_cursor;
4575   LOOP
4576      FETCH l_action_request_line_cursor
4577       INTO l_action_rec.orig_sys_line_ref
4578          , l_action_rec.orig_sys_shipment_ref
4579 	 , l_action_rec.hold_id
4580 	 , l_action_rec.hold_type_code
4581 	 , l_action_rec.hold_type_id
4582 	 , l_action_rec.hold_until_date
4583 	 , l_action_rec.release_reason_code
4584 	 , l_action_rec.comments
4585 	 , l_action_rec.context
4586 	 , l_action_rec.attribute1
4587 	 , l_action_rec.attribute2
4588 	 , l_action_rec.attribute3
4589 	 , l_action_rec.attribute4
4590 	 , l_action_rec.attribute5
4591 	 , l_action_rec.attribute6
4592 	 , l_action_rec.attribute7
4593 	 , l_action_rec.attribute8
4594 	 , l_action_rec.attribute9
4595 	 , l_action_rec.attribute10
4596 	 , l_action_rec.attribute11
4597 	 , l_action_rec.attribute12
4598 	 , l_action_rec.attribute13
4599 	 , l_action_rec.attribute14
4600 	 , l_action_rec.attribute15
4601 	 , l_action_rec.operation_code
4602          , l_action_rec.fulfillment_set_name
4603 	 , l_action_rec.error_flag
4604 	 , l_action_rec.status_flag
4605 	 , l_action_rec.interface_status
4606 --myerrams,start, modified the fetch statement to fetch newly introduced
4607 --fields in oe_actions_interface for Customer Acceptance
4608 	 , l_action_rec.char_param1
4609 	 , l_action_rec.char_param2
4610 	 , l_action_rec.char_param3
4611 	 , l_action_rec.char_param4
4612 	 , l_action_rec.char_param5
4613 	 , l_action_rec.date_param1
4614 	 , l_action_rec.date_param2
4615 	 , l_action_rec.date_param3
4616 	 , l_action_rec.date_param4
4617 	 , l_action_rec.date_param5
4618 --myerrams, end
4619 ;
4620       EXIT WHEN l_action_request_line_cursor%NOTFOUND;
4621 
4622       l_action_request_rec.request_type := l_action_rec.operation_code;
4623 
4624       IF OE_CODE_CONTROL.CODE_RELEASE_LEVEL >= '110510' AND
4625          (l_action_rec.operation_code = OE_GLOBALS.G_ADD_FULFILLMENT_SET OR
4626           l_action_rec.operation_code = OE_GLOBALS.G_REMOVE_FULFILLMENT_SET) THEN
4627 
4628           l_action_request_rec.param5 :=  l_action_rec.fulfillment_set_name;
4629       END IF;
4630 
4631       l_action_request_rec.entity_code := OE_Globals.G_ENTITY_LINE;
4632       l_action_request_rec.entity_index := l_line_count;
4633 
4634       IF l_debug_level  > 0 THEN
4635           oe_debug_pub.add(  'ACTION CODE: '|| L_ACTION_REQUEST_REC.REQUEST_TYPE , 1 ) ;
4636 
4637           oe_debug_pub.add(  'ENTITY CODE: '|| L_ACTION_REQUEST_REC.ENTITY_CODE , 1 ) ;
4638 
4639           oe_debug_pub.add(  'ENTITY ID : '|| L_ACTION_REQUEST_REC.ENTITY_ID , 1 ) ;
4640       END IF;
4641 
4642       IF l_action_rec.operation_code = OE_Globals.G_APPLY_HOLD THEN
4643 	 l_action_request_rec.param1  := l_action_rec.hold_id;
4644 	 l_action_request_rec.param2  := nvl(l_action_rec.hold_type_code,'O');
4645 	 l_action_request_rec.param3  := nvl(l_action_rec.hold_type_id,
4646 					     l_action_request_rec.entity_id);
4647 	 l_action_request_rec.param4  := l_action_rec.comments;
4648 	 l_action_request_rec.date_param1  := l_action_rec.hold_until_date;
4649 	 l_action_request_rec.param10 := l_action_rec.context;
4650 	 l_action_request_rec.param11 := l_action_rec.attribute1;
4651 	 l_action_request_rec.param12 := l_action_rec.attribute2;
4652 	 l_action_request_rec.param13 := l_action_rec.attribute3;
4653 	 l_action_request_rec.param14 := l_action_rec.attribute4;
4654 	 l_action_request_rec.param15 := l_action_rec.attribute5;
4655 	 l_action_request_rec.param16 := l_action_rec.attribute6;
4656 	 l_action_request_rec.param17 := l_action_rec.attribute7;
4657 	 l_action_request_rec.param18 := l_action_rec.attribute8;
4658 	 l_action_request_rec.param19 := l_action_rec.attribute9;
4659 	 l_action_request_rec.param20 := l_action_rec.attribute10;
4660 	 l_action_request_rec.param21 := l_action_rec.attribute11;
4661 	 l_action_request_rec.param22 := l_action_rec.attribute12;
4662 	 l_action_request_rec.param23 := l_action_rec.attribute13;
4663 	 l_action_request_rec.param24 := l_action_rec.attribute14;
4664 	 l_action_request_rec.param25 := l_action_rec.attribute15;
4665 
4666       IF l_debug_level  > 0 THEN
4667           oe_debug_pub.add(  'PARAM1/HOLD_ID: ' || L_ACTION_REQUEST_REC.PARAM1 , 1 ) ;
4668 
4669           oe_debug_pub.add(  'PARAM2/HOLD_ENT_CD: '|| L_ACTION_REQUEST_REC.PARAM2 , 1 ) ;
4670 
4671           oe_debug_pub.add(  'PARAM3/HOLD_ENT_ID: '|| L_ACTION_REQUEST_REC.PARAM3 , 1 ) ;
4672 
4673           oe_debug_pub.add(  'PARAM4/HOLD_CMNTS: ' || L_ACTION_REQUEST_REC.PARAM4 , 1 ) ;
4674       END IF;
4675 
4676       ELSIF l_action_rec.operation_code = OE_Globals.G_RELEASE_HOLD THEN
4677 	 l_action_request_rec.param1  := l_action_rec.hold_id;
4678 	 l_action_request_rec.param2  := nvl(l_action_rec.hold_type_code,'O');
4679 	 l_action_request_rec.param3  := nvl(l_action_rec.hold_type_id,
4680 					     l_action_request_rec.entity_id);
4681 	 l_action_request_rec.param4  := l_action_rec.release_reason_code;
4682 	 l_action_request_rec.param5  := l_action_rec.comments;
4683 
4684       IF l_debug_level  > 0 THEN
4685           oe_debug_pub.add(  'PARAM1/HOLD_ID: ' || L_ACTION_REQUEST_REC.PARAM1 , 1 ) ;
4686 
4687           oe_debug_pub.add(  'PARAM2/HOLD_ENT_CD: '|| L_ACTION_REQUEST_REC.PARAM2 , 1 ) ;
4688 
4689           oe_debug_pub.add(  'PARAM3/HOLD_ENT_ID: '|| L_ACTION_REQUEST_REC.PARAM3 , 1 ) ;
4690 
4691           oe_debug_pub.add(  'PARAM4/REL_REASON: ' || L_ACTION_REQUEST_REC.PARAM4 , 1 ) ;
4692 
4693           oe_debug_pub.add(  'PARAM5/REL_COMMNTS: '|| L_ACTION_REQUEST_REC.PARAM5 , 1 ) ;
4694       END IF;
4695 
4696 --myerrams, introduced the following check for Customer Acceptance.
4697       ELSIF  l_action_rec.operation_code = OE_Globals.G_ACCEPT_FULFILLMENT OR l_action_rec.operation_code = OE_Globals.G_REJECT_FULFILLMENT THEN
4698          IF (OE_SYS_PARAMETERS.VALUE('ENABLE_FULFILLMENT_ACCEPTANCE',p_org_id) = 'Y')
4699 	 THEN
4700         -- Customer Comments
4701 	 l_action_request_rec.param1  := l_action_rec.char_param1;
4702         -- Customer Signature
4703 	 l_action_request_rec.param2  := l_action_rec.char_param2;
4704         -- Reference Document
4705 	 l_action_request_rec.param3  := l_action_rec.char_param3;
4706         -- Implicit Acceptance Flag
4707 	 l_action_request_rec.param4  := l_action_rec.char_param4;
4708         -- Customer Signature Date
4709 	 l_action_request_rec.date_param1  := l_action_rec.date_param1;
4710 
4711 --myerrams, Bug:4724191	 l_action_request_rec.param5 := l_header_id_temp;
4712 
4713          ELSE
4714 --display a message saying Customer Acceptance is not enabled
4715    	       FND_MESSAGE.Set_Name('ONT', 'ONT_CUST_ACC_DISABLED');
4716 	       OE_MSG_PUB.add;
4717 	 END IF;
4718       IF l_debug_level  > 0 THEN
4719           oe_debug_pub.add(  'PARAM2/CUSTOMER_COMMENTS: ' || L_ACTION_REQUEST_REC.PARAM2 , 1 ) ;
4720 
4721           oe_debug_pub.add(  'PARAM3/CUSTOMER_SIGNATURE: '|| L_ACTION_REQUEST_REC.PARAM3 , 1 ) ;
4722 
4723           oe_debug_pub.add(  'PARAM4/REFERENCE_DOCUMENT: '|| L_ACTION_REQUEST_REC.PARAM4 , 1 ) ;
4724 
4725           oe_debug_pub.add(  'PARAM5/IMPLICIT ACCEPTANCE FLAG: ' || L_ACTION_REQUEST_REC.PARAM5 , 1 ) ;
4726 
4727           oe_debug_pub.add(  'DATE_PARAM1/SIGNATURE_DATE: '|| L_ACTION_REQUEST_REC.DATE_PARAM1 , 1 ) ;
4728       END IF;
4729 --myerrams, end
4730       END IF;
4731 
4732       l_action_request_count := l_action_request_count+1;
4733       l_action_request_tbl(l_action_request_count) := l_action_request_rec;
4734 
4735   END LOOP;
4736   CLOSE l_action_request_line_cursor;
4737   IF l_debug_level  > 0 THEN
4738       oe_debug_pub.add(  'LINES L_ACTION_REQUEST_COUNT : '||L_ACTION_REQUEST_COUNT ) ;
4739   END IF;
4740 
4741   END LOOP;			/* Lines cursor */
4742   CLOSE l_line_cursor;
4743 
4744 /* -----------------------------------------------------------
4745    Action Requests header
4746    -----------------------------------------------------------
4747 */
4748    IF l_debug_level  > 0 THEN
4749        oe_debug_pub.add(  'BEFORE ACTION REQUEST HEADER LOOP' ) ;
4750    END IF;
4751 
4752   --l_action_request_count := 0;
4753 
4754 
4755 /* -----------------------------------------------------------
4756    Call Order Import Pre-Process
4757    -----------------------------------------------------------
4758 */
4759      IF l_debug_level  > 0 THEN
4760          oe_debug_pub.add(  'BEFORE CALLING ORDERIMPORT PRE-PROCESS' ) ;
4761      END IF;
4762 
4763 
4764      OE_ORDER_IMPORT_SPECIFIC_PVT.Pre_Process(
4765    	 p_x_header_rec			=> l_header_rec
4766   	,p_x_header_adj_tbl		=> l_header_adj_tbl
4767         ,p_x_header_price_att_tbl       => l_header_price_att_tbl
4768         ,p_x_header_adj_att_tbl         => l_header_adj_att_tbl
4769         ,p_x_header_adj_assoc_tbl      => l_header_adj_assoc_tbl
4770   	,p_x_header_scredit_tbl		=> l_header_scredit_tbl
4771   	,p_x_header_payment_tbl		=> l_header_payment_tbl
4772   	,p_x_line_tbl			=> l_line_tbl
4773   	,p_x_line_adj_tbl		=> l_line_adj_tbl
4774         ,p_x_line_price_att_tbl         => l_line_price_att_tbl
4775         ,p_x_line_adj_att_tbl           => l_line_adj_att_tbl
4776         ,p_x_line_adj_assoc_tbl         => l_line_adj_assoc_tbl
4777   	,p_x_line_scredit_tbl		=> l_line_scredit_tbl
4778   	,p_x_line_payment_tbl		=> l_line_payment_tbl
4779   	,p_x_lot_serial_tbl		=> l_lot_serial_tbl
4780   	,p_x_reservation_tbl		=> l_reservation_tbl
4781         ,p_x_action_request_tbl         => l_action_request_tbl
4782 --put back the action table for booked order processing
4783   	,p_x_header_val_rec		=> l_header_val_rec
4784   	,p_x_header_adj_val_tbl		=> l_header_adj_val_tbl
4785   	,p_x_header_scredit_val_tbl	=> l_header_scredit_val_tbl
4786   	,p_x_header_payment_val_tbl	=> l_header_payment_val_tbl
4787   	,p_x_line_val_tbl		=> l_line_val_tbl
4788   	,p_x_line_adj_val_tbl		=> l_line_adj_val_tbl
4789   	,p_x_line_scredit_val_tbl	=> l_line_scredit_val_tbl
4790   	,p_x_line_payment_val_tbl	=> l_line_payment_val_tbl
4791   	,p_x_lot_serial_val_tbl		=> l_lot_serial_val_tbl
4792   	,p_x_reservation_val_tbl	=> l_reservation_val_tbl
4793 
4794   --{ Start of the variable declaration for the add customer
4795         ,p_header_customer_rec          => l_header_customer_rec
4796         ,p_line_customer_tbl            => l_line_customer_tbl
4797   --End of the variable declaration for the add customer}
4798   	,p_return_status		=> l_return_status_oi_pre
4799 
4800 	);
4801 
4802 /* -----------------------------------------------------------
4803    Set Return Status
4804    -----------------------------------------------------------
4805 */
4806    IF l_debug_level  > 0 THEN
4807        oe_debug_pub.add(  'PRE-PROCESS RETURN STATUS: '||L_RETURN_STATUS_OI_PRE ) ;
4808    END IF;
4809 
4810    IF    l_return_status_oi_pre IN (FND_API.G_RET_STS_ERROR)
4811    AND   p_return_status    NOT IN (FND_API.G_RET_STS_ERROR,
4812 			                     FND_API.G_RET_STS_UNEXP_ERROR)
4813    THEN  p_return_status :=         FND_API.G_RET_STS_ERROR;
4814    ELSIF l_return_status_oi_pre IN (FND_API.G_RET_STS_UNEXP_ERROR)
4815    AND   p_return_status    NOT IN (FND_API.G_RET_STS_ERROR,
4816 			            FND_API.G_RET_STS_UNEXP_ERROR)
4817    THEN  p_return_status :=         FND_API.G_RET_STS_UNEXP_ERROR;
4818    END IF;
4819 
4820 -- aksingh
4821    IF l_debug_level  > 0 THEN
4822        oe_debug_pub.add(  'P_RETURN_STATUS AFTER PRE-PROCESS : '|| P_RETURN_STATUS ) ;
4823 
4824 /* -----------------------------------------------------------
4825    Set control flags for Process_Order
4826    -----------------------------------------------------------
4827 */
4828        oe_debug_pub.add(  'BEFORE SETTING UP CONTROL FLAGS' ) ;
4829    END IF;
4830 
4831    l_init_msg_list := FND_API.G_FALSE;
4832 
4833 /* -----------------------------------------------------------
4834    If the Order Import validation failed, we still want the
4835    Process_Order to do the validation but not import.
4836    -----------------------------------------------------------
4837 */
4838    IF l_return_status_oi_pre <> FND_API.G_RET_STS_SUCCESS THEN
4839 -- aksingh
4840       IF l_debug_level  > 0 THEN
4841           oe_debug_pub.add(  'PRE-PROCESS FAILED SETTTING L_VALIDATE_ONLY TO TRUE' ) ;
4842       END IF;
4843       l_validate_only := FND_API.G_TRUE;
4844    END IF;
4845 
4846 /* -----------------------------------------------------------
4847    Set the api service level to Validate_only for Process_Order
4848    -----------------------------------------------------------
4849 */
4850    IF l_validate_only = FND_API.G_TRUE THEN
4851 -- aksingh
4852       IF l_debug_level  > 0 THEN
4853           oe_debug_pub.add(  'SETTTING L_API_SERVICE_LEVEL TO VALIDATE_ONLY' ) ;
4854       END IF;
4855       l_api_service_level := OE_GLOBALS.G_VALIDATION_ONLY;
4856 -- Following is added to fix the bug# 1267887
4857 -- It will allow the processing of all the line if API is called in
4858 -- validate only mode
4859    --   l_control_rec.process_partial := TRUE;
4860       l_control_rec.controlled_operation := TRUE;
4861    END IF;
4862    l_control_rec.controlled_operation := TRUE; -- Bug #1913056
4863    l_control_rec.process_partial := TRUE;
4864 
4865    -- bug 3636884, set require_reason to true
4866    l_control_rec.require_reason := TRUE;
4867 
4868 /* -----------------------------------------------------------
4869    This procedure sets the global G_RESET_APPS_CONTEXT to FALSE
4870    by doing OE_STANDARD_WF.G_RESET_APPS_CONTEXT := FALSE
4871    -----------------------------------------------------------
4872 */
4873    OE_STANDARD_WF.Reset_Apps_Context_Off;
4874    -- Following line added to fix the code for bug 2756895
4875    OE_STANDARD_WF.Save_Messages_Off;
4876 
4877 
4878 /* -----------------------------------------------------------
4879    Call Process_Order
4880    -----------------------------------------------------------
4881 */
4882    IF l_debug_level  > 0 THEN
4883        oe_debug_pub.add(  'BEFORE CALLING PROCESS_ORDER' ) ;
4884 
4885        oe_debug_pub.add(  'BEFORE L_HEADER.OPERATION ' || L_HEADER_REC.OPERATION ) ;
4886        oe_debug_pub.add('trim data = '||l_rtrim_data);
4887    END IF;
4888 
4889    If l_action_request_tbl.count > 0 then
4890        oe_debug_pub.add('action table count = '|| l_action_request_tbl.count);
4891        l_action_request_tbl_old := l_action_request_tbl;
4892        oe_debug_pub.add('action table old count = '|| l_action_request_tbl_old.count);
4893 
4894    End If;
4895 
4896    OE_GLOBALS.G_FAIL_ORDER_IMPORT := FALSE; /* Bug # 4036765 */
4897 
4898    OE_GLOBALS.G_ORDER_IMPORT_CALL := TRUE; -- Bug 7367433
4899 
4900       OE_Order_Grp.Process_Order(
4901 	     p_api_version_number 		=> 1
4902         ,p_init_msg_list 		=> l_init_msg_list
4903         ,p_validation_level 		=> l_validation_level
4904         ,p_return_values 		=> l_return_values
4905         ,p_commit 			=> l_commit
4906         ,p_api_service_level 		=> l_api_service_level
4907     	,p_control_rec 			=> l_control_rec
4908         ,p_header_rec 			=> l_header_rec
4909         ,p_header_adj_tbl		=> l_header_adj_tbl
4910         ,p_header_price_att_tbl		=> l_header_price_att_tbl
4911         ,p_header_adj_att_tbl		=> l_header_adj_att_tbl
4912         ,p_header_adj_assoc_tbl		=> l_header_adj_assoc_tbl
4913         ,p_header_Scredit_tbl		=> l_header_scredit_tbl
4914         ,p_header_payment_tbl		=> l_header_payment_tbl
4915         ,p_line_tbl 			=> l_line_tbl
4916         ,p_line_adj_tbl			=> l_line_adj_tbl
4917         ,p_line_price_att_tbl		=> l_line_price_att_tbl
4918         ,p_line_adj_att_tbl		=> l_line_adj_att_tbl
4919         ,p_line_adj_assoc_tbl		=> l_line_adj_assoc_tbl
4920         ,p_line_scredit_tbl		=> l_line_scredit_tbl
4921         ,p_line_payment_tbl		=> l_line_payment_tbl
4922         ,p_lot_serial_tbl		=> l_lot_serial_tbl
4923 	,p_action_request_tbl 		=> l_action_request_tbl_old
4924         ,p_header_val_rec 		=> l_header_val_rec
4925         ,p_header_adj_val_tbl		=> l_header_adj_val_tbl
4926         ,p_header_Scredit_val_tbl	=> l_header_scredit_val_tbl
4927         ,p_header_payment_val_tbl	=> l_header_payment_val_tbl
4928         ,p_line_val_tbl 		=> l_line_val_tbl
4929         ,p_line_adj_val_tbl		=> l_line_adj_val_tbl
4930         ,p_line_scredit_val_tbl		=> l_line_scredit_val_tbl
4931         ,p_line_payment_val_tbl		=> l_line_payment_val_tbl
4932         ,p_lot_serial_val_tbl		=> l_lot_serial_val_tbl
4933         ,p_old_header_rec 		=> l_header_rec_old
4934         ,p_old_header_adj_tbl 		=> l_header_adj_tbl_old
4935         ,p_old_header_price_att_tbl 	=> l_header_price_att_tbl_old
4936         ,p_old_header_adj_att_tbl 	=> l_header_adj_att_tbl_old
4937         ,p_old_header_adj_assoc_tbl 	=> l_header_adj_assoc_tbl_old
4938         ,p_old_header_Scredit_tbl 	=> l_header_scredit_tbl_old
4939         ,p_old_header_payment_tbl 	=> l_header_payment_tbl_old
4940         ,p_old_line_tbl 		=> l_line_tbl_old
4941         ,p_old_line_adj_tbl 		=> l_line_adj_tbl_old
4942         ,p_old_line_price_att_tbl 	=> l_line_price_att_tbl_old
4943         ,p_old_line_adj_att_tbl 	=> l_line_adj_att_tbl_old
4944         ,p_old_line_adj_assoc_tbl 	=> l_line_adj_assoc_tbl_old
4945         ,p_old_line_scredit_tbl 	=> l_line_scredit_tbl_old
4946         ,p_old_line_payment_tbl 	=> l_line_payment_tbl_old
4947         ,p_old_lot_serial_tbl		=> l_lot_serial_tbl_old
4948         ,p_old_header_val_rec 		=> l_header_val_rec_old
4949         ,p_old_header_adj_val_tbl	=> l_header_adj_val_tbl_old
4950         ,p_old_header_Scredit_val_tbl	=> l_header_scredit_val_tbl_old
4951         ,p_old_header_payment_val_tbl	=> l_header_payment_val_tbl_old
4952         ,p_old_line_val_tbl 		=> l_line_val_tbl_old
4953         ,p_old_line_adj_val_tbl		=> l_line_adj_val_tbl_old
4954         ,p_old_line_scredit_val_tbl	=> l_line_scredit_val_tbl_old
4955         ,p_old_line_payment_val_tbl	=> l_line_payment_val_tbl_old
4956         ,p_old_lot_serial_val_tbl	=> l_lot_serial_val_tbl_old
4957         ,p_rtrim_data                   => l_rtrim_data
4958         ,x_header_rec 			=> l_header_rec_new
4959         ,x_header_adj_tbl 		=> l_header_adj_tbl_new
4960         ,x_header_price_att_tbl 	=> l_header_price_att_tbl_new
4961         ,x_header_adj_att_tbl 		=> l_header_adj_att_tbl_new
4962         ,x_header_adj_assoc_tbl 	=> l_header_adj_assoc_tbl_new
4963         ,x_header_scredit_tbl 		=> l_header_scredit_tbl_new
4964         ,x_header_payment_tbl 		=> l_header_payment_tbl_new
4965         ,x_line_tbl 			=> l_line_tbl_new
4966         ,x_line_adj_tbl         	=> l_line_adj_tbl_new
4967         ,x_line_price_att_tbl 		=> l_line_price_att_tbl_new
4968         ,x_line_adj_att_tbl 		=> l_line_adj_att_tbl_new
4969         ,x_line_adj_assoc_tbl 		=> l_line_adj_assoc_tbl_new
4970         ,x_line_scredit_tbl		=> l_line_Scredit_tbl_new
4971         ,x_line_payment_tbl		=> l_line_payment_tbl_new
4972         ,x_lot_serial_tbl		=> l_lot_serial_tbl_new
4973 	,x_action_request_tbl   	=> l_action_request_tbl
4974         ,x_header_val_rec 		=> l_header_val_rec_new
4975         ,x_header_adj_val_tbl		=> l_header_adj_val_tbl_new
4976         ,x_header_Scredit_val_tbl	=> l_header_scredit_val_tbl_new
4977         ,x_header_payment_val_tbl	=> l_header_payment_val_tbl_new
4978         ,x_line_val_tbl 		=> l_line_val_tbl_new
4979         ,x_line_adj_val_tbl		=> l_line_adj_val_tbl_new
4980         ,x_line_scredit_val_tbl		=> l_line_scredit_val_tbl_new
4981         ,x_line_payment_val_tbl		=> l_line_payment_val_tbl_new
4982         ,x_lot_serial_val_tbl		=> l_lot_serial_val_tbl_new
4983         ,x_return_status 		=> l_return_status_po
4984         ,x_msg_count 			=> p_msg_count
4985         ,x_msg_data 			=> p_msg_data
4986 	,p_validate_desc_flex           => p_validate_desc_flex --bug 4343612
4987 	);
4988 
4989    OE_GLOBALS.G_ORDER_IMPORT_CALL := FALSE; -- Bug 7367433
4990 
4991    -- For Actions call is directly made to delayed request
4992    -- Process_Order_Action, which is changed from the calling
4993    -- process_order group appi twice
4994    -- once for normal processing and next for processing actions
4995    -- Right now call to the process order is commented down
4996    -- will be removed later
4997 
4998       IF l_debug_level  > 0 THEN
4999           oe_debug_pub.add(  'PROCESS_ORDER RETURN STATUS BEFORE ACTION : '||L_RETURN_STATUS_PO , 1 ) ;
5000       END IF;
5001 
5002    /* Bug # 4036765 */
5003    IF OE_GLOBALS.G_FAIL_ORDER_IMPORT THEN
5004       IF l_debug_level  > 0 THEN
5005           oe_debug_pub.add(  'G_FAIL_ORDER_IMPORT WAS SET TO TRUE.  SETTING PROCESS_ORDER RETURN STATUS TO FAILURE' , 1 ) ;
5006       END IF;
5007       l_return_status_po := FND_API.G_RET_STS_ERROR;
5008    END IF;
5009 
5010    IF l_return_status_po IN (FND_API.G_RET_STS_ERROR,
5011                                  FND_API.G_RET_STS_UNEXP_ERROR) THEN
5012       IF l_debug_level  > 0 THEN
5013           oe_debug_pub.add(  'PROCESS ORDER FAILED. NO NEED TO CALL FOR ACTIONS' , 1 ) ;
5014       END IF;
5015    ELSE --{
5016       l_header_rec 			:= OE_Order_Pub.G_MISS_HEADER_REC;
5017       l_header_rec            := l_header_rec_new;
5018   END IF; -- return status error }
5019 
5020    For i in 1..l_action_request_tbl.count
5021    Loop
5022      If l_action_request_tbl(i).return_status <>
5023         FND_API.G_RET_STS_SUCCESS
5024      Then
5025         IF l_debug_level  > 0 THEN
5026             oe_debug_pub.add(  'FAILED TO PERFORM ACTION REQUEST ' || L_ACTION_REQUEST_TBL ( I ) .REQUEST_TYPE , 1 ) ;
5027         END IF;
5028        fnd_file.put_line(FND_FILE.OUTPUT,
5029         'Failed to perform Action Request ' ||
5030         l_action_request_tbl(i).request_type);
5031      End If;
5032    End Loop;
5033 
5034    IF l_debug_level  > 0 THEN
5035        oe_debug_pub.add(  'AFTER CALLING PROCESS_ORDER' , 3 ) ;
5036 
5037 /* -----------------------------------------------------------
5038    Set Return Status
5039    -----------------------------------------------------------
5040 */
5041        oe_debug_pub.add(  'PROCESS_ORDER RETURN STATUS: '||L_RETURN_STATUS_PO , 3 ) ;
5042    END IF;
5043 
5044    IF    l_return_status_po  IN (FND_API.G_RET_STS_ERROR)
5045    AND   p_return_status NOT IN (FND_API.G_RET_STS_ERROR,
5046 			                  FND_API.G_RET_STS_UNEXP_ERROR)
5047    THEN  p_return_status :=      FND_API.G_RET_STS_ERROR;
5048    ELSIF l_return_status_po  IN (FND_API.G_RET_STS_UNEXP_ERROR)
5049    AND   p_return_status NOT IN (FND_API.G_RET_STS_ERROR,
5050 			                  FND_API.G_RET_STS_UNEXP_ERROR)
5051    THEN  p_return_status :=      FND_API.G_RET_STS_UNEXP_ERROR;
5052    END IF;
5053 
5054 
5055    -- aksingh
5056    IF l_debug_level  > 0 THEN
5057        oe_debug_pub.add(  'P_RETURN_STATUS '||P_RETURN_STATUS , 3 ) ;
5058    END IF;
5059 
5060 /* -----------------------------------------------------------
5061    Check Process_Order Results
5062    -----------------------------------------------------------
5063 */
5064    IF p_msg_count = 0 THEN
5065       IF l_return_status_po = FND_API.G_RET_STS_ERROR THEN
5066 	 IF l_debug_level  > 0 THEN
5067 	     oe_debug_pub.add(  'PROCESS ORDER FAILED WITH ERRORS BUT RETURNED NO MESSAGE' ) ;
5068 	 END IF;
5069 	 FND_MESSAGE.SET_NAME('ONT','OE_OI_PO_ERROR');
5070          OE_MSG_PUB.Add;
5071       ELSIF l_return_status_po = FND_API.G_RET_STS_UNEXP_ERROR THEN
5072 	 IF l_debug_level  > 0 THEN
5073 	     oe_debug_pub.add(  'PROCESS ORDER FAILED WITH UNEXPECTED ERRORS BUT RETURNED NO MESSAGE... ' ) ;
5074 	 END IF;
5075 	 FND_MESSAGE.SET_NAME('ONT','OE_OI_PO_UNEXP_ERROR');
5076          OE_MSG_PUB.Add;
5077       END IF;
5078    END IF;
5079 
5080    IF l_header_rec.operation IN ('INSERT', 'CREATE') AND
5081       l_return_status_po = FND_API.G_RET_STS_SUCCESS
5082    THEN
5083 				IF l_debug_level  > 0 THEN
5084 				    oe_debug_pub.add(  'HEADER ID GENERATED: '|| TO_CHAR ( L_HEADER_REC_NEW.HEADER_ID ) ) ;
5085 
5086 				    oe_debug_pub.add(  'ORDER NUMBER GENERATED: '|| TO_CHAR ( L_HEADER_REC_NEW.ORDER_NUMBER ) ) ;
5087 				END IF;
5088    END IF;
5089 
5090 
5091 /* -----------------------------------------------------------
5092    Call Order Import Post-Process
5093    -----------------------------------------------------------
5094 */
5095    IF l_return_status_po = FND_API.G_RET_STS_SUCCESS THEN
5096       IF l_debug_level  > 0 THEN
5097           oe_debug_pub.add(  'BEFORE CALLING ORDERIMPORT POST-PROCESS' ) ;
5098       END IF;
5099 
5100       OE_ORDER_IMPORT_SPECIFIC_PVT.Post_Process(
5101    	 p_x_header_rec			=> l_header_rec_new
5102   	,p_x_header_adj_tbl		=> l_header_adj_tbl_new
5103         ,p_x_header_price_att_tbl       => l_header_price_att_tbl_new
5104         ,p_x_header_adj_att_tbl         => l_header_adj_att_tbl_new
5105         ,p_x_header_adj_assoc_tbl       => l_header_adj_assoc_tbl_new
5106   	,p_x_header_scredit_tbl		=> l_header_scredit_tbl_new
5107   	,p_x_line_tbl			=> l_line_tbl_new
5108   	,p_x_line_adj_tbl		=> l_line_adj_tbl_new
5109         ,p_x_line_price_att_tbl         => l_line_price_att_tbl_new
5110         ,p_x_line_adj_att_tbl           => l_line_adj_att_tbl_new
5111         ,p_x_line_adj_assoc_tbl         => l_line_adj_assoc_tbl_new
5112   	,p_x_line_scredit_tbl		=> l_line_scredit_tbl_new
5113   	,p_x_lot_serial_tbl		=> l_lot_serial_tbl_new
5114 
5115   	,p_x_header_val_rec		=> l_header_val_rec_new
5116   	,p_x_header_adj_val_tbl		=> l_header_adj_val_tbl_new
5117   	,p_x_header_scredit_val_tbl	=> l_header_scredit_val_tbl_new
5118   	,p_x_line_val_tbl		=> l_line_val_tbl_new
5119   	,p_x_line_adj_val_tbl		=> l_line_adj_val_tbl_new
5120   	,p_x_line_scredit_val_tbl	=> l_line_scredit_val_tbl_new
5121   	,p_x_lot_serial_val_tbl		=> l_lot_serial_val_tbl_new
5122 
5123    	,p_x_header_rec_old		=> l_header_rec
5124   	,p_x_header_adj_tbl_old		=> l_header_adj_tbl
5125   	,p_x_header_scredit_tbl_old	=> l_header_scredit_tbl
5126   	,p_x_line_tbl_old		=> l_line_tbl
5127   	,p_x_line_adj_tbl_old		=> l_line_adj_tbl
5128         ,p_x_line_price_att_tbl_old     => l_line_price_att_tbl
5129   	,p_x_line_scredit_tbl_old	=> l_line_scredit_tbl
5130   	,p_x_lot_serial_tbl_old		=> l_lot_serial_tbl
5131 
5132   	,p_x_header_val_rec_old		=> l_header_val_rec
5133   	,p_x_header_adj_val_tbl_old	=> l_header_adj_val_tbl
5134   	,p_x_header_scredit_val_tbl_old	=> l_header_scredit_val_tbl
5135   	,p_x_line_val_tbl_old		=> l_line_val_tbl
5136   	,p_x_line_adj_val_tbl_old	=> l_line_adj_val_tbl
5137   	,p_x_line_scredit_val_tbl_old	=> l_line_scredit_val_tbl
5138   	,p_x_lot_serial_val_tbl_old	=> l_lot_serial_val_tbl
5139 
5140   	,p_x_reservation_tbl		=> l_reservation_tbl
5141   	,p_x_reservation_val_tbl	=> l_reservation_val_tbl
5142 
5143   	,p_return_status		=> l_return_status_oi_pst
5144 	);
5145    END IF;
5146 
5147 
5148 /* -----------------------------------------------------------
5149    Set Return Status
5150    -----------------------------------------------------------
5151 */
5152    IF l_debug_level  > 0 THEN
5153        oe_debug_pub.add(  'POST-PROCESS RETURN STATUS: '||L_RETURN_STATUS_OI_PST ) ;
5154    END IF;
5155 
5156    IF    l_return_status_oi_pst IN (FND_API.G_RET_STS_ERROR)
5157    AND   p_return_status    NOT IN (FND_API.G_RET_STS_ERROR,
5158 			                     FND_API.G_RET_STS_UNEXP_ERROR)
5159    THEN  p_return_status :=         FND_API.G_RET_STS_ERROR;
5160    ELSIF l_return_status_oi_pst IN (FND_API.G_RET_STS_UNEXP_ERROR)
5161    AND   p_return_status    NOT IN (FND_API.G_RET_STS_ERROR,
5162 			                     FND_API.G_RET_STS_UNEXP_ERROR)
5163    THEN  p_return_status :=         FND_API.G_RET_STS_UNEXP_ERROR;
5164    END IF;
5165 
5166 
5167   --END LOOP;			/* Headers cursor */
5168   CLOSE l_header_cursor;
5169 
5170 /* -----------------------------------------------------------
5171    Delete order from interface tables
5172    -----------------------------------------------------------
5173 */
5174    -- aksingh
5175    IF l_debug_level  > 0 THEN
5176        oe_debug_pub.add('l_validate_only '||l_validate_only ) ;
5177        oe_debug_pub.add('p_return_status '||p_return_status ) ;
5178    END IF;
5179 
5180 -- aksingh   IF p_validate_only = FND_API.G_FALSE AND
5181    IF l_validate_only = FND_API.G_FALSE AND
5182       p_return_status = FND_API.G_RET_STS_SUCCESS	/* S=Success */
5183    THEN
5184       l_delete_flag := 'Y';
5185    ELSE
5186       l_delete_flag := 'N';
5187    END IF;
5188 
5189    IF l_debug_level  > 0 THEN
5190        oe_debug_pub.add(  'DELETE FLAG '||L_DELETE_FLAG ) ;
5191    END IF;
5192 
5193    IF l_delete_flag = 'Y' THEN
5194 
5195       IF l_debug_level  > 0 THEN
5196           oe_debug_pub.add(  'BEFORE DELETING ORDER FROM INTERFACE TABLES' ) ;
5197       END IF;
5198 
5199       OE_ORDER_IMPORT_UTIL_PVT.Delete_Order (
5200 	    p_request_id		=> l_request_id,
5201       	    p_order_source_id		=> l_order_source_id,
5202 	    p_orig_sys_document_ref	=> l_orig_sys_document_ref,
5203             p_sold_to_org_id            => l_sold_to_org_id,
5204             p_sold_to_org               => l_sold_to_org,
5205 	    p_change_sequence		=> l_change_sequence,
5206 	    p_return_status		=> l_return_status_del_ord
5207 	   );
5208 
5209 
5210       IF l_debug_level  > 0 THEN
5211           oe_debug_pub.add(  'BEFORE CALLING DELETE OF CUSTOMER INFO' ) ;
5212       END IF;
5213       OE_INLINE_CUSTOMER_PUB.Delete_Customer_Info(
5214             p_header_customer_rec   => l_header_customer_rec,
5215             p_line_customer_tbl     => l_line_customer_tbl
5216            );
5217       IF l_debug_level  > 0 THEN
5218           oe_debug_pub.add(  'AFTER CALLING DELETE OF CUSTOMER INFO' ) ;
5219 
5220 
5221 /* -----------------------------------------------------------
5222       Set Return Status
5223    -----------------------------------------------------------
5224 */
5225            oe_debug_pub.add(  'DELETE ORDER RETURN STATUS: '||L_RETURN_STATUS_DEL_ORD ) ;
5226       END IF;
5227 
5228       IF    l_return_status_del_ord IN (FND_API.G_RET_STS_ERROR)
5229       AND   p_return_status     NOT IN (FND_API.G_RET_STS_ERROR)
5230       THEN  p_return_status :=          FND_API.G_RET_STS_ERROR;
5231       ELSIF l_return_status_del_ord IN (FND_API.G_RET_STS_UNEXP_ERROR)
5232       AND   p_return_status     NOT IN (FND_API.G_RET_STS_ERROR,
5233 				        FND_API.G_RET_STS_UNEXP_ERROR)
5234       THEN  p_return_status :=          FND_API.G_RET_STS_UNEXP_ERROR;
5235       END IF;
5236 
5237    END IF;	/* l_delete_flag = 'Y' */
5238 
5239 
5240 /* -----------------------------------------------------------
5241    Commit or rollback the transaction
5242    -----------------------------------------------------------
5243 */
5244    IF l_debug_level  > 0 THEN
5245        oe_debug_pub.add(  'BEFORE COMMIT OR ROLLBACK' ) ;
5246    END IF;
5247 
5248    IF l_validate_only =   FND_API.G_TRUE
5249    OR p_return_status in (FND_API.G_RET_STS_ERROR,	 -- E:Expected error
5250 			  FND_API.G_RET_STS_UNEXP_ERROR) -- U:Unexpected error
5251    THEN
5252       l_commit_flag := 'N';
5253    ELSE
5254       l_commit_flag := 'Y';
5255    END IF;
5256 
5257    IF l_debug_level  > 0 THEN
5258        oe_debug_pub.add(  'COMMIT FLAG '||L_COMMIT_FLAG ) ;
5259    END IF;
5260 
5261    IF l_commit_flag = 'Y' THEN
5262       COMMIT;
5263           -- For Bug 7367433
5264           -- From Order Import we will make a call to Verfify Payment, only after committing the data.
5265           -- The call to Verify Payment from Booking code is suppressed for Order Import flow.
5266           -- This change is only for Verify Payment call that is triggered as part of Booking.
5267           IF nvl(OE_GLOBALS.G_PAYMENT_PROCESSED, 'N') = 'O' THEN
5268            BEGIN
5269              SAVEPOINT VERIFY_PAYMENT;
5270 
5271              if l_debug_level > 5 then
5272                oe_debug_pub.add('Calling Verify Payment from Order Import, after committing data', 5);
5273              end if;
5274              OE_Verify_Payment_PUB.Verify_Payment
5275                   ( p_header_id           => l_header_rec_new.header_id
5276                   , p_calling_action      => 'BOOKING'
5277                   , p_msg_count           => l_msg_count_vp
5278                   , p_msg_data            => l_msg_data_vp
5279                   , p_return_status       => l_return_status
5280                   );
5281             EXCEPTION WHEN OTHERS THEN
5282               l_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5283             END;
5284 
5285             if l_debug_level > 0 then
5286               oe_debug_pub.add('After Verify Payment from Order Import Status : ' || l_return_status, 5);
5287             end if;
5288 
5289              IF l_return_status = FND_API.G_RET_STS_ERROR OR l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5290                  ROLLBACK TO SAVEPOINT VERIFY_PAYMENT;
5291              END IF;
5292           END IF;
5293         -- End of Bug 7367433
5294 
5295    ELSE
5296       /* Code changes for the bug 6378240 */
5297       oe_schedule_util.call_mrp_rollback(x_return_status => l_return_status);
5298 
5299       ROLLBACK;
5300    END IF;
5301 
5302 /* -----------------------------------------------------------
5303    Update error_flag in interface tables
5304    -----------------------------------------------------------
5305 */
5306    IF p_return_status IN (FND_API.G_RET_STS_ERROR,
5307 			  FND_API.G_RET_STS_UNEXP_ERROR)
5308    THEN
5309    BEGIN
5310       BEGIN
5311          IF l_debug_level  > 0 THEN
5312              oe_debug_pub.add(  'BEFORE UPDATING ERROR FLAG FOR HEADER' ) ;
5313          END IF;
5314 
5315 	 UPDATE oe_headers_interface
5316             SET error_flag = 'Y', xml_message_id = nvl(xml_message_id, l_header_rec.xml_message_id)
5317           WHERE order_source_id		= l_order_source_id
5318             AND orig_sys_document_ref 	= l_orig_sys_document_ref
5319             AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
5320               = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
5321             AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
5322               = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
5323        	    AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
5324 	      = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
5325             AND nvl(  request_id,	FND_API.G_MISS_NUM)
5326 	      = nvl(l_request_id,	FND_API.G_MISS_NUM);
5327       EXCEPTION
5328         WHEN OTHERS THEN
5329 	  IF l_debug_level  > 0 THEN
5330 	      oe_debug_pub.add(  'UNEXPECTED ERROR: '||SQLERRM ) ;
5331 	  END IF;
5332           IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5333 	     l_return_status_upd_err := FND_API.G_RET_STS_UNEXP_ERROR;
5334              OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, 'Import_Order');
5335           END IF;
5336       END;
5337 /* Fixing Bug #2026177 and processing the out nocopy table from process order */
5338 
5339       BEGIN
5340          FOR I in 1..l_header_adj_tbl_new.count
5341          LOOP
5342   	   IF l_debug_level  > 0 THEN
5343   	       oe_debug_pub.add(  'BEFORE UPDATING ERROR FLAG FOR HEADER PRICE ADJUSTMENTS' ) ;
5344   	   END IF;
5345    	   IF l_header_adj_tbl_new(I).return_status IN (
5346 				  	FND_API.G_RET_STS_ERROR,
5347 		  	          	FND_API.G_RET_STS_UNEXP_ERROR)
5348    	   THEN
5349            BEGIN
5350 	     UPDATE oe_price_adjs_interface
5351                 SET error_flag = 'Y'
5352               WHERE order_source_id		= l_order_source_id
5353                 AND orig_sys_document_ref 	= l_orig_sys_document_ref
5354                 AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
5355                   = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
5356                 AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
5357                   = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
5358        	        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
5359 	          = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
5360                 AND nvl(  request_id,		FND_API.G_MISS_NUM)
5361 	          = nvl(l_request_id,		FND_API.G_MISS_NUM)
5362                 AND nvl(orig_sys_discount_ref, 	FND_API.G_MISS_CHAR)
5363 	          = nvl(l_header_adj_tbl_new(I).orig_sys_discount_ref,
5364 					       	FND_API.G_MISS_CHAR);
5365            EXCEPTION
5366             WHEN OTHERS THEN
5367 	      IF l_debug_level  > 0 THEN
5368 	          oe_debug_pub.add(  'UNEXPECTED ERROR: '||SQLERRM ) ;
5369 	      END IF;
5370               IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5371               THEN
5372 	         l_return_status_upd_err := FND_API.G_RET_STS_UNEXP_ERROR;
5373                  OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, 'Import_Order');
5374               END IF;
5375            END;
5376 	   END IF;
5377          END LOOP;
5378       END;
5379 
5380 /* 1433292  */
5381       BEGIN
5382          FOR I in 1..l_header_price_att_tbl_new.count
5383          LOOP
5384            IF l_debug_level  > 0 THEN
5385                oe_debug_pub.add(  'BEFORE UPDATING ERROR FLAG FOR HEADER PRICE ATT' ) ;
5386            END IF;
5387            IF l_header_price_att_tbl_new(I).return_status IN (
5388                                         FND_API.G_RET_STS_ERROR,
5389                                         FND_API.G_RET_STS_UNEXP_ERROR)
5390            THEN
5391            BEGIN
5392              UPDATE oe_price_atts_interface
5393                 SET error_flag = 'Y'
5394               WHERE order_source_id             = l_order_source_id
5395                 AND orig_sys_document_ref       = l_orig_sys_document_ref
5396                 AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
5397                   = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
5398                 AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
5399                   = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
5400                 AND nvl(  change_sequence,      FND_API.G_MISS_CHAR)
5401                   = nvl(l_change_sequence,      FND_API.G_MISS_CHAR)
5402                 AND nvl(  request_id,           FND_API.G_MISS_NUM)
5403                   = nvl(l_request_id,           FND_API.G_MISS_NUM);
5404            EXCEPTION
5405             WHEN OTHERS THEN
5406               IF l_debug_level  > 0 THEN
5407                   oe_debug_pub.add(  'UNEXPECTED ERROR: '||SQLERRM ) ;
5408               END IF;
5409               IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5410               THEN
5411                  l_return_status_upd_err := FND_API.G_RET_STS_UNEXP_ERROR;
5412                  OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, 'Import_Order');
5413               END IF;
5414            END;
5415            END IF;
5416          END LOOP;
5417       END;
5418       BEGIN
5419          FOR I in 1..l_header_scredit_tbl_new.count
5420          LOOP
5421   	   IF l_debug_level  > 0 THEN
5422   	       oe_debug_pub.add(  'BEFORE UPDATING ERROR FLAG FOR HEADER SALES CREDITS' ) ;
5423   	   END IF;
5424    	   IF l_header_scredit_tbl_new(I).return_status IN (
5425 					FND_API.G_RET_STS_ERROR,
5426 		  	          	FND_API.G_RET_STS_UNEXP_ERROR)
5427    	   THEN
5428            BEGIN
5429 	     UPDATE oe_credits_interface
5430                 SET error_flag = 'Y'
5431               WHERE order_source_id		= l_order_source_id
5432                 AND orig_sys_document_ref 	= l_orig_sys_document_ref
5433                 AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
5434                   = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
5435                 AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
5436                   = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
5437        	        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
5438 	          = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
5439                 AND nvl(  request_id,		FND_API.G_MISS_NUM)
5440 	          = nvl(l_request_id,		FND_API.G_MISS_NUM)
5441                 AND nvl(orig_sys_credit_ref,	FND_API.G_MISS_CHAR)
5442 	          = nvl(l_header_scredit_tbl_new(I).orig_sys_credit_ref,
5443 						FND_API.G_MISS_CHAR);
5444            EXCEPTION
5445             WHEN OTHERS THEN
5446 	      IF l_debug_level  > 0 THEN
5447 	          oe_debug_pub.add(  'UNEXPECTED ERROR: '||SQLERRM ) ;
5448 	      END IF;
5449               IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5450               THEN
5451 	         l_return_status_upd_err := FND_API.G_RET_STS_UNEXP_ERROR;
5452                  OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, 'Import_Order');
5453               END IF;
5454            END;
5455 	   END IF;
5456          END LOOP;
5457       END;
5458 
5459       -- multiple payments: header payments start...
5460 
5461       BEGIN
5462          FOR I in 1..l_header_payment_tbl_new.count
5463          LOOP
5464   	   IF l_debug_level  > 0 THEN
5465   	       oe_debug_pub.add(  'BEFORE UPDATING ERROR FLAG FOR HEADER PAYMENTS' ) ;
5466   	   END IF;
5467    	   IF l_header_payment_tbl_new(I).return_status IN (
5468 					FND_API.G_RET_STS_ERROR,
5469 		  	          	FND_API.G_RET_STS_UNEXP_ERROR)
5470    	   THEN
5471            BEGIN
5472 	     UPDATE oe_payments_interface
5473                 SET error_flag = 'Y'
5474               WHERE order_source_id		= l_order_source_id
5475                 AND orig_sys_document_ref 	= l_orig_sys_document_ref
5476        	        AND nvl(  change_sequence,	FND_API.G_MISS_CHAR)
5477 	          = nvl(l_change_sequence,	FND_API.G_MISS_CHAR)
5478                 AND nvl(  request_id,		FND_API.G_MISS_NUM)
5479 	          = nvl(l_request_id,		FND_API.G_MISS_NUM)
5480                 AND nvl(orig_sys_payment_ref,	FND_API.G_MISS_CHAR)
5481 	          = nvl(l_header_payment_tbl_new(I).orig_sys_payment_ref,
5482 						FND_API.G_MISS_CHAR);
5483            EXCEPTION
5484             WHEN OTHERS THEN
5485 	      IF l_debug_level  > 0 THEN
5486 	          oe_debug_pub.add(  'UNEXPECTED ERROR: '||SQLERRM ) ;
5487 	      END IF;
5488               IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5489               THEN
5490 	         l_return_status_upd_err := FND_API.G_RET_STS_UNEXP_ERROR;
5491                  OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, 'Import_Order');
5492               END IF;
5493            END;
5494 	   END IF;
5495          END LOOP;
5496       END;
5497       -- end of multiple payments: header payments.
5498 
5499 
5500       BEGIN
5501          FOR I in 1..l_line_tbl_new.count
5502          LOOP
5503   	   IF l_debug_level  > 0 THEN
5504   	       oe_debug_pub.add(  'BEFORE UPDATING ERROR FLAG FOR LINES' ) ;
5505   	   END IF;
5506    	   IF l_line_tbl_new(I).return_status IN (
5507 					FND_API.G_RET_STS_ERROR,
5508 		  	                FND_API.G_RET_STS_UNEXP_ERROR)
5509    	   THEN
5510            BEGIN
5511 	    UPDATE oe_lines_interface
5512                SET error_flag = 'Y'
5513              WHERE order_source_id		= l_order_source_id
5514                AND orig_sys_document_ref 	= l_orig_sys_document_ref
5515                AND nvl(sold_to_org_id,                  FND_API.G_MISS_NUM)
5516                  = nvl(l_sold_to_org_id,                FND_API.G_MISS_NUM)
5517                AND nvl(sold_to_org,                  FND_API.G_MISS_CHAR)
5518                  = nvl(l_sold_to_org,                FND_API.G_MISS_CHAR)
5519        	       AND nvl(  change_sequence,	  FND_API.G_MISS_CHAR)
5520 	         = nvl(l_change_sequence,	  FND_API.G_MISS_CHAR)
5521                AND nvl(  request_id,		  FND_API.G_MISS_NUM)
5522 	         = nvl(l_request_id,		  FND_API.G_MISS_NUM)
5523                AND nvl(orig_sys_line_ref,      	    	   FND_API.G_MISS_CHAR)
5524 	         = nvl(l_line_tbl_new(I).orig_sys_line_ref,    FND_API.G_MISS_CHAR)
5525                AND nvl(orig_sys_shipment_ref,              FND_API.G_MISS_CHAR)
5526 	         = nvl(l_line_tbl_new(I).orig_sys_shipment_ref,FND_API.G_MISS_CHAR);
5527            EXCEPTION
5528             WHEN OTHERS THEN
5529 	      IF l_debug_level  > 0 THEN
5530 	          oe_debug_pub.add(  'UNEXPECTED ERROR: '||SQLERRM ) ;
5531 	      END IF;
5532               IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5533               THEN
5534 	         l_return_status_upd_err := FND_API.G_RET_STS_UNEXP_ERROR;
5535                  OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, 'Import_Order');
5536               END IF;
5537            END;
5538 	   END IF;
5539          END LOOP;
5540       END;
5541 /*
5542         l_tbl_index := oe_msg_pub.g_msg_tbl.FIRST;
5543         LOOP
5544           IF l_debug_level  > 0 THEN
5545               oe_debug_pub.add(  'L_TBL_INDEX = '||L_TBL_INDEX ) ;
5546           END IF;
5547           If oe_msg_pub.g_msg_tbl(l_tbl_index).entity_code = 'OI_INL_CUSTSUCC'
5548           Then
5549              IF l_debug_level  > 0 THEN
5550                  oe_debug_pub.add(  'BEFORE DELETING OI_INL_ADDCUST MSG' ) ;
5551              END IF;
5552              --oe_msg_pub.g_msg_tbl(l_tbl_index).message := Null;
5553              --oe_msg_pub.g_msg_tbl(l_tbl_index).message_text := Null;
5554              oe_msg_pub.Delete_Msg(p_msg_index => l_tbl_index);
5555           End If;
5556           Exit When l_tbl_index = oe_msg_pub.g_msg_tbl.LAST;
5557           l_tbl_index := oe_msg_pub.g_msg_tbl.NEXT(l_tbl_index);
5558         End Loop;
5559 */
5560 
5561 /* -----------------------------------------------------------
5562       Set Return Status
5563    -----------------------------------------------------------
5564 */
5565       IF l_debug_level  > 0 THEN
5566           oe_debug_pub.add(  'UPDATE ERROR_FLAG RETURN STATUS: '||L_RETURN_STATUS_UPD_ERR ) ;
5567       END IF;
5568 
5569       IF    l_return_status_upd_err IN (FND_API.G_RET_STS_ERROR)
5570       AND   p_return_status     NOT IN (FND_API.G_RET_STS_ERROR)
5571       THEN  p_return_status :=          FND_API.G_RET_STS_ERROR;
5572       ELSIF l_return_status_upd_err IN (FND_API.G_RET_STS_UNEXP_ERROR)
5573       AND   p_return_status     NOT IN (FND_API.G_RET_STS_ERROR,
5574 				        FND_API.G_RET_STS_UNEXP_ERROR)
5575       THEN  p_return_status :=          FND_API.G_RET_STS_UNEXP_ERROR;
5576       END IF;
5577 
5578 /* -----------------------------------------------------------
5579       Commit or rollback the error_flag
5580    -----------------------------------------------------------
5581 */
5582       IF  l_return_status_upd_err NOT IN (FND_API.G_RET_STS_ERROR,
5583                                           FND_API.G_RET_STS_UNEXP_ERROR)
5584       THEN
5585          IF l_debug_level  > 0 THEN
5586              oe_debug_pub.add(  'COMMITING' ) ;
5587          END IF;
5588          COMMIT;	/* commit the error_flag updated */
5589       ELSE
5590          ROLLBACK; 	/* rollback the error_flag updated */
5591       END IF;
5592 
5593    END;
5594    END IF;	/* IF p_return_status IN ... */
5595 
5596 
5597 /* -----------------------------------------------------------
5598    Update the processing messages table
5599    -----------------------------------------------------------
5600 */
5601    OE_MSG_PUB.Count_And_Get (p_count => p_msg_count
5602         		    ,p_data  => p_msg_data);
5603 
5604    IF l_debug_level  > 0 THEN
5605        oe_debug_pub.add(  'MESSAGES RETURNED: '|| TO_CHAR ( P_MSG_COUNT ) ) ;
5606    END IF;
5607 
5608    IF p_msg_count > 0 THEN
5609 
5610      IF l_debug_level  > 0 THEN
5611          oe_debug_pub.add(  'BEFORE UPDATING THE PROCESSING MESSAGES TABLE' ) ;
5612      END IF;
5613      l_tbl_index := oe_msg_pub.g_msg_tbl.FIRST;
5614 
5615      LOOP
5616        IF l_debug_level  > 0 THEN
5617            oe_debug_pub.add(  'BEFORE CALLING GET' ) ;
5618        END IF;
5619        l_msg_order_source_id 		:= '';
5620        l_msg_orig_sys_document_ref 	:= '';
5621        l_msg_orig_sys_line_ref     	:= '';
5622        l_msg_orig_sys_shipment_ref 	:= '';
5623        l_msg_sold_to_org_id       	:= '';
5624        l_msg_sold_to_org  	     	:= '';
5625        l_msg_change_sequence       	:= '';
5626        l_msg_entity_code	        := '';
5627        l_msg_entity_ref 	        := '';
5628 
5629        IF l_debug_level  > 0 THEN
5630            oe_debug_pub.add(  'BEFORE CALLING GET_MSG_CONTEXT' ) ;
5631        END IF;
5632        oe_msg_pub.get_msg_context (
5633      		 p_msg_index                    => l_tbl_index
5634     		,x_entity_code                  => l_msg_entity_code
5635     		,x_entity_ref                   => l_msg_entity_ref
5636     		,x_entity_id                    => l_msg_entity_id
5637     		,x_header_id                    => l_msg_header_id
5638     		,x_line_id                      => l_msg_line_id
5639     		,x_order_source_id              => l_msg_order_source_id
5640     		,x_orig_sys_document_ref        => l_msg_orig_sys_document_ref
5641     		,x_orig_sys_line_ref   		=> l_msg_orig_sys_line_ref
5642     		,x_orig_sys_shipment_ref   	=> l_msg_orig_sys_shipment_ref
5643     		,x_change_sequence	        => l_msg_change_sequence
5644     		,x_source_document_type_id      => l_msg_source_document_type_id
5645     		,x_source_document_id           => l_msg_source_document_id
5646     		,x_source_document_line_id      => l_msg_source_document_line_id
5647     		,x_attribute_code               => l_msg_attribute_code
5648     		,x_constraint_id                => l_msg_constraint_id
5649     		,x_process_activity             => l_msg_process_activity
5650     		,x_notification_flag            => l_msg_notification_flag
5651     		,x_type                 	=> l_msg_type
5652 		);
5653 
5654         IF l_debug_level  > 0 THEN
5655             oe_debug_pub.add(  'AFTER CALLING GET_MSG_CONTEXT' ) ;
5656         END IF;
5657 	IF oe_msg_pub.g_msg_tbl(l_tbl_index).message_text IS NULL THEN
5658           IF l_debug_level  > 0 THEN
5659               oe_debug_pub.add(  'IN INDEX.MESSAGE_TEXT IS NULL' ) ;
5660           END IF;
5661     	   p_msg_data := oe_msg_pub.get(l_tbl_index, 'F');
5662 	END IF;
5663 
5664 l_msg_context := '';
5665 	IF l_msg_order_source_id IS NOT NULL THEN
5666            l_msg_context := 'Src: ' || l_msg_order_source_id;
5667         END IF;
5668         IF l_msg_orig_sys_document_ref IS NOT NULL THEN
5669 	   l_msg_context := l_msg_context ||
5670                          ', ' || 'Hdr: '||rtrim(l_msg_orig_sys_document_ref);
5671 	END IF;
5672 	IF l_msg_orig_sys_line_ref IS NOT NULL THEN
5673 	   l_msg_context := l_msg_context ||
5674 			 ', ' || 'Line: '||rtrim(l_msg_orig_sys_line_ref);
5675 	END IF;
5676 	IF l_msg_orig_sys_shipment_ref IS NOT NULL THEN
5677 	   l_msg_context := l_msg_context ||
5678 			 ', ' || 'Ship: '||rtrim(l_msg_orig_sys_shipment_ref);
5679 	END IF;
5680 	IF l_msg_sold_to_org_id IS NOT NULL THEN
5681 	   l_msg_context := l_msg_context ||
5682 			 ', ' || 'Customer ID: '|| l_msg_sold_to_org_id;
5683 	END IF;
5684 IF l_msg_sold_to_org IS NOT NULL THEN
5685 	   l_msg_context := l_msg_context ||
5686 			 ', ' || 'Customer Name: '|| rtrim(l_msg_sold_to_org);
5687 	END IF;
5688 	IF l_msg_change_sequence IS NOT NULL THEN
5689 	   l_msg_context := l_msg_context ||
5690 			 ', ' || 'Chg: '||rtrim(l_msg_change_sequence);
5691 	END IF;
5692 
5693 
5694 
5695 	IF l_msg_entity_code IS NOT NULL AND
5696 	   l_msg_entity_ref  IS NOT NULL
5697 	THEN
5698 	   IF    l_msg_entity_code IN ('HEADER_ADJ', 'LINE_ADJ') THEN
5699 	         l_msg_context := l_msg_context || ', ' || 'Adj: ';
5700 	   ELSIF l_msg_entity_code IN ('HEADER_SCREDIT', 'LINE_SCREDIT') THEN
5701 	         l_msg_context := l_msg_context || ', ' || 'SCredit: ';
5702            ELSIF l_msg_entity_code IN ('HEADER_PAYMENT', 'LINE_PAYMENT') THEN
5703                  l_msg_context := l_msg_context || ', ' || 'Payment: ';
5704 	   ELSIF l_msg_entity_code IN ('LOT_SERIAL') THEN
5705 	         l_msg_context := l_msg_context || ', ' || 'Lot: ';
5706 	   ELSIF l_msg_entity_code IN ('RESERVATION') THEN
5707 	         l_msg_context := l_msg_context || ', ' || 'Rsrvtn: ';
5708 	   END IF;
5709 	         l_msg_context := l_msg_context || rtrim(l_msg_entity_ref);
5710 	END IF;
5711 	l_msg_data := 'Msg-'||l_tbl_index||' for '||l_msg_context||': '||p_msg_data;
5712 
5713         IF l_debug_level  > 0 THEN
5714             oe_debug_pub.add(  L_MSG_DATA ) ;
5715         END IF;
5716 	--bug 4195533
5717         IF p_return_status = FND_API.G_RET_STS_SUCCESS
5718            AND l_header_rec.header_id <> FND_API.G_MISS_NUM THEN
5719            IF l_debug_level  > 0 THEN
5720               oe_debug_pub.add(  'Header id updated in msg stack:' || l_header_rec.header_id ) ;
5721            END IF;
5722            oe_msg_pub.g_msg_tbl(l_tbl_index).header_id := l_header_rec.header_id;
5723         END IF;
5724 	--bug 4195533
5725         Exit When l_tbl_index = oe_msg_pub.g_msg_tbl.LAST;
5726         l_tbl_index := oe_msg_pub.g_msg_tbl.NEXT(l_tbl_index);
5727 
5728      END LOOP;
5729    END IF;
5730 
5731 /* -----------------------------------------------------------
5732    Delete messages from the database table
5733    -----------------------------------------------------------
5734 */
5735    IF l_debug_level  > 0 THEN
5736        oe_debug_pub.add(  'BEFORE DELETING OLD MESSAGES FROM THE DATABASE TABLE' ) ;
5737    END IF;
5738 
5739 /* Commmenting the call to delete message bug 2467558
5740 
5741    OE_ORDER_IMPORT_UTIL_PVT.Delete_Messages (
5742 	    p_request_id		=> l_request_id,
5743 	    p_order_source_id		=> l_order_source_id,
5744 	    p_orig_sys_document_ref	=> l_orig_sys_document_ref,
5745 	    p_change_sequence		=> l_change_sequence,
5746 	    p_return_status		=> l_return_status_del_msg
5747 	   );
5748 
5749 */
5750 
5751 /* -----------------------------------------------------------
5752    Set Return Status
5753    -----------------------------------------------------------
5754 */
5755    IF l_debug_level  > 0 THEN
5756        oe_debug_pub.add(  'DELETE MESSAGES RETURN STATUS: '||L_RETURN_STATUS_DEL_MSG ) ;
5757    END IF;
5758 
5759    IF    l_return_status_del_msg IN (FND_API.G_RET_STS_ERROR)
5760    AND   p_return_status     NOT IN (FND_API.G_RET_STS_ERROR)
5761    THEN  p_return_status :=          FND_API.G_RET_STS_ERROR;
5762    ELSIF l_return_status_del_msg IN (FND_API.G_RET_STS_UNEXP_ERROR)
5763    AND   p_return_status     NOT IN (FND_API.G_RET_STS_ERROR,
5764 			             FND_API.G_RET_STS_UNEXP_ERROR)
5765    THEN  p_return_status :=          FND_API.G_RET_STS_UNEXP_ERROR;
5766    END IF;
5767 
5768 
5769 /* -----------------------------------------------------------
5770    Save messages in the database table
5771    -----------------------------------------------------------
5772 */
5773    IF l_debug_level  > 0 THEN
5774        oe_debug_pub.add(  'BEFORE SAVING MESSAGES IN THE DATABASE TABLE' ) ;
5775    END IF;
5776 
5777    IF p_msg_count > 0 THEN
5778         OE_MSG_PUB.save_messages (l_request_id);
5779    END IF;
5780    COMMIT;	/* commit again to commit the error messages */
5781 
5782 
5783 /* -----------------------------------------------------------
5784    Commit or rollback the messages
5785    -----------------------------------------------------------
5786 */
5787    IF  l_return_status_del_msg = FND_API.G_RET_STS_SUCCESS
5788 -- AND l_return_status_sav_msg = FND_API.G_RET_STS_SUCCESS -- Currently not set
5789    THEN
5790       COMMIT;	/* commit again to commit the error messages */
5791    ELSE
5792       ROLLBACK; /* rollback the error messages deleted */
5793    END IF;
5794 
5795 
5796 /* -----------------------------------------------------------
5797    Report final order processing results
5798    -----------------------------------------------------------
5799 */
5800    IF l_debug_level  > 0 THEN
5801        oe_debug_pub.add(  'RETURN_STATUS: '||P_RETURN_STATUS ) ;
5802    END IF;
5803 
5804    IF    p_return_status = FND_API.G_RET_STS_ERROR THEN
5805       IF l_debug_level  > 0 THEN
5806           oe_debug_pub.add(  'ORDER FAILED WITH ERROR ( S ) ' ) ;
5807       END IF;
5808    ELSIF p_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5809       IF l_debug_level  > 0 THEN
5810           oe_debug_pub.add(  'ORDER FAILED WITH UNEXPECTED ERROR ( S ) ' ) ;
5811       END IF;
5812    ELSE
5813       IF l_debug_level  > 0 THEN
5814           oe_debug_pub.add(  'ORDER PROCESSED SUCCESSFULLY' ) ;
5815       END IF;
5816    END IF;
5817 
5818 
5819    -- Call to raise the appropriate event for XML transactions
5820    -- This should only be raised when the profile is set to ASYNCHRONOUS
5821 
5822     -- {Start If for raising event for XML Trans
5823     If l_header_rec.order_source_id = Oe_Acknowledgment_Pub.G_XML_ORDER_SOURCE_ID Then
5824        OE_GLOBALS.G_XML_TXN_CODE := NULL;
5825        IF l_debug_level  > 0 THEN
5826           oe_debug_pub.add(  'SET GLOBAL TXN CODE TO NULL' ) ;
5827        END IF;
5828 
5829      -- Check if Order is Imported
5830      -- Else Ack will have to be sent from the Inf tables.
5831      If p_return_status In (FND_API.G_RET_STS_ERROR, FND_API.G_RET_STS_UNEXP_ERROR) Then
5832        l_order_imported := 'N';
5833      Else
5834        l_order_imported := 'Y';
5835      End If;
5836      -- raise the appropriate event
5837      IF l_debug_level  > 0 THEN
5838          oe_debug_pub.add(  'BEFORE CALLING RAISE_EVENT_FROM_OEOI' ) ;
5839 
5840          oe_debug_pub.add(  'REF = '||L_HEADER_REC.ORIG_SYS_DOCUMENT_REF ) ;
5841          oe_debug_pub.add('3A8 ACK SEND PROFILE ' || l_cho_ack_send_pfile);
5842          oe_debug_pub.add('3A7 RESP PROFILE ' || l_cso_response_pfile);
5843          oe_debug_pub.add('3A8 RESP MSG TYPE ' || l_header_cso_response_flag);
5844          oe_debug_pub.add('XML TXN CODE ' || l_header_rec.xml_transaction_type_code);
5845      END IF;
5846 
5847      IF NOT (nvl(l_header_rec.xml_transaction_type_code, FND_API.G_MISS_CHAR) = OE_Acknowledgment_Pub.G_TRANSACTION_CHO
5848         AND nvl(l_header_cso_response_flag, 'N') = 'Y'
5849         AND l_cho_ack_send_pfile = 'N'
5850         AND l_cso_response_pfile = 'Y') THEN
5851 
5852         Oe_Acknowledgment_Pub.Raise_Event_From_Oeoi(
5853            p_transaction_type       =>  l_header_rec.xml_transaction_type_code,
5854            p_orig_sys_document_ref  =>  l_header_rec.orig_sys_document_ref,
5855            p_request_id             =>  l_header_rec.request_id,
5856            p_order_imported         =>  l_order_imported,
5857            p_sold_to_org_id         =>  l_header_rec.sold_to_org_id,
5858            p_change_sequence        =>  l_header_rec.change_sequence,
5859            p_xml_message_id         =>  l_header_rec.xml_message_id,
5860            p_org_id                 =>  l_header_rec.org_id,
5861            x_return_status          =>  l_return_status);
5862 
5863         If p_return_status NOT IN (FND_API.G_RET_STS_ERROR) And
5864            l_return_status     IN (FND_API.G_RET_STS_ERROR, FND_API.G_RET_STS_UNEXP_ERROR) Then
5865            p_return_status := l_return_status;
5866         End If;
5867      END IF;
5868 
5869    End If;
5870    -- End If for raising event for XML Trans}
5871    -- we raise the event in all cases except Synchronous Order Import for XML
5872    If OE_Code_Control.Code_Release_Level >= '110510' Then
5873           OE_Acknowledgment_Pub.Raise_Event_XMLInt (
5874              p_order_source_id        =>  l_header_rec.order_source_id,
5875              p_partner_document_num   =>  l_header_rec.orig_sys_document_ref,
5876              p_sold_to_org_id         =>  l_header_rec.sold_to_org_id,
5877              p_transaction_type       =>  Oe_Acknowledgment_Pub.G_TRANSACTION_TYPE,
5878              p_transaction_subtype    =>  l_header_rec.xml_transaction_type_code,
5879              p_itemtype               =>  NULL,
5880              p_itemkey                =>  NULL,
5881              p_message_text           =>  NULL,
5882              p_xmlg_icn               =>  l_header_rec.xml_message_id,
5883              p_document_num           =>  l_header_rec.order_number,
5884              p_order_type_id          =>  l_header_rec.order_type_id,
5885              p_doc_status             =>  p_return_status,
5886              p_change_sequence        =>  l_header_rec.change_sequence,
5887              p_org_id                 =>  l_header_rec.org_id,
5888              p_conc_request_id        =>  l_header_rec.request_id,
5889              p_header_id              =>  l_header_rec.header_id,
5890              p_response_flag          =>  l_header_cso_response_flag,
5891              x_return_status          =>  l_return_status);
5892           Commit; -- to raise the business event
5893    End If;
5894 
5895 /*-----------------------------------------------------------
5896   End of Order Import
5897   -----------------------------------------------------------
5898 */
5899 --oe_debug_pub.add('End of Order Import');
5900 
5901 
5902   EXCEPTION
5903   WHEN OTHERS THEN
5904        IF l_debug_level  > 0 THEN
5905            oe_debug_pub.add(  'UNEXPECTED ERROR: '||SQLERRM ) ;
5906        END IF;
5907        IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
5908           OE_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, 'Import_Order');
5909        END IF;
5910        p_msg_count := p_msg_count + 1;
5911        p_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
5912 
5913        OE_GLOBALS.G_ORDER_IMPORT_CALL := FALSE; -- Bug 7367433
5914 
5915 END IMPORT_ORDER;
5916 
5917 END OE_ORDER_IMPORT_PVT;