DBA Data[Home] [Help]

PACKAGE BODY: APPS.PO_REQ_WF_BUILD_ACCOUNT_INIT

Source


1 PACKAGE BODY PO_REQ_WF_BUILD_ACCOUNT_INIT AS
2 /* $Header: POXWRQSB.pls 120.1 2006/04/27 17:46:48 bao noship $ */
3 
4 -- Read the profile option that enables/disables the debug log
5 g_po_wf_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('PO_SET_DEBUG_WORKFLOW_ON'),'N');
6 
7  /*=======================================================================+
8  | FILENAME
9  |   POXWRQSB.pls
10  |
11  | DESCRIPTION
12  |   PL/SQL body for package:  PO_REQ_WF_BUILD_ACCOUNT_INIT
13  |
14  | NOTES        Imran Ali Created 9/9/97
15  | MODIFIED    (MM/DD/YY)	  03/31/98
16  |              David Chan        05/29/98 Modify for bug 669011
17  *=======================================================================*/
18 
19 /*
20     * A Global variable to set the debug mode
21 */
22 debug_acc_generator_wf BOOLEAN := FALSE;
23 
24 /*****************************************************************************
25 * The following are local/Private procedure that support the workflow APIs:  *
26 *****************************************************************************/
27 
28 PROCEDURE Call_WF_API_to_set_Att (ItemType varchar2, ItemKey varchar2,
29 				  aname varchar2, avalue varchar2);
30 PROCEDURE Call_WF_API_to_set_no_Att (ItemType varchar2, ItemKey varchar2,
31 				  aname varchar2, avalue number);
32 PROCEDURE Call_WF_API_to_set_date_Att (ItemType varchar2, ItemKey varchar2,
33 				  aname varchar2, avalue date);
34 
35 
36 /**************************************************************************************
37 * The following are the global APIs.						      *
38 **************************************************************************************/
39 
40 --
41 --  Start_Workflow
42 --  Generates the itemkey, sets up the Item Attributes,
43 --  then starts the workflow process.
44 --
45 FUNCTION Start_Workflow (
46    x_charge_success       IN OUT NOCOPY  BOOLEAN,  x_budget_success        IN OUT NOCOPY   BOOLEAN,
47    x_accrual_success      IN OUT NOCOPY  BOOLEAN,  x_variance_success      IN OUT NOCOPY   BOOLEAN,
48    x_code_combination_id  IN OUT NOCOPY  NUMBER,   x_budget_account_id     IN OUT NOCOPY   NUMBER,
49    x_accrual_account_id   IN OUT NOCOPY  NUMBER,   x_variance_account_id   IN OUT NOCOPY   NUMBER,
50    x_charge_account_flex  IN OUT NOCOPY  VARCHAR2, x_budget_account_flex   IN OUT NOCOPY   VARCHAR2,
51    x_accrual_account_flex IN OUT NOCOPY  VARCHAR2, x_variance_account_flex IN OUT NOCOPY   VARCHAR2,
52    x_charge_account_desc  IN OUT NOCOPY  VARCHAR2, x_budget_account_desc   IN OUT NOCOPY   VARCHAR2,
53    x_accrual_account_desc IN OUT NOCOPY  VARCHAR2, x_variance_account_desc IN OUT NOCOPY   VARCHAR2,
54    x_coa_id                       NUMBER,   x_bom_resource_id                NUMBER,
55    x_bom_cost_element_id          NUMBER,   x_category_id                    NUMBER,
56    x_destination_type_code        VARCHAR2, x_deliver_to_location_id         NUMBER,
57    x_destination_organization_id  NUMBER,   x_destination_subinventory       VARCHAR2,
58    x_expenditure_type             VARCHAR2,
59    x_expenditure_organization_id  NUMBER,   x_expenditure_item_date          DATE,
60    x_item_id                      NUMBER,   x_line_type_id                   NUMBER,
61    x_result_billable_flag         VARCHAR2, x_preparer_id                    NUMBER,
62    x_project_id                   NUMBER,
63    x_document_type_code		  VARCHAR2,
64    x_blanket_po_header_id	  NUMBER,
65    x_source_type_code		  VARCHAR2,
66    x_source_organization_id	  NUMBER,
67    x_source_subinventory	  VARCHAR2,
68    x_task_id                      NUMBER,   x_deliver_to_person_id           NUMBER,
69    x_type_lookup_code             VARCHAR2, x_suggested_vendor_id            NUMBER,
70    x_wip_entity_id                NUMBER,   x_wip_entity_type                VARCHAR2,
71    x_wip_line_id                  NUMBER,   x_wip_repetitive_schedule_id     NUMBER,
72    x_wip_operation_seq_num        NUMBER,   x_wip_resource_seq_num           NUMBER,
73    x_po_encumberance_flag         VARCHAR2, x_gl_encumbered_date             DATE,
74    WF_itemkey		  IN OUT NOCOPY  VARCHAR2, -- because of changes due to WF synch mode this input parameter is not used.
75    x_new_combination	  IN OUT NOCOPY  BOOLEAN,
76 
77    header_att1  VARCHAR2, header_att2   VARCHAR2, header_att3  VARCHAR2, header_att4  VARCHAR2,
78    header_att5  VARCHAR2, header_att6   VARCHAR2, header_att7  VARCHAR2, header_att8  VARCHAR2,
79    header_att9   VARCHAR2, header_att10  VARCHAR2, header_att11  VARCHAR2,
80    header_att12  VARCHAR2, header_att13  VARCHAR2, header_att14  VARCHAR2,header_att15  VARCHAR2,
81 
82    line_att1   VARCHAR2, line_att2   VARCHAR2, line_att3   VARCHAR2, line_att4   VARCHAR2,
83    line_att5   VARCHAR2, line_att6   VARCHAR2, line_att7   VARCHAR2, line_att8   VARCHAR2,
84    line_att9   VARCHAR2, line_att10  VARCHAR2, line_att11  VARCHAR2, line_att12  VARCHAR2,
85    line_att13  VARCHAR2, line_att14  VARCHAR2, line_att15  VARCHAR2,
86 
87    distribution_att1   VARCHAR2, distribution_att2   VARCHAR2, distribution_att3   VARCHAR2,
88    distribution_att4   VARCHAR2, distribution_att5   VARCHAR2, distribution_att6   VARCHAR2,
89    distribution_att7   VARCHAR2, distribution_att8   VARCHAR2, distribution_att9   VARCHAR2,
90    distribution_att10  VARCHAR2, distribution_att11  VARCHAR2, distribution_att12  VARCHAR2,
91    distribution_att13  VARCHAR2, distribution_att14  VARCHAR2, distribution_att15  VARCHAR2,
92 
93    FB_ERROR_MSG               IN OUT NOCOPY VARCHAR2,
94    x_award_id	              NUMBER default NULL, -- OGM_0.0 changes...
95    x_suggested_vendor_site_id NUMBER default NULL, -- B1548597 Common Receiving RVK
96    p_unit_price               IN NUMBER DEFAULT NULL,  --<BUG 3407630>
97    p_blanket_po_line_num      IN NUMBER DEFAULT NULL   --<BUG 3611341>
98 ) RETURN Boolean IS
99 
100 ItemType                varchar2(8);
101 ccid			NUMBER;
102 
103 -- Bug 752384: Increase the size of flexfield to 2000
104 
105 concat_segs		varchar2(2000);
106 concat_ids		varchar2(240);
107 concat_descrs		varchar2(2000);
108 
109 x_block_activity_label  varchar2(60);
110 x_insert_if_new		BOOLEAN := TRUE;
111 x_new_ccid_generated	BOOLEAN := FALSE;
112 x_success		BOOLEAN;
113 x_progress              varchar2(5000);
114 x_appl_short_name       varchar2(40);
115 x_flex_field_code       varchar2(150);
116 x_flex_field_struc_num  number;                        -- x_coa_id
117 
118 was_ccid_passed_in_from_form     BOOLEAN := FALSE;
119 
120 -- PA project accounting parameters to the WF
121 
122   l_class_code			pa_class_codes.class_code%TYPE;
123   l_direct_flag			pa_project_types_all.direct_flag%TYPE;
124   l_expenditure_category	pa_expenditure_categories.expenditure_category%TYPE;
125   l_expenditure_org_name	hr_organization_units.name%TYPE;
126   l_project_number		pa_projects_all.segment1%TYPE;
127   l_project_organization_name	hr_organization_units.name%TYPE;
128   l_project_organization_id	hr_organization_units.organization_id %TYPE;
129   l_project_type		pa_project_types_all.project_type%TYPE;
130 
131   l_public_sector_flag		pa_projects_all.public_sector_flag%TYPE;
132   l_revenue_category		pa_expenditure_types.revenue_category_code%TYPE;
133   l_task_number			pa_tasks.task_number%TYPE;
134   l_task_organization_name	hr_organization_units.name%TYPE;
135   l_task_organization_id	hr_organization_units.organization_id %TYPE;
136   l_task_service_type		pa_tasks.service_type_code%TYPE;
137   l_top_task_id			pa_tasks.task_id%TYPE;
138   l_top_task_number		pa_tasks.task_number%TYPE;
139   l_vendor_employee_id		per_people_f.person_id%TYPE;
140   l_vendor_employee_number	per_people_f.employee_number%TYPE;
141   l_vendor_type			po_vendors.vendor_type_lookup_code%TYPE;
142 
143 BEGIN
144 /*
145   If (debug_acc_generator_wf) then
146  	dbms_output.put_line ('Beginning  Account Generation');
147   end if;
148 */
149 /* Bug 2249061. Added the following code to clear the temporary cache
150                 before calling the workflow so that there will be no
151                 errors in the account generator workflow.
152 */
153 
154 
155   -- Note from bug5075361: We probably don't need to keep the clearcache
156   -- at the beginning of the procedure since they're called at the end
157   -- but it doesn't hurt to keep them anyway
158   WF_ENGINE_UTIL.CLEARCACHE;
159   WF_ACTIVITY.CLEARCACHE;
160   WF_ITEM_ACTIVITY_STATUS.CLEARCACHE;
161   WF_ITEM.CLEARCACHE;
162   WF_PROCESS_ACTIVITY.CLEARCACHE;
163 
164 
165 -- Bug 2249061. Changes End.
166 
167 
168   ItemType := 'POWFRQAG';            -- PO Requisition Account Generator Workflow
169   x_appl_short_name      := 'SQLGL';
170   x_flex_field_code      := 'GL#';
171   x_flex_field_struc_num := x_coa_id;
172 
173   WF_ItemKey := FND_FLEX_WORKFLOW.INITIALIZE (x_appl_short_name, x_flex_field_code, x_flex_field_struc_num, ItemType);
174 
175 /*  If (debug_acc_generator_wf) then dbms_output.put_line ('WF Itemkey is : ' || WF_ItemKey);  end if;
176 */
177 
178   x_progress :=  'ITEM KEY FOR REQ ACCOUNT:' || WF_ItemKey;
179   IF (g_po_wf_debug = 'Y') THEN
180      /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,WF_ItemKey,x_progress);
181   END IF;
182 
183   IF  ( ItemType is not NULL ) AND ( WF_ItemKey is not NULL)  THEN
184         	-- Initialize workflow item attributes
185         	--
186 	IF (x_project_id IS NOT NULL) THEN
187 
188         	-- Calling AP routine to get raw and derived parameters for project accounting accounts.
189 
190 		BEGIN
191 
192 	   	x_progress :=  'Calling pa_acc_gen_wf_pkg.wf_acc_derive_params with project_id:' ||
193 			   to_char(x_project_id);
194 	   	IF (g_po_wf_debug = 'Y') THEN
195    	   	/* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,WF_ItemKey,x_progress);
196 	   	END IF;
197 
198            	pa_acc_gen_wf_pkg.wf_acc_derive_params (p_project_id => x_project_id,
199                 				p_task_id  => x_task_id,
200                 				p_expenditure_type  => x_expenditure_type,
201                 				p_vendor_id  => x_suggested_vendor_id,
202                        				p_expenditure_organization_id => x_expenditure_organization_id,
203                 				p_expenditure_item_date => x_expenditure_item_date,
204                      				x_class_code  => l_class_code,
205                 				x_direct_flag => l_direct_flag,
206                 				x_expenditure_category  => l_expenditure_category,
207                       				x_expenditure_org_name  => l_expenditure_org_name,
208                 				x_project_number  => l_project_number,
209                 				x_project_organization_name => l_project_organization_name,
210                 				x_project_organization_id => l_project_organization_id,
211                 				x_project_type => l_project_type,
212                 				x_public_sector_flag => l_public_sector_flag,
213                 				x_revenue_category => l_revenue_category,
214                 				x_task_number => l_task_number,
215                 				x_task_organization_name => l_task_organization_name,
216                 				x_task_organization_id => l_task_organization_id,
217                 				x_task_service_type => l_task_service_type,
218                 				x_top_task_id => l_top_task_id,
219                 				x_top_task_number => l_top_task_number,
220                 				x_vendor_employee_id => l_vendor_employee_id,
221                 				x_vendor_employee_number => l_vendor_employee_number,
222                 				x_vendor_type => l_vendor_type);
223 		EXCEPTION
224 			when others then
225 			NULL;
226 		END;
227 
228 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'CLASS_CODE', l_class_code);
229 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DIRECT_FLAG', l_direct_flag);
230 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'EXPENDITURE_CATEGORY', l_expenditure_category);
231 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'EXPENDITURE_ORG_NAME', l_expenditure_org_name);
232 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PROJECT_NUMBER', l_project_number);
233 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PROJECT_ORGANIZATION_NAME', l_project_organization_name);
234 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PROJECT_ORGANIZATION_ID', l_project_organization_id);
235 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PROJECT_TYPE', l_project_type);
236 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PUBLIC_SECTOR_FLAG', l_public_sector_flag);
237 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'REVENUE_CATEGORY', l_revenue_category);
238 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TASK_NUMBER', l_task_number);
239 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TASK_ORGANIZATION_NAME', l_task_organization_name);
240 	   	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'TASK_ORGANIZATION_ID', l_task_organization_id);
241 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TASK_SERVICE_TYPE', l_task_service_type);
242 	   	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'TOP_TASK_ID', l_top_task_id);
243 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TOP_TASK_NUMBER', l_top_task_number);
244 	   	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'VENDOR_EMPLOYEE_ID', l_vendor_employee_id);
245 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'VENDOR_EMPLOYEE_NUMBER', l_vendor_employee_number);
246 	   	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'VENDOR_TYPE', l_vendor_type);
247 
248                 -- -----------------------------------------------------------------------
249 		-- OGM_0.0 changes . Set award_id into award_set_id item attribute..
250 		-- OGM stores award_set_id into award_id and award_id is derived from
251 		-- award_distribution table.
252 		-- ------------------------------------------------------------------------
253 		IF x_award_id is not NULL then
254 	   		Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'AWARD_SET_ID', x_award_id); -- OGM_0.0 changes...
255 		END IF ;
256 
257 	END IF;
258 
259 	-- done setting AP project accounting attributes.
260 
261 	IF (ItemType IN ('POWFRQBA', 'POWFRQAA', 'POWFRQVA')) THEN
262 	   Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'CODE_COMBINATION_ID', x_code_combination_id);
263      	END IF;
264 
265     	IF (ItemType IN ('POWFRQAA', 'POWFRQVA')) THEN
266 	   Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'BUDGET_ACCOUNT_ID', x_budget_account_id);
267     	END IF;
268 
269     	IF (ItemType IN ('POWFRQVA')) THEN
270 	   Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'ACCRUAL_ACCOUNT_ID', x_accrual_account_id);
271     	END IF;
272 
273 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'CHART_OF_ACCOUNTS_ID', x_coa_id);
274 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'BOM_COST_ELEMENT_ID', x_bom_cost_element_id);
275 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'BOM_RESOURCE_ID', x_bom_resource_id);
276 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'CATEGORY_ID', x_category_id);
277 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'DELIVER_TO_LOCATION_ID', x_deliver_to_location_id);
278 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'DESTINATION_ORGANIZATION_ID',
279 							x_destination_organization_id);
280 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DESTINATION_SUBINVENTORY',
281 							x_destination_subinventory);
282 
283 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DESTINATION_TYPE_CODE', x_destination_type_code);
284 
285 	wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
286         	                       itemkey    =>  WF_ItemKey,
287                 	               aname      =>  'PO_ENCUMBRANCE_FLAG',
288                         	       avalue     =>  x_po_encumberance_flag );
289 
290 -- Header
291 
292 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT1',  header_att1);
293 	If header_att1 is not null then
294 	   begin
295 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
296         	                               itemkey    =>  WF_ItemKey,
297                 	                       aname      =>  'HEADER_ATT1',
298                         	               avalue     =>  header_att1 );
299 	   exception when others then
300 		null;
301 	   end;
302 	end if;
303 
304 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT2',  header_att2);
305 	If header_att2 is not null then
306 	   begin
307 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
308         	                               itemkey    =>  WF_ItemKey,
309                 	                       aname      =>  'HEADER_ATT2',
310                         	               avalue     =>  header_att2 );
311 	   exception  when others then
312 		null;
313 	   end;
314 	end if;
315 
316 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT3',  header_att3);
317 	If header_att3 is not null then
318 	   begin
319 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
320         	                               itemkey    =>  WF_ItemKey,
321                 	                       aname      =>  'HEADER_ATT3',
322                         	               avalue     =>  header_att3 );
323 	   exception  when others then
324 		null;
325 	   end;
326 	end if;
327 
328 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT4',  header_att4);
329 	If header_att4 is not null then
330 	   begin
331 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
332         	                               itemkey    =>  WF_ItemKey,
333                 	                       aname      =>  'HEADER_ATT4',
334                         	               avalue     =>  header_att4 );
335 	   exception  when others then
336 		null;
337 	   end;
338 	end if;
339 
340 	-- Call_WF_API_to_set_Att (ItemType, ItemKey, 'HEADER_ATT5',  header_att5);
341 	If header_att5 is not null then
342 	   begin
343 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
344         	                               itemkey    =>  WF_ItemKey,
345                 	                       aname      =>  'HEADER_ATT5',
346                         	               avalue     =>  header_att5 );
347 	   exception  when others then
348 		null;
349 	   end;
350 	end if;
351 
352 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT6',  header_att6);
353 	If header_att6 is not null then
354 	   begin
355 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
356         	                               itemkey    =>  WF_ItemKey,
357                 	                       aname      =>  'HEADER_ATT6',
358                         	               avalue     =>  header_att6 );
359 	   exception  when others then
360 		null;
361 	   end;
362 	end if;
363 
364 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT7',  header_att7);
365 	If header_att7 is not null then
366 	   begin
367 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
368         	                               itemkey    =>  WF_ItemKey,
369                 	                       aname      =>  'HEADER_ATT7',
370                         	               avalue     =>  header_att7 );
371 	   exception  when others then
372 		null;
373 	   end;
374 	end if;
375 
376 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT8',  header_att8);
377 	If header_att8 is not null then
378 	   begin
379 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
380         	                               itemkey    =>  WF_ItemKey,
381                 	                       aname      =>  'HEADER_ATT8',
382                         	               avalue     =>  header_att8 );
383 	   exception  when others then
384 		null;
385 	   end;
386 	end if;
387 
388 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT9',  header_att9);
389 	If header_att9 is not null then
390 	   begin
391 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
392         	                               itemkey    =>  WF_ItemKey,
393                 	                       aname      =>  'HEADER_ATT9',
394                         	               avalue     =>  header_att9 );
395 	   exception  when others then
396 		null;
397 	   end;
398 	end if;
399 
400 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT10', header_att10);
401 	If header_att10 is not null then
402 	   begin
403 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
404         	                               itemkey    =>  WF_ItemKey,
405                 	                       aname      =>  'HEADER_ATT10',
406                         	               avalue     =>  header_att10 );
407 	   exception  when others then
408 		null;
409 	   end;
410 	end if;
411 
412 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT11', header_att11);
413 	If header_att11 is not null then
414 	   begin
415 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
416         	                               itemkey    =>  WF_ItemKey,
417                 	                       aname      =>  'HEADER_ATT11',
418                         	               avalue     =>  header_att11 );
419 	   exception  when others then
420 		null;
421 	   end;
422 	end if;
423 
424 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT12', header_att12);
425 	If header_att12 is not null then
426 	   begin
427 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
428         	                               itemkey    =>  WF_ItemKey,
429                 	                       aname      =>  'HEADER_ATT12',
430                         	               avalue     =>  header_att12 );
431 	   exception  when others then
432 		null;
433 	   end;
434 	end if;
435 
436 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT13', header_att13);
437 	If header_att13 is not null then
438 	   begin
439 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
440         	                               itemkey    =>  WF_ItemKey,
441                 	                       aname      =>  'HEADER_ATT13',
442                         	               avalue     =>  header_att13 );
443 	   exception  when others then
444 		null;
445 	   end;
446 	end if;
447 
448 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT14', header_att14);
449 	If header_att14 is not null then
450 	   begin
451 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
452         	                               itemkey    =>  WF_ItemKey,
453                 	                       aname      =>  'HEADER_ATT14',
454                         	               avalue     =>  header_att14 );
455 	   exception  when others then
456 		null;
457 	   end;
458 	end if;
459 
460 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'HEADER_ATT15', header_att15);
461 	If header_att15 is not null then
462 	   begin
463 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
464         	                               itemkey    =>  WF_ItemKey,
465                 	                       aname      =>  'HEADER_ATT15',
466                         	               avalue     =>  header_att15 );
467 	   exception  when others then
468 		null;
469 	   end;
470 	end if;
471 
472 -- Line
473 
474 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT1',  line_att1);
475 	If line_att1 is not null then
476 	   begin
477 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
478         	                               itemkey    =>  WF_ItemKey,
479                 	                       aname      =>  'LINE_ATT1',
480                         	               avalue     =>  line_att1 );
481 	   exception  when others then
482 		null;
483 	   end;
484 	end if;
485 
486 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT2',  line_att2);
487 	If line_att2 is not null then
488 	   begin
489 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
490         	                               itemkey    =>  WF_ItemKey,
491                 	                       aname      =>  'LINE_ATT2',
492                         	               avalue     =>  line_att2 );
493 	   exception  when others then
494 		null;
495 	   end;
496 	end if;
497 
498 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT3',  line_att3);
499 	If line_att3 is not null then
500 	   begin
501 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
502         	                               itemkey    =>  WF_ItemKey,
503                 	                       aname      =>  'LINE_ATT3',
504                         	               avalue     =>  line_att3 );
505 	   exception  when others then
506 		null;
507 	   end;
508 	end if;
509 
510 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT4',  line_att4);
511 	If line_att4 is not null then
512 	   begin
513 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
514         	                               itemkey    =>  WF_ItemKey,
515                 	                       aname      =>  'LINE_ATT4',
516                         	               avalue     =>  line_att4 );
517 	   exception  when others then
518 		null;
519 	   end;
520 	end if;
521 
522 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT5',  line_att5);
523 	If line_att5 is not null then
524 	   begin
525 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
526         	                               itemkey    =>  WF_ItemKey,
527                 	                       aname      =>  'LINE_ATT5',
528                         	               avalue     =>  line_att5 );
529 	   exception  when others then
530 		null;
531 	   end;
532 	end if;
533 
534 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT6',  line_att6);
535 	If line_att6 is not null then
536 	   begin
537 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
538         	                               itemkey    =>  WF_ItemKey,
539                 	                       aname      =>  'LINE_ATT6',
540                         	               avalue     =>  line_att6 );
541 	   exception  when others then
542 		null;
543 	   end;
544 	end if;
545 
546 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT7',  line_att7);
547 	If line_att7 is not null then
548 	   begin
549 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
550         	                               itemkey    =>  WF_ItemKey,
551                 	                       aname      =>  'LINE_ATT7',
552                         	               avalue     =>  line_att7 );
553 	   exception  when others then
554 		null;
555 	   end;
556 	end if;
557 
558 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT8',  line_att8);
559 	If line_att8 is not null then
560 	   begin
561 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
562         	                               itemkey    =>  WF_ItemKey,
563                 	                       aname      =>  'LINE_ATT8',
564                         	               avalue     =>  line_att8 );
565 	   exception  when others then
566 		null;
567 	   end;
568 	end if;
569 
570 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT9',  line_att9);
571 	If line_att9 is not null then
572 	   begin
573 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
574         	                               itemkey    =>  WF_ItemKey,
575                 	                       aname      =>  'LINE_ATT9',
576                         	               avalue     =>  line_att9 );
577 	   exception  when others then
578 		null;
579 	   end;
580 	end if;
581 
582 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT10', line_att10);
583 	If line_att10 is not null then
584 	   begin
585 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
586         	                               itemkey    =>  WF_ItemKey,
587                 	                       aname      =>  'LINE_ATT10',
588                         	               avalue     =>  line_att10 );
589 	   exception  when others then
590 		null;
591 	   end;
592 	end if;
593 
594 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT11', line_att11);
595 	If line_att11 is not null then
596 	   begin
597 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
598         	                               itemkey    =>  WF_ItemKey,
599                 	                       aname      =>  'LINE_ATT11',
600                         	               avalue     =>  line_att11 );
601 	   exception  when others then
602 		null;
603 	   end;
604 	end if;
605 
606 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT12', line_att12);
607 	If line_att12 is not null then
608 	   begin
609 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
610         	                               itemkey    =>  WF_ItemKey,
611                 	                       aname      =>  'LINE_ATT12',
612                         	               avalue     =>  line_att12 );
613 	   exception  when others then
614 		null;
615 	   end;
616 	end if;
617 
618 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT13', line_att13);
619 	If line_att13 is not null then
620 	   begin
621 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
622         	                               itemkey    =>  WF_ItemKey,
623                 	                       aname      =>  'LINE_ATT13',
624                         	               avalue     =>  line_att13 );
625 	   exception  when others then
626 		null;
627 	   end;
628 	end if;
629 
630 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT14', line_att14);
631 	If line_att14 is not null then
632 	   begin
633 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
634         	                               itemkey    =>  WF_ItemKey,
635                 	                       aname      =>  'LINE_ATT14',
636                         	               avalue     =>  line_att14 );
637 	   exception  when others then
638 		null;
639 	   end;
640 	end if;
641 
642 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'LINE_ATT15', line_att15);
643 	If line_att15 is not null then
644 	   begin
645 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
646         	                               itemkey    =>  WF_ItemKey,
647                 	                       aname      =>  'LINE_ATT15',
648                         	               avalue     =>  line_att15 );
649 	   exception  when others then
650 		null;
651 	   end;
652 	end if;
653 
654 -- Distribution
655 
656 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT1',  distribution_att1);
657 	If distribution_att1 is not null then
658 	   begin
659 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
660         	                               itemkey    =>  WF_ItemKey,
661                 	                       aname      =>  'DISTRIBUTION_ATT1',
662                         	               avalue     =>  distribution_att1 );
663 	   exception  when others then
664 		null;
665 	   end;
666 	end if;
667 
668 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT2',  distribution_att2);
669 	If distribution_att2 is not null then
670 	   begin
671 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
672         	                               itemkey    =>  WF_ItemKey,
673                 	                       aname      =>  'DISTRIBUTION_ATT2',
674                         	               avalue     =>  distribution_att2 );
675 	   exception  when others then
676 		null;
677 	   end;
678 	end if;
679 
680 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT3',  distribution_att3);
681 	If distribution_att3 is not null then
682 	   begin
683 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
684         	                               itemkey    =>  WF_ItemKey,
685                 	                       aname      =>  'DISTRIBUTION_ATT3',
686                         	               avalue     =>  distribution_att3 );
687 	   exception  when others then
688 		null;
689 	   end;
690 	end if;
691 
692 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT4',  distribution_att4);
693 	If distribution_att4 is not null then
694 	   begin
695 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
696         	                               itemkey    =>  WF_ItemKey,
697                 	                       aname      =>  'DISTRIBUTION_ATT4',
698                         	               avalue     =>  distribution_att4 );
699 	   exception  when others then
700 		null;
701 	   end;
702 	end if;
703 
704 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT5',  distribution_att5);
705 	If distribution_att5 is not null then
706 	   begin
707 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
708         	                               itemkey    =>  WF_ItemKey,
709                 	                       aname      =>  'DISTRIBUTION_ATT5',
710                         	               avalue     =>  distribution_att5 );
711 	   exception  when others then
712 		null;
713 	   end;
714 	end if;
715 
716 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT6',  distribution_att6);
717 	If distribution_att6 is not null then
718 	   begin
719 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
720         	                               itemkey    =>  WF_ItemKey,
721                 	                       aname      =>  'DISTRIBUTION_ATT6',
722                         	               avalue     =>  distribution_att6 );
723 	   exception  when others then
724 		null;
725 	   end;
726 	end if;
727 
728 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT7',  distribution_att7);
729 	If distribution_att7 is not null then
730 	   begin
731 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
732         	                               itemkey    =>  WF_ItemKey,
733                 	                       aname      =>  'DISTRIBUTION_ATT7',
734                         	               avalue     =>  distribution_att7 );
735 	   exception  when others then
736 		null;
737 	   end;
738 	end if;
739 
740 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT8',  distribution_att8);
741 	If distribution_att8 is not null then
742 	   begin
743 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
744         	                               itemkey    =>  WF_ItemKey,
745                 	                       aname      =>  'DISTRIBUTION_ATT8',
746                         	               avalue     =>  distribution_att8 );
747 	   exception  when others then
748 		null;
749 	   end;
750 	end if;
751 
752 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT9',  distribution_att9);
753 	If distribution_att9 is not null then
754 	   begin
755 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
756         	                               itemkey    =>  WF_ItemKey,
757                 	                       aname      =>  'DISTRIBUTION_ATT9',
758                         	               avalue     =>  distribution_att9 );
759 	   exception  when others then
760 		null;
761 	   end;
762 	end if;
763 
764 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT10', distribution_att10);
765 	If distribution_att10 is not null then
766 	   begin
767 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
768         	                               itemkey    =>  WF_ItemKey,
769                 	                       aname      =>  'DISTRIBUTION_ATT10',
770                         	               avalue     =>  distribution_att10 );
771 	   exception  when others then
772 		null;
773 	   end;
774 	end if;
775 
776 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT11', distribution_att11);
777 	If distribution_att11 is not null then
778 	   begin
779 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
780         	                               itemkey    =>  WF_ItemKey,
781                 	                       aname      =>  'DISTRIBUTION_ATT11',
782                         	               avalue     =>  distribution_att11 );
783 	   exception  when others then
784 		null;
785 	   end;
786 	end if;
787 
788 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT12', distribution_att12);
789 	If distribution_att12 is not null then
790 	   begin
791 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
792         	                               itemkey    =>  WF_ItemKey,
793                 	                       aname      =>  'DISTRIBUTION_ATT12',
794                         	               avalue     =>  distribution_att12 );
795 	   exception  when others then
796 		null;
797 	   end;
798 	end if;
799 
800 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT13', distribution_att13);
801 	If distribution_att13 is not null then
802 	   begin
803 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
804         	                               itemkey    =>  WF_ItemKey,
805                 	                       aname      =>  'DISTRIBUTION_ATT13',
806                         	               avalue     =>  distribution_att13 );
807 	   exception  when others then
808 		null;
809 	   end;
810 	end if;
811 
812 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT14', distribution_att14);
813 	If distribution_att14 is not null then
814 	   begin
815 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
816         	                               itemkey    =>  WF_ItemKey,
817                 	                       aname      =>  'DISTRIBUTION_ATT14',
818                         	               avalue     =>  distribution_att14 );
819 	   exception  when others then
820 		null;
821 	   end;
822 	end if;
823 
824 	-- Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DISTRIBUTION_ATT15', distribution_att15);
825 	If distribution_att15 is not null then
826 	   begin
827 		wf_engine.SetItemAttrText   (  itemtype   =>  itemtype,
828         	                               itemkey    =>  WF_ItemKey,
829                 	                       aname      =>  'DISTRIBUTION_ATT15',
830                         	               avalue     =>  distribution_att15 );
831 	   exception  when others then
832 		null;
833 	   end;
834 	end if;
835 
836 
837 	Call_WF_API_to_set_date_Att (ItemType, WF_ItemKey, 'EXPENDITURE_ITEM_DATE', x_expenditure_item_date);
838 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'EXPENDITURE_ORGANIZATION_ID',
839 							x_expenditure_organization_id);
840 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'EXPENDITURE_TYPE', x_expenditure_type);
841 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'ITEM_ID', x_item_id);
842 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'LINE_TYPE_ID', x_line_type_id);
843 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'PA_BILLABLE_FLAG', x_result_billable_flag);
844 
845 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'PREPARER_ID', x_preparer_id);
846 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'PROJECT_ID', x_project_id);
847 
848 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'DOCUMENT_TYPE_CODE', x_document_type_code);
849 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'BLANKET_PO_HEADER_ID', x_blanket_po_header_id);
850 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'SOURCE_TYPE_CODE', x_source_type_code);
851 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'SOURCE_ORGANIZATION_ID',
852 							x_source_organization_id);
853 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'SOURCE_SUBINVENTORY', x_source_subinventory);
854 
855 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'TASK_ID', x_task_id);
856 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'TO_PERSON_ID', x_deliver_to_person_id);
857 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'TYPE_LOOKUP_CODE', x_type_lookup_code);
858 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'SUGGESTED_VENDOR_ID', x_suggested_vendor_id);
859 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'VENDOR_SITE_ID', x_suggested_vendor_site_id); /* B1548597 Common Receiving RVK */
860 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_ENTITY_ID', x_wip_entity_id);
861 
862 
863 	Call_WF_API_to_set_Att (ItemType, WF_ItemKey, 'WIP_ENTITY_TYPE', x_wip_entity_type);
864 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_LINE_ID', x_wip_line_id );
865 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_OPERATION_SEQ_NUM', x_wip_operation_seq_num);
866 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_REPETITIVE_SCHEDULE_ID',
867 							x_wip_repetitive_schedule_id);
868 	Call_WF_API_to_set_no_Att (ItemType, WF_ItemKey, 'WIP_RESOURCE_SEQ_NUM', x_wip_resource_seq_num);
869 
870         --<BUG 3407630 START>
871         --Call WF API to set unit_price attribute.
872         --unit_price will be taken into consideration when generating accounts.
873 
874         PO_WF_UTIL_PKG.SetItemAttrNumber (itemtype   =>  itemtype,
875         	                          itemkey    =>  wf_itemkey,
876                 	                  aname      =>  'UNIT_PRICE',
877                         	          avalue     =>  p_unit_price);
878 
879    	IF (g_po_wf_debug = 'Y') THEN
880           PO_WF_DEBUG_PKG.insert_debug(itemtype,
881                                        wf_itemkey,
882                                        'Set WF item UNIT_PRICE to ' ||
883                                         PO_WF_UTIL_PKG.GetItemAttrNumber (
884                                                   itemtype   =>  itemtype,
885         	                                  itemkey    =>  wf_itemkey,
886                 	                          aname      =>  'UNIT_PRICE'));
887 	END IF;
888         --<BUG 3407630 END>
889 
890         --<BUG 3611341 START>
891         -- Call WF API to set blanket_po_line_num attribute.
892         -- blanket_po_line_num will be taken into consideration when generating accounts.
893         PO_WF_UTIL_PKG.SetItemAttrNumber(itemtype => itemtype,
894                                          itemkey  => wf_itemkey,
895                                          aname    => 'BLANKET_PO_LINE_NUM',
896                                          avalue   => p_blanket_po_line_num);
897 
898         IF (g_po_wf_debug = 'Y') THEN
899           PO_WF_DEBUG_PKG.insert_debug(itemtype, wf_itemkey,
900                                        'Set WF item BLANKET_PO_LINE_NUM to ' ||
901                                        PO_WF_UTIL_PKG.GetItemAttrNumber(
902                                        itemtype => itemtype,
903                                        itemkey  => wf_itemkey,
904                                        aname    => 'BLANKET_PO_LINE_NUM'));
905         END IF;
906         --<BUG 3611341 END>
907 
908 
909 	-- Done setting WF item attributes
910 
911 	if x_code_combination_id is null then
912 
913            x_progress :=  'FND_FLEX_WORKFLOW.GENERATE: Before call';
914            IF (g_po_wf_debug = 'Y') THEN
915               /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,WF_ItemKey,x_progress);
916            END IF;
917 
918 /*	   If (debug_acc_generator_wf) then  dbms_output.put_line ('Calling generate to build Charge Account'); end if;
919 */
920 
921 	   x_block_activity_label := NULL;
922 
923            -- Bug 1497909 : Set the encumbrance date for validation
924            po_wf_util_pkg.SetItemAttrDate(itemtype   =>  itemtype,
925                                         itemkey    =>  wf_itemkey,
926                                         aname      =>  'ENCUMBRANCE_DATE',
927                                         avalue     =>  x_gl_encumbered_date);
928 
929 	   x_success := FND_FLEX_WORKFLOW.GENERATE_PARTIAL ( ItemType,
930 						  	  WF_ItemKey,
931 							  'DEFAULT_CHARGE_ACC_GENERATION',
932 							  x_block_activity_label,
933 							  x_insert_if_new,
934 						  	  ccid,
935 						  	  concat_segs,
936 						  	  concat_ids,
937 						  	  concat_descrs,
938 						  	  FB_ERROR_MSG,
939 							  x_new_combination );
940 
941 	   if (x_success  and ( ccid is null or ccid = 0 or ccid = -1 )) then
942 
943 		-- Complete the blocked workflow as it may be running in synch mode and cause problems for consequent
944 		-- account generation runs for this session.
945 		begin
946 			wf_engine.CompleteActivity(itemtype, wf_itemkey, 'BLOCK_BUDGET_ACC_GENERATION', 'FAILURE');
947 		exception
948 			when others then
949 			IF (g_po_wf_debug = 'Y') THEN
950    			PO_WF_DEBUG_PKG.insert_debug(itemtype,wf_itemkey,'Exception when completing WF' ||  Wf_Itemkey);
951 			END IF;
952 --			DBMS_OUTPUT.put_line ('Exception completing blocked WF');
953 		end;
954 	   end if;
955 
956 	   x_charge_success := x_success;
957 
958 	   if x_new_combination then
959 		x_new_ccid_generated	:= TRUE;
960 		-- commit; Need this commit else the entire GL_CODE_COMBINATIONS table will be locked. commit in form.
961 	   end if;
962 
963 	   -- Copy the returned value into appropriate function parameters to pass them
964 	   -- back to the form.
965 
966            x_progress :=  'ccid:' || to_char(ccid) || ' concat_segs:' || concat_segs || ' concat_ids:' || concat_ids ||
967 			' concat_descrs:' || concat_descrs || ' FB_ERROR_MSG:' || FB_ERROR_MSG;
968            IF (g_po_wf_debug = 'Y') THEN
969               /* DEBUG */ PO_WF_DEBUG_PKG.insert_debug(itemtype,WF_ItemKey,x_progress);
970            END IF;
971 
972 	   x_code_combination_id := ccid;
973            x_charge_account_flex := concat_segs;
974            x_charge_account_desc := concat_descrs;
975 
976 	   was_ccid_passed_in_from_form := false;
977 
978 	else
979 
980 	   x_charge_success := TRUE;
981 	   x_success := TRUE;
982 	   was_ccid_passed_in_from_form := true;
983 
984 	end if;
985 
986 
987      	If (x_success and (x_code_combination_id IS NOT NULL) and (x_code_combination_id <> 0) and
988 		(x_code_combination_id <> -1))   then
989 
990 		wf_engine.SetItemAttrNumber (  itemtype   =>  itemtype,
991         	        	               itemkey    =>  WF_ItemKey,
992                 	        	       aname      =>  'CODE_COMBINATION_ID',
993                         	               avalue     =>  x_code_combination_id );
994 
995 		x_charge_success := x_success;
996 
997 		-- Generate Budget Account if encumbrance is on
998 
999 		if ((x_po_encumberance_flag = 'Y')  and (x_destination_type_code <> 'SHOP FLOOR')) then
1000 
1001 /*		    If (debug_acc_generator_wf) then dbms_output.put_line ('Calling generate to build Budget Account'); end if;
1002 */
1003 		    if was_ccid_passed_in_from_form = false then
1004 		       x_block_activity_label := 'BLOCK_BUDGET_ACC_GENERATION';
1005                     else
1006                        x_block_activity_label := NULL;
1007                     end if;
1008 
1009                     -- Bug 1497909 : Set the encumbrance date for validation
1010                     po_wf_util_pkg.SetItemAttrDate(itemtype   =>  itemtype,
1011                                         itemkey    =>  wf_itemkey,
1012                                         aname      =>  'ENCUMBRANCE_DATE',
1013                                         avalue     =>  x_gl_encumbered_date);
1014 
1015 		    x_success := FND_FLEX_WORKFLOW.GENERATE_PARTIAL ( 	ItemType,
1016 						  	  	      	WF_ItemKey,
1017 									'DEFAULT_BUDGET_ACC_GENERATION',
1018 							  		x_block_activity_label,
1019 									x_insert_if_new,
1020 						  	  		ccid,
1021 						  	  		concat_segs,
1022 						  	  		concat_ids,
1023 						  	  		concat_descrs,
1024 						  	  		FB_ERROR_MSG,
1025 									x_new_combination);
1026 		    x_budget_success := x_success;
1027 
1028 	   	    if x_new_combination then
1029 			x_new_ccid_generated	:= TRUE;
1030 	   	    end if;
1031 
1032 		    x_budget_account_id := ccid;
1033 		    x_budget_account_flex := concat_segs;
1034 		    x_budget_account_desc := concat_descrs;
1035 
1036 
1037         	    x_progress :=  'ccid:' || to_char(ccid) || ' concat_segs:' || concat_segs || ' concat_ids:' ||
1038 				    concat_ids || ' concat_descrs:' || concat_descrs || ' FB_ERROR_MSG:' ||
1039 				    FB_ERROR_MSG;
1040 
1041 	        else
1042 			x_success := TRUE;
1043 		        x_budget_success := x_success;
1044 		end if;
1045 
1046 		if x_success then
1047 
1048 		    wf_engine.SetItemAttrNumber (  itemtype   =>  itemtype,
1049         	        	                   itemkey    =>  WF_ItemKey,
1050                 	        	           aname      =>  'BUDGET_ACCOUNT_ID',
1051                         	        	   avalue     =>  x_budget_account_id );
1052 
1053 		    -- Generate Accrual Account
1054 
1055 /*		    If (debug_acc_generator_wf) then dbms_output.put_line ('Calling generate to build Accrual Account'); end if;
1056 */
1057                     if was_ccid_passed_in_from_form = false then
1058                        if ((x_po_encumberance_flag = 'Y')  and (x_destination_type_code <> 'SHOP FLOOR')) then
1059 		    	   x_block_activity_label := 'BLOCK_ACCRUAL_ACC_GENERATION';
1060 		       else
1061 		    	   x_block_activity_label := 'BLOCK_BUDGET_ACC_GENERATION';
1062 		       end if;
1063                     else
1064                        if ((x_po_encumberance_flag = 'Y')  and (x_destination_type_code <> 'SHOP FLOOR')) then
1065 		    	   x_block_activity_label := 'BLOCK_ACCRUAL_ACC_GENERATION';
1066 		       else
1067 		    	   x_block_activity_label := NULL;
1068 		       end if;
1069                     end if;
1070 
1071                     -- Bug 1497909 : Set the encumbrance date for validation
1072                     po_wf_util_pkg.SetItemAttrDate(itemtype   =>  itemtype,
1073                                         itemkey    =>  wf_itemkey,
1074                                         aname      =>  'ENCUMBRANCE_DATE',
1075                                         avalue     =>  x_gl_encumbered_date);
1076 
1077 		    x_success := FND_FLEX_WORKFLOW.GENERATE_PARTIAL ( 	ItemType,
1078 						  	  	      	WF_ItemKey,
1079 							  		'DEFAULT_ACCRUAL_ACC_GENERATION',
1080 							  		x_block_activity_label,
1081 									x_insert_if_new,
1082 						  	  		ccid,
1083 						  	  		concat_segs,
1084 						  	  		concat_ids,
1085 						  	  		concat_descrs,
1086 						  	  		FB_ERROR_MSG,
1087 									x_new_combination );
1088 		    x_accrual_success := x_success;
1089 
1090 	   	    if x_new_combination then
1091 			x_new_ccid_generated	:= TRUE;
1092 	   	    end if;
1093 
1094 		    x_accrual_account_id := ccid;
1095 		    x_accrual_account_flex := concat_segs;
1096 		    x_accrual_account_desc := concat_descrs;
1097 
1098 
1099         	    x_progress :=  'ccid:' || to_char(ccid) || ' concat_segs:' || concat_segs || ' concat_ids:' ||
1100 				    concat_ids || ' concat_descrs:' || concat_descrs || ' FB_ERROR_MSG:' ||
1101 				    FB_ERROR_MSG;
1102 
1103 		    If x_success then
1104 
1105 		        wf_engine.SetItemAttrNumber (  itemtype   =>  itemtype,
1106         	        	                       itemkey    =>  WF_ItemKey,
1107                 	        	               aname      =>  'ACCRUAL_ACCOUNT_ID',
1108                         	        	       avalue     =>  x_accrual_account_id );
1109 
1110 			-- Generate Variance Account
1111                         -- Bug 1497909 : Set the encumbrance date for validation
1112                         po_wf_util_pkg.SetItemAttrDate(itemtype   =>  itemtype,
1113                                         itemkey    =>  wf_itemkey,
1114                                         aname      =>  'ENCUMBRANCE_DATE',
1115                                         avalue     =>  x_gl_encumbered_date);
1116 
1117 		    	x_success := FND_FLEX_WORKFLOW.GENERATE_PARTIAL ( ItemType,
1118 						  	  	      	  WF_ItemKey,
1119 							  		  'DEFAULT_VARIANCE_ACC_GENERATION',
1120 							  		  'BLOCK_VARIANCE_ACC_GENERATION',
1121 									  x_insert_if_new,
1122 						  	  		  ccid,
1123 						  	  		  concat_segs,
1124 						  	  		  concat_ids,
1125 						  	  		  concat_descrs,
1126 						  	  		  FB_ERROR_MSG,
1127 									  x_new_combination );
1128 
1129 		    	x_variance_success := x_success;
1130 
1131 	   	    	if x_new_combination then
1132 				x_new_ccid_generated	:= TRUE;
1133 	   	    	end if;
1134 
1135 			x_variance_account_id := ccid;
1136 			x_variance_account_flex := concat_segs;
1137 			x_variance_account_desc := concat_descrs;
1138 
1139 
1140         		x_progress :=  'ccid:' || to_char(ccid) || ' concat_segs:' || concat_segs || ' concat_ids:'
1141 					|| concat_ids || ' concat_descrs:' || concat_descrs || ' FB_ERROR_MSG:' ||
1142 					FB_ERROR_MSG;
1143 
1144 /*			If (debug_acc_generator_wf) then
1145 				if (not x_success) then
1146 					dbms_output.put_line (' va failed');
1147 				end if;
1148 			end if;
1149 */
1150 
1151 			x_new_combination := x_new_ccid_generated;
1152 
1153                         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1154 
1155 			return (x_success);
1156 
1157 		    else		-- accrual acc failed.
1158 
1159 /*			If (debug_acc_generator_wf) then
1160 				dbms_output.put_line (' aa failed');
1161 			end if;   */
1162 
1163                         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1164 
1165 			return (x_success);
1166 
1167 		    end if;
1168 
1169 		else			-- budget acc failed.
1170 
1171 /*			If (debug_acc_generator_wf) then
1172 				dbms_output.put_line (' ba failed');
1173 			end if;    */
1174 
1175                         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1176 
1177 			return (x_success);
1178 		end if;
1179 
1180 
1181 	else		-- charge acc failed.
1182 
1183 /*		If (debug_acc_generator_wf) then  dbms_output.put_line (' ca failed');  end if;
1184 */
1185 
1186                 PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1187 
1188 		return (x_success);
1189 
1190      	end if;
1191 
1192         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1193 
1194      	return x_success;
1195   ELSE
1196 
1197 	FB_ERROR_MSG := 'Invalid Item Type OR Item Key';
1198 
1199         PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1200 
1201 	return FALSE;
1202   END IF;
1203 
1204 EXCEPTION
1205  WHEN OTHERS THEN
1206 
1207    PO_WF_UTIL_PKG.clear_wf_cache; -- bug5075361
1208 
1209    po_message_s.sql_error('PO_REQ_WF_BUILD_ACCOUNT_INIT.Start_Workflow', x_progress, sqlcode);
1210    RAISE;
1211 
1212 END Start_Workflow;
1213 
1214 
1215 /*
1216     * Set the debug mode on
1217 */
1218 
1219 PROCEDURE debug_on IS
1220 BEGIN
1221         debug_acc_generator_wf := TRUE;
1222 
1223         PO_WF_PO_CHARGE_ACC.debug_on;
1224         PO_WF_PO_BUDGET_ACC.debug_on;
1225 --        PO_WF_PO_ACCRUAL_ACC.debug_on;
1226 --        PO_WF_PO_VARIANCE_ACC.debug_on;
1227 
1228 END debug_on;
1229 
1230 /*
1231     * Set the debug mode off
1232 */
1233 
1234 PROCEDURE debug_off IS
1235 BEGIN
1236         debug_acc_generator_wf := FALSE;
1237 
1238         PO_WF_PO_CHARGE_ACC.debug_off;
1239         PO_WF_PO_BUDGET_ACC.debug_off;
1240 --        PO_WF_PO_ACCRUAL_ACC.debug_off;
1241 --        PO_WF_PO_VARIANCE_ACC.debug_off;
1242 
1243 END debug_off;
1244 
1245 
1246 -- ************************************************************************************ --
1247 /*
1248 	PRIVATE PROCEDURES / FUNCTIONS
1249 */
1250 -- ************************************************************************************ --
1251 
1252 
1253 PROCEDURE Call_WF_API_to_set_Att (ItemType varchar2, ItemKey varchar2, aname varchar2,
1254 				  avalue varchar2)
1255 IS
1256 BEGIN
1257 
1258 	wf_engine.SetItemAttrText (    itemtype   =>  itemtype,
1259                                        itemkey    =>  itemkey,
1260                                        aname      =>  aname,
1261                                        avalue     =>  avalue );
1262 END Call_WF_API_to_set_Att;
1263 
1264 PROCEDURE Call_WF_API_to_set_no_Att (ItemType varchar2, ItemKey varchar2, aname varchar2,
1265 				  avalue number)
1266 IS
1267 BEGIN
1268 
1269 	wf_engine.SetItemAttrNumber (  itemtype   =>  itemtype,
1270                                        itemkey    =>  itemkey,
1271                                        aname      =>  aname,
1272                                        avalue     =>  avalue );
1273 END Call_WF_API_to_set_no_Att;
1274 
1275 PROCEDURE Call_WF_API_to_set_date_Att (ItemType varchar2, ItemKey varchar2, aname varchar2,
1276 				  avalue date)
1277 IS
1278 BEGIN
1279 
1280 	wf_engine.SetItemAttrDate (    itemtype   =>  itemtype,
1281                                        itemkey    =>  itemkey,
1282                                        aname      =>  aname,
1283                                        avalue     =>  avalue );
1284 END Call_WF_API_to_set_date_Att;
1285 
1286 end  PO_REQ_WF_BUILD_ACCOUNT_INIT;