DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSTPLCWP

Source


1 PACKAGE BODY CSTPLCWP AS
2 /* $Header: CSTLCWPB.pls 120.1 2005/10/13 08:52:39 visrivas noship $ */
3 
4 PROCEDURE cost_wip_trx (
5   l_trx_id                IN      NUMBER,
6   l_comm_iss_flag         IN      NUMBER,
7   l_cost_type_id          IN      NUMBER,
8   l_cost_method           IN      NUMBER,
9   l_rates_cost_type_id    IN      NUMBER,
10   l_cost_grp_id           IN      NUMBER,
11   l_txfr_cost_grp_id      IN      NUMBER,
12   l_exp_flag              IN      NUMBER,
13   l_exp_item_flag         IN      NUMBER,
14   l_flow_schedule         IN      NUMBER,
15   l_user_id               IN      NUMBER,
16   l_login_id              IN      NUMBER,
17   l_request_id            IN      NUMBER,
18   l_prog_id               IN      NUMBER,
19   l_prog_app_id           IN      NUMBER,
20   err_num                 OUT NOCOPY     NUMBER,
21   err_code                OUT NOCOPY     VARCHAR2,
22   err_msg                 OUT NOCOPY     VARCHAR2
23 )
24 is
25 
26   l_layer_id              NUMBER;
27   l_cost_group_id         NUMBER;
28   l_inv_item_id           NUMBER;
29   l_org_id                NUMBER;
30   l_txn_date              DATE;
31   l_period_id             NUMBER;
32   l_action_id             NUMBER;
33   l_src_type_id           NUMBER;
34   l_txn_qty               NUMBER;
35   l_wip_entity_id         NUMBER;
36   l_op_seq_num            NUMBER;
37   l_final_comp_flag       VARCHAR2(1);
38   l_movhd_cost_type_id    NUMBER;
39   stmt_num                NUMBER;
40   l_return                NUMBER;
41   l_row_count             NUMBER;
42   l_mtl_txn_exists        NUMBER;
43   l_entity_type		  NUMBER;
44   l_err_num               NUMBER;
45   l_err_code              VARCHAR2(240);
46   l_err_msg               VARCHAR2(240);
47   proc_fail               EXCEPTION;
48 
49 
50   l_trx_info              CST_XLA_PVT.t_xla_inv_trx_info;
51 
52   l_msg_data		  VARCHAR2(8000);
53   l_msg_count		  NUMBER;
54   l_return_status	  VARCHAR2(1);
55   l_msg_return_status	  VARCHAR2(1);
56 BEGIN
57 
58   --
59   -- initialize l_movhd_cost_type_id. Bug 609 -
60   l_movhd_cost_type_id := l_rates_cost_type_id;
61 
62   err_num:=0;
63   l_err_num := 0;
64 
65   stmt_num := 110;
66 
67   select
68     inventory_item_id,
69     organization_id,
70     transaction_date,
71     transaction_action_id,
72     transaction_source_type_id,
73     primary_quantity,
74     transaction_source_id,
75     operation_seq_num,
76     nvl(final_completion_flag,'N'),
77     acct_period_id
78   into
79     l_inv_item_id,
80     l_org_id,
81     l_txn_date,
82     l_action_id,
83     l_src_type_id,
84     l_txn_qty,
85     l_wip_entity_id,
86     l_op_seq_num,
87     l_final_comp_flag,
88     l_period_id
89   from
90     mtl_material_transactions
91   where
92     transaction_id = l_trx_id;
93 
94 
95 
96 
97 
98 
99   -- Check to see if the item has a row in cst_quantity_layers.
100 
101   -- For a regular transaction the layer_id in MCACD corresponds to
102   -- the cost_group_id in MMT. For a CITW txn however, the WIP issue
103   -- is being done from the txfr_cost_group in MMT and so we should
104   -- fetch the layer_id corresponding to this.
105 
106   IF l_comm_iss_flag <> 1 THEN
107 
108     l_layer_id := CSTPACLM.layer_id
109     (
110       l_org_id,
111       l_inv_item_id,
112       l_cost_grp_id,
113       l_err_num,
114       l_err_code,
115       l_err_msg
116     );
117 
118   ELSE
119 
120     l_layer_id := CSTPACLM.layer_id
121     (
122       l_org_id,
123       l_inv_item_id,
124       l_txfr_cost_grp_id,
125       l_err_num,
126       l_err_code,
127       l_err_msg
128     );
129 
130   END IF;
131 
132   IF l_err_num <> 0 THEN
133     raise proc_fail;
134   END IF;
135 
136 
137   -- If row exists proceed, else create row.
138 
139   IF l_layer_id = 0 THEN
140     l_layer_id:= CSTPACLM.create_layer
141     (
142       i_org_id        => l_org_id,
143       i_item_id       => l_inv_item_id,
144       i_cost_group_id => l_cost_grp_id,
145       i_user_id       => l_user_id,
146       i_request_id    => l_request_id,
147       i_prog_id       => l_prog_id,
148       i_prog_appl_id  => l_prog_app_id,
149       i_txn_id        => l_trx_id,
150       o_err_num       => l_err_num,
151       o_err_code      => l_err_code,
152       o_err_msg       => l_err_msg
153     );
154 
155     IF (l_err_num<>0) THEN
156       raise proc_fail;
157     END IF;
158 
159   END IF;
160 
161 
162 
163 
164   -- Prior to doing any further processing, check for a CFM txn if a row
165   -- exists in WPB for that schedule. If no row exists then this fn will
166   -- create a row automatically.
167 
168 
169   If (l_flow_schedule = 1) THEN
170 
171     l_return := CSTPCFMS.wip_cfm_cbr
172     (
173       i_org_id         => l_org_id,
174       i_user_id        => l_user_id,
175       i_login_id       => l_user_id,
176       i_acct_period_id => l_period_id,
177       i_wip_entity_id  => l_wip_entity_id,
178       err_buf          => l_err_msg
179     );
180 
181     If (l_return <> 0) THEN
182       raise proc_fail;
183     END IF;
184 
185   END IF;
186 
187 
188   -- Based on transaction_action_id call appropriate function for processing.
189   -- Need to also account for the 2 new wip txns.
190 
191 
192 
193   IF ( l_action_id = 1 OR l_action_id = 34 ) THEN
194 
195     CSTPLCIR.component_issue
196     (
197       i_cost_method_id => l_cost_method,
198       i_txn_id         => l_trx_id,
199       i_layer_id       => l_layer_id,
200       i_inv_item_id    => l_inv_item_id,
201       i_org_id         => l_org_id,
202       i_wip_entity_id  => l_wip_entity_id,
203       i_txn_qty        => l_txn_qty,
204       i_op_seq_num     => l_op_seq_num,
205       i_cost_type_id   => l_cost_type_id,
206       i_exp_flag       => l_exp_flag,
207       i_user_id        => l_user_id,
208       i_login_id       => l_login_id,
209       i_request_id     => l_request_id,
210       i_prog_id        => l_prog_id,
211       i_prog_appl_id   => l_prog_app_id,
212       o_err_num        => l_err_num,
213       o_err_msg        => l_err_msg
214     );
215 
216   ELSIF ( l_action_id = 27 OR l_action_id = 33 ) THEN
217 
218     CSTPLCIR.component_return
219     (
220       i_cost_method_id => l_cost_method,
221       i_txn_id         => l_trx_id,
222       i_layer_id       => l_layer_id,
223       i_inv_item_id    => l_inv_item_id,
224       i_org_id         => l_org_id,
225       i_wip_entity_id  => l_wip_entity_id,
226       i_txn_qty        => l_txn_qty,
227       i_op_seq_num     => l_op_seq_num,
228       i_user_id        => l_user_id,
229       i_login_id       => l_login_id,
230       i_request_id     => l_request_id,
231       i_prog_id        => l_prog_id,
232       i_prog_appl_id   => l_prog_app_id,
233       o_err_num        => l_err_num,
234       o_err_msg        => l_err_msg
235     );
236 
237   ELSIF ( l_action_id = 31 and l_flow_schedule <> 1 ) THEN
238 
239     CSTPLCAC.assembly_completion
240     (
241       i_cost_method_id      => l_cost_method,
242       i_txn_id              => l_trx_id,
243       i_txn_date            => l_txn_date,
244       i_layer_id            => l_layer_id,
245       i_inv_item_id         => l_inv_item_id,
246       i_org_id              => l_org_id,
247       i_wip_entity_id       => l_wip_entity_id,
248       i_txn_qty             => l_txn_qty,
249       i_final_comp_flag     => l_final_comp_flag,
250       i_cost_type_id        => l_cost_type_id,
251       i_res_cost_type_id    => l_rates_cost_type_id,
252       i_cost_group_id       => l_cost_grp_id,
253       i_acct_period_id      => l_period_id,
254       i_user_id             => l_user_id,
255       i_login_id            => l_login_id,
256       i_request_id          => l_request_id,
257       i_prog_id             => l_prog_id,
258       i_prog_appl_id        => l_prog_app_id,
259       o_movhd_cost_type_id  => l_movhd_cost_type_id,
260       o_err_num             => l_err_num,
261       o_err_msg             => l_err_msg
262     );
263 
264   ELSIF ( l_action_id = 32 and l_flow_schedule <> 1 ) THEN
265 
266     -- Note that we're not passing the l_movhd_cost_type_id anymore;
267     -- this is because we always return at the WIP component layer
268     -- cost, so we'll ignore the user-specified cost type for
269     -- assembly returns.
270 
271     CSTPLCAC.assembly_return
272     (
273       i_cost_method_id      => l_cost_method,
274       i_txn_id              => l_trx_id,
275       i_layer_id            => l_layer_id,
276       i_inv_item_id         => l_inv_item_id,
277       i_org_id              => l_org_id,
278       i_wip_entity_id       => l_wip_entity_id,
279       i_txn_qty             => l_txn_qty,
280       i_user_id             => l_user_id,
281       i_login_id            => l_login_id,
282       i_request_id          => l_request_id,
283       i_prog_id             => l_prog_id,
284       i_prog_appl_id        => l_prog_app_id,
285       o_err_num             => l_err_num,
286       o_err_msg             => l_err_msg
287     );
288 
289   ELSIF ( l_action_id = 30 and l_txn_qty >= 0 and l_flow_schedule <> 1 ) THEN
290 
291     CSTPLCAS.scrap
292     (
293       i_cost_method_id      => l_cost_method,
294       i_txn_id              => l_trx_id,
295       i_layer_id            => l_layer_id,
296       i_inv_item_id         => l_inv_item_id,
297       i_org_id              => l_org_id,
298       i_wip_entity_id       => l_wip_entity_id,
299       i_txn_qty             => l_txn_qty,
300       i_op_seq_num          => l_op_seq_num,
301       i_user_id             => l_user_id,
302       i_login_id            => l_login_id,
303       i_request_id          => l_request_id,
304       i_prog_id             => l_prog_id,
305       i_prog_appl_id        => l_prog_app_id,
306       o_err_num             => l_err_num,
307       o_err_msg             => l_err_msg
308     );
309 
310   ELSIF ( l_action_id = 30 and l_txn_qty < 0 and l_flow_schedule <> 1 ) THEN
311 
312     CSTPLCAS.scrap_return
313     (
314       i_cost_method_id      => l_cost_method,
315       i_txn_id              => l_trx_id,
316       i_layer_id            => l_layer_id,
317       i_inv_item_id         => l_inv_item_id,
318       i_org_id              => l_org_id,
319       i_wip_entity_id       => l_wip_entity_id,
320       i_txn_qty             => l_txn_qty,
321       i_op_seq_num          => l_op_seq_num,
322       i_user_id             => l_user_id,
323       i_login_id            => l_login_id,
324       i_request_id          => l_request_id,
325       i_prog_id             => l_prog_id,
326       i_prog_appl_id        => l_prog_app_id,
327       o_err_num             => l_err_num,
328       o_err_msg             => l_err_msg
329     );
330 
331   ELSIF ( (l_action_id = 31 OR (l_action_id=30 AND l_txn_qty>0) ) AND
332           l_flow_schedule = 1 ) THEN
333 
334     CSTPCFMS.wip_cfm_complete
335     (
336       i_trx_id              => l_trx_id,
337       i_org_id              => l_org_id,
338       i_inv_item_id         => l_inv_item_id,
339       i_txn_qty             => l_txn_qty,
340       i_wip_entity_id       => l_wip_entity_id,
341       i_txn_src_type_id     => 5,
342       i_flow_schedule       => l_flow_schedule,
343       i_txn_action_id       => l_action_id,
344       i_user_id             => l_user_id,
345       i_login_id            => l_login_id,
346       i_request_id          => l_request_id,
347       i_prog_id             => l_prog_id,
348       i_prog_appl_id        => l_prog_app_id,
349       err_num               => l_err_num,
350       err_code              => l_err_code,
351       err_msg               => l_err_msg
352     );
353 
354   ELSIF ( (l_action_id = 32 OR (l_action_id=30 AND l_txn_qty<0) ) AND
355           l_flow_schedule = 1 ) THEN
356 
357     CSTPCFMS.wip_cfm_assy_return
358     (
359       i_trx_id              => l_trx_id,
360       i_org_id              => l_org_id,
361       i_inv_item_id         => l_inv_item_id,
362       i_txn_qty             => l_txn_qty,
363       i_wip_entity_id       => l_wip_entity_id,
364       i_txn_src_type_id     => 5,
365       i_flow_schedule       => l_flow_schedule,
366       i_txn_action_id       => l_action_id,
367       i_user_id             => l_user_id,
368       i_login_id            => l_login_id,
369       i_request_id          => l_request_id,
370       i_prog_id             => l_prog_id,
371       i_prog_appl_id        => l_prog_app_id,
372       err_num               => l_err_num,
373       err_code              => l_err_code,
374       err_msg               => l_err_msg
375     );
376 
377   ELSE
378 
379     l_err_num  := 1101;
380     l_err_code := 'CSTPLCWP: Unsupported MMT transaction type';
381     l_err_msg  := 'CSTPLCWP: Unsupported MMT transaction type';
382 
383   END IF;
384 
385 
386   -- Check if processing is succesful, if not, pass control back to calling
387   -- module.
388 
389   IF (l_err_num<>0) THEN
390     raise proc_fail;
391   END IF;
392 
393 
394 
395 
396     -- Flush out all WIP layer quantities after CFM completion, return,
397     -- or scrap transactions
398 
399   IF ( l_flow_schedule = 1 and l_action_id in (30, 31, 32) ) THEN
400 
401     stmt_num := 120;
402     update cst_wip_layers CWL
403     set
404       CWL.relieved_matl_comp_qty =
405       ( CWL.applied_matl_qty -
406         CWL.relieved_matl_scrap_qty -
407         CWL.relieved_matl_final_comp_qty ),
408       CWL.temp_relieved_qty =
409       ( CWL.applied_matl_qty -
410         CWL.relieved_matl_comp_qty -
411         CWL.relieved_matl_scrap_qty -
412         CWL.relieved_matl_final_comp_qty )
413     where
414       CWL.wip_entity_id = l_wip_entity_id and
415       ( CWL.applied_matl_qty -
416         CWL.relieved_matl_comp_qty -
417         CWL.relieved_matl_scrap_qty -
418         CWL.relieved_matl_final_comp_qty ) >= 0;
419 
420     stmt_num := 130;
421     update cst_wip_layers CWL
422     set
423       CWL.relieved_matl_final_comp_qty =
424       ( CWL.applied_matl_qty -
425         CWL.relieved_matl_comp_qty -
426         CWL.relieved_matl_scrap_qty ),
427       CWL.temp_relieved_qty =
428       ( CWL.applied_matl_qty -
429         CWL.relieved_matl_comp_qty -
430         CWL.relieved_matl_scrap_qty -
431         CWL.relieved_matl_final_comp_qty )
432     where
433       CWL.wip_entity_id = l_wip_entity_id and
434       ( CWL.applied_matl_qty -
435         CWL.relieved_matl_comp_qty -
436         CWL.relieved_matl_scrap_qty -
437         CWL.relieved_matl_final_comp_qty ) < 0;
438 
439   END IF;
440 
441 
442 
443 
444   -- All the logic below should be exectued only if the transaction
445   -- is not a CITW txn.  If it is then the cost proc and distbn proc
446   -- is done within CSTPACIn, the Inv library.
447 
448   IF (l_comm_iss_flag <> 1) THEN
449 
450 
451     /*----------------------------------------------------
452     | The cost processor operates under the assumption that
453     | if there are no rows in the transaction cost table,
454     | then the transaction occured at the current average
455     | cost. For component issue/return transactions we
456     | therefore deliberately refrain from inserting a
457     | cost row. For completions, assembly returns and
458     | scrap transactions however, in the respective
459     | packages, we do not insert  row if the cost is zero.
460     | To prevent such transactions from being processed at
461     | current average cost, we need to insert a dummy
462     | TL materil row into the cost table with zero cost.
463     |------------------------------------------------------*/
464 
465 
466 
467     stmt_num := 140;
468 
469     select count(*)
470     into   l_mtl_txn_exists
471     from   mtl_cst_txn_cost_details
472     where  transaction_id = l_trx_id;
473 
474     IF( l_mtl_txn_exists=0 AND
475         ( l_action_id=30 OR l_action_id=31 OR l_action_id=32 ) ) THEN
476 
477 
478       stmt_num := 150;
479 
480       INSERT INTO mtl_cst_txn_cost_details
481       (
482         TRANSACTION_ID,
483         ORGANIZATION_ID,
484         INVENTORY_ITEM_ID,
485         COST_ELEMENT_ID,
486         LEVEL_TYPE,
487         TRANSACTION_COST,
488         NEW_AVERAGE_COST,
489         PERCENTAGE_CHANGE,
490         VALUE_CHANGE,
491         LAST_UPDATE_DATE,
492         LAST_UPDATED_BY,
493         CREATION_DATE,
494         CREATED_BY,
495         LAST_UPDATE_LOGIN,
496         REQUEST_ID,
497         PROGRAM_APPLICATION_ID,
498         PROGRAM_ID,
499         PROGRAM_UPDATE_DATE
500       )
501       VALUES
502       (
503         l_trx_id,
504         l_org_id,
505         l_inv_item_id,
506         1,
507         1,
508         0,
509         NULL,
510         NULL,
511         NULL,
512         SYSDATE,
513         l_user_id,
514         SYSDATE,
515         l_user_id,
516         l_login_id,
517         l_request_id,
518         l_prog_app_id,
519         l_prog_id,
520         SYSDATE
521       );
522 
523     END IF;
524 
525 
526 
527 
528     -- For all txns call the cost processor, then the distribution
529     -- processor. Note that for scrap there is no avg cost recomputed though.
530 
531     -- This calls the new FIFO cost processor
532 
533     CSTPLVCP.cost_processor
534     (
535       i_org_id          => l_org_id,
536       i_txn_id          => l_trx_id,
537       i_layer_id        => l_layer_id,
538       i_cost_type       => l_cost_type_id,
539       i_cost_method     => l_cost_method,
540       i_mat_ct_id       => l_movhd_cost_type_id,
541       i_avg_rates_id    => l_rates_cost_type_id,
542       i_item_id         => l_inv_item_id,
543       i_txn_qty         => l_txn_qty,
544       i_txn_action_id   => l_action_id,
545       i_txn_src_type    => 5,
546       i_txn_org_id      => l_org_id,
547       i_txfr_org_id     => NULL,
548       i_cost_grp_id     => l_cost_grp_id,
549       i_txfr_cost_grp   => l_txfr_cost_grp_id,
550       i_txfr_layer_id   => NULL,
551       i_fob_point       => NULL,
552       i_exp_item        => l_exp_item_flag,
553       i_exp_flag        => l_exp_flag,
554       i_citw_flag       => 0,
555       i_flow_schedule   => l_flow_schedule,
556       i_user_id         => l_user_id,
557       i_login_id        => l_login_id,
558       i_req_id          => l_request_id,
559       i_prg_appl_id     => l_prog_app_id,
560       i_prg_id          => l_prog_id,
561       i_tprice_option     => 0,
562       i_txf_price         => 0,
563       o_err_num         => l_err_num,
564       o_err_code        => l_err_code,
565       o_err_msg         => l_err_msg
566     );
567 
568 
569     /****************************************************
570     *Call distribution processor - if the avg cost proc**
571     *succeeds                                          **
572     *****************************************************/
573 
574     IF (l_err_num<>0) THEN
575        raise proc_fail;
576     ELSE
577 
578       CSTPACDP.cost_txn
579       (
580         i_org_id            => l_org_id,
581         i_txn_id            => l_trx_id,
582         i_layer_id          => l_layer_id,
583         i_fob_point         => NULL,
584         i_exp_item          => l_exp_item_flag,
585         I_COMM_ISS_FLAG     => L_COMM_ISS_FLAG,
586         i_flow_schedule     => l_flow_schedule,
587         I_USER_ID           => l_user_id,
588         i_login_id          => l_login_id,
589         i_req_id            => l_request_id,
590         i_prg_appl_id       => l_prog_app_id,
591         i_prg_id            => l_prog_id,
592         i_tprice_option     => 0,
593         i_txf_price         => 0,
594         o_error_num         => l_err_num,
595         o_error_code        => l_err_code,
596         o_error_message     => l_err_msg
597       );
598 
599     END IF;
600 
601 
602 
603     IF (l_err_num<>0) THEN
604       raise proc_fail;
605     END IF;
606 
607     /* Create SLA Event */
608     l_trx_info.TRANSACTION_ID       := l_trx_id;
609     l_trx_info.TXN_ACTION_ID        := l_action_id;
610     l_trx_info.TXN_ORGANIZATION_ID  := l_org_id;
611     l_trx_info.TXN_SRC_TYPE_ID      := l_src_type_id;
612     l_trx_info.TRANSACTION_DATE     := l_txn_date;
613 
614     CST_XLA_PVT.Create_INVXLAEvent (
615       p_api_version       => 1.0,
616       p_init_msg_list     => FND_API.G_FALSE,
617       p_commit            => FND_API.G_FALSE,
618       p_validation_level  => FND_API.G_VALID_LEVEL_FULL,
619       x_return_status     => l_return_status,
620       x_msg_count         => l_msg_count,
621       x_msg_data          => l_msg_data,
622       p_trx_info          => l_trx_info
623     );
624     IF l_return_status <> 'S' THEN
625       l_err_num := -1;
626       l_err_code := 'Error raising SLA Event for transaction: '||to_char(l_trx_id);
627       RAISE proc_fail;
628     END IF;
629 
630 
631   END IF; -- CITW condition check IF statement ends here.
632 
633   /*---------------------------------------------------------
634   | If processing was succesful in the prior step, we need
635   | to update wip_period_balances.
636   |----------------------------------------------------------*/
637 
638   stmt_num := 160;
639 
640   select count(*)
641   into   l_row_count
642   from   mtl_cst_actual_cost_details
643   where  transaction_id = l_trx_id;
644 
645 
646   IF (l_row_count <> 0) THEN
647 
648     IF ( l_action_id = 1  OR
649          l_action_id = 27 OR
650          l_action_id = 33 OR
651          l_action_id = 34 ) THEN
652 
653       CSTPACWB.cost_in
654       (
655         i_trx_id               => l_trx_id,
656         i_layer_id             => l_layer_id,
657         i_comm_iss_flag        => l_comm_iss_flag,
658         I_COST_TXN_ACTION_ID   => l_action_id,
659         i_txn_qty              => l_txn_qty,
660         i_period_id            => l_period_id,
661         i_wip_entity_id        => l_wip_entity_id,
662         i_org_id               => l_org_id,
663         i_user_id              => l_user_id,
664         i_request_id           => l_request_id,
665         err_num                => l_err_num,
666         err_code               => l_err_code,
667         err_msg                => l_err_msg
668       );
669 
670       /* Bug 3062249 - Call EAM API only if transaction is not CITW
671          This is because, distributions have not yet been created for
672          CITW txns. For these, EAM API will be called in CSTPACIN */
673       if (l_comm_iss_flag <> 1) then
674 
675       /* Check if the job is EAM. If yes, then update material asset cost */
676       if (l_err_num = 0) then
677         select entity_type
678         into l_entity_type
679         from wip_entities
680         where wip_entity_id = l_wip_entity_id;
681 
682         if (l_entity_type in (6,7)) then
683          CST_eamCost_PUB.process_matCost (
684 		p_api_version	=>	1.0,
685 		x_return_status	=>	l_return_status,
686 		x_msg_count	=>	l_msg_count,
687 		x_msg_data	=>	l_msg_data,
688 		p_txn_id	=>	l_trx_id,
689 		p_user_id	=>	l_user_id,
690 		p_request_id	=>	l_request_id,
691 		p_prog_id	=>	l_prog_id,
692 		p_prog_app_id	=>	l_prog_app_id,
693 		p_login_id	=>	l_login_id
694           );
695 
696           if (l_return_status <> fnd_api.g_ret_sts_success) then
697              CST_UTILITY_PUB.writelogmessages
698                   ( p_api_version	=>	1.0,
699 		    p_msg_count		=>	l_msg_count,
700 		    p_msg_data		=>	l_msg_data,
701 		    x_return_status	=>	l_msg_return_status );
702              l_err_num := l_msg_count;
703           else
704              l_err_num := 0;
705           end if;
706         end if;
707       end if;
708      end if; --not citw for EAM API check
709 
710     ELSIF( (l_action_id = 31 OR
711            l_action_id = 32 OR
712            l_action_id = 30) AND l_exp_item_flag <>1 ) THEN
713 
714       CSTPACWB.cost_out
715       (
716         i_trx_id          => l_trx_id,
717         i_txn_qty         => l_txn_qty,
718         i_period_id       => l_period_id,
719         i_wip_entity_id   => l_wip_entity_id,
720         i_org_id          => l_org_id,
721         i_user_id         => l_user_id,
722         i_request_id      => l_request_id,
723         err_num           => l_err_num,
724         err_code          => l_err_code,
725         err_msg           => l_err_msg
726       );
727 
728     END IF;
729 
730 
731 
732     -- Raise exception if there is an error in updating WPB.
733 
734     IF (l_err_num<>0) THEN
735       raise proc_fail;
736     END IF;
737 
738   END IF;
739 
740 
741 
742 
743 EXCEPTION
744 
745   WHEN proc_fail THEN
746     err_num := l_err_num;
747     err_code := l_err_code;
748     err_msg := l_err_msg;
749     ROLLBACK;
750 
751   WHEN OTHERS THEN
752     err_num := SQLCODE;
753     err_msg := 'CSTPLCWP:' || to_char(stmt_num) || substr(SQLERRM,1,150);
754     ROLLBACK;
755 
756 END cost_wip_trx;
757 
758 
759 END CSTPLCWP;