DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSI_TIME_BASED_CTR_ENGINE_PKG

Source


1 PACKAGE BODY CSI_Time_Based_Ctr_Engine_PKG AS
2 /* $Header: csictimb.pls 120.11.12020000.6 2013/01/08 05:23:33 jrkumar ship $ */
3 
4 --
5 /*******************************
6  * Private program units *
7  *******************************/
8 
9 PROCEDURE Increment_Reading
10 (
11    p_capture_date   IN  DATE,
12    p_ctr_id	    IN  NUMBER,
13    p_ctr_rdg	    IN  NUMBER,
14    p_txn_rec	IN	csi_datastructures_pub.transaction_rec, -- bug 15972103
15    x_return_status  OUT NOCOPY VARCHAR2,
16    x_msg_data       OUT NOCOPY VARCHAR2,
17    x_msg_count      OUT NOCOPY NUMBER
18 ) IS
19 
20    -- l_txn_rec                 csi_datastructures_pub.transaction_rec;
21    l_ctr_rdg_rec             csi_ctr_datastructures_pub.counter_readings_rec;
22    l_msg_index               NUMBER;
23    l_msg_count               NUMBER;
24    --
25 BEGIN
26    SAVEPOINT Increment_Reading;
27    --
28    fnd_file.put_line(fnd_file.log, 'Inside Increment_Reading...');
29    fnd_file.put_line(fnd_file.log, 'p_ctr_id :'||p_ctr_id);
30    fnd_file.put_line(fnd_file.log, 'p_ctr_rdg :'||p_ctr_rdg);
31    fnd_file.put_line(fnd_file.log, 'p_capture_date :'||to_char(p_capture_date,'DD-MON-YYYY HH24:MI:SS'));
32    -- bug 15972103
33    --
34    --l_txn_rec.source_transaction_date := sysdate;
35    --l_txn_rec.transaction_type_id := 89;
36    --l_txn_rec.source_header_ref_id := 0;
37    --
38    l_ctr_rdg_rec.counter_id := p_ctr_id;
39    l_ctr_rdg_rec.value_timestamp := p_capture_date;
40    l_ctr_rdg_rec.counter_reading := p_ctr_rdg;
41    --
42    /* -- bug 15972103
43    Csi_Counter_Readings_Pvt.Create_Reading_Transaction
44 	 ( p_api_version           =>  1.0
45 	  ,p_commit                =>  fnd_api.g_false
46 	  ,p_init_msg_list         =>  fnd_api.g_true
47 	  ,p_validation_level      =>  fnd_api.g_valid_level_full
48 	  ,p_txn_rec               =>  l_txn_rec
49 	  ,x_return_status         =>  x_return_status
50 	  ,x_msg_count             =>  x_msg_count
51 	  ,x_msg_data              =>  x_msg_data
52 	 );*/
53    IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
54       fnd_file.put_line(fnd_file.log,'Error from Create_Reading_Transaction...');
55       l_msg_index := 1;
56       FND_MSG_PUB.Count_And_Get
57 	      (p_count  =>  x_msg_count,
58 	       p_data   =>  x_msg_data
59 	      );
60       l_msg_count := x_msg_count;
61       WHILE l_msg_count > 0 LOOP
62 	 x_msg_data := FND_MSG_PUB.GET
63 		    (  l_msg_index,
64 		       FND_API.G_FALSE        );
65 	 fnd_file.put_line(fnd_file.log,'MESSAGE DATA = '||x_msg_data);
66 	 l_msg_index := l_msg_index + 1;
67 	 l_msg_count := l_msg_count - 1;
68       END LOOP;
69       RAISE FND_API.G_EXC_ERROR;
70    END IF;
71    fnd_file.put_line(fnd_file.log, 'Inserting Counter Reading...');
72    select CSI_COUNTER_READINGS_S.nextval
73    into l_ctr_rdg_rec.counter_value_id from dual;
74    --
75       CSI_COUNTER_READINGS_PKG.Insert_Row(
76 	  px_COUNTER_VALUE_ID         =>  l_ctr_rdg_rec.counter_value_id
77 	 ,p_COUNTER_ID                =>  l_ctr_rdg_rec.counter_id
78 	 ,p_VALUE_TIMESTAMP           =>  l_ctr_rdg_rec.value_timestamp
79 	 ,p_COUNTER_READING           =>  l_ctr_rdg_rec.counter_reading
80 	 ,p_RESET_MODE                =>  NULL
81 	 ,p_RESET_REASON              =>  NULL
82 	 ,p_ADJUSTMENT_TYPE           =>  NULL
83 	 ,p_ADJUSTMENT_READING        =>  NULL
84 	 ,p_OBJECT_VERSION_NUMBER     =>  1
85 	 ,p_LAST_UPDATE_DATE          =>  SYSDATE
86 	 ,p_LAST_UPDATED_BY           =>  fnd_global.user_id
87 	 ,p_CREATION_DATE             =>  SYSDATE
88 	 ,p_CREATED_BY                =>  fnd_global.user_id
89 	 ,p_LAST_UPDATE_LOGIN         =>  fnd_global.conc_login_id
90 	 ,p_ATTRIBUTE1                =>  NULL
91 	 ,p_ATTRIBUTE2                =>  NULL
92 	 ,p_ATTRIBUTE3                =>  NULL
93 	 ,p_ATTRIBUTE4                =>  NULL
94 	 ,p_ATTRIBUTE5                =>  NULL
95 	 ,p_ATTRIBUTE6                =>  NULL
96 	 ,p_ATTRIBUTE7                =>  NULL
97 	 ,p_ATTRIBUTE8                =>  NULL
98 	 ,p_ATTRIBUTE9                =>  NULL
99 	 ,p_ATTRIBUTE10               =>  NULL
100 	 ,p_ATTRIBUTE11               =>  NULL
101 	 ,p_ATTRIBUTE12               =>  NULL
102 	 ,p_ATTRIBUTE13               =>  NULL
103 	 ,p_ATTRIBUTE14               =>  NULL
104 	 ,p_ATTRIBUTE15               =>  NULL
105 	 ,p_ATTRIBUTE16               =>  NULL
106 	 ,p_ATTRIBUTE17               =>  NULL
107 	 ,p_ATTRIBUTE18               =>  NULL
108 	 ,p_ATTRIBUTE19               =>  NULL
109 	 ,p_ATTRIBUTE20               =>  NULL
110 	 ,p_ATTRIBUTE21               =>  NULL
111 	 ,p_ATTRIBUTE22               =>  NULL
112 	 ,p_ATTRIBUTE23               =>  NULL
113 	 ,p_ATTRIBUTE24               =>  NULL
114 	 ,p_ATTRIBUTE25               =>  NULL
115 	 ,p_ATTRIBUTE26               =>  NULL
116 	 ,p_ATTRIBUTE27               =>  NULL
117 	 ,p_ATTRIBUTE28               =>  NULL
118 	 ,p_ATTRIBUTE29               =>  NULL
119 	 ,p_ATTRIBUTE30               =>  NULL
120 	 ,p_ATTRIBUTE_CATEGORY        =>  NULL
121 	 ,p_MIGRATED_FLAG             =>  'N'
122 	 ,p_COMMENTS                  =>  NULL
123 	 ,p_LIFE_TO_DATE_READING      =>  l_ctr_rdg_rec.counter_reading
124 	 ,p_TRANSACTION_ID            =>  p_txn_rec.transaction_id -- bug 15972103
125 	 ,p_AUTOMATIC_ROLLOVER_FLAG   =>  NULL
126 	 ,p_INCLUDE_TARGET_RESETS     =>  NULL
127 	 ,p_SOURCE_COUNTER_VALUE_ID   =>  NULL
128 	 ,p_NET_READING               =>  l_ctr_rdg_rec.counter_reading
129 	 ,p_DISABLED_FLAG             =>  'N'
130 	 ,p_SOURCE_CODE               =>  NULL
131 	 ,p_SOURCE_LINE_ID            =>  NULL
132 	 ,p_INITIAL_READING_FLAG      =>  NULL
133        );
134       -- Added for FP Tracking bug 7390758 (base bug 7374316)
135       CSI_COUNTER_PVT.update_ctr_val_max_seq_no(
136           p_api_version           =>  1.0
137          ,p_commit                =>  fnd_api.g_false
138          ,p_init_msg_list         =>  fnd_api.g_true
139          ,p_validation_level      =>  fnd_api.g_valid_level_full
140          ,p_counter_id            =>  l_ctr_rdg_rec.counter_id
141          ,px_ctr_val_max_seq_no   =>  l_ctr_rdg_rec.counter_value_id
142          ,x_return_status         =>  x_return_status
143          ,x_msg_count             =>  x_msg_count
144          ,x_msg_data              =>  x_msg_data
145          );
146 
147       IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
148         l_msg_index := 1;
149         l_msg_count := x_msg_count;
150 	WHILE l_msg_count > 0 LOOP
151           x_msg_data := FND_MSG_PUB.GET
152             (l_msg_index,
153             FND_API.G_FALSE
154 	    );
155           csi_ctr_gen_utility_pvt.put_line('ERROR FROM CSI_COUNTER_PVT.update_ctr_val_max_seq_no');
156 	  csi_ctr_gen_utility_pvt.put_line('MESSAGE DATA = '||x_msg_data);
157 	  l_msg_index := l_msg_index + 1;
158 	  l_msg_count := l_msg_count - 1;
159         END LOOP;
160 	RAISE FND_API.G_EXC_ERROR;
161       END IF;
162    -- End add for FP Tracking bug 7390758 (base bug 7374316)
163    --
164    fnd_file.put_line(fnd_file.log, 'Calling OKC Assembler Event...');
165    OKC_CG_UPD_ASMBLR_PVT.Acn_Assemble
166       (  p_api_version        =>  1.0,
167 	 x_return_status      =>  x_return_status,
168 	 x_msg_count          =>  x_msg_count,
169 	 x_msg_data           =>  x_msg_data,
170 	 p_counter_id         =>  l_ctr_rdg_rec.counter_id
171       );
172    IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
173       fnd_file.put_line(fnd_file.log,'ERROR FROM OKC_CG_UPD_ASMBLR_PVT.Acn_Assemble API ');
174       l_msg_index := 1;
175       l_msg_count := x_msg_count;
176       WHILE l_msg_count > 0 LOOP
177 	 x_msg_data := FND_MSG_PUB.GET
178 	 (  l_msg_index,
179 	    FND_API.G_FALSE
180 	 );
181 	 fnd_file.put_line(fnd_file.log,'MESSAGE DATA = '||x_msg_data);
182 	 l_msg_index := l_msg_index + 1;
183 	 l_msg_count := l_msg_count - 1;
184       END LOOP;
185       RAISE FND_API.G_EXC_ERROR;
186    END IF;
187 EXCEPTION
188    WHEN FND_API.G_EXC_ERROR THEN
189       x_return_status := FND_API.G_RET_STS_ERROR;
190       Rollback To Increment_Reading;
191    WHEN OTHERS THEN
192       x_return_status := FND_API.G_RET_STS_ERROR;
193       Rollback To Increment_Reading;
194       fnd_file.put_line(fnd_file.log,'Into when others error in Increment_Reading...');
195       fnd_file.put_line(fnd_file.log,sqlerrm);
196 END Increment_Reading;
197 --
198 
199 FUNCTION DOES_FORMULA_COUNTER_EXISTS
200          (p_src_counter_id IN NUMBER)
201 RETURN BOOLEAN IS
202    l_return_value  BOOLEAN := FALSE;
203    l_exists        VARCHAR2(1);
204    l_rel_type      VARCHAR2(30) := 'FORMULA';
205 BEGIN
206    Begin
207       select '1'
208       into l_exists
209       from dual
210       where exists (select distinct object_counter_id
211                      from csi_counter_relationships
212                      where source_counter_id = p_src_counter_id
213                      and   relationship_type_code = 'FORMULA'
214                      and   nvl(active_end_date,(sysdate+1)) > sysdate
215                      AND ROWNUM = 1);
216       l_return_value := TRUE;
217    Exception
218       when no_data_found then
219          l_return_value := FALSE;
220    End;
221    RETURN l_return_value;
222 END DOES_FORMULA_COUNTER_EXISTS;
223 
224 
225 /*******************************
226  * Public program units *
227  *******************************/
228 
229 --This is the main procedure that will be called as a conc program
230 PROCEDURE Capture_Readings
231   (
232      errbuf	OUT NOCOPY VARCHAR2,
233      retcode	OUT NOCOPY NUMBER,
234      p_counter_group_id IN NUMBER --bug 16041167
235   ) IS
236    l_incr_rdg	   NUMBER;	--incremental reading
237    l_new_rdg       NUMBER;	--incremental reading
238    l_run_time	   DATE;
239    l_conc_start_time DATE;
240    l_ctr_rdg       NUMBER;
241    l_ctr_value_id  NUMBER;
242    l_timestamp     DATE;
243    l_ctr_creation_date DATE;
244    x_msg_data      VARCHAR2(2000);
245    x_msg_count     NUMBER;
246    x_return_status VARCHAR2(1);
247    l_counter       NUMBER := 0;
248    l_days          NUMBER;
249    l_day_uom_code  VARCHAR2(30);
250    l_hour_uom_code  VARCHAR2(30);
251    l_ignore_time_component  VARCHAR2(30);
252    l_formula_ctr_rec               csi_ctr_datastructures_pub.counter_readings_rec;
253    l_txn_rec                       csi_datastructures_pub.transaction_rec;
254    l_temp_txn_rec                       csi_datastructures_pub.transaction_rec;
255    l_msg_index NUMBER;
256    l_msg_count NUMBER;
257    --
258    --bug 16041167, new parameter added to ctr_cur
259    CURSOR CTR_CUR(p_counter_group_id IN NUMBER) IS
260    SELECT ctr.counter_id, ctr.creation_date, ctr.uom_code, ctr.ctr_val_max_seq_no --Bug 15972103
261    FROM   CSI_COUNTERS_B ctr, CS_CSI_COUNTER_GROUPS ccg
262    WHERE  ctr.group_id  =   ccg.counter_group_id
263    AND    ccg.created_from_ctr_grp_tmpl_id  = nvl(p_counter_group_id, ccg.created_from_ctr_grp_tmpl_id)
264    AND    ccg.template_flag    = 'N'
265    AND    ctr.counter_type = 'REGULAR'
266    AND    nvl(ctr.end_date_active,(sysdate+1)) > sysdate
267    AND    nvl(ctr.time_based_manual_entry, 'N') = 'N'
268    AND    exists (select 'x'
269                   from   MTL_UNITS_OF_MEASURE_VL uom
270                   where  upper(uom.uom_class) = 'TIME'
271                   and    uom.uom_code = ctr.uom_code);
272 
273   TYPE counter_array IS TABLE OF CTR_CUR%ROWTYPE;
274   time_ctr_array counter_array;
275  --
276    CURSOR RDG_CUR(p_ctr_val_max_seq_no IN NUMBER) IS  --Bug 15972103
277    SELECT counter_value_id,counter_reading,value_timestamp
278    FROM CSI_COUNTER_READINGS
279    WHERE counter_value_id = p_ctr_val_max_seq_no --Bug 15972103
280    AND   nvl(disabled_flag,'N') = 'N'
281    ORDER BY value_timestamp desc;
282 
283 BEGIN
284    l_run_time := sysdate;
285    l_conc_start_time := l_run_time;
286    fnd_file.put_line(fnd_file.log, 'Start Execution : '|| to_char(sysdate, 'DD-MON-YYYY HH24:MI:SS'));
287    --
288    l_day_uom_code := FND_PROFILE.VALUE('DAY_UNIT_OF_MEASURE');
289    l_hour_uom_code := FND_PROFILE.VALUE('HOUR_UNIT_OF_MEASURE');
290    l_ignore_time_component := FND_PROFILE.VALUE('CSI_IGNORE_TIME_COMPONENT');
291    --
292    IF l_day_uom_code IS NULL THEN
293       fnd_file.put_line(fnd_file.log,'DAY_UNIT_OF_MEASURE Profile Not Set..');
294       errbuf := 'DAY_UNIT_OF_MEASURE Profile Not Set';
295       RAISE FND_API.G_EXC_ERROR;
296    END IF;
297    --
298    --Bug 15972103
299    l_txn_rec := l_temp_txn_rec;
300    l_txn_rec.source_transaction_date := sysdate;
301    l_txn_rec.transaction_type_id := 89;
302    l_txn_rec.source_header_ref_id := 0;
303 
304    Csi_Counter_Readings_Pvt.Create_Reading_Transaction
305 	( p_api_version           =>  1.0
306 	,p_commit                =>  fnd_api.g_false
307 	,p_init_msg_list         =>  fnd_api.g_true
308 	,p_validation_level      =>  fnd_api.g_valid_level_full
309 	,p_txn_rec               =>  l_txn_rec
310 	,x_return_status         =>  x_return_status
311 	,x_msg_count             =>  x_msg_count
312 	,x_msg_data              =>  x_msg_data
313 	);
314    --
315 
316    OPEN ctr_cur(p_counter_group_id); --bug 16041167
317    LOOP
318    FETCH ctr_cur BULK COLLECT INTO time_ctr_array LIMIT 1000;
319 
320    --FOR i IN time_ctr_array.first..time_ctr_array.last --bug 16041167
321    FOR i IN 1..time_ctr_array.COUNT
322    loop
323       fnd_file.put_line(fnd_file.log, '------------------------------------------------------');
324      -- fnd_file.put_line(fnd_file.log, 'Fetched ctr-id '|| to_char(time_ctr_array(i).counter_id));
325 
326       -- Bug 9210555
327       --
328       -- If "CSI: Ignore Counter time component" profile is set to 'Y'
329       -- then runtime will be truncated to ignore time component
330       -- If "CSI: Ignore Counter time component" is Null or 'N'
331       -- then time component and date/time calculation decimals are not
332       -- ignored
333       --
334       -- Ignoring Time component is valid only for Day and Hour
335       -- bases counters
336       -- In case of Day based counter Hour/Minutes/Seconds will be truncated
337       -- In case of Hour Based Counter Minutes/Seconds will be truncated
338 
339       IF (UPPER(time_ctr_array(i).uom_code) = l_day_uom_code)
340          AND ( NVL(l_ignore_time_component,'N') = 'Y') THEN
341         fnd_file.put_line(fnd_file.log, 'Truncating time component from concurrent program start time');
342         l_run_time := trunc(to_date(sysdate), 'DDD');
343         l_ctr_creation_date := trunc(to_date(time_ctr_array(i).creation_date), 'DDD');
344       ELSIF (UPPER(time_ctr_array(i).uom_code) = l_hour_uom_code)
345          AND ( NVL(l_ignore_time_component,'N') = 'Y') THEN
346         -- ER 9285073
347         fnd_file.put_line(fnd_file.log, 'Truncating minutes/seconds component from concurrent program start time');
348         l_run_time := trunc(l_conc_start_time, 'HH');
349         l_ctr_creation_date := trunc(time_ctr_array(i).creation_date, 'HH');
350       ELSE
351         fnd_file.put_line(fnd_file.log, 'Retaining concurrent program start time');
352         l_run_time := l_conc_start_time;
353         l_ctr_creation_date := time_ctr_array(i).creation_date;
354       END IF;
355 
356       -- End Bug 9210555
357       --
358 
359       l_ctr_value_id := NULL;
360       l_ctr_rdg := NULL;
361       l_timestamp := NULL;
362       --
363       --OPEN RDG_CUR(time_ctr_array(i).counter_id);
364       OPEN RDG_CUR(time_ctr_array(i).ctr_val_max_seq_no);  --Bug 15972103
365       FETCH RDG_CUR INTO l_ctr_value_id,l_ctr_rdg,l_timestamp;
366       CLOSE RDG_CUR;
367 
368       --
369       l_days := l_run_time - nvl(l_timestamp,l_ctr_creation_date);
370       fnd_file.put_line(fnd_file.log, 'l_days '|| l_days);
371       fnd_file.put_line(fnd_file.log, 'l_run_time'|| to_char(l_run_time, 'DD-MON-YYYY HH24:MI:SS'));
372       fnd_file.put_line(fnd_file.log, 'l_timestamp'|| to_char(l_timestamp, 'DD-MON-YYYY HH24:MI:SS'));
373       fnd_file.put_line(fnd_file.log, 'l_day_uom_code'|| to_char(l_day_uom_code));
374       fnd_file.put_line(fnd_file.log, 'l_hour_uom_code'|| to_char(l_hour_uom_code));
375       fnd_file.put_line(fnd_file.log, 'time_ctr_array(i).uom_code'|| to_char(time_ctr_array(i).uom_code));
376       IF l_days = 0 THEN
377          l_incr_rdg := 0;
378       ELSE
379          l_incr_rdg := oks_time_measures_pub.get_target_qty
380                              ( p_start_date     =>  nvl(l_timestamp,time_ctr_array(i).creation_date),
381                                p_source_qty     =>  l_days,
382                                p_source_uom     =>  l_day_uom_code,
383                                p_target_uom     =>  time_ctr_array(i).uom_code,
384                                p_round_dec      =>  1
385                              );
386       END IF;
387       --
388       fnd_file.put_line(fnd_file.log, 'l_incr_rdg'|| to_char(l_incr_rdg));
389       IF l_incr_rdg >= 1 THEN
390          IF l_ctr_value_id IS NULL THEN
391               -- This is the first rdg being captured
392               l_new_rdg := l_incr_rdg;
393            ELSE
394               l_new_rdg := l_incr_rdg + l_ctr_rdg;
395            END IF;
396            --
397            Increment_Reading
398                     ( p_capture_date     =>  l_run_time,
399                       p_ctr_id           =>  time_ctr_array(i).counter_id,
400                       p_ctr_rdg          =>  l_new_rdg,
401 		      p_txn_rec  	 =>  l_txn_rec, -- bug 15972103
402                       x_return_status    =>  x_return_status,
403                       x_msg_data         =>  x_msg_data,
404                       x_msg_count        =>  x_msg_count
405                     );
406            IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
407               RAISE FND_API.G_EXC_ERROR;
408            END IF;
409 
410       -- Moving the END IF to the end of formulae counter update block
411       -- END IF;
412       --
413 
414       -- Bug 9283089
415       -- Verify if formula counter exists for source counter id or not
416       IF (DOES_FORMULA_COUNTER_EXISTS(time_ctr_array(i).counter_id)) THEN
417 
418         fnd_file.put_line(fnd_file.log, 'Formual Counter Updating');
419 
420         --
421          -- Bug 9386676
422          /* bug 15972103
423          l_txn_rec := l_temp_txn_rec;
424          l_txn_rec.source_transaction_date := sysdate;
425          l_txn_rec.transaction_type_id := 89;
426          l_txn_rec.source_header_ref_id := 0;
427 
428          Csi_Counter_Readings_Pvt.Create_Reading_Transaction
429          ( p_api_version           =>  1.0
430           ,p_commit                =>  fnd_api.g_false
431           ,p_init_msg_list         =>  fnd_api.g_true
432           ,p_validation_level      =>  fnd_api.g_valid_level_full
433           ,p_txn_rec               =>  l_txn_rec
434           ,x_return_status         =>  x_return_status
435           ,x_msg_count             =>  x_msg_count
436           ,x_msg_data              =>  x_msg_data
437          );*/
438          IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
439             fnd_file.put_line(fnd_file.log,'Error from Create_Reading_Transaction...');
440             l_msg_index := 1;
441             FND_MSG_PUB.Count_And_Get
442               (p_count  =>  x_msg_count,
443                p_data   =>  x_msg_data
444               );
445             l_msg_count := x_msg_count;
446             WHILE l_msg_count > 0 LOOP
447            x_msg_data := FND_MSG_PUB.GET
448                 (  l_msg_index,
449                    FND_API.G_FALSE        );
450            fnd_file.put_line(fnd_file.log,'MESSAGE DATA = '||x_msg_data);
451            l_msg_index := l_msg_index + 1;
452            l_msg_count := l_msg_count - 1;
453             END LOOP;
454             RAISE FND_API.G_EXC_ERROR;
455          END IF;
456         -- End of bug 9386676
457 
458         l_formula_ctr_rec.counter_id := time_ctr_array(i).counter_id;
459 
460         -- Formula counter uses the same timestamp as used by source counter id
461         -- If the run time was truncated due profile value setup
462         -- the same run time is used for formula counter as well
463         l_formula_ctr_rec.value_timestamp := l_run_time;
464 
465         --l_formula_ctr_rec.disabled_flag := 'Y';
466         fnd_file.put_line(fnd_file.log, 'l_txn_rec.transaction_id - '|| l_txn_rec.transaction_id);
467         fnd_file.put_line(fnd_file.log, 'l_formula_ctr_rec.value_timestamp - '||to_char(l_formula_ctr_rec.value_timestamp, 'DD-MON-YYYY HH24:MI:SS'));
468         fnd_file.put_line(fnd_file.log, 'l_formula_ctr_rec.counter_id - '||l_formula_ctr_rec.counter_id);
469         fnd_file.put_line(fnd_file.log, 'Calling Compute_Formula_Counters');
470 
471         CSI_COUNTER_READINGS_PVT.Compute_Formula_Counters
472         (
473           p_api_version           => 1.0
474          ,p_commit                => FND_API.G_FALSE
475          ,p_init_msg_list         => FND_API.G_TRUE
476          ,p_validation_level      => fnd_api.g_valid_level_full
477          ,p_txn_rec               => l_txn_rec
478          ,p_ctr_rdg_rec           => l_formula_ctr_rec
479          ,x_return_status         => x_return_status
480          ,x_msg_count             => x_msg_count
481          ,x_msg_data              => x_msg_data
482        );
483          IF NOT(x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
484             fnd_file.put_line(fnd_file.log, 'Error from Compute_Formula_Counters API');
485             l_msg_index := 1;
486             l_msg_count := x_msg_count;
487             WHILE l_msg_count > 0 LOOP
488                x_msg_data := FND_MSG_PUB.GET
489                (  l_msg_index,
490                   FND_API.G_FALSE
491                );
492                fnd_file.put_line(fnd_file.log, 'MESSAGE DATA = '||x_msg_data);
493                l_msg_index := l_msg_index + 1;
494                l_msg_count := l_msg_count - 1;
495             END LOOP;
496             RAISE FND_API.G_EXC_ERROR;
497          END IF;
498       END IF; -- IS_FORMULA_COUNTER_EXISTS(time_ctr_array(i).counter_id)
499       -- End Bug 9283089
500 
501       -- This END IF is common to increment reading and formula computation
502       -- The formula computation is necessary only if source counter is updated
503       END IF; -- l_incr_rdg >= 1
504 
505       l_counter := l_counter + 1;
506       IF l_counter = 500 THEN
507          l_counter := 0;
508          commit;
509       END IF;
510    end loop;
511     EXIT WHEN ctr_cur%NOTFOUND;
512   END LOOP;
513 
514    fnd_file.put_line(fnd_file.log, '------------------------------------------------------');
515    fnd_file.put_line(fnd_file.log, 'Finished Execution : '|| to_char(sysdate, 'DD-MON-YYYY HH24:MI:SS'));
516    --
517    -- Return 0 for successful completion, 1 for warnings, 2 for error
518    errbuf := '';
519    retcode := 0;
520    --
521 EXCEPTION
522    WHEN FND_API.G_EXC_ERROR THEN
523       retcode := 2;
524       fnd_file.put_line(fnd_file.log,'Program Aborting....');
525    WHEN OTHERS THEN
526       fnd_file.put_line(fnd_file.log, 'Into when others in Capture_Readings..');
527       fnd_file.put_line(fnd_file.log,sqlerrm);
528       fnd_file.put_line(fnd_file.log,'Program Aborting....');
529       errbuf := sqlerrm;
530       retcode := 2;
531 END Capture_Readings;
532 --
533 END CSI_Time_Based_Ctr_Engine_PKG;