DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMF_API_WRP

Source


1 PACKAGE BODY GMF_API_WRP AS
2 /*  $Header: GMFPWRPB.pls 120.4.12000000.3 2007/05/02 10:21:14 pmarada ship $ */
3 
4 
5 /*  Body start of comments
6  +==========================================================================+
7  | PROCEDURE NAME                                                           |
8  |    Create_Item_Cost                                                      |
9  |                                                                          |
10  | TYPE                                                                     |
11  |    Public                                                                |
12  |                                                                          |
13  | USAGE                                                                    |
14  |    Create item Cost                                                      |
15  |                                                                          |
16  | DESCRIPTION                                                              |
17  |    This is a PL/SQL wrapper procedure to call the                        |
18  |    Create_Item_Cost API wrapper function                                 |
19  |                                                                          |
20  | PARAMETERS                                                               |
21  |    p_dir              IN VARCHAR2         - Working directory for input  |
22  |                                             and output files.            |
23  |    p_input_file       IN VARCHAR2         - Name of input file           |
24  |    p_output_file      IN VARCHAR2         - Name of output file          |
25  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
26  |                                                                          |
27  | RETURNS                                                                  |
28  |    None                                                                  |
29  |                                                                          |
30  | HISTORY                                                                  |
31  |    27/Feb/2001  Uday Moogala  Created  Bug# 1418689                      |
32  |                                                                          |
33  +==========================================================================+
34   Api end of comments
35 */
36   PROCEDURE         Create_Item_Cost
37   (
38   p_dir                 IN              VARCHAR2,
39   p_input_file          IN              VARCHAR2,
40   p_output_file         IN              VARCHAR2,
41   p_delimiter           IN              VARCHAR2
42   )
43   IS
44 
45     /******************
46     * Local variables *
47     ******************/
48     l_return_status  VARCHAR2(1);
49 
50   BEGIN
51     l_return_status  :=   Create_Item_Cost(p_dir, p_input_file, p_output_file, p_delimiter);
52   End Create_Item_Cost;
53 
54 /* +========================================================================+
55  | FUNCTION NAME                                                            |
56  |    Create_Item_Cost                                                      |
57  |                                                                          |
58  | TYPE                                                                     |
59  |    Public                                                                |
60  |                                                                          |
61  | USAGE                                                                    |
62  |    Create item Cost                                                      |
63  |                                                                          |
64  | DESCRIPTION                                                              |
65  |    This is a PL/SQL wrapper function to call the                         |
66  |    Create_Item_Cost API.                                                 |
67  |    It reads item data from a flat file and outputs any error             |
68  |    messages to a second flat file. It also generates a Status            |
69  |    called gmf_rsrc_wrapper<session_id>.log in the /tmp directory.        |
70  |                                                                          |
71  | PARAMETERS                                                               |
72  |    p_dir              IN VARCHAR2         - Working directory for input  |
73  |                                             and output files.            |
74  |    p_input_file       IN VARCHAR2         - Name of input file           |
75  |    p_output_file      IN VARCHAR2         - Name of output file          |
76  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
77  |                                                                          |
78  | RETURNS                                                                  |
79  |    VARCHAR2 - 'S' All records processed successfully                     |
80  |               'E' 1 or more records errored                              |
81  |               'U' 1 or more record unexpected error                      |
82  |                                                                          |
83  | HISTORY                                                                  |
84  | 06-Apr-07 Pmarada Bug 5586406 commented goto statment in after reading   |
85  |           line from file. because of this API inserting last record only |
86  |                                                                          |
87  +==========================================================================+
88   Api end of comments
89 */
90   FUNCTION Create_Item_Cost
91   (
92   p_dir                 IN              VARCHAR2,
93   p_input_file          IN              VARCHAR2,
94   p_output_file         IN              VARCHAR2,
95   p_delimiter           IN              VARCHAR2
96   )
97   RETURN VARCHAR2
98   IS
99 
100     /******************
101     * Local variables *
102     ******************/
103     l_status              VARCHAR2(11);
104     l_return_status       VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
105     l_count               NUMBER(10)  ;
106     l_record_count        NUMBER(10)  :=0;
107     l_loop_cnt            NUMBER(10)  :=0;
108     l_dummy_cnt           NUMBER(10)  :=0;
109     l_data                VARCHAR2(1000);
110     l_header_rec          GMF_ItemCost_PUB.Header_Rec_Type;
111     l_this_lvl_tbl        GMF_ItemCost_PUB.This_Level_Dtl_Tbl_Type;
112     l_lower_lvl_tbl       GMF_ItemCost_PUB.Lower_Level_Dtl_Tbl_Type;
113     l_costcmpnt_ids       GMF_ItemCost_PUB.costcmpnt_ids_tbl_type;
114     l_p_dir               VARCHAR2(150);
115     l_output_file         VARCHAR2(120);
116     l_outfile_handle      UTL_FILE.FILE_TYPE;
117     l_input_file          VARCHAR2(120);
118     l_infile_handle       UTL_FILE.FILE_TYPE;
119     l_line                VARCHAR2(4000);
120     l_delimiter           VARCHAR(11);
121     l_log_dir             VARCHAR2(150);
122     l_log_name            VARCHAR2(120)  :='gmf_api_cric_wrapper';
123     l_log_handle          UTL_FILE.FILE_TYPE;
124     l_global_file         VARCHAR2(120);
125     l_idx		              NUMBER(10);
126     l_idx1		            NUMBER(10);
127     l_type		            VARCHAR2(100);
128     l_continue            VARCHAR2(1) := 'Y' ;
129     l_skip_details        VARCHAR2(1) := 'N' ;
130     l_session_id          VARCHAR2(110);
131 
132   BEGIN
133 
134     l_p_dir              :=p_dir;
135     l_input_file         :=p_input_file;
136     l_output_file        :=p_output_file;
137     l_delimiter          :=p_delimiter;
138     l_global_file        :=l_input_file;
139 
140     /*******************************************************
141     * Obtain The SessionId To Append To wrapper File Name. *
142     *******************************************************/
143     l_session_id := USERENV('sessionid');
144     l_log_name  := CONCAT(l_log_name,l_session_id);
145     l_log_name  := CONCAT(l_log_name,'.log');
146 
147     /*****************************************************
148     * Directory is now the same same as for the out FILE *
149     *****************************************************/
150     l_log_dir   := p_dir;
151 
152     /****************************************************************
153     * Open The Wrapper File For Output And The Input File for Input *
154     ****************************************************************/
155     l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
156     l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
157 
158     /********************************************************
159     * Loop thru flat file and call Inventory Quantities API *
160     ********************************************************/
161     -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
162     -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
163     -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
164     -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
165     -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
166     UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
167     UTL_FILE.NEW_LINE(l_log_handle);
168     UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
169     UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
170     UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
171     UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
172     l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
173     BEGIN
174       UTL_FILE.GET_LINE(l_infile_handle, l_line);
175       l_record_count    :=l_record_count+1;
176       l_type   := Get_Field(l_line,l_delimiter,1) ; /* = 10 : header rec, 20 : this level, 30 : lower level*/
177     EXCEPTION
178       WHEN NO_DATA_FOUND THEN
179         raise;
180     END;
181     LOOP
182       BEGIN
183         UTL_FILE.PUT_LINE(l_log_handle, '--');
184         UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
185         UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
186         IF l_type = '10' THEN
187           /*******************
188           * empty the tables *
189           *******************/
190           l_this_lvl_tbl.delete ;
191           l_lower_lvl_tbl.delete ;
192           l_costcmpnt_ids.delete;
193           l_skip_details := 'N' ;
194           l_header_rec.period_id          := Get_Field(l_line,l_delimiter,2) ;
195           l_header_rec.calendar_code      := Get_Field(l_line,l_delimiter,3) ;
196           l_header_rec.period_code        := Get_Field(l_line,l_delimiter,4) ;
197           l_header_rec.cost_type_id       := Get_Field(l_line,l_delimiter,5) ;
198           l_header_rec.cost_mthd_code     := Get_Field(l_line,l_delimiter,6) ;
199           l_header_rec.organization_id    := Get_Field(l_line,l_delimiter,7) ;
200           l_header_rec.organization_code  := Get_Field(l_line,l_delimiter,8) ;
201           l_header_rec.inventory_item_id  := Get_Field(l_line,l_delimiter,9) ;
202           l_header_rec.item_number        := Get_Field(l_line,l_delimiter,10) ;
203           l_header_rec.user_name          := Get_Field(l_line,l_delimiter,11) ;
204           l_idx  := 0 ;
205           l_idx1 := 0 ;
206           /*
207           UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
208           UTL_FILE.PUT_LINE(l_log_handle, 'calendar_code   = ' || l_header_rec.calendar_code) ;
209           UTL_FILE.PUT_LINE(l_log_handle, 'period_code   = ' || l_header_rec.period_code) ;
210           UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code   = ' || l_header_rec.cost_mthd_code) ;
211           UTL_FILE.PUT_LINE(l_log_handle, 'whse_code   = ' || l_header_rec.whse_code) ;
212           UTL_FILE.PUT_LINE(l_log_handle, 'item_id   = ' || l_header_rec.item_id) ;
213           UTL_FILE.PUT_LINE(l_log_handle, 'item_no   = ' || l_header_rec.item_no) ;
214           UTL_FILE.PUT_LINE(l_log_handle, 'user_name   = ' || l_header_rec.user_name) ;
215           */
216 
217         ELSIF l_type = '20' AND l_skip_details = 'Y' THEN
218           UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skipping this record...');
219         ELSIF l_type = '20' AND l_skip_details = 'N' THEN
220           l_idx := l_idx + 1 ;
221           l_this_lvl_tbl(l_idx).cmpntcost_id         := Get_Field(l_line,l_delimiter,2) ;
222           l_this_lvl_tbl(l_idx).cost_cmpntcls_id     := Get_Field(l_line,l_delimiter,3) ;
223           l_this_lvl_tbl(l_idx).cost_cmpntcls_code   := Get_Field(l_line,l_delimiter,4) ;
224           l_this_lvl_tbl(l_idx).cost_analysis_code   := Get_Field(l_line,l_delimiter,5) ;
225           l_this_lvl_tbl(l_idx).cmpnt_cost           := Get_Field(l_line,l_delimiter,6) ;
226           l_this_lvl_tbl(l_idx).burden_ind           := Get_Field(l_line,l_delimiter,7) ;
227           l_this_lvl_tbl(l_idx).total_qty            := Get_Field(l_line,l_delimiter,8) ;
228           l_this_lvl_tbl(l_idx).costcalc_orig        := Get_Field(l_line,l_delimiter,9) ;
229           l_this_lvl_tbl(l_idx).rmcalc_type          := Get_Field(l_line,l_delimiter,10) ;
230           l_this_lvl_tbl(l_idx).delete_mark          := Get_Field(l_line,l_delimiter,11) ;
231           l_this_lvl_tbl(l_idx).attribute1           := Get_Field(l_line,l_delimiter,12) ;
232           l_this_lvl_tbl(l_idx).attribute2           := Get_Field(l_line,l_delimiter,13) ;
233           l_this_lvl_tbl(l_idx).attribute3           := Get_Field(l_line,l_delimiter,14) ;
234           l_this_lvl_tbl(l_idx).attribute4           := Get_Field(l_line,l_delimiter,15) ;
235           l_this_lvl_tbl(l_idx).attribute5           := Get_Field(l_line,l_delimiter,16) ;
236           l_this_lvl_tbl(l_idx).attribute6           := Get_Field(l_line,l_delimiter,17) ;
237           l_this_lvl_tbl(l_idx).attribute7           := Get_Field(l_line,l_delimiter,18) ;
238           l_this_lvl_tbl(l_idx).attribute8           := Get_Field(l_line,l_delimiter,19) ;
239           l_this_lvl_tbl(l_idx).attribute9           := Get_Field(l_line,l_delimiter,20) ;
240           l_this_lvl_tbl(l_idx).attribute10          := Get_Field(l_line,l_delimiter,21) ;
241           l_this_lvl_tbl(l_idx).attribute11          := Get_Field(l_line,l_delimiter,22) ;
242           l_this_lvl_tbl(l_idx).attribute12          := Get_Field(l_line,l_delimiter,23) ;
243           l_this_lvl_tbl(l_idx).attribute13          := Get_Field(l_line,l_delimiter,24) ;
244           l_this_lvl_tbl(l_idx).attribute14          := Get_Field(l_line,l_delimiter,25) ;
245           l_this_lvl_tbl(l_idx).attribute15          := Get_Field(l_line,l_delimiter,26) ;
246           l_this_lvl_tbl(l_idx).attribute16          := Get_Field(l_line,l_delimiter,27) ;
247           l_this_lvl_tbl(l_idx).attribute17          := Get_Field(l_line,l_delimiter,28) ;
248           l_this_lvl_tbl(l_idx).attribute18          := Get_Field(l_line,l_delimiter,29) ;
249           l_this_lvl_tbl(l_idx).attribute19          := Get_Field(l_line,l_delimiter,30) ;
250           l_this_lvl_tbl(l_idx).attribute20          := Get_Field(l_line,l_delimiter,31) ;
251           l_this_lvl_tbl(l_idx).attribute21          := Get_Field(l_line,l_delimiter,32) ;
252           l_this_lvl_tbl(l_idx).attribute22          := Get_Field(l_line,l_delimiter,33) ;
253           l_this_lvl_tbl(l_idx).attribute23          := Get_Field(l_line,l_delimiter,34) ;
254           l_this_lvl_tbl(l_idx).attribute24          := Get_Field(l_line,l_delimiter,35) ;
255           l_this_lvl_tbl(l_idx).attribute25          := Get_Field(l_line,l_delimiter,36) ;
256           l_this_lvl_tbl(l_idx).attribute26          := Get_Field(l_line,l_delimiter,37) ;
257           l_this_lvl_tbl(l_idx).attribute27          := Get_Field(l_line,l_delimiter,38) ;
258           l_this_lvl_tbl(l_idx).attribute28          := Get_Field(l_line,l_delimiter,39) ;
259           l_this_lvl_tbl(l_idx).attribute29          := Get_Field(l_line,l_delimiter,40) ;
260           l_this_lvl_tbl(l_idx).attribute30          := Get_Field(l_line,l_delimiter,41) ;
261           l_this_lvl_tbl(l_idx).attribute_category   := Get_Field(l_line,l_delimiter,42) ;
262 
263           /*
264           UTL_FILE.PUT_LINE(l_log_handle,'tl cmpntcost_id('||l_idx||') = '||l_this_lvl_tbl(l_idx).cmpntcost_id) ;
265           UTL_FILE.PUT_LINE(l_log_handle,'tl cost_cmpntcls_id('||l_idx||') = '||l_this_lvl_tbl(l_idx).cost_cmpntcls_id) ;
266           UTL_FILE.PUT_LINE(l_log_handle,'tl cost_cmpntcls_code('||l_idx||') = '||l_this_lvl_tbl(l_idx).cost_cmpntcls_code) ;
267           UTL_FILE.PUT_LINE(l_log_handle,'tl cost_analysis_code('||l_idx||') = '||l_this_lvl_tbl(l_idx).cost_analysis_code) ;
268           UTL_FILE.PUT_LINE(l_log_handle,'tl cmpnt_cost('||l_idx||') = '||l_this_lvl_tbl(l_idx).cmpnt_cost) ;
269           UTL_FILE.PUT_LINE(l_log_handle,'tl burden_ind('||l_idx||') = '||l_this_lvl_tbl(l_idx).burden_ind) ;
270           UTL_FILE.PUT_LINE(l_log_handle,'tl total_qty('||l_idx||') = '||l_this_lvl_tbl(l_idx).total_qty) ;
271           UTL_FILE.PUT_LINE(l_log_handle,'tl costcalc_orig('||l_idx||') = '||l_this_lvl_tbl(l_idx).costcalc_orig) ;
272           UTL_FILE.PUT_LINE(l_log_handle,'tl rmcalc_type('||l_idx||') = '||l_this_lvl_tbl(l_idx).rmcalc_type) ;
273           UTL_FILE.PUT_LINE(l_log_handle,'tl delete_mark('||l_idx||') = '||l_this_lvl_tbl(l_idx).delete_mark) ;
274           */
275         ELSIF l_type = '30' AND l_skip_details = 'Y' THEN
276           UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skipping this record...');
277         ELSIF l_type = '30' AND l_skip_details = 'N'  THEN
278           l_idx1 := l_idx1 + 1 ;
279           l_type                                       := Get_Field(l_line,l_delimiter,1) ;
280           l_lower_lvl_tbl(l_idx1).cmpntcost_id         := Get_Field(l_line,l_delimiter,2) ;
281           l_lower_lvl_tbl(l_idx1).cost_cmpntcls_id     := Get_Field(l_line,l_delimiter,3) ;
282           l_lower_lvl_tbl(l_idx1).cost_cmpntcls_code   := Get_Field(l_line,l_delimiter,4) ;
283           l_lower_lvl_tbl(l_idx1).cost_analysis_code   := Get_Field(l_line,l_delimiter,5) ;
284           l_lower_lvl_tbl(l_idx1).cmpnt_cost           := Get_Field(l_line,l_delimiter,6) ;
285           l_lower_lvl_tbl(l_idx1).delete_mark          := Get_Field(l_line,l_delimiter,7) ;
286           /*
287           UTL_FILE.PUT_LINE(l_log_handle,'ll cmpntcost_id('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cmpntcost_id) ;
288           UTL_FILE.PUT_LINE(l_log_handle,'ll cost_cmpntcls_id('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cost_cmpntcls_id)      ;
289           UTL_FILE.PUT_LINE(l_log_handle,'ll cost_cmpntcls_code('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cost_cmpntcls_code) ;
290           UTL_FILE.PUT_LINE(l_log_handle,'ll cost_analysis_code('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cost_analysis_code) ;
291           UTL_FILE.PUT_LINE(l_log_handle,'ll cmpnt_cost('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cmpnt_cost) ;
292           */
293         END IF ;
294       EXCEPTION
295         WHEN OTHERS THEN
296           UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
297           UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
298           IF l_type = '10' THEN
299             l_skip_details := 'Y' ;
300             UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skip detail records.');
301           ELSIF l_type = '20' THEN
302             l_this_lvl_tbl.delete(l_idx);
303             l_idx := l_idx-1;
304           ELSIF l_type = '30' THEN
305             l_lower_lvl_tbl.delete(l_idx1);
306             l_idx1 := l_idx1-1;
307           END IF ;
308       END ;
309       BEGIN
310         UTL_FILE.GET_LINE(l_infile_handle, l_line);
311         l_record_count    :=l_record_count+1;
312         UTL_FILE.NEW_LINE(l_log_handle);
313         l_type   := Get_Field(l_line,l_delimiter,1) ;  -- 10 : header rec, 20 : this level, 30 : lower level
314         -- goto GET_MSG_STACK ;  commented this goto as per bug 5586406, otherwise it is skiping the records inserting
315         --l_skip_details := 'N' ;
316         --UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
317         --UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
318       EXCEPTION
319         WHEN NO_DATA_FOUND THEN
320           IF l_skip_details = 'N' THEN
321             GMF_ItemCost_PUB.Create_Item_Cost
322             (
323             p_api_version           =>        3.0,
324             p_init_msg_list         =>        FND_API.G_TRUE,
325             p_commit                =>        FND_API.G_TRUE,
326             x_return_status         =>        l_status,
327             x_msg_count             =>        l_count,
328             x_msg_data              =>        l_data,
329             p_header_rec            =>        l_header_rec,
330             p_this_level_dtl_tbl    =>        l_this_lvl_tbl,
331             p_lower_level_dtl_Tbl   =>        l_lower_lvl_tbl,
332             x_costcmpnt_ids         =>        l_costcmpnt_ids
333             );
334             UTL_FILE.PUT_LINE(l_log_handle, 'in exception. after API call. status := ' || l_status ||' cnt := ' || l_count );
335             l_continue := 'N' ;
336             goto GET_MSG_STACK ;
337           END IF ;
338       END;
339 
340       -- DBMS_OUTPUT.PUT_LINE('Check to call Create_Item_Cost API...type - ' || l_type || ' count = ' || l_record_count);
341       IF (l_type = '10' AND l_record_count <> 1 AND l_skip_details = 'N') THEN
342         -- DBMS_OUTPUT.PUT_LINE('Calling Create_Item_Cost API...');
343         GMF_ItemCost_PUB.Create_Item_Cost
344         (
345         p_api_version           =>        3.0,
346         p_init_msg_list         =>        FND_API.G_TRUE,
347         p_commit                =>        FND_API.G_TRUE,
348         x_return_status         =>        l_status,
349         x_msg_count             =>        l_count,
350         x_msg_data              =>        l_data,
351         p_header_rec            =>        l_header_rec,
352         p_this_level_dtl_tbl    =>        l_this_lvl_tbl,
353         p_lower_level_dtl_Tbl   =>        l_lower_lvl_tbl,
354         x_costcmpnt_ids         =>        l_costcmpnt_ids
355         );
356         UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
357 
358       END IF;
359 
360       <<GET_MSG_STACK>>
361       NULL;
362 
363       /*******************************************************************************************
364       * Check if any messages generated. If so then decode and output to error message flat file *
365       *******************************************************************************************/
366       IF l_count > 0 THEN
367         l_loop_cnt  :=1;
368         LOOP
369           FND_MSG_PUB.Get
370           (
371           p_msg_index     => l_loop_cnt,
372           p_data          => l_data,
373           p_encoded       => FND_API.G_FALSE,
374           p_msg_index_out => l_dummy_cnt
375           );
376 
377           -- DBMS_OUTPUT.PUT_LINE(l_data );
378           --UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
379           --UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
380           --UTL_FILE.NEW_LINE(l_outfile_handle);
381           UTL_FILE.PUT_LINE(l_log_handle, l_data);
382 
383           /**********************
384           * Update error status *
385           **********************/
386           IF (l_status = 'U') THEN
387             l_return_status  :=l_status;
388           ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
389             l_return_status  :=l_status;
390           ELSE
391             l_return_status  :=l_status;
392           END IF;
393           l_loop_cnt  := l_loop_cnt + 1;
394           IF l_loop_cnt > l_count THEN
395             EXIT;
396           END IF;
397         END LOOP;
398         l_count := 0 ;
399       END IF;
400       -- DBMS_OUTPUT.PUT_LINE('# of CostIds inserted : ' || l_costcmpnt_ids.count);
401       FOR i in 1..l_costcmpnt_ids.count
402       LOOP
403         UTL_FILE.PUT_LINE(l_log_handle, ' CmpntClsId : ' || l_costcmpnt_ids(i).cost_cmpntcls_id ||
404                                         ' Analysis Code : ' || l_costcmpnt_ids(i).cost_analysis_code ||
405                                         ' Cost Level : ' || l_costcmpnt_ids(i).cost_level ||
406                                         ' CostId : ' || l_costcmpnt_ids(i).cmpntcost_id);
407       END LOOP ;
408       IF l_continue = 'N' THEN
409         EXIT ;
410       END IF ;
411     END LOOP;
412     -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
413     UTL_FILE.NEW_LINE(l_log_handle);
414     UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
415     UTL_FILE.FCLOSE_ALL;
416 
417     RETURN l_return_status;
418   EXCEPTION
419     WHEN UTL_FILE.INVALID_OPERATION THEN
420       -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file);
421       UTL_FILE.FCLOSE_ALL;
422       RETURN l_return_status;
423     WHEN UTL_FILE.INVALID_PATH THEN
424       -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file);
425       UTL_FILE.FCLOSE_ALL;
426       RETURN l_return_status;
427     WHEN UTL_FILE.INVALID_MODE THEN
428       -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file);
429       UTL_FILE.FCLOSE_ALL;
430       RETURN l_return_status;
431     WHEN UTL_FILE.INVALID_FILEHANDLE THEN
432       -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file);
433       UTL_FILE.FCLOSE_ALL;
434       RETURN l_return_status;
435     WHEN UTL_FILE.WRITE_ERROR THEN
436       -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file);
437       UTL_FILE.FCLOSE_ALL;
438       RETURN l_return_status;
439     WHEN UTL_FILE.READ_ERROR THEN
440       -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file);
441       UTL_FILE.FCLOSE_ALL;
442       RETURN l_return_status;
443     WHEN UTL_FILE.INTERNAL_ERROR THEN
444       -- DBMS_OUTPUT.PUT_LINE('Internal Error');
445       UTL_FILE.FCLOSE_ALL;
446       RETURN l_return_status;
447     WHEN OTHERS THEN
448       -- DBMS_OUTPUT.PUT_LINE('Other Error');
449       UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
450       UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
451       UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
452       UTL_FILE.FCLOSE_ALL;
453       l_return_status := 'U' ;
454       RETURN l_return_status;
455   END Create_Item_Cost;
456 
457 /*  API start of comments
458  +==========================================================================+
459  | PROCEDURE NAME                                                           |
460  |    Update_Item_Cost                                                  |
461  |                                                                          |
462  | TYPE                                                                     |
463  |    Public                                                                |
464  |                                                                          |
465  | USAGE                                                                    |
466  |    Update item Cost                                                  |
467  |                                                                          |
468  | DESCRIPTION                                                              |
469  |    This is a PL/SQL wrapper procedure to call the                        |
470  |    Update_Item_Cost API wrapper function                             |
471  |                                                                          |
472  | PARAMETERS                                                               |
473  |    p_dir              IN VARCHAR2         - Working directory for input  |
474  |                                             and output files.            |
475  |    p_input_file       IN VARCHAR2         - Name of input file           |
476  |    p_output_file      IN VARCHAR2         - Name of output file          |
477  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
478  |                                                                          |
479  | RETURNS                                                                  |
480  |    None                                                                  |
481  |                                                                          |
482  | HISTORY                                                                  |
483  |    07-Mar-2001  Uday Moogala    created                                  |
484  |                                                                          |
485  +==========================================================================+
486   Api end of comments
487 */
488   PROCEDURE Update_Item_Cost
489   (
490   p_dir                 IN              VARCHAR2,
491   p_input_file          IN              VARCHAR2,
492   p_output_file         IN              VARCHAR2,
493   p_delimiter           IN              VARCHAR2
494   )
495   IS
496 
497     /******************
498     * Local Variables *
499     ******************/
500     l_return_status  VARCHAR2(1);
501   BEGIN
502     l_return_status  := Update_Item_Cost  (p_dir, p_input_file, p_output_file, p_delimiter);
503   END Update_Item_Cost;
504 
505 /* +==========================================================================+
506  | FUNCTION NAME                                                            |
507  |    Update_Item_Cost                                                  |
508  |                                                                          |
509  | TYPE                                                                     |
510  |    Public                                                                |
511  |                                                                          |
512  | USAGE                                                                    |
513  |    Update item Cost                                                  |
514  |                                                                          |
515  | DESCRIPTION                                                              |
516  |    This is a PL/SQL wrapper function to call the                         |
517  |    Update_Item_Cost API.                                             |
518  |    It reads item data from a flat file and outputs any error             |
519  |    messages to a second flat file. It also generates a Status            |
520  |    called gmf_aloc_wrapper<session_id>.log in the temp directory.        |
521  |                                                                          |
522  | PARAMETERS                                                               |
523  |    p_dir              IN VARCHAR2         - Working directory for input  |
524  |                                             and output files.            |
525  |    p_input_file       IN VARCHAR2         - Name of input file           |
526  |    p_output_file      IN VARCHAR2         - Name of output file          |
527  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
528  |                                                                          |
529  | RETURNS                                                                  |
530  |    VARCHAR2 - 'S' All records processed successfully                     |
531  |               'E' 1 or more records errored                              |
532  |               'U' 1 or more record unexpected error                      |
533  |                                                                          |
534  | HISTORY                                                                  |
535  |                                                                          |
536  +==========================================================================+
537   Api end of comments
538 */
539   FUNCTION Update_Item_Cost
540   (
541   p_dir                 IN              VARCHAR2,
542   p_input_file          IN              VARCHAR2,
543   p_output_file         IN              VARCHAR2,
544   p_delimiter           IN              VARCHAR2
545   )
546   RETURN VARCHAR2
547   IS
548 
549     /******************
550     * Local variables *
551     ******************/
552     l_status              VARCHAR2(100);
553     l_return_status       VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
554     l_count               NUMBER(10)  ;
555     l_record_count        NUMBER(10)  :=0;
556     l_loop_cnt            NUMBER(10)  :=0;
557     l_dummy_cnt           NUMBER(10)  :=0;
558     l_data                VARCHAR2(2000);
559     l_header_rec          GMF_ItemCost_PUB.Header_Rec_Type;
560     l_this_lvl_tbl        GMF_ItemCost_PUB.This_Level_Dtl_Tbl_Type;
561     l_lower_lvl_tbl       GMF_ItemCost_PUB.Lower_Level_Dtl_Tbl_Type;
562     l_costcmpnt_ids       GMF_ItemCost_PUB.costcmpnt_ids_tbl_type;
563     l_p_dir               VARCHAR2(150);
564     l_output_file         VARCHAR2(120);
565     l_outfile_handle      UTL_FILE.FILE_TYPE;
566     l_input_file          VARCHAR2(120);
567     l_infile_handle       UTL_FILE.FILE_TYPE;
568     l_line                VARCHAR2(1800);
569     l_delimiter           VARCHAR(11);
570     l_log_dir             VARCHAR2(150);
571     l_log_name            VARCHAR2(120)  :='gmf_api_updic_wrapper';
572     l_log_handle          UTL_FILE.FILE_TYPE;
573     l_global_file         VARCHAR2(120);
574     l_idx		              NUMBER(10);
575     l_idx1		            NUMBER(10);
576     l_type		            VARCHAR2(100);
577     l_continue            VARCHAR2(1) := 'Y' ;
578     l_skip_details        VARCHAR2(1) := 'N' ;
579     l_session_id          VARCHAR2(110);
580   BEGIN
581     /********************
582     * Enable The Buffer *
583     ********************/
584     /*  DBMS_OUTPUT.ENABLE(1000000); */
585     -- DBMS_OUTPUT.PUT_LINE('in Update_Item_Cost function...');
586     l_p_dir              :=       p_dir;
587     l_input_file         :=       p_input_file;
588     l_output_file        :=       p_output_file;
589     l_delimiter          :=       p_delimiter;
590     l_global_file        :=       l_input_file;
591 
592     /*******************************************************
593     * Obtain The SessionId To Append To wrapper File Name. *
594     *******************************************************/
595     l_session_id := USERENV('sessionid');
596     l_log_name  := CONCAT(l_log_name,l_session_id);
597     l_log_name  := CONCAT(l_log_name,'.log');
598 
599     /*****************************************************
600     * Directory is now the same same as for the out file *
601     *****************************************************/
602     l_log_dir   := p_dir;
603 
604     /****************************************************************
605     * Open The Wrapper File For Output And The Input File for Input *
606     ****************************************************************/
607     l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
608     l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
609 
610     /********************************************************
611     * Loop thru flat file and call Inventory Quantities API *
612     ********************************************************/
613     -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
614     -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
615     -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
616     -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
617     -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
618     /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
619     UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
620     UTL_FILE.NEW_LINE(l_log_handle);
621     UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
622     UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
623     UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
624     UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
625     l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
626     BEGIN
627       UTL_FILE.GET_LINE(l_infile_handle, l_line);
628       l_record_count    :=l_record_count+1;
629       l_type   := Get_Field(l_line,l_delimiter,1) ;  /* = 10 : header rec, 20 : this level, 30 : lower level*/
630       --UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
631       --UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
632     EXCEPTION
633       WHEN NO_DATA_FOUND THEN
634         RAISE;
635     END;
636     /*
637     UTL_FILE.NEW_LINE(l_log_handle);
638     UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
639     l_type   := Get_Field(l_line,l_delimiter,1) ;  -- 10 : header rec, 20 : this level, 30 : lower level
640     UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
641     DBMS_OUTPUT.PUT_LINE('firt record of type = ' || l_type);
642     */
643     LOOP
644       BEGIN
645         UTL_FILE.PUT_LINE(l_log_handle, '--');
646         UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
647         UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
648         IF l_type = '10' THEN
649           /*******************
650           * empty the tables *
651           *******************/
652           l_this_lvl_tbl.delete ;
653           l_lower_lvl_tbl.delete ;
654           l_costcmpnt_ids.delete;
655           l_skip_details := 'N' ;
656           l_header_rec.period_id          := Get_Field(l_line,l_delimiter,2) ;
657           l_header_rec.calendar_code      := Get_Field(l_line,l_delimiter,3) ;
658           l_header_rec.period_code        := Get_Field(l_line,l_delimiter,4) ;
659           l_header_rec.cost_type_id       := Get_Field(l_line,l_delimiter,5) ;
660           l_header_rec.cost_mthd_code     := Get_Field(l_line,l_delimiter,6) ;
661           l_header_rec.organization_id    := Get_Field(l_line,l_delimiter,7) ;
662           l_header_rec.organization_code  := Get_Field(l_line,l_delimiter,8) ;
663           l_header_rec.inventory_item_id  := Get_Field(l_line,l_delimiter,9) ;
664           l_header_rec.item_number        := Get_Field(l_line,l_delimiter,10) ;
665           l_header_rec.user_name          := Get_Field(l_line,l_delimiter,11) ;
666           l_idx  := 0 ;
667           l_idx1 := 0 ;
668           -- DBMS_OUTPUT.PUT_LINE('in wrapper. l_this_lvl_tbl count : ' || l_this_lvl_tbl.count) ;
669           -- DBMS_OUTPUT.PUT_LINE('in wrapper. l_lower_lvl_tbl count : ' || l_lower_lvl_tbl.count) ;
670           -- DBMS_OUTPUT.PUT_LINE('calendar_code   = ' || l_header_rec.calendar_code) ;
671           /*
672           UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
673           UTL_FILE.PUT_LINE(l_log_handle, 'calendar_code   = ' || l_header_rec.calendar_code) ;
674           UTL_FILE.PUT_LINE(l_log_handle, 'period_code   = ' || l_header_rec.period_code) ;
675           UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code   = ' || l_header_rec.cost_mthd_code) ;
676           UTL_FILE.PUT_LINE(l_log_handle, 'whse_code   = ' || l_header_rec.whse_code) ;
677           UTL_FILE.PUT_LINE(l_log_handle, 'item_id   = ' || l_header_rec.item_id) ;
678           UTL_FILE.PUT_LINE(l_log_handle, 'item_no   = ' || l_header_rec.item_no) ;
679           UTL_FILE.PUT_LINE(l_log_handle, 'user_name   = ' || l_header_rec.user_name) ;
680           */
681         ELSIF l_type = '20' AND l_skip_details = 'Y' THEN
682           UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skipping this record...');
683         ELSIF l_type = '20' AND l_skip_details = 'N' THEN
684           l_idx := l_idx + 1 ;
685           --UTL_FILE.PUT_LINE(l_log_handle, 'Populating this level table...' || l_idx ) ;
686           l_this_lvl_tbl(l_idx).cmpntcost_id         := Get_Field(l_line,l_delimiter,2) ;
687           l_this_lvl_tbl(l_idx).cost_cmpntcls_id     := Get_Field(l_line,l_delimiter,3) ;
688           l_this_lvl_tbl(l_idx).cost_cmpntcls_code   := Get_Field(l_line,l_delimiter,4) ;
689           l_this_lvl_tbl(l_idx).cost_analysis_code   := Get_Field(l_line,l_delimiter,5) ;
690           l_this_lvl_tbl(l_idx).cmpnt_cost           := Get_Field(l_line,l_delimiter,6) ;
691           l_this_lvl_tbl(l_idx).burden_ind           := Get_Field(l_line,l_delimiter,7) ;
692           l_this_lvl_tbl(l_idx).total_qty            := Get_Field(l_line,l_delimiter,8) ;
693           l_this_lvl_tbl(l_idx).costcalc_orig        := Get_Field(l_line,l_delimiter,9) ;
694           l_this_lvl_tbl(l_idx).rmcalc_type          := Get_Field(l_line,l_delimiter,10) ;
695           l_this_lvl_tbl(l_idx).delete_mark          := Get_Field(l_line,l_delimiter,11) ;
696           l_this_lvl_tbl(l_idx).attribute1           := Get_Field(l_line,l_delimiter,12) ;
697           l_this_lvl_tbl(l_idx).attribute2           := Get_Field(l_line,l_delimiter,13) ;
698           l_this_lvl_tbl(l_idx).attribute3           := Get_Field(l_line,l_delimiter,14) ;
699           l_this_lvl_tbl(l_idx).attribute4           := Get_Field(l_line,l_delimiter,15) ;
700           l_this_lvl_tbl(l_idx).attribute5           := Get_Field(l_line,l_delimiter,16) ;
701           l_this_lvl_tbl(l_idx).attribute6           := Get_Field(l_line,l_delimiter,17) ;
702           l_this_lvl_tbl(l_idx).attribute7           := Get_Field(l_line,l_delimiter,18) ;
703           l_this_lvl_tbl(l_idx).attribute8           := Get_Field(l_line,l_delimiter,19) ;
704           l_this_lvl_tbl(l_idx).attribute9           := Get_Field(l_line,l_delimiter,20) ;
705           l_this_lvl_tbl(l_idx).attribute10          := Get_Field(l_line,l_delimiter,21) ;
706           l_this_lvl_tbl(l_idx).attribute11          := Get_Field(l_line,l_delimiter,22) ;
707           l_this_lvl_tbl(l_idx).attribute12          := Get_Field(l_line,l_delimiter,23) ;
708           l_this_lvl_tbl(l_idx).attribute13          := Get_Field(l_line,l_delimiter,24) ;
709           l_this_lvl_tbl(l_idx).attribute14          := Get_Field(l_line,l_delimiter,25) ;
710           l_this_lvl_tbl(l_idx).attribute15          := Get_Field(l_line,l_delimiter,26) ;
711           l_this_lvl_tbl(l_idx).attribute16          := Get_Field(l_line,l_delimiter,27) ;
712           l_this_lvl_tbl(l_idx).attribute17          := Get_Field(l_line,l_delimiter,28) ;
713           l_this_lvl_tbl(l_idx).attribute18          := Get_Field(l_line,l_delimiter,29) ;
714           l_this_lvl_tbl(l_idx).attribute19          := Get_Field(l_line,l_delimiter,30) ;
715           l_this_lvl_tbl(l_idx).attribute20          := Get_Field(l_line,l_delimiter,31) ;
716           l_this_lvl_tbl(l_idx).attribute21          := Get_Field(l_line,l_delimiter,32) ;
717           l_this_lvl_tbl(l_idx).attribute22          := Get_Field(l_line,l_delimiter,33) ;
718           l_this_lvl_tbl(l_idx).attribute23          := Get_Field(l_line,l_delimiter,34) ;
719           l_this_lvl_tbl(l_idx).attribute24          := Get_Field(l_line,l_delimiter,35) ;
720           l_this_lvl_tbl(l_idx).attribute25          := Get_Field(l_line,l_delimiter,36) ;
721           l_this_lvl_tbl(l_idx).attribute26          := Get_Field(l_line,l_delimiter,37) ;
722           l_this_lvl_tbl(l_idx).attribute27          := Get_Field(l_line,l_delimiter,38) ;
723           l_this_lvl_tbl(l_idx).attribute28          := Get_Field(l_line,l_delimiter,39) ;
724           l_this_lvl_tbl(l_idx).attribute29          := Get_Field(l_line,l_delimiter,40) ;
725           l_this_lvl_tbl(l_idx).attribute30          := Get_Field(l_line,l_delimiter,41) ;
726           l_this_lvl_tbl(l_idx).attribute_category   := Get_Field(l_line,l_delimiter,42) ;
727           /*
728           UTL_FILE.PUT_LINE(l_log_handle,'tl cmpntcost_id('||l_idx||') = '||l_this_lvl_tbl(l_idx).cmpntcost_id) ;
729           UTL_FILE.PUT_LINE(l_log_handle,'tl cost_cmpntcls_id('||l_idx||') = '||l_this_lvl_tbl(l_idx).cost_cmpntcls_id) ;
730           UTL_FILE.PUT_LINE(l_log_handle,'tl cost_cmpntcls_code('||l_idx||') = '||l_this_lvl_tbl(l_idx).cost_cmpntcls_code) ;
731           UTL_FILE.PUT_LINE(l_log_handle,'tl cost_analysis_code('||l_idx||') = '||l_this_lvl_tbl(l_idx).cost_analysis_code) ;
732           UTL_FILE.PUT_LINE(l_log_handle,'tl cmpnt_cost('||l_idx||') = '||l_this_lvl_tbl(l_idx).cmpnt_cost) ;
733           UTL_FILE.PUT_LINE(l_log_handle,'tl burden_ind('||l_idx||') = '||l_this_lvl_tbl(l_idx).burden_ind) ;
734           UTL_FILE.PUT_LINE(l_log_handle,'tl total_qty('||l_idx||') = '||l_this_lvl_tbl(l_idx).total_qty) ;
735           UTL_FILE.PUT_LINE(l_log_handle,'tl costcalc_orig('||l_idx||') = '||l_this_lvl_tbl(l_idx).costcalc_orig) ;
736           UTL_FILE.PUT_LINE(l_log_handle,'tl rmcalc_type('||l_idx||') = '||l_this_lvl_tbl(l_idx).rmcalc_type) ;
737           UTL_FILE.PUT_LINE(l_log_handle,'tl delete_mark('||l_idx||') = '||l_this_lvl_tbl(l_idx).delete_mark) ;
738           */
739         ELSIF l_type = '30' AND l_skip_details = 'Y' THEN
740           UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skipping this record...');
741         ELSIF l_type = '30' AND l_skip_details = 'N'  THEN
742           l_idx1 := l_idx1 + 1 ;
743           --UTL_FILE.PUT_LINE(l_log_handle, 'Populating lower level table...' || l_idx1 ) ;
744           l_type                                       := Get_Field(l_line,l_delimiter,1) ;
745           l_lower_lvl_tbl(l_idx1).cmpntcost_id         := Get_Field(l_line,l_delimiter,2) ;
746           l_lower_lvl_tbl(l_idx1).cost_cmpntcls_id     := Get_Field(l_line,l_delimiter,3) ;
747           l_lower_lvl_tbl(l_idx1).cost_cmpntcls_code   := Get_Field(l_line,l_delimiter,4) ;
748           l_lower_lvl_tbl(l_idx1).cost_analysis_code   := Get_Field(l_line,l_delimiter,5) ;
749           l_lower_lvl_tbl(l_idx1).cmpnt_cost           := Get_Field(l_line,l_delimiter,6) ;
750           l_lower_lvl_tbl(l_idx1).delete_mark          := Get_Field(l_line,l_delimiter,7) ;
751           /*
752           UTL_FILE.PUT_LINE(l_log_handle,'ll cmpntcost_id('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cmpntcost_id) ;
753           UTL_FILE.PUT_LINE(l_log_handle,'ll cost_cmpntcls_id('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cost_cmpntcls_id)      ;
754           UTL_FILE.PUT_LINE(l_log_handle,'ll cost_cmpntcls_code('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cost_cmpntcls_code) ;
755           UTL_FILE.PUT_LINE(l_log_handle,'ll cost_analysis_code('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cost_analysis_code) ;
756           UTL_FILE.PUT_LINE(l_log_handle,'ll cmpnt_cost('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cmpnt_cost) ;
757           */
758         END IF ;
759       EXCEPTION
760         WHEN OTHERS THEN
761           UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
762           UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
763           IF l_type = '10' THEN
764             l_skip_details := 'Y' ;
765             UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skip detail records.');
766           ELSIF l_type = '20' THEN
767             l_this_lvl_tbl.delete(l_idx);
768             l_idx := l_idx-1;
769           ELSIF l_type = '30' THEN
770             l_lower_lvl_tbl.delete(l_idx1);
771             l_idx1 := l_idx1-1;
772           END IF ;
773       END ;
774       BEGIN
775         UTL_FILE.GET_LINE(l_infile_handle, l_line);
776         l_record_count    :=l_record_count+1;
777         UTL_FILE.NEW_LINE(l_log_handle);
778         l_type   := Get_Field(l_line,l_delimiter,1) ;  -- 10 : header rec, 20 : this level, 30 : lower level
779         --l_skip_details := 'N' ;
780         --UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
781         --UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
782       EXCEPTION
783         WHEN NO_DATA_FOUND THEN
784           IF l_skip_details = 'N' THEN
785             -- DBMS_OUTPUT.PUT_LINE('In exception. Calling Update_Item_Cost API...');
786             GMF_ItemCost_PUB.Update_Item_Cost
787             (
788             p_api_version         =>      3.0,
789             p_init_msg_list       =>      FND_API.G_TRUE,
790             p_commit              =>      FND_API.G_TRUE,
791             x_return_status       =>      l_status,
792             x_msg_count           =>      l_count,
793             x_msg_data            =>      l_data,
794             p_header_rec          =>      l_header_rec,
795             p_this_level_dtl_tbl  =>      l_this_lvl_tbl,
796             p_lower_level_dtl_Tbl =>      l_lower_lvl_tbl
797             );
798             UTL_FILE.PUT_LINE(l_log_handle, 'in exception. after API call. status := ' || l_status ||' cnt := ' || l_count );
799             l_continue := 'N' ;
800             goto GET_MSG_STACK ;
801           END IF ;
802       END;
803       -- DBMS_OUTPUT.PUT_LINE('Check to call Update_Item_Cost API...type - ' || l_type || ' count = ' || l_record_count);
804       IF (l_type = '10' AND l_record_count <> 1 AND l_skip_details = 'N') THEN
805         -- DBMS_OUTPUT.PUT_LINE('Calling Update_Item_Cost API...');
806         GMF_ItemCost_PUB.Update_Item_Cost
807         (
808         p_api_version         =>      3.0,
809         p_init_msg_list       =>      FND_API.G_TRUE,
810         p_commit              =>      FND_API.G_TRUE,
811         x_return_status       =>      l_status,
812         x_msg_count           =>      l_count,
813         x_msg_data            =>      l_data,
814         p_header_rec          =>      l_header_rec,
815         p_this_level_dtl_tbl  =>      l_this_lvl_tbl,
816         p_lower_level_dtl_Tbl =>      l_lower_lvl_tbl
817         );
818         UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
819       END IF;
820       <<GET_MSG_STACK>>
821       NULL;
822 
823       /*******************************************************************************************
824       * Check if any messages generated. If so then decode and output to error message flat file *
825       *******************************************************************************************/
826       IF l_count > 0 THEN
827         l_loop_cnt  :=1;
828         LOOP
829           FND_MSG_PUB.Get
830           (
831           p_msg_index     => l_loop_cnt,
832           p_data          => l_data,
833           p_encoded       => FND_API.G_FALSE,
834           p_msg_index_out => l_dummy_cnt
835           );
836           -- DBMS_OUTPUT.PUT_LINE(l_data );
837           --UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
838           --UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
839           --UTL_FILE.NEW_LINE(l_outfile_handle);
840           UTL_FILE.PUT_LINE(l_log_handle, l_data);
841           /**********************
842           * Update error status *
843           **********************/
844           IF (l_status = 'U') THEN
845             l_return_status  :=l_status;
846           ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
847             l_return_status  :=l_status;
848           ELSE
849             l_return_status  :=l_status;
850           END IF;
851           l_loop_cnt  := l_loop_cnt + 1;
852           IF l_loop_cnt > l_count THEN
853             EXIT;
854           END IF;
855         END LOOP; -- msg stack loop
856         l_count := 0 ;
857       END IF;	-- if count of msg stack > 0
858       IF l_continue = 'N' THEN
859         EXIT ;
860       END IF ;
861     END LOOP;
862     -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
863     UTL_FILE.NEW_LINE(l_log_handle);
864     UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
865     UTL_FILE.FCLOSE_ALL;
866     RETURN l_return_status;
867   EXCEPTION
868     WHEN UTL_FILE.INVALID_OPERATION THEN
869       -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file);
870       UTL_FILE.FCLOSE_ALL;
871       RETURN l_return_status;
872     WHEN UTL_FILE.INVALID_PATH THEN
873       -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file);
874       UTL_FILE.FCLOSE_ALL;
875       RETURN l_return_status;
876     WHEN UTL_FILE.INVALID_MODE THEN
877       -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file);
878       UTL_FILE.FCLOSE_ALL;
879       RETURN l_return_status;
880     WHEN UTL_FILE.INVALID_FILEHANDLE THEN
881       -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file);
882       UTL_FILE.FCLOSE_ALL;
883       RETURN l_return_status;
884     WHEN UTL_FILE.WRITE_ERROR THEN
885       -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file);
886       UTL_FILE.FCLOSE_ALL;
887       RETURN l_return_status;
888     WHEN UTL_FILE.READ_ERROR THEN
889       -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file);
890       UTL_FILE.FCLOSE_ALL;
891       RETURN l_return_status;
892     WHEN UTL_FILE.INTERNAL_ERROR THEN
893       -- DBMS_OUTPUT.PUT_LINE('Internal Error');
894       UTL_FILE.FCLOSE_ALL;
895       RETURN l_return_status;
896     WHEN OTHERS THEN
897       -- DBMS_OUTPUT.PUT_LINE('Other Error');
898       UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
899       UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
900       UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
901       UTL_FILE.FCLOSE_ALL;
902       l_return_status := 'U' ;
903       RETURN l_return_status;
904   END Update_Item_Cost;
905 
906 /*  API start of comments
907  +==========================================================================+
908  | PROCEDURE NAME                                                           |
909  |    Delete_Item_Cost                                                  |
910  |                                                                          |
911  | TYPE                                                                     |
912  |    Public                                                                |
913  |                                                                          |
914  | USAGE                                                                    |
915  |    Delete item Cost                                                  |
916  |                                                                          |
917  | DESCRIPTION                                                              |
918  |    This is a PL/SQL wrapper procedure to call the                        |
919  |    Delete_Item_Cost API wrapper function                             |
920  |                                                                          |
921  | PARAMETERS                                                               |
922  |    p_dir              IN VARCHAR2         - Working directory for input  |
923  |                                             and output files.            |
924  |    p_input_file       IN VARCHAR2         - Name of input file           |
925  |    p_output_file      IN VARCHAR2         - Name of output file          |
926  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
927  |                                                                          |
928  | RETURNS                                                                  |
929  |    None                                                                  |
930  |                                                                          |
931  | HISTORY                                                                  |
932  |    07-Mar-2001  Uday Moogala    created                                  |
933  |                                                                          |
934  +==========================================================================+
935   Api end of comments
936 */
937   PROCEDURE Delete_Item_Cost
938   (
939   p_dir                 IN              VARCHAR2,
940   p_input_file          IN              VARCHAR2,
941   p_output_file         IN              VARCHAR2,
942   p_delimiter           IN              VARCHAR2
943   )
944   IS
945     /******************
946     * Local Variables *
947     ******************/
948     l_return_status  VARCHAR2(1);
949   BEGIN
950     l_return_status  :=Delete_Item_Cost(p_dir, p_input_file, p_output_file, p_delimiter);
951   End Delete_Item_Cost;
952 
953 /* +==========================================================================+
954  | FUNCTION NAME                                                            |
955  |    Delete_Item_Cost                                                  |
956  |                                                                          |
957  | TYPE                                                                     |
958  |    Public                                                                |
959  |                                                                          |
960  | USAGE                                                                    |
961  |    Delete item Cost                                                  |
962  |                                                                          |
963  | DESCRIPTION                                                              |
964  |    This is a PL/SQL wrapper function to call the                         |
965  |    Delete_Item_Cost API.                                             |
966  |    It reads item data from a flat file and outputs any error             |
967  |    messages to a second flat file. It also generates a Status            |
968  |    called gmf_rsrc_wrapper<session_id>.log in the temp directory.        |
969  |                                                                          |
970  | PARAMETERS                                                               |
971  |    p_dir              IN VARCHAR2         - Working directory for input  |
972  |                                             and output files.            |
973  |    p_input_file       IN VARCHAR2         - Name of input file           |
974  |    p_output_file      IN VARCHAR2         - Name of output file          |
975  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
976  |                                                                          |
977  | RETURNS                                                                  |
978  |    VARCHAR2 - 'S' All records processed successfully                     |
979  |               'E' 1 or more records errored                              |
980  |               'U' 1 or more record unexpected error                      |
981  |                                                                          |
982  | HISTORY                                                                  |
983  |                                                                          |
984  +==========================================================================+
985   Api end of comments
986 */
987   FUNCTION Delete_Item_Cost
988   (
989   p_dir                 IN              VARCHAR2,
990   p_input_file          IN              VARCHAR2,
991   p_output_file         IN              VARCHAR2,
992   p_delimiter           IN              VARCHAR2
993   )
994   RETURN VARCHAR2
995   IS
996     /******************
997     * Local variables *
998     ******************/
999     l_status              VARCHAR2(100);
1000     l_return_status       VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
1001     l_count               NUMBER(10)  ;
1002     l_record_count        NUMBER(10)  :=0;
1003     l_loop_cnt            NUMBER(10)  :=0;
1004     l_dummy_cnt           NUMBER(10)  :=0;
1005     l_data                VARCHAR2(2000);
1006     l_header_rec          GMF_ItemCost_PUB.Header_Rec_Type;
1007     l_this_lvl_tbl        GMF_ItemCost_PUB.This_Level_Dtl_Tbl_Type;
1008     l_lower_lvl_tbl       GMF_ItemCost_PUB.Lower_Level_Dtl_Tbl_Type;
1009     l_costcmpnt_ids       GMF_ItemCost_PUB.costcmpnt_ids_tbl_type;
1010     l_p_dir               VARCHAR2(150);
1011     l_output_file         VARCHAR2(120);
1012     l_outfile_handle      UTL_FILE.FILE_TYPE;
1013     l_input_file          VARCHAR2(120);
1014     l_infile_handle       UTL_FILE.FILE_TYPE;
1015     l_line                VARCHAR2(1800);
1016     l_delimiter           VARCHAR(11);
1017     l_log_dir             VARCHAR2(150);
1018     l_log_name            VARCHAR2(120)  :='gmf_api_delic_wrapper';
1019     l_log_handle          UTL_FILE.FILE_TYPE;
1020     l_global_file         VARCHAR2(120);
1021     l_idx		              NUMBER(10);
1022     l_idx1		            NUMBER(10);
1023     l_type		            VARCHAR2(100);
1024     l_continue            VARCHAR2(1) := 'Y' ;
1025     l_skip_details        VARCHAR2(1) := 'N' ;
1026     l_session_id         VARCHAR2(110);
1027   BEGIN
1028     /********************
1029     * Enable The Buffer *
1030     ********************/
1031     /*  DBMS_OUTPUT.ENABLE(1000000); */
1032     -- DBMS_OUTPUT.PUT_LINE('in Delete_Item_Cost function...');
1033     l_p_dir              :=     p_dir;
1034     l_input_file         :=     p_input_file;
1035     l_output_file        :=     p_output_file;
1036     l_delimiter          :=     p_delimiter;
1037     l_global_file        :=     l_input_file;
1038 
1039     /*******************************************************
1040     * Obtain The SessionId To Append To wrapper File Name. *
1041     *******************************************************/
1042     l_session_id := USERENV('sessionid');
1043     l_log_name  := CONCAT(l_log_name,l_session_id);
1044     l_log_name  := CONCAT(l_log_name,'.log');
1045 
1046     /*****************************************************
1047     * Directory is now the same same as for the out file *
1048     *****************************************************/
1049     l_log_dir   := p_dir;
1050 
1051     /*****************************************************************
1052     * Open The Wrapper File For Output And The Input File for Input. *
1053     *****************************************************************/
1054     l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
1055     l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
1056 
1057     /********************************************************
1058     * Loop thru flat file and call Inventory Quantities API *
1059     ********************************************************/
1060     -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1061     -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
1062     -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
1063     -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
1064     -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
1065     /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
1066     UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1067     UTL_FILE.NEW_LINE(l_log_handle);
1068     UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
1069     UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
1070     UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
1071     UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
1072     l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
1073     BEGIN
1074       UTL_FILE.GET_LINE(l_infile_handle, l_line);
1075       l_record_count    :=l_record_count+1;
1076       l_type   := Get_Field(l_line,l_delimiter,1) ;  /* = 10 : header rec, 20 : this level, 30 : lower level */
1077       --UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
1078       --UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
1079     EXCEPTION
1080       WHEN NO_DATA_FOUND THEN
1081         RAISE;
1082     END;
1083     LOOP
1084       BEGIN
1085         UTL_FILE.PUT_LINE(l_log_handle, '--');
1086         UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
1087         UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
1088         IF l_type = '10' THEN
1089           /*******************
1090           * empty the tables *
1091           *******************/
1092           l_this_lvl_tbl.delete ;
1093           l_lower_lvl_tbl.delete ;
1094           l_costcmpnt_ids.delete;
1095           l_skip_details := 'N' ;
1096           l_header_rec.period_id          := Get_Field(l_line,l_delimiter,2) ;
1097           l_header_rec.calendar_code      := Get_Field(l_line,l_delimiter,3) ;
1098           l_header_rec.period_code        := Get_Field(l_line,l_delimiter,4) ;
1099           l_header_rec.cost_type_id       := Get_Field(l_line,l_delimiter,5) ;
1100           l_header_rec.cost_mthd_code     := Get_Field(l_line,l_delimiter,6) ;
1101           l_header_rec.organization_id    := Get_Field(l_line,l_delimiter,7) ;
1102           l_header_rec.organization_code  := Get_Field(l_line,l_delimiter,8) ;
1103           l_header_rec.inventory_item_id  := Get_Field(l_line,l_delimiter,9) ;
1104           l_header_rec.item_number        := Get_Field(l_line,l_delimiter,10) ;
1105           l_header_rec.user_name          := Get_Field(l_line,l_delimiter,11) ;
1106           l_idx  := 0 ;
1107           l_idx1 := 0 ;
1108           -- DBMS_OUTPUT.PUT_LINE('in wrapper. l_this_lvl_tbl count : ' || l_this_lvl_tbl.count) ;
1109           -- DBMS_OUTPUT.PUT_LINE('in wrapper. l_lower_lvl_tbl count : ' || l_lower_lvl_tbl.count) ;
1110           -- DBMS_OUTPUT.PUT_LINE('calendar_code   = ' || l_header_rec.calendar_code) ;
1111           /*
1112           UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
1113           UTL_FILE.PUT_LINE(l_log_handle, 'calendar_code   = ' || l_header_rec.calendar_code) ;
1114           UTL_FILE.PUT_LINE(l_log_handle, 'period_code   = ' || l_header_rec.period_code) ;
1115           UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code   = ' || l_header_rec.cost_mthd_code) ;
1116           UTL_FILE.PUT_LINE(l_log_handle, 'whse_code   = ' || l_header_rec.whse_code) ;
1117           UTL_FILE.PUT_LINE(l_log_handle, 'item_id   = ' || l_header_rec.item_id) ;
1118           UTL_FILE.PUT_LINE(l_log_handle, 'item_no   = ' || l_header_rec.item_no) ;
1119           UTL_FILE.PUT_LINE(l_log_handle, 'user_name   = ' || l_header_rec.user_name) ;
1120           */
1121         ELSIF l_type = '20' AND l_skip_details = 'Y' THEN
1122           UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skipping this record...');
1123         ELSIF l_type = '20' AND l_skip_details = 'N' THEN
1124           l_idx := l_idx + 1 ;
1125           --UTL_FILE.PUT_LINE(l_log_handle, 'Populating this level table...' || l_idx ) ;
1126           l_this_lvl_tbl(l_idx).cmpntcost_id         := Get_Field(l_line,l_delimiter,2) ;
1127           l_this_lvl_tbl(l_idx).cost_cmpntcls_id     := Get_Field(l_line,l_delimiter,3) ;
1128           l_this_lvl_tbl(l_idx).cost_cmpntcls_code   := Get_Field(l_line,l_delimiter,4) ;
1129           l_this_lvl_tbl(l_idx).cost_analysis_code   := Get_Field(l_line,l_delimiter,5) ;
1130           l_this_lvl_tbl(l_idx).cmpnt_cost           := Get_Field(l_line,l_delimiter,6) ;
1131           l_this_lvl_tbl(l_idx).burden_ind           := Get_Field(l_line,l_delimiter,7) ;
1132           l_this_lvl_tbl(l_idx).total_qty            := Get_Field(l_line,l_delimiter,8) ;
1133           l_this_lvl_tbl(l_idx).costcalc_orig        := Get_Field(l_line,l_delimiter,9) ;
1134           l_this_lvl_tbl(l_idx).rmcalc_type          := Get_Field(l_line,l_delimiter,10) ;
1135           l_this_lvl_tbl(l_idx).delete_mark          := Get_Field(l_line,l_delimiter,11) ;
1136           l_this_lvl_tbl(l_idx).attribute1           := Get_Field(l_line,l_delimiter,12) ;
1137           l_this_lvl_tbl(l_idx).attribute2           := Get_Field(l_line,l_delimiter,13) ;
1138           l_this_lvl_tbl(l_idx).attribute3           := Get_Field(l_line,l_delimiter,14) ;
1139           l_this_lvl_tbl(l_idx).attribute4           := Get_Field(l_line,l_delimiter,15) ;
1140           l_this_lvl_tbl(l_idx).attribute5           := Get_Field(l_line,l_delimiter,16) ;
1141           l_this_lvl_tbl(l_idx).attribute6           := Get_Field(l_line,l_delimiter,17) ;
1142           l_this_lvl_tbl(l_idx).attribute7           := Get_Field(l_line,l_delimiter,18) ;
1143           l_this_lvl_tbl(l_idx).attribute8           := Get_Field(l_line,l_delimiter,19) ;
1144           l_this_lvl_tbl(l_idx).attribute9           := Get_Field(l_line,l_delimiter,20) ;
1145           l_this_lvl_tbl(l_idx).attribute10          := Get_Field(l_line,l_delimiter,21) ;
1146           l_this_lvl_tbl(l_idx).attribute11          := Get_Field(l_line,l_delimiter,22) ;
1147           l_this_lvl_tbl(l_idx).attribute12          := Get_Field(l_line,l_delimiter,23) ;
1148           l_this_lvl_tbl(l_idx).attribute13          := Get_Field(l_line,l_delimiter,24) ;
1149           l_this_lvl_tbl(l_idx).attribute14          := Get_Field(l_line,l_delimiter,25) ;
1150           l_this_lvl_tbl(l_idx).attribute15          := Get_Field(l_line,l_delimiter,26) ;
1151           l_this_lvl_tbl(l_idx).attribute16          := Get_Field(l_line,l_delimiter,27) ;
1152           l_this_lvl_tbl(l_idx).attribute17          := Get_Field(l_line,l_delimiter,28) ;
1153           l_this_lvl_tbl(l_idx).attribute18          := Get_Field(l_line,l_delimiter,29) ;
1154           l_this_lvl_tbl(l_idx).attribute19          := Get_Field(l_line,l_delimiter,30) ;
1155           l_this_lvl_tbl(l_idx).attribute20          := Get_Field(l_line,l_delimiter,31) ;
1156           l_this_lvl_tbl(l_idx).attribute21          := Get_Field(l_line,l_delimiter,32) ;
1157           l_this_lvl_tbl(l_idx).attribute22          := Get_Field(l_line,l_delimiter,33) ;
1158           l_this_lvl_tbl(l_idx).attribute23          := Get_Field(l_line,l_delimiter,34) ;
1159           l_this_lvl_tbl(l_idx).attribute24          := Get_Field(l_line,l_delimiter,35) ;
1160           l_this_lvl_tbl(l_idx).attribute25          := Get_Field(l_line,l_delimiter,36) ;
1161           l_this_lvl_tbl(l_idx).attribute26          := Get_Field(l_line,l_delimiter,37) ;
1162           l_this_lvl_tbl(l_idx).attribute27          := Get_Field(l_line,l_delimiter,38) ;
1163           l_this_lvl_tbl(l_idx).attribute28          := Get_Field(l_line,l_delimiter,39) ;
1164           l_this_lvl_tbl(l_idx).attribute29          := Get_Field(l_line,l_delimiter,40) ;
1165           l_this_lvl_tbl(l_idx).attribute30          := Get_Field(l_line,l_delimiter,41) ;
1166           l_this_lvl_tbl(l_idx).attribute_category   := Get_Field(l_line,l_delimiter,42) ;
1167           /*
1168           UTL_FILE.PUT_LINE(l_log_handle,'tl cmpntcost_id('||l_idx||') = '||l_this_lvl_tbl(l_idx).cmpntcost_id) ;
1169           UTL_FILE.PUT_LINE(l_log_handle,'tl cost_cmpntcls_id('||l_idx||') = '||l_this_lvl_tbl(l_idx).cost_cmpntcls_id) ;
1170           UTL_FILE.PUT_LINE(l_log_handle,'tl cost_cmpntcls_code('||l_idx||') = '||l_this_lvl_tbl(l_idx).cost_cmpntcls_code) ;
1171           UTL_FILE.PUT_LINE(l_log_handle,'tl cost_analysis_code('||l_idx||') = '||l_this_lvl_tbl(l_idx).cost_analysis_code) ;
1172           UTL_FILE.PUT_LINE(l_log_handle,'tl cmpnt_cost('||l_idx||') = '||l_this_lvl_tbl(l_idx).cmpnt_cost) ;
1173           UTL_FILE.PUT_LINE(l_log_handle,'tl burden_ind('||l_idx||') = '||l_this_lvl_tbl(l_idx).burden_ind) ;
1174           UTL_FILE.PUT_LINE(l_log_handle,'tl total_qty('||l_idx||') = '||l_this_lvl_tbl(l_idx).total_qty) ;
1175           UTL_FILE.PUT_LINE(l_log_handle,'tl costcalc_orig('||l_idx||') = '||l_this_lvl_tbl(l_idx).costcalc_orig) ;
1176           UTL_FILE.PUT_LINE(l_log_handle,'tl rmcalc_type('||l_idx||') = '||l_this_lvl_tbl(l_idx).rmcalc_type) ;
1177           UTL_FILE.PUT_LINE(l_log_handle,'tl delete_mark('||l_idx||') = '||l_this_lvl_tbl(l_idx).delete_mark) ;
1178           */
1179         ELSIF l_type = '30' AND l_skip_details = 'Y' THEN
1180           UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skipping this record...');
1181         ELSIF l_type = '30' AND l_skip_details = 'N'  THEN
1182           l_idx1 := l_idx1 + 1 ;
1183           --UTL_FILE.PUT_LINE(l_log_handle, 'Populating lower level table...' || l_idx1 ) ;
1184           l_type                                       := Get_Field(l_line,l_delimiter,1) ;
1185           l_lower_lvl_tbl(l_idx1).cmpntcost_id         := Get_Field(l_line,l_delimiter,2) ;
1186           l_lower_lvl_tbl(l_idx1).cost_cmpntcls_id     := Get_Field(l_line,l_delimiter,3) ;
1187           l_lower_lvl_tbl(l_idx1).cost_cmpntcls_code   := Get_Field(l_line,l_delimiter,4) ;
1188           l_lower_lvl_tbl(l_idx1).cost_analysis_code   := Get_Field(l_line,l_delimiter,5) ;
1189           l_lower_lvl_tbl(l_idx1).cmpnt_cost           := Get_Field(l_line,l_delimiter,6) ;
1190           l_lower_lvl_tbl(l_idx1).delete_mark          := Get_Field(l_line,l_delimiter,7) ;
1191           /*
1192           UTL_FILE.PUT_LINE(l_log_handle,'ll cmpntcost_id('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cmpntcost_id) ;
1193           UTL_FILE.PUT_LINE(l_log_handle,'ll cost_cmpntcls_id('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cost_cmpntcls_id)      ;
1194           UTL_FILE.PUT_LINE(l_log_handle,'ll cost_cmpntcls_code('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cost_cmpntcls_code) ;
1195           UTL_FILE.PUT_LINE(l_log_handle,'ll cost_analysis_code('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cost_analysis_code) ;
1196           UTL_FILE.PUT_LINE(l_log_handle,'ll cmpnt_cost('||l_idx1||') = '||l_lower_lvl_tbl(l_idx1).cmpnt_cost) ;
1197           */
1198         END IF ;
1199       EXCEPTION
1200         WHEN OTHERS THEN
1201           UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1202           UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1203           IF l_type = '10' THEN
1204             l_skip_details := 'Y' ;
1205             UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skip detail records.');
1206           ELSIF l_type = '20' THEN
1207             l_this_lvl_tbl.delete(l_idx);
1208             l_idx := l_idx-1;
1209           ELSIF l_type = '30' THEN
1210             l_lower_lvl_tbl.delete(l_idx1);
1211             l_idx1 := l_idx1-1;
1212           END IF ;
1213       END ;
1214       BEGIN
1215         UTL_FILE.GET_LINE(l_infile_handle, l_line);
1216         l_record_count    :=l_record_count+1;
1217         UTL_FILE.NEW_LINE(l_log_handle);
1218         l_type   := Get_Field(l_line,l_delimiter,1) ;  -- 10 : header rec, 20 : this level, 30 : lower level
1219         --l_skip_details := 'N' ;
1220         --UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
1221         --UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
1222       EXCEPTION
1223         WHEN NO_DATA_FOUND THEN
1224           IF l_skip_details = 'N' THEN
1225             -- DBMS_OUTPUT.PUT_LINE('In exception. Calling Delete_Item_Cost API...');
1226             GMF_ItemCost_PUB.Delete_Item_Cost
1227             (
1228             p_api_version         =>      3.0,
1229             p_init_msg_list       =>      FND_API.G_TRUE,
1230             p_commit              =>      FND_API.G_TRUE,
1231             x_return_status       =>      l_status,
1232             x_msg_count           =>      l_count,
1233             x_msg_data            =>      l_data,
1234             p_header_rec          =>      l_header_rec,
1235             p_this_level_dtl_tbl  =>      l_this_lvl_tbl,
1236             p_lower_level_dtl_Tbl =>      l_lower_lvl_tbl
1237             );
1238             UTL_FILE.PUT_LINE(l_log_handle, 'in exception. after API call. status := ' || l_status ||' cnt := ' || l_count );
1239             l_continue := 'N' ;
1240             GOTO GET_MSG_STACK ;
1241           END IF ;
1242       END;
1243       -- DBMS_OUTPUT.PUT_LINE('Check to call Delete_Item_Cost API...type - ' || l_type || ' count = ' || l_record_count);
1244       IF (l_type = '10' AND l_record_count <> 1 AND l_skip_details = 'N') THEN
1245         -- DBMS_OUTPUT.PUT_LINE('Calling Delete_Item_Cost API...');
1246         GMF_ItemCost_PUB.Delete_Item_Cost
1247         (
1248         p_api_version         =>      3.0,
1249         p_init_msg_list       =>      FND_API.G_TRUE,
1250         p_commit              =>      FND_API.G_TRUE,
1251         x_return_status       =>      l_status,
1252         x_msg_count           =>      l_count,
1253         x_msg_data            =>      l_data,
1254         p_header_rec          =>      l_header_rec,
1255         p_this_level_dtl_tbl  =>      l_this_lvl_tbl,
1256         p_lower_level_dtl_Tbl =>      l_lower_lvl_tbl
1257         );
1258         UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
1259       END IF;
1260       <<GET_MSG_STACK>>
1261       NULL;
1262 
1263       /*******************************************************************************************
1264       * Check if any messages generated. If so then decode and output to error message flat file *
1265       *******************************************************************************************/
1266       IF l_count > 0 THEN
1267         l_loop_cnt  :=1;
1268         LOOP
1269           FND_MSG_PUB.Get
1270           (
1271           p_msg_index     => l_loop_cnt,
1272           p_data          => l_data,
1273           p_encoded       => FND_API.G_FALSE,
1274           p_msg_index_out => l_dummy_cnt
1275           );
1276           -- DBMS_OUTPUT.PUT_LINE(l_data );
1277           --UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
1278           --UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
1279           --UTL_FILE.NEW_LINE(l_outfile_handle);
1280           UTL_FILE.PUT_LINE(l_log_handle, l_data);
1281 
1282           /**********************
1283           * Update error status *
1284           **********************/
1285           IF (l_status = 'U') THEN
1286             l_return_status  :=l_status;
1287           ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
1288             l_return_status  :=l_status;
1289           ELSE
1290             l_return_status  :=l_status;
1291           END IF;
1292           l_loop_cnt  := l_loop_cnt + 1;
1293           IF l_loop_cnt > l_count THEN
1294             EXIT;
1295           END IF;
1296         END LOOP; -- msg stack loop
1297         l_count := 0 ;
1298       END IF;	-- if count of msg stack > 0
1299       IF l_continue = 'N' THEN
1300         EXIT ;
1301       END IF ;
1302     END LOOP;
1303     -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1304     UTL_FILE.NEW_LINE(l_log_handle);
1305     UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1306     UTL_FILE.FCLOSE_ALL;
1307     RETURN l_return_status;
1308   EXCEPTION
1309     WHEN UTL_FILE.INVALID_OPERATION THEN
1310       -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file);
1311       UTL_FILE.FCLOSE_ALL;
1312       RETURN l_return_status;
1313     WHEN UTL_FILE.INVALID_PATH THEN
1314       -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file);
1315       UTL_FILE.FCLOSE_ALL;
1316       RETURN l_return_status;
1317     WHEN UTL_FILE.INVALID_MODE THEN
1318       -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file);
1319       UTL_FILE.FCLOSE_ALL;
1320       RETURN l_return_status;
1321     WHEN UTL_FILE.INVALID_FILEHANDLE THEN
1322       -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file);
1323       UTL_FILE.FCLOSE_ALL;
1324       RETURN l_return_status;
1325     WHEN UTL_FILE.WRITE_ERROR THEN
1326       -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file);
1327       UTL_FILE.FCLOSE_ALL;
1328       RETURN l_return_status;
1329     WHEN UTL_FILE.READ_ERROR THEN
1330       -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file);
1331       UTL_FILE.FCLOSE_ALL;
1332       RETURN l_return_status;
1333     WHEN UTL_FILE.INTERNAL_ERROR THEN
1334       -- DBMS_OUTPUT.PUT_LINE('Internal Error');
1335       UTL_FILE.FCLOSE_ALL;
1336       RETURN l_return_status;
1337     WHEN OTHERS THEN
1338       -- DBMS_OUTPUT.PUT_LINE('Other Error');
1339       UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1340       UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1341       UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1342       UTL_FILE.FCLOSE_ALL;
1343       l_return_status := 'U' ;
1344       RETURN l_return_status;
1345   END Delete_Item_Cost;
1346 
1347 /*  Body start of comments
1348  +==========================================================================+
1349  | PROCEDURE NAME                                                           |
1350  |    Get_Item_Cost                                                         |
1351  |                                                                          |
1352  | TYPE                                                                     |
1353  |    Public                                                                |
1354  |                                                                          |
1355  | USAGE                                                                    |
1356  |    Get Item Cost                                                         |
1357  |                                                                          |
1358  | DESCRIPTION                                                              |
1359  |    This is a PL/SQL wrapper procedure to call the                        |
1360  |    Get_Item_Cost API wrapper function                                    |
1361  |                                                                          |
1362  | PARAMETERS                                                               |
1363  |    p_dir              IN VARCHAR2         - Working directory for input  |
1364  |                                             and output files.            |
1365  |    p_input_file       IN VARCHAR2         - Name of input file           |
1366  |    p_output_file      IN VARCHAR2         - Name of output file          |
1367  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
1368  |                                                                          |
1369  | RETURNS                                                                  |
1370  |    None                                                                  |
1371  |                                                                          |
1372  | HISTORY                                                                  |
1373  |    27/Feb/2001  Uday Moogala  Created  Bug# 1418689                      |
1374  |                                                                          |
1375  +==========================================================================+
1376   Api end of comments
1377 */
1378   PROCEDURE Get_Item_Cost
1379   (
1380   p_dir                 IN              VARCHAR2,
1381   p_input_file          IN              VARCHAR2,
1382   p_output_file         IN              VARCHAR2,
1383   p_delimiter           IN              VARCHAR2
1384   )
1385   IS
1386     /******************
1387     * Local Variables *
1388     ******************/
1389     l_return_status  VARCHAR2(1);
1390   BEGIN
1391     l_return_status  :=Get_Item_Cost(p_dir, p_input_file, p_output_file, p_delimiter);
1392   END Get_Item_Cost;
1393 
1394 /* +========================================================================+
1395  | FUNCTION NAME                                                            |
1396  |    Get_Item_Cost                                                         |
1397  |                                                                          |
1398  | TYPE                                                                     |
1399  |    Public                                                                |
1400  |                                                                          |
1401  | USAGE                                                                    |
1402  |    Get Item Cost                                                         |
1403  |                                                                          |
1404  | DESCRIPTION                                                              |
1405  |    This is a PL/SQL wrapper function to call the                         |
1406  |    Get_Item_Cost API.                                                    |
1407  |    It reads item data from a flat file and outputs any error             |
1408  |    messages to a second flat file. It also generates a Status            |
1409  |    called gmf_rsrc_wrapper<session_id>.log in the /tmp directory.        |
1410  |                                                                          |
1411  | PARAMETERS                                                               |
1412  |    p_dir              IN VARCHAR2         - Working directory for input  |
1413  |                                             and output files.            |
1414  |    p_input_file       IN VARCHAR2         - Name of input file           |
1415  |    p_output_file      IN VARCHAR2         - Name of output file          |
1416  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
1417  |                                                                          |
1418  | RETURNS                                                                  |
1419  |    VARCHAR2 - 'S' All records processed successfully                     |
1420  |               'E' 1 or more records errored                              |
1421  |               'U' 1 or more record unexpected error                      |
1422  |                                                                          |
1423  | HISTORY                                                                  |
1424  |                                                                          |
1425  +==========================================================================+
1426   Api end of comments
1427 */
1428 
1429   FUNCTION Get_Item_Cost
1430   (
1431   p_dir                 IN              VARCHAR2,
1432   p_input_file          IN              VARCHAR2,
1433   p_output_file         IN              VARCHAR2,
1434   p_delimiter           IN              VARCHAR2
1435   )
1436   RETURN VARCHAR2
1437   IS
1438 
1439     /******************
1440     * Local variables *
1441     ******************/
1442     l_status              VARCHAR2(11);
1443     l_return_status       VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
1444     l_count               NUMBER(10)  ;
1445     l_record_count        NUMBER(10)  :=0;
1446     l_loop_cnt            NUMBER(10)  :=0;
1447     l_dummy_cnt           NUMBER(10)  :=0;
1448     l_data                VARCHAR2(1000);
1449     l_header_rec          GMF_ItemCost_PUB.Header_Rec_Type;
1450     l_this_lvl_tbl        GMF_ItemCost_PUB.This_Level_Dtl_Tbl_Type;
1451     l_lower_lvl_tbl       GMF_ItemCost_PUB.Lower_Level_Dtl_Tbl_Type;
1452     l_costcmpnt_ids       GMF_ItemCost_PUB.costcmpnt_ids_tbl_type;
1453     l_p_dir               VARCHAR2(150);
1454     l_output_file         VARCHAR2(120);
1455     l_outfile_handle      UTL_FILE.FILE_TYPE;
1456     l_input_file          VARCHAR2(120);
1457     l_infile_handle       UTL_FILE.FILE_TYPE;
1458     l_line                VARCHAR2(1000);
1459     l_delimiter           VARCHAR(11);
1460     l_log_dir             VARCHAR2(150);
1461     l_log_name            VARCHAR2(120)  :='gmf_api_getic_wrapper';
1462     l_log_handle          UTL_FILE.FILE_TYPE;
1463     l_global_file         VARCHAR2(120);
1464     l_idx		              NUMBER(10);
1465     l_idx1		            NUMBER(10);
1466     l_type		            VARCHAR2(100);
1467     l_continue            VARCHAR2(1) := 'Y' ;
1468     l_skip_details        VARCHAR2(1) := 'N' ;
1469     l_session_id          VARCHAR2(110);
1470   BEGIN
1471     /********************
1472     * Enable The Buffer *
1473     ********************/
1474     /*  DBMS_OUTPUT.ENABLE(1000000); */
1475     -- DBMS_OUTPUT.PUT_LINE('in Get_Item_Cost function...');
1476     l_p_dir              :=       p_dir;
1477     l_input_file         :=       p_input_file;
1478     l_output_file        :=       p_output_file;
1479     l_delimiter          :=       p_delimiter;
1480     l_global_file        :=       l_input_file;
1481 
1482     /*******************************************************
1483     * Obtain The SessionId To Append To wrapper File Name. *
1484     *******************************************************/
1485     l_session_id := USERENV('sessionid');
1486     l_log_name  := CONCAT(l_log_name,l_session_id);
1487     l_log_name  := CONCAT(l_log_name,'.log');
1488 
1489     /*****************************************************
1490     * Directory is now the same same as for the out file *
1491     *****************************************************/
1492     l_log_dir   := p_dir;
1493 
1494     /*****************************************************************
1495     * Open The Wrapper File For Output And The Input File for Input. *
1496     *****************************************************************/
1497     l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
1498     l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
1499 
1500     /*  Loop thru flat file and call Inventory Quantities API */
1501     -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1502     -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
1503     -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
1504     -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
1505     -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
1506     /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
1507     UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1508     UTL_FILE.NEW_LINE(l_log_handle);
1509     UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
1510     UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
1511     UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
1512     UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
1513     l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
1514     LOOP
1515       l_record_count    :=l_record_count+1;
1516       BEGIN
1517         UTL_FILE.GET_LINE(l_infile_handle, l_line);
1518       EXCEPTION
1519         WHEN NO_DATA_FOUND THEN
1520           EXIT;
1521       END;
1522       BEGIN
1523         UTL_FILE.NEW_LINE(l_log_handle);
1524         UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
1525         l_header_rec.period_id          := Get_Field(l_line,l_delimiter,1) ;
1526         l_header_rec.calendar_code      := Get_Field(l_line,l_delimiter,2) ;
1527         l_header_rec.period_code        := Get_Field(l_line,l_delimiter,3) ;
1528         l_header_rec.cost_type_id       := Get_Field(l_line,l_delimiter,4) ;
1529         l_header_rec.cost_mthd_code     := Get_Field(l_line,l_delimiter,5) ;
1530         l_header_rec.organization_id    := Get_Field(l_line,l_delimiter,6) ;
1531         l_header_rec.organization_code  := Get_Field(l_line,l_delimiter,7) ;
1532         l_header_rec.inventory_item_id  := Get_Field(l_line,l_delimiter,8) ;
1533         l_header_rec.item_number        := Get_Field(l_line,l_delimiter,9) ;
1534         l_header_rec.user_name          := Get_Field(l_line,l_delimiter,10) ;
1535         UTL_FILE.PUT_LINE(l_log_handle, 'Period_id        = ' || l_header_rec.period_id) ;
1536         UTL_FILE.PUT_LINE(l_log_handle, 'Calendar_code    = ' || l_header_rec.Calendar_code) ;
1537         UTL_FILE.PUT_LINE(l_log_handle, 'period_code      = ' || l_header_rec.period_code) ;
1538         UTL_FILE.PUT_LINE(l_log_handle, 'cost_type_id     = ' || l_header_rec.cost_type_id) ;
1539         UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code   = ' || l_header_rec.cost_mthd_code) ;
1540         UTL_FILE.PUT_LINE(l_log_handle, 'Organization_id  = ' || l_header_rec.organization_id) ;
1541         UTL_FILE.PUT_LINE(l_log_handle, 'Organization_code= ' || l_header_rec.organization_code) ;
1542         UTL_FILE.PUT_LINE(l_log_handle, 'inventory_item_id= ' || l_header_rec.inventory_item_id) ;
1543         UTL_FILE.PUT_LINE(l_log_handle, 'item_number      = ' || l_header_rec.item_number) ;
1544         UTL_FILE.PUT_LINE(l_log_handle, 'user_name       = ' || l_header_rec.user_name) ;
1545         -- DBMS_OUTPUT.PUT_LINE('Calling Get_Item_Cost API...');
1546         GMF_ItemCost_PUB.Get_Item_Cost
1547         (
1548         p_api_version         =>          3.0,
1549         p_init_msg_list       =>          FND_API.G_TRUE,
1550         x_return_status       =>          l_status,
1551         x_msg_count           =>          l_count,
1552         x_msg_data            =>          l_data,
1553         p_header_rec          =>          l_header_rec,
1554         x_this_level_dtl_tbl  =>          l_this_lvl_tbl,
1555         x_lower_level_dtl_Tbl =>          l_lower_lvl_tbl
1556         );
1557         UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
1558         IF l_count > 0 THEN
1559           l_loop_cnt  :=1;
1560           LOOP
1561             FND_MSG_PUB.Get
1562             (
1563             p_msg_index     => l_loop_cnt,
1564             p_data          => l_data,
1565             p_encoded       => FND_API.G_FALSE,
1566             p_msg_index_out => l_dummy_cnt
1567             );
1568             -- DBMS_OUTPUT.PUT_LINE(l_data );
1569             --UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
1570             --UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
1571             --UTL_FILE.NEW_LINE(l_outfile_handle);
1572             UTL_FILE.PUT_LINE(l_log_handle, l_data);
1573 
1574             /**********************
1575             * Update error status *
1576             **********************/
1577             IF (l_status = 'U') THEN
1578               l_return_status  :=l_status;
1579             ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
1580               l_return_status  :=l_status;
1581             ELSE
1582               l_return_status  :=l_status;
1583             END IF;
1584             l_loop_cnt  := l_loop_cnt + 1;
1585             IF l_loop_cnt > l_count THEN
1586               EXIT;
1587             END IF;
1588           END LOOP;
1589         END IF;
1590         UTL_FILE.NEW_LINE(l_log_handle);
1591         UTL_FILE.PUT_LINE( l_log_handle, 'This Level Cost Components : ' ) ;
1592         FOR i in 1..l_this_lvl_tbl.count LOOP
1593           UTL_FILE.PUT_LINE( l_log_handle,  ' CostId : '        || l_this_lvl_tbl(i).cmpntcost_id ||
1594                                             ' CmpntClsId : '    || l_this_lvl_tbl(i).cost_cmpntcls_id ||
1595                                             ' CmpntCls Code : ' || l_this_lvl_tbl(i).cost_cmpntcls_Code ||
1596                                             ' Analysis Code : ' || l_this_lvl_tbl(i).cost_analysis_code ||
1597                                             ' Cmpt Cost : '     || l_this_lvl_tbl(i).cmpnt_cost) ;
1598         END LOOP ;
1599         UTL_FILE.NEW_LINE(l_log_handle);
1600         UTL_FILE.PUT_LINE( l_log_handle, 'Lower Level Cost Components : ' ) ;
1601         FOR i in 1..l_lower_lvl_tbl.count LOOP
1602           UTL_FILE.PUT_LINE( l_log_handle,  ' CostId : '        || l_lower_lvl_tbl(i).cmpntcost_id ||
1603                                             ' CmpntClsId : '    || l_lower_lvl_tbl(i).cost_cmpntcls_id ||
1604                                             ' CmpntCls Code : ' || l_lower_lvl_tbl(i).cost_cmpntcls_Code ||
1605                                             ' Analysis Code : ' || l_lower_lvl_tbl(i).cost_analysis_code ||
1606                                             ' Cmpt Cost : '     || l_lower_lvl_tbl(i).cmpnt_cost) ;
1607         END LOOP ;
1608       EXCEPTION
1609         WHEN OTHERS THEN
1610           UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1611           UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1612           l_return_status := 'U' ;
1613       END ;
1614     END LOOP;
1615     -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1616     UTL_FILE.NEW_LINE(l_log_handle);
1617     UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1618     UTL_FILE.FCLOSE_ALL;
1619     RETURN l_return_status;
1620   EXCEPTION
1621     WHEN UTL_FILE.INVALID_OPERATION THEN
1622       -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file);
1623       UTL_FILE.FCLOSE_ALL;
1624       RETURN l_return_status;
1625     WHEN UTL_FILE.INVALID_PATH THEN
1626       -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file);
1627       UTL_FILE.FCLOSE_ALL;
1628       RETURN l_return_status;
1629     WHEN UTL_FILE.INVALID_MODE THEN
1630       -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file);
1631       UTL_FILE.FCLOSE_ALL;
1632       RETURN l_return_status;
1633     WHEN UTL_FILE.INVALID_FILEHANDLE THEN
1634       -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file);
1635       UTL_FILE.FCLOSE_ALL;
1636       RETURN l_return_status;
1637     WHEN UTL_FILE.WRITE_ERROR THEN
1638       -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file);
1639       UTL_FILE.FCLOSE_ALL;
1640       RETURN l_return_status;
1641     WHEN UTL_FILE.READ_ERROR THEN
1642       -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file);
1643       UTL_FILE.FCLOSE_ALL;
1644       RETURN l_return_status;
1645     WHEN UTL_FILE.INTERNAL_ERROR THEN
1646       -- DBMS_OUTPUT.PUT_LINE('Internal Error');
1647       UTL_FILE.FCLOSE_ALL;
1648       RETURN l_return_status;
1649     WHEN OTHERS THEN
1650       -- DBMS_OUTPUT.PUT_LINE('Other Error');
1651       UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1652       UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1653       UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1654       UTL_FILE.FCLOSE_ALL;
1655       l_return_status := 'U' ;
1656       RETURN l_return_status;
1657   END Get_Item_Cost;
1658 
1659 --+==========================================================================+
1660 --| PROCEDURE NAME                                                           |
1661 --|    Process_ActualCost_Adjustment                                         |
1662 --|                                                                          |
1663 --| TYPE                                                                     |
1664 --|    Public                                                                |
1665 --|                                                                          |
1666 --| USAGE                                                                    |
1667 --|    Create/Insert, Update,Delete Actual Lot Cost Adjustment               |
1668 --|                                                                          |
1669 --| DESCRIPTION                                                              |
1670 --|    This is a PL/SQL wrapper procedure to call the                        |
1671 --|    Call_ActualCost_API wrapper function	   		                           |
1672 --|                                                                          |
1673 --| PARAMETERS                                                               |
1674 --|    p_dir              IN VARCHAR2         - Working directory for input  |
1675 --|                                             and output files.            |
1676 --|    p_input_file       IN VARCHAR2         - Name of input file           |
1677 --|    p_output_file      IN VARCHAR2         - Name of output file          |
1678 --|    p_delimiter        IN VARCHAR2         - Delimiter character          |
1679 --|    p_operation	  IN VARCHAR2	      - Operation to be performed          |
1680 --|                                                                          |
1681 --| RETURNS                                                                  |
1682 --|    None                                                                  |
1683 --|                                                                          |
1684 --| HISTORY                                                                  |
1685 --|    30/Oct/2005  Anand Thiyagarajan      Created                          |
1686 --|                                                                          |
1687 --+==========================================================================+
1688 
1689   PROCEDURE Process_ActualCost_Adjustment
1690   (
1691   p_dir                   IN            VARCHAR2,
1692   p_input_file            IN            VARCHAR2,
1693   p_output_file           IN            VARCHAR2,
1694   p_delimiter             IN            VARCHAR2,
1695   p_operation             IN            VARCHAR2
1696   )
1697   IS
1698 
1699     /******************
1700     * Local Variables *
1701     ******************/
1702     l_return_status  VARCHAR2(1);
1703   BEGIN
1704     l_return_status  := Process_ActualCost_Adjustment(p_dir, p_input_file, p_output_file, p_delimiter, p_operation);
1705   End Process_ActualCost_Adjustment;
1706 
1707 /* +==========================================================================+
1708  | FUNCTION NAME                                                              |
1709  |    Process_ActualCost_Adjustment                                           |
1710  |                                                                            |
1711  | TYPE                                                                       |
1712  |    Public                                                                  |
1713  |                                                                            |
1714  | USAGE                                                                      |
1715  |    Create/Insert, Update or Delete Actual Cost Adjustment                  |
1716  |                                                                            |
1717  | DESCRIPTION                                                                |
1718  |    This is a PL/SQL wrapper function to call the                           |
1719  |    Call_ActualCost_API.							                                      |
1720  |    It reads item data from a flat file and outputs any error               |
1721  |    messages to a second flat file. It also generates a Status              |
1722  |    called gmf_api_<operation>_wrapper<session_id>.log in the /tmp directory|
1723  |                                                                            |
1724  | PARAMETERS                                                                 |
1725  |    p_dir              IN VARCHAR2         - Working directory for input    |
1726  |                                             and output files.              |
1727  |    p_input_file       IN VARCHAR2         - Name of input file             |
1728  |    p_output_file      IN VARCHAR2         - Name of output file            |
1729  |    p_delimiter        IN VARCHAR2         - Delimiter character            |
1730  |    p_operation	  IN VARCHAR2	     - Operation to be performed              |
1731  |									                                                          |
1732  | RETURNS                                                                    |
1733  |    VARCHAR2 - 'S' All records processed successfully                       |
1734  |               'E' 1 or more records errored                                |
1735  |               'U' 1 or more record unexpected error                        |
1736  |                                                                            |
1737  | HISTORY                                                                    |
1738  |    30-Oct-2005     Anand Thiyagarajan      Created                         |
1739  |                                                                            |
1740  +============================================================================+
1741   Api end of comments
1742 */
1743   FUNCTION Process_ActualCost_Adjustment
1744   (
1745   p_dir                   IN            VARCHAR2,
1746   p_input_file            IN            VARCHAR2,
1747   p_output_file           IN            VARCHAR2,
1748   p_delimiter             IN            VARCHAR2,
1749   p_operation             IN            VARCHAR2
1750   )
1751   RETURN VARCHAR2
1752   IS
1753 
1754     /******************
1755     * Local variables *
1756     ******************/
1757     l_status              VARCHAR2(11);
1758     l_return_status       VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
1759     l_count               NUMBER(10)  ;
1760     l_record_count        NUMBER(10)  :=0;
1761     l_loop_cnt            NUMBER(10)  :=0;
1762     l_dummy_cnt           NUMBER(10)  :=0;
1763     l_data                VARCHAR2(32767);
1764     l_adjustment_rec      GMF_ACTUAL_COST_ADJUSTMENT_PUB.ADJUSTMENT_REC_TYPE;
1765     l_p_dir               VARCHAR2(150);
1766     l_output_file         VARCHAR2(120);
1767     l_outfile_handle      UTL_FILE.FILE_TYPE;
1768     l_input_file          VARCHAR2(120);
1769     l_infile_handle       UTL_FILE.FILE_TYPE;
1770     l_line                VARCHAR2(32767);
1771     l_delimiter           VARCHAR(11);
1772     l_log_dir             VARCHAR2(150);
1773     l_log_name            VARCHAR2(120) ;
1774     l_log_handle          UTL_FILE.FILE_TYPE;
1775     l_global_file         VARCHAR2(120);
1776     l_idx		              NUMBER(10);
1777     l_idx1		            NUMBER(10);
1778     l_type		            VARCHAR2(32767);
1779     l_continue            VARCHAR2(1) := 'Y' ;
1780     l_skip_details        VARCHAR2(1) := 'N' ;
1781     l_session_id          VARCHAR2(110);
1782   BEGIN
1783     /********************
1784     * Enable The Buffer *
1785     ********************/
1786     l_p_dir               :=        p_dir;
1787     l_log_dir	            :=        p_dir;
1788     l_input_file          :=        p_input_file;
1789     l_output_file         :=        p_output_file;
1790     l_delimiter           :=        p_delimiter;
1791     l_global_file         :=        l_input_file;
1792     IF p_operation = 'INSERT' THEN
1793       l_log_name := 'gmf_api_crtacadj_wrapper' ;
1794     ELSIF p_operation = 'UPDATE' THEN
1795       l_log_name := 'gmf_api_updacadj_wrapper' ;
1796     ELSIF p_operation = 'DELETE' THEN
1797       l_log_name := 'gmf_api_delacadj_wrapper' ;
1798     END IF ;
1799 
1800     /*******************************************************
1801     * Obtain The SessionId To Append To wrapper File Name. *
1802     *******************************************************/
1803     l_session_id := USERENV('sessionid');
1804     l_log_name  := CONCAT(l_log_name,l_session_id);
1805     l_log_name  := CONCAT(l_log_name,'.log');
1806 
1807     /*****************************************************
1808     * Directory is now the same same as for the out file *
1809     *****************************************************/
1810     l_log_dir   := p_dir;
1811 
1812     /*****************************************************************
1813     * Open The Wrapper File For Output And The Input File for Input. *
1814     *****************************************************************/
1815     l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
1816     l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
1817     /*
1818     DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1819     DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
1820     DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
1821     DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
1822     DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
1823     */
1824 
1825     UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1826     UTL_FILE.NEW_LINE(l_log_handle);
1827     UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
1828     UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
1829     UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
1830     UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
1831     l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
1832     LOOP
1833       l_record_count    :=l_record_count+1;
1834       BEGIN
1835         UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || to_char(l_record_count));
1836         UTL_FILE.GET_LINE(l_infile_handle, l_line);
1837         IF l_line IS NOT NULL THEN
1838           l_adjustment_rec.cost_adjust_id       :=	 Get_Field(l_line,l_delimiter,1);
1839           l_adjustment_rec.organization_id      :=	 Get_Field(l_line,l_delimiter,2);
1840           l_adjustment_rec.organization_code    :=	 Get_Field(l_line,l_delimiter,3);
1841           l_adjustment_rec.inventory_item_id    :=	 Get_Field(l_line,l_delimiter,4);
1842           l_adjustment_rec.item_number          :=	 Get_Field(l_line,l_delimiter,5);
1843           l_adjustment_rec.cost_type_id         :=	 Get_Field(l_line,l_delimiter,6);
1844           l_adjustment_rec.cost_mthd_code       :=	 Get_Field(l_line,l_delimiter,7);
1845           l_adjustment_rec.period_id            :=	 Get_Field(l_line,l_delimiter,8);
1846           l_adjustment_rec.calendar_code        :=	 Get_Field(l_line,l_delimiter,9);
1847           l_adjustment_rec.period_code          :=	 Get_Field(l_line,l_delimiter,10);
1848           l_adjustment_rec.cost_cmpntcls_id     :=	 Get_Field(l_line,l_delimiter,11);
1849           l_adjustment_rec.cost_cmpntcls_code   :=	 Get_Field(l_line,l_delimiter,12);
1850           l_adjustment_rec.cost_analysis_code   :=	 Get_Field(l_line,l_delimiter,13);
1851           l_adjustment_rec.adjust_qty           :=	 Get_Field(l_line,l_delimiter,14);
1852           l_adjustment_rec.adjust_qty_uom       :=	 Get_Field(l_line,l_delimiter,15);
1853           l_adjustment_rec.adjust_cost          :=	 Get_Field(l_line,l_delimiter,16);
1854           l_adjustment_rec.reason_code          :=	 Get_Field(l_line,l_delimiter,17);
1855           l_adjustment_rec.adjust_status        :=	 Get_Field(l_line,l_delimiter,18);
1856           l_adjustment_rec.delete_mark          :=	 Get_Field(l_line,l_delimiter,19);
1857           l_adjustment_rec.attribute1           :=	 Get_Field(l_line,l_delimiter,20);
1858           l_adjustment_rec.attribute2           :=	 Get_Field(l_line,l_delimiter,21);
1859           l_adjustment_rec.attribute3           :=	 Get_Field(l_line,l_delimiter,22);
1860           l_adjustment_rec.attribute4           :=	 Get_Field(l_line,l_delimiter,23);
1861           l_adjustment_rec.attribute5           :=	 Get_Field(l_line,l_delimiter,24);
1862           l_adjustment_rec.attribute6           :=	 Get_Field(l_line,l_delimiter,25);
1863           l_adjustment_rec.attribute7           :=	 Get_Field(l_line,l_delimiter,26);
1864           l_adjustment_rec.attribute8           :=	 Get_Field(l_line,l_delimiter,27);
1865           l_adjustment_rec.attribute9           :=	 Get_Field(l_line,l_delimiter,28);
1866           l_adjustment_rec.attribute10          :=	 Get_Field(l_line,l_delimiter,29);
1867           l_adjustment_rec.attribute11          :=	 Get_Field(l_line,l_delimiter,30);
1868           l_adjustment_rec.attribute12          :=	 Get_Field(l_line,l_delimiter,31);
1869           l_adjustment_rec.attribute13          :=	 Get_Field(l_line,l_delimiter,32);
1870           l_adjustment_rec.attribute14          :=	 Get_Field(l_line,l_delimiter,33);
1871           l_adjustment_rec.attribute15          :=	 Get_Field(l_line,l_delimiter,34);
1872           l_adjustment_rec.attribute16          :=	 Get_Field(l_line,l_delimiter,35);
1873           l_adjustment_rec.attribute17          :=	 Get_Field(l_line,l_delimiter,36);
1874           l_adjustment_rec.attribute18          :=	 Get_Field(l_line,l_delimiter,37);
1875           l_adjustment_rec.attribute19          :=	 Get_Field(l_line,l_delimiter,38);
1876           l_adjustment_rec.attribute20          :=	 Get_Field(l_line,l_delimiter,39);
1877           l_adjustment_rec.attribute21          :=	 Get_Field(l_line,l_delimiter,40);
1878           l_adjustment_rec.attribute22          :=	 Get_Field(l_line,l_delimiter,41);
1879           l_adjustment_rec.attribute23          :=	 Get_Field(l_line,l_delimiter,42);
1880           l_adjustment_rec.attribute24          :=	 Get_Field(l_line,l_delimiter,43);
1881           l_adjustment_rec.attribute25          :=	 Get_Field(l_line,l_delimiter,44);
1882           l_adjustment_rec.attribute26          :=	 Get_Field(l_line,l_delimiter,45);
1883           l_adjustment_rec.attribute27          :=	 Get_Field(l_line,l_delimiter,46);
1884           l_adjustment_rec.attribute28          :=	 Get_Field(l_line,l_delimiter,47);
1885           l_adjustment_rec.attribute29          :=	 Get_Field(l_line,l_delimiter,48);
1886           l_adjustment_rec.attribute30          :=	 Get_Field(l_line,l_delimiter,49);
1887           l_adjustment_rec.attribute_category   :=	 Get_Field(l_line,l_delimiter,50);
1888           l_adjustment_rec.adjustment_ind       :=	 Get_Field(l_line,l_delimiter,51);
1889           l_adjustment_rec.subledger_ind        :=	 Get_Field(l_line,l_delimiter,52);
1890           l_adjustment_rec.adjustment_date		  :=   fnd_date.canonical_to_date(Get_Field(l_line,l_delimiter,53));
1891           l_adjustment_rec.user_name            :=	 Get_Field(l_line,l_delimiter,54);
1892 
1893           Call_ActualCost_API
1894           (
1895           p_adjustment_rec		=>        l_adjustment_rec,
1896           p_operation    	    =>        p_operation,
1897           x_status       	    =>        l_status,
1898           x_count    		      =>        l_count,
1899           x_data         	    =>        l_data
1900           );
1901         ELSE
1902           l_continue := 'N';
1903         END IF;
1904       EXCEPTION
1905         WHEN no_data_found THEN
1906           l_continue := 'N';
1907         WHEN OTHERS THEN
1908 	        UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1909           UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1910           l_continue := 'N' ;
1911       END;
1912 
1913       /*******************************************************************************************
1914       * Check if any messages generated. If so then decode and output to error message flat file *
1915       *******************************************************************************************/
1916       IF l_count > 0 THEN
1917         l_loop_cnt  :=1;
1918         LOOP
1919           FND_MSG_PUB.Get
1920           (
1921           p_msg_index     => l_loop_cnt,
1922           p_data          => l_data,
1923           p_encoded       => FND_API.G_FALSE,
1924           p_msg_index_out => l_dummy_cnt
1925           );
1926           UTL_FILE.PUT_LINE(l_log_handle, l_data);
1927 
1928           /**********************
1929           * Update error status *
1930           **********************/
1931           IF (l_status = 'U') THEN
1932             l_return_status  :=l_status;
1933           ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
1934             l_return_status  :=l_status;
1935           ELSE
1936             l_return_status  :=l_status;
1937           END IF;
1938           l_loop_cnt  := l_loop_cnt + 1;
1939           IF l_loop_cnt > l_count THEN
1940             EXIT;
1941           END IF;
1942         END LOOP;
1943         l_count := 0 ;
1944       END IF;
1945       IF l_continue = 'N' THEN
1946         EXIT ;
1947       END IF ;
1948     END LOOP;
1949     UTL_FILE.NEW_LINE(l_log_handle);
1950     UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1951     UTL_FILE.FCLOSE_ALL;
1952     RETURN l_return_status;
1953   EXCEPTION
1954     WHEN UTL_FILE.INVALID_OPERATION THEN
1955       -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file);
1956       UTL_FILE.FCLOSE_ALL;
1957       RETURN l_return_status;
1958     WHEN UTL_FILE.INVALID_PATH THEN
1959       -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file);
1960       UTL_FILE.FCLOSE_ALL;
1961       RETURN l_return_status;
1962     WHEN UTL_FILE.INVALID_MODE THEN
1963       -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file);
1964       UTL_FILE.FCLOSE_ALL;
1965       RETURN l_return_status;
1966     WHEN UTL_FILE.INVALID_FILEHANDLE THEN
1967       -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file);
1968       UTL_FILE.FCLOSE_ALL;
1969       RETURN l_return_status;
1970     WHEN UTL_FILE.WRITE_ERROR THEN
1971       -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file);
1972       UTL_FILE.FCLOSE_ALL;
1973       RETURN l_return_status;
1974     WHEN UTL_FILE.READ_ERROR THEN
1975       -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file);
1976       UTL_FILE.FCLOSE_ALL;
1977       RETURN l_return_status;
1978     WHEN UTL_FILE.INTERNAL_ERROR THEN
1979       -- DBMS_OUTPUT.PUT_LINE('Internal Error');
1980       UTL_FILE.FCLOSE_ALL;
1981       RETURN l_return_status;
1982     WHEN OTHERS THEN
1983       -- DBMS_OUTPUT.PUT_LINE('Other Error');
1984       UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1985       UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
1986       UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
1987       UTL_FILE.FCLOSE_ALL;
1988       l_return_status := 'U' ;
1989       RETURN l_return_status;
1990 END Process_ActualCost_Adjustment;
1991 
1992 /* +============================================================================+
1993  | PROCEDURE NAME                                                               |
1994  |    Call_ActualCost_API							                                          |
1995  |                                                                              |
1996  | TYPE                                                                         |
1997  |    Public                                                                    |
1998  |										                                                          |
1999  | USAGE									                                                      |
2000  |    Calls Actual Cost Adjsutment APIs based on the operation being performed	|
2001  |										                                                          |
2002  | DESCRIPTION									                                                |
2003  |    This is a PL/SQL wrapper function to call the Actual Cost Adjustment API. |
2004  |    Data is sent from through the parameters.					                        |
2005  |										                                                          |
2006  | PARAMETERS                                                                   |
2007  |    p_adjustment_rec	    IN VARCHAR2         - Adjustment Details		        |
2008  |    p_operation	    IN VARCHAR2         - Insert/Update/Delete		            |
2009  |    x_status              OUT VARCHAR2        - Return Status			            |
2010  |    x_count               OUT VARCHAR2        - # of msgs on message stack	  |
2011  |    x_data                OUT VARCHAR2        - Actual Message from msg stack	|
2012  |										                                                          |
2013  |										                                                          |
2014  | HISTORY									                                                    |
2015  |     30-Oct-2005 Anand Thiyagarajan Created                                   |
2016  +==============================================================================+
2017 */
2018 
2019   PROCEDURE Call_ActualCost_API
2020   (
2021   p_adjustment_rec		      IN  OUT   NOCOPY    GMF_ACTUAL_COST_ADJUSTMENT_PUB.ADJUSTMENT_REC_TYPE,
2022   p_operation               IN			            VARCHAR2,
2023   x_status                      OUT		NOCOPY	  VARCHAR2,
2024   x_count                       OUT		NOCOPY	  NUMBER,
2025   x_data                        OUT		NOCOPY	  VARCHAR2
2026   )
2027   IS
2028   BEGIN
2029     IF p_operation = 'INSERT' THEN
2030       GMF_ACTUAL_COST_ADJUSTMENT_PUB.CREATE_ACTUAL_COST_ADJUSTMENT
2031       (
2032       p_api_version			        =>              1.0,
2033       p_init_msg_list		        =>              FND_API.G_TRUE,
2034       p_commit		              =>              FND_API.G_TRUE,
2035       x_return_status		        =>              x_status,
2036       x_msg_count			          =>              x_count,
2037       x_msg_data			          =>              x_data,
2038       p_adjustment_rec			    =>              p_adjustment_rec
2039       );
2040     ELSIF p_operation = 'UPDATE' THEN
2041       GMF_ACTUAL_COST_ADJUSTMENT_PUB.UPDATE_ACTUAL_COST_ADJUSTMENT
2042       (
2043       p_api_version			        =>              1.0,
2044       p_init_msg_list		        =>              FND_API.G_TRUE,
2045       p_commit		              =>              FND_API.G_TRUE,
2046       x_return_status		        =>              x_status,
2047       x_msg_count			          =>              x_count,
2048       x_msg_data			          =>              x_data,
2049       p_adjustment_rec			    =>              p_adjustment_rec
2050       );
2051     ELSIF p_operation = 'DELETE' THEN
2052       GMF_ACTUAL_COST_ADJUSTMENT_PUB.DELETE_ACTUAL_COST_ADJUSTMENT
2053       (
2054       p_api_version			        =>              1.0,
2055       p_init_msg_list		        =>              FND_API.G_TRUE,
2056       p_commit		              =>              FND_API.G_TRUE,
2057       x_return_status		        =>              x_status,
2058       x_msg_count			          =>              x_count,
2059       x_msg_data			          =>              x_data,
2060       p_adjustment_rec			    =>              p_adjustment_rec
2061       );
2062     END IF ;
2063   END Call_ActualCost_API ;
2064 
2065 /* +========================================================================+
2066  | FUNCTION NAME                                                            |
2067  |    Get_ActualCost_Adjsutment                                             |
2068  |                                                                          |
2069  | TYPE                                                                     |
2070  |    Public                                                                |
2071  |                                                                          |
2072  | USAGE                                                                    |
2073  |    Get Actual Cost Adjustment Details                                    |
2074  |                                                                          |
2075  | DESCRIPTION                                                              |
2076  |    This is a PL/SQL wrapper function to call the                         |
2077  |    Get_ActualCost_Adjustment API.                                        |
2078  |    It reads item data from a flat file and outputs any error             |
2079  |    messages to a second flat file. It also generates a Status            |
2080  |    called gmf_rsrc_wrapper<session_id>.log in the /tmp directory.        |
2081  |                                                                          |
2082  | PARAMETERS                                                               |
2083  |    p_dir              IN VARCHAR2         - Working directory for input  |
2084  |                                             and output files.            |
2085  |    p_input_file       IN VARCHAR2         - Name of input file           |
2086  |    p_output_file      IN VARCHAR2         - Name of output file          |
2087  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
2088  |                                                                          |
2089  | RETURNS                                                                  |
2090  |    VARCHAR2 - 'S' All records processed successfully                     |
2091  |               'E' 1 or more records errored                              |
2092  |               'U' 1 or more record unexpected error                      |
2093  |                                                                          |
2094  | HISTORY                                                                  |
2095  |    28-Oct-2005 Anand Thiyagarajan Created                                |
2096  |									                                                        |
2097  +==========================================================================+
2098 */
2099 
2100   FUNCTION Get_ActualCost_Adjustment
2101   (
2102   p_dir                     IN                VARCHAR2,
2103   p_input_file              IN                VARCHAR2,
2104   p_output_file             IN                VARCHAR2,
2105   p_delimiter               IN                VARCHAR2
2106   )
2107   RETURN VARCHAR2
2108   IS
2109 
2110     /******************
2111     * Local variables *
2112     ******************/
2113     l_status                VARCHAR2(11);
2114     l_return_status         VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
2115     l_count                 NUMBER(10)  ;
2116     l_record_count          NUMBER(10)  :=0;
2117     l_loop_cnt              NUMBER(10)  :=0;
2118     l_dummy_cnt             NUMBER(10)  :=0;
2119     l_data                  VARCHAR2(1000);
2120     l_adjustment_rec        GMF_ACTUAL_COST_ADJUSTMENT_PUB.ADJUSTMENT_REC_TYPE;
2121     l_p_dir                 VARCHAR2(150);
2122     l_output_file           VARCHAR2(120);
2123     l_outfile_handle        UTL_FILE.FILE_TYPE;
2124     l_input_file            VARCHAR2(120);
2125     l_infile_handle         UTL_FILE.FILE_TYPE;
2126     l_line                  VARCHAR2(1000);
2127     l_delimiter             VARCHAR(11);
2128     l_log_dir               VARCHAR2(150);
2129     l_log_name              VARCHAR2(120) :='gmf_api_getactualcost_wrapper';
2130     l_log_handle            UTL_FILE.FILE_TYPE;
2131     l_global_file           VARCHAR2(120);
2132     l_idx		                NUMBER(10);
2133     l_idx1		              NUMBER(10);
2134     l_continue              VARCHAR2(1) := 'Y' ;
2135     l_skip_details          VARCHAR2(1) := 'N' ;
2136     l_session_id            VARCHAR2(110);
2137   BEGIN
2138 
2139     /********************
2140     * Enable The Buffer *
2141     ********************/
2142     l_p_dir               :=        p_dir;
2143     l_log_dir	            :=        p_dir;
2144     l_input_file          :=        p_input_file;
2145     l_output_file         :=        p_output_file;
2146     l_delimiter           :=        p_delimiter;
2147     l_global_file         :=        l_input_file;
2148 
2149     /*******************************************************
2150     * Obtain The SessionId To Append To wrapper File Name. *
2151     *******************************************************/
2152     l_session_id := USERENV('sessionid');
2153     l_log_name  := CONCAT(l_log_name,l_session_id);
2154     l_log_name  := CONCAT(l_log_name,'.log');
2155 
2156     /*****************************************************
2157     * Directory is now the same same as for the out file *
2158     *****************************************************/
2159     l_log_dir   := p_dir;
2160 
2161     /****************************************************************
2162     * Open The Wrapper File For Output And The Input File for Input *
2163     ****************************************************************/
2164     l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
2165     l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
2166     -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2167     -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
2168     -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
2169     -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
2170     -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
2171     UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2172     UTL_FILE.NEW_LINE(l_log_handle);
2173     UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
2174     UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
2175     UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
2176     UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
2177     l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
2178     LOOP
2179       l_record_count    :=l_record_count+1;
2180       BEGIN
2181         UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || to_char(l_record_count));
2182         UTL_FILE.GET_LINE(l_infile_handle, l_line);
2183         l_adjustment_rec.cost_adjust_id       :=	 Get_Field(l_line,l_delimiter,1);
2184         l_adjustment_rec.organization_id      :=	 Get_Field(l_line,l_delimiter,2);
2185         l_adjustment_rec.organization_code    :=	 Get_Field(l_line,l_delimiter,3);
2186         l_adjustment_rec.inventory_item_id    :=	 Get_Field(l_line,l_delimiter,4);
2187         l_adjustment_rec.item_number          :=	 Get_Field(l_line,l_delimiter,5);
2188         l_adjustment_rec.cost_type_id         :=	 Get_Field(l_line,l_delimiter,6);
2189         l_adjustment_rec.cost_mthd_code       :=	 Get_Field(l_line,l_delimiter,7);
2190         l_adjustment_rec.period_id            :=	 Get_Field(l_line,l_delimiter,8);
2191         l_adjustment_rec.calendar_code        :=	 Get_Field(l_line,l_delimiter,9);
2192         l_adjustment_rec.period_code          :=	 Get_Field(l_line,l_delimiter,10);
2193         l_adjustment_rec.cost_cmpntcls_id     :=	 Get_Field(l_line,l_delimiter,11);
2194         l_adjustment_rec.cost_cmpntcls_code   :=	 Get_Field(l_line,l_delimiter,12);
2195         l_adjustment_rec.cost_analysis_code   :=	 Get_Field(l_line,l_delimiter,13);
2196         l_adjustment_rec.adjust_qty           :=	 Get_Field(l_line,l_delimiter,14);
2197         l_adjustment_rec.adjust_qty_uom       :=	 Get_Field(l_line,l_delimiter,15);
2198         l_adjustment_rec.adjust_cost          :=	 Get_Field(l_line,l_delimiter,16);
2199         l_adjustment_rec.reason_code          :=	 Get_Field(l_line,l_delimiter,17);
2200         l_adjustment_rec.adjust_status        :=	 Get_Field(l_line,l_delimiter,18);
2201         l_adjustment_rec.delete_mark          :=	 Get_Field(l_line,l_delimiter,19);
2202         l_adjustment_rec.attribute1           :=	 Get_Field(l_line,l_delimiter,20);
2203         l_adjustment_rec.attribute2           :=	 Get_Field(l_line,l_delimiter,21);
2204         l_adjustment_rec.attribute3           :=	 Get_Field(l_line,l_delimiter,22);
2205         l_adjustment_rec.attribute4           :=	 Get_Field(l_line,l_delimiter,23);
2206         l_adjustment_rec.attribute5           :=	 Get_Field(l_line,l_delimiter,24);
2207         l_adjustment_rec.attribute6           :=	 Get_Field(l_line,l_delimiter,25);
2208         l_adjustment_rec.attribute7           :=	 Get_Field(l_line,l_delimiter,26);
2209         l_adjustment_rec.attribute8           :=	 Get_Field(l_line,l_delimiter,27);
2210         l_adjustment_rec.attribute9           :=	 Get_Field(l_line,l_delimiter,28);
2211         l_adjustment_rec.attribute10          :=	 Get_Field(l_line,l_delimiter,29);
2212         l_adjustment_rec.attribute11          :=	 Get_Field(l_line,l_delimiter,30);
2213         l_adjustment_rec.attribute12          :=	 Get_Field(l_line,l_delimiter,31);
2214         l_adjustment_rec.attribute13          :=	 Get_Field(l_line,l_delimiter,32);
2215         l_adjustment_rec.attribute14          :=	 Get_Field(l_line,l_delimiter,33);
2216         l_adjustment_rec.attribute15          :=	 Get_Field(l_line,l_delimiter,34);
2217         l_adjustment_rec.attribute16          :=	 Get_Field(l_line,l_delimiter,35);
2218         l_adjustment_rec.attribute17          :=	 Get_Field(l_line,l_delimiter,36);
2219         l_adjustment_rec.attribute18          :=	 Get_Field(l_line,l_delimiter,37);
2220         l_adjustment_rec.attribute19          :=	 Get_Field(l_line,l_delimiter,38);
2221         l_adjustment_rec.attribute20          :=	 Get_Field(l_line,l_delimiter,39);
2222         l_adjustment_rec.attribute21          :=	 Get_Field(l_line,l_delimiter,40);
2223         l_adjustment_rec.attribute22          :=	 Get_Field(l_line,l_delimiter,41);
2224         l_adjustment_rec.attribute23          :=	 Get_Field(l_line,l_delimiter,42);
2225         l_adjustment_rec.attribute24          :=	 Get_Field(l_line,l_delimiter,43);
2226         l_adjustment_rec.attribute25          :=	 Get_Field(l_line,l_delimiter,44);
2227         l_adjustment_rec.attribute26          :=	 Get_Field(l_line,l_delimiter,45);
2228         l_adjustment_rec.attribute27          :=	 Get_Field(l_line,l_delimiter,46);
2229         l_adjustment_rec.attribute28          :=	 Get_Field(l_line,l_delimiter,47);
2230         l_adjustment_rec.attribute29          :=	 Get_Field(l_line,l_delimiter,48);
2231         l_adjustment_rec.attribute30          :=	 Get_Field(l_line,l_delimiter,49);
2232         l_adjustment_rec.attribute_category   :=	 Get_Field(l_line,l_delimiter,50);
2233         l_adjustment_rec.adjustment_ind       :=	 Get_Field(l_line,l_delimiter,51);
2234         l_adjustment_rec.subledger_ind        :=	 Get_Field(l_line,l_delimiter,52);
2235         l_adjustment_rec.adjustment_date		  :=	 fnd_date.canonical_to_date(Get_Field(l_line,l_delimiter,53));
2236         l_adjustment_rec.user_name            :=	 Get_Field(l_line,l_delimiter,54);
2237 
2238         GMF_ACTUAL_COST_ADJUSTMENT_PUB.GET_ACTUAL_COST_ADJUSTMENT
2239         (
2240         p_api_version			        =>              1.0,
2241         p_init_msg_list		        =>              FND_API.G_TRUE,
2242         x_return_status		        =>              l_status,
2243         x_msg_count			          =>              l_count,
2244         x_msg_data			          =>              l_data,
2245         p_adjustment_rec			    =>              l_adjustment_rec
2246         );
2247 
2248         UTL_FILE.PUT_LINE(l_log_handle, 'After API call. status := ' || l_status ||' cnt := ' || l_count );
2249 
2250       EXCEPTION
2251         WHEN OTHERS THEN
2252 	        UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2253           UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2254           l_continue := 'N' ;
2255       END;
2256 
2257       /*******************************************************************************************
2258       * Check if any messages generated. If so then decode and output to error message flat file *
2259       *******************************************************************************************/
2260       IF l_count > 0 THEN
2261         l_loop_cnt  :=1;
2262         LOOP
2263           FND_MSG_PUB.Get
2264           (
2265           p_msg_index     => l_loop_cnt,
2266           p_data          => l_data,
2267           p_encoded       => FND_API.G_FALSE,
2268           p_msg_index_out => l_dummy_cnt
2269           );
2270           UTL_FILE.PUT_LINE(l_log_handle, l_data);
2271 
2272           /**********************
2273           * Update error status *
2274           **********************/
2275           IF (l_status = 'U') THEN
2276             l_return_status  :=l_status;
2277           ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
2278             l_return_status  :=l_status;
2279           ELSE
2280             l_return_status  :=l_status;
2281           END IF;
2282           l_loop_cnt  := l_loop_cnt + 1;
2283           IF l_loop_cnt > l_count THEN
2284             EXIT;
2285           END IF;
2286         END LOOP;
2287         l_count := 0 ;
2288       END IF;
2289       UTL_FILE.NEW_LINE(l_log_handle);
2290       UTL_FILE.NEW_LINE(l_log_handle);
2291       UTL_FILE.NEW_LINE(l_log_handle);
2292       IF l_continue = 'N' THEN
2293         EXIT;
2294       END IF;
2295     END LOOP;
2296     UTL_FILE.NEW_LINE(l_log_handle);
2297     UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2298     UTL_FILE.FCLOSE_ALL;
2299     RETURN l_return_status;
2300   EXCEPTION
2301     WHEN UTL_FILE.INVALID_OPERATION THEN
2302       -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file);
2303       UTL_FILE.FCLOSE_ALL;
2304       RETURN l_return_status;
2305     WHEN UTL_FILE.INVALID_PATH THEN
2306       -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file);
2307       UTL_FILE.FCLOSE_ALL;
2308       RETURN l_return_status;
2309     WHEN UTL_FILE.INVALID_MODE THEN
2310       -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file);
2311       UTL_FILE.FCLOSE_ALL;
2312       RETURN l_return_status;
2313     WHEN UTL_FILE.INVALID_FILEHANDLE THEN
2314       -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file);
2315       UTL_FILE.FCLOSE_ALL;
2316       RETURN l_return_status;
2317     WHEN UTL_FILE.WRITE_ERROR THEN
2318       -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file);
2319       UTL_FILE.FCLOSE_ALL;
2320       RETURN l_return_status;
2321     WHEN UTL_FILE.READ_ERROR THEN
2322       -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file);
2323       UTL_FILE.FCLOSE_ALL;
2324       RETURN l_return_status;
2325     WHEN UTL_FILE.INTERNAL_ERROR THEN
2326       -- DBMS_OUTPUT.PUT_LINE('Internal Error');
2327       UTL_FILE.FCLOSE_ALL;
2328       RETURN l_return_status;
2329     WHEN OTHERS THEN
2330       -- DBMS_OUTPUT.PUT_LINE('Other Error');
2331       UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2332       UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2333       UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2334       UTL_FILE.FCLOSE_ALL;
2335       l_return_status := 'U' ;
2336       RETURN l_return_status;
2337   END Get_ActualCost_Adjustment;
2338 
2339 
2340   /*  Body start of comments
2341 --+==========================================================================+
2342 --| PROCEDURE NAME                                                           |
2343 --|    Create_Alloc_Def                                                      |
2344 --|                                                                          |
2345 --| TYPE                                                                     |
2346 --|    Public                                                                |
2347 --|                                                                          |
2348 --| USAGE                                                                    |
2349 --|    Create Allocation Definition                                          |
2350 --|                                                                          |
2351 --| DESCRIPTION                                                              |
2352 --|    This is a PL/SQL wrapper procedure to call the                        |
2353 --|    Create_Allocation_definition API wrapper function                     |
2354 --|                                                                          |
2355 --| PARAMETERS                                                               |
2356 --|    p_dir              IN VARCHAR2         - Working directory for input  |
2357 --|                                             and output files.            |
2358 --|    p_input_file       IN VARCHAR2         - Name of input file           |
2359 --|    p_output_file      IN VARCHAR2         - Name of output file          |
2360 --|    p_delimiter        IN VARCHAR2         - Delimiter character          |
2361 --|                                                                          |
2362 --| RETURNS                                                                  |
2363 --|    None                                                                  |
2364 --|                                                                          |
2365 --| HISTORY                                                                  |
2366 --|    27/Feb/2001  Uday Moogala      Created             Bug# 1418689       |
2367 --|    30/Oct/2002  R.Sharath Kumar   Added NOCOPY hint   Bug# 2641405       |
2368 --|                                                                          |
2369 --+==========================================================================+
2370   Api end of comments
2371 */
2372 PROCEDURE Create_Alloc_Def
2373 ( p_dir          IN VARCHAR2
2374 , p_input_file   IN VARCHAR2
2375 , p_output_file  IN VARCHAR2
2376 , p_delimiter    IN VARCHAR2
2377 )
2378 IS
2379 
2380 l_return_status  VARCHAR2(1);
2381 
2382 BEGIN
2383 
2384  ---- DBMS_OUTPUT.PUT_LINE('in Create_Alloc_Def procedure... ');
2385 l_return_status  :=Create_Alloc_Def( p_dir
2386 			      	     , p_input_file
2387                                      , p_output_file
2388                                      , p_delimiter
2389                                    );
2390 
2391  -- DBMS_OUTPUT.PUT_LINE('return status := ' || l_return_status);
2392 End Create_Alloc_Def;
2393 
2394 /* +==========================================================================+
2395  | FUNCTION NAME                                                            |
2396  |    Create_Alloc_Def                                                      |
2397  |                                                                          |
2398  | TYPE                                                                     |
2399  |    Public                                                                |
2400  |                                                                          |
2401  | USAGE                                                                    |
2402  |    Create Allocation Definition                                          |
2403  |                                                                          |
2404  | DESCRIPTION                                                              |
2405  |    This is a PL/SQL wrapper function to call the                         |
2406  |    Create_Allocation_definition API.                                     |
2407  |    It reads item data from a flat file and outputs any error             |
2408  |    messages to a second flat file. It also generates a Status            |
2409  |    called gmf_aloc_wrapper<session_id>.log in the /tmp directory.                 |
2410  |                                                                          |
2411  | PARAMETERS                                                               |
2412  |    p_dir              IN VARCHAR2         - Working directory for input  |
2413  |                                             and output files.            |
2414  |    p_input_file       IN VARCHAR2         - Name of input file           |
2415  |    p_output_file      IN VARCHAR2         - Name of output file          |
2416  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
2417  |                                                                          |
2418  | RETURNS                                                                  |
2419  |    VARCHAR2 - 'S' All records processed successfully                     |
2420  |               'E' 1 or more records errored                              |
2421  |               'U' 1 or more record unexpected error                      |
2422  |                                                                          |
2423  | HISTORY                                                                  |
2424  |                                                                          |
2425  +==========================================================================+
2426   Api end of comments
2427 */
2428 FUNCTION Create_Alloc_Def
2429 ( p_dir          IN VARCHAR2
2430 , p_input_file   IN VARCHAR2
2431 , p_output_file  IN VARCHAR2
2432 , p_delimiter    IN VARCHAR2
2433 )
2434 RETURN VARCHAR2
2435 IS
2436 
2437 /* Local variables */
2438 
2439 l_status             VARCHAR2(11);
2440 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
2441 l_count              NUMBER(10)  ;
2442 l_record_count       NUMBER(10)  :=0;
2443 l_loop_cnt           NUMBER(10)  :=0;
2444 l_dummy_cnt          NUMBER(10)  :=0;
2445 l_data               VARCHAR2(2000);
2446 alloc_rec            GMF_ALLOCATIONDEFINITION_PUB.Allocation_Definition_Rec_Type;
2447 l_p_dir              VARCHAR2(150);
2448 l_output_file        VARCHAR2(120);
2449 l_outfile_handle     UTL_FILE.FILE_TYPE;
2450 l_input_file         VARCHAR2(120);
2451 l_infile_handle      UTL_FILE.FILE_TYPE;
2452 l_line               VARCHAR2(1800);
2453 l_delimiter          VARCHAR(11);
2454 l_log_dir            VARCHAR2(150);
2455 l_log_name           VARCHAR2(120)  :='gmf_api_cralloc_wrapper';
2456 l_log_handle         UTL_FILE.FILE_TYPE;
2457 l_global_file        VARCHAR2(120);
2458 
2459 l_session_id         VARCHAR2(110);
2460 
2461 BEGIN
2462 
2463 /*  Enable The Buffer  */
2464 /*  DBMS_OUTPUT.ENABLE(1000000); */
2465 
2466 -- DBMS_OUTPUT.PUT_LINE('in Create_Alloc_Def function...');
2467 
2468 l_p_dir              :=p_dir;
2469 l_input_file         :=p_input_file;
2470 l_output_file        :=p_output_file;
2471 l_delimiter          :=p_delimiter;
2472 l_global_file        :=l_input_file;
2473 
2474 /*  Obtain The SessionId To Append To wrapper File Name. */
2475 
2476 l_session_id := USERENV('sessionid');
2477 
2478 l_log_name  := CONCAT(l_log_name,l_session_id);
2479 l_log_name  := CONCAT(l_log_name,'.log');
2480 
2481 /*  Directory is now the same same as for the out file */
2482 l_log_dir   := p_dir;
2483 
2484 
2485 /*  Open The Wrapper File For Output And The Input File for Input. */
2486 
2487 l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
2488 l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
2489 
2490 /*  Loop thru flat file and call Inventory Quantities API */
2491 -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2492 -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
2493 -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
2494 -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
2495 -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
2496 
2497 
2498 /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
2499 UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2500 UTL_FILE.NEW_LINE(l_log_handle);
2501 UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
2502 UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
2503 UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
2504 UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
2505 
2506 l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
2507 
2508 
2509 LOOP
2510 l_record_count    :=l_record_count+1;
2511 
2512   BEGIN
2513   UTL_FILE.GET_LINE(l_infile_handle, l_line);
2514   EXCEPTION
2515     WHEN NO_DATA_FOUND THEN
2516      EXIT;
2517   END;
2518 
2519 BEGIN
2520   UTL_FILE.NEW_LINE(l_log_handle);
2521   UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
2522 
2523   alloc_rec.alloc_id            := Get_Field(l_line,l_delimiter,1) ;
2524   alloc_rec.alloc_code          := Get_Field(l_line,l_delimiter,2) ;
2525   alloc_rec.legal_entity_id     := Get_Field(l_line,l_delimiter,3) ;
2526   alloc_rec.alloc_method        := Get_Field(l_line,l_delimiter,4) ;
2527   alloc_rec.line_no             := Get_Field(l_line,l_delimiter,5) ;
2528   alloc_rec.organization_id     := Get_Field(l_line,l_delimiter,6) ;
2529   alloc_rec.organization_code   := Get_Field(l_line,l_delimiter,7) ;
2530   alloc_rec.item_id             := Get_Field(l_line,l_delimiter,8) ;
2531   alloc_rec.item_number         := Get_Field(l_line,l_delimiter,9) ;
2532   alloc_rec.basis_account_id    := Get_Field(l_line,l_delimiter,10) ;
2533   alloc_rec.basis_account_key   := Get_Field(l_line,l_delimiter,11) ;
2534   alloc_rec.balance_type        := Get_Field(l_line,l_delimiter,12) ;
2535   alloc_rec.bas_ytd_ptd         := Get_Field(l_line,l_delimiter,13) ;
2536   alloc_rec.basis_type          := Get_Field(l_line,l_delimiter,14) ;
2537   alloc_rec.fixed_percent       := Get_Field(l_line,l_delimiter,15) ;
2538   alloc_rec.cmpntcls_id         := Get_Field(l_line,l_delimiter,16) ;
2539   alloc_rec.cost_cmpntcls_code  := Get_Field(l_line,l_delimiter,17) ;
2540   alloc_rec.analysis_code       := Get_Field(l_line,l_delimiter,18) ;
2541   alloc_rec.delete_mark         := Get_Field(l_line,l_delimiter,19) ;
2542   alloc_rec.user_name           := Get_Field(l_line,l_delimiter,20) ;
2543   /*
2544   UTL_FILE.PUT_LINE(l_log_handle, 'alloc_id     	= ' || alloc_rec.alloc_id) ;
2545   UTL_FILE.PUT_LINE(l_log_handle, 'alloc_code     	= ' || alloc_rec.alloc_code) ;
2546   UTL_FILE.PUT_LINE(l_log_handle, 'co_code     		= ' || alloc_rec.co_code) ;
2547   UTL_FILE.PUT_LINE(l_log_handle, 'alloc_method 	= ' || alloc_rec.alloc_method) ;
2548   UTL_FILE.PUT_LINE(l_log_handle, 'line_no      	= ' || alloc_rec.line_no) ;
2549   UTL_FILE.PUT_LINE(l_log_handle, 'item_id      	= ' || alloc_rec.item_id) ;
2550   UTL_FILE.PUT_LINE(l_log_handle, 'item_no      	= ' || alloc_rec.item_no) ;
2551   UTL_FILE.PUT_LINE(l_log_handle, 'basis_account_key    = ' || alloc_rec.basis_account_key) ;
2552   UTL_FILE.PUT_LINE(l_log_handle, 'balance_type 	= ' || alloc_rec.balance_type) ;
2553   UTL_FILE.PUT_LINE(l_log_handle, 'bas_ytd_ptd  	= ' || alloc_rec.bas_ytd_ptd) ;
2554   UTL_FILE.PUT_LINE(l_log_handle, 'fixed_percent        = ' || alloc_rec.fixed_percent) ;
2555   UTL_FILE.PUT_LINE(l_log_handle, 'cmpntcls_id  	= ' || alloc_rec.cmpntcls_id) ;
2556   UTL_FILE.PUT_LINE(l_log_handle, 'cost_cmpntcls_code  	= ' || alloc_rec.cost_cmpntcls_code) ;
2557   UTL_FILE.PUT_LINE(l_log_handle, 'analysis_code        = ' || alloc_rec.analysis_code) ;
2558   UTL_FILE.PUT_LINE(l_log_handle, 'whse_code    	= ' || alloc_rec.whse_code) ;
2559   UTL_FILE.PUT_LINE(l_log_handle, 'delete_mark  	= ' || alloc_rec.delete_mark) ;
2560   UTL_FILE.PUT_LINE(l_log_handle, 'user_name  		= ' || alloc_rec.user_name) ;
2561   */
2562   GMF_ALLOCATIONDEFINITION_PUB.Create_Allocation_Definition
2563   ( p_api_version    => 3.0
2564   , p_init_msg_list  => FND_API.G_TRUE
2565   , p_commit         => FND_API.G_TRUE
2566 
2567   , x_return_status  =>l_status
2568   , x_msg_count      =>l_count
2569   , x_msg_data       =>l_data
2570 
2571   , p_allocation_definition_rec => alloc_rec
2572   );
2573 
2574   UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
2575   IF l_count > 0
2576   THEN
2577    l_loop_cnt  :=1;
2578    LOOP
2579 
2580     FND_MSG_PUB.Get(
2581     p_msg_index     => l_loop_cnt,
2582     p_data          => l_data,
2583     p_encoded       => FND_API.G_FALSE,
2584     p_msg_index_out => l_dummy_cnt);
2585 
2586 
2587    -- DBMS_OUTPUT.PUT_LINE(l_data );
2588 
2589    UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
2590    UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
2591    UTL_FILE.NEW_LINE(l_outfile_handle);
2592 
2593    /*
2594      IF l_status = 'E' OR
2595         l_status = 'U'
2596      THEN
2597         l_data    := CONCAT('ERROR : ',l_data);
2598      END IF;
2599    */
2600 
2601    UTL_FILE.PUT_LINE(l_log_handle, l_data);
2602 
2603    /*  Update error status */
2604     IF (l_status = 'U')
2605     THEN
2606       l_return_status  :=l_status;
2607     ELSIF (l_status = 'E' and l_return_status <> 'U')
2608     THEN
2609       l_return_status  :=l_status;
2610     ELSE
2611       l_return_status  :=l_status;
2612     END IF;
2613 
2614     l_loop_cnt  := l_loop_cnt + 1;
2615     IF l_loop_cnt > l_count
2616     THEN
2617       EXIT;
2618     END IF;
2619 
2620   END LOOP;
2621 
2622  END IF;
2623 
2624 EXCEPTION
2625  WHEN OTHERS THEN
2626   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2627   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2628   l_return_status := 'U' ;
2629 END ;
2630 
2631 END LOOP;
2632 
2633   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2634   UTL_FILE.NEW_LINE(l_log_handle);
2635   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2636 
2637 /*  Check if any messages generated. If so then decode and */
2638 /*  output to error message flat file */
2639 
2640 UTL_FILE.FCLOSE_ALL;
2641 
2642 RETURN l_return_status;
2643 
2644 EXCEPTION
2645 WHEN UTL_FILE.INVALID_OPERATION THEN
2646    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
2647    UTL_FILE.FCLOSE_ALL;
2648    RETURN l_return_status;
2649 
2650 WHEN UTL_FILE.INVALID_PATH THEN
2651    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
2652    UTL_FILE.FCLOSE_ALL;
2653    RETURN l_return_status;
2654 
2655 WHEN UTL_FILE.INVALID_MODE THEN
2656    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
2657    UTL_FILE.FCLOSE_ALL;
2658    RETURN l_return_status;
2659 
2660 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
2661    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
2662    UTL_FILE.FCLOSE_ALL;
2663    RETURN l_return_status;
2664 
2665 WHEN UTL_FILE.WRITE_ERROR THEN
2666    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
2667    UTL_FILE.FCLOSE_ALL;
2668    RETURN l_return_status;
2669 
2670 WHEN UTL_FILE.READ_ERROR THEN
2671    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
2672    UTL_FILE.FCLOSE_ALL;
2673    RETURN l_return_status;
2674 
2675 WHEN UTL_FILE.INTERNAL_ERROR THEN
2676    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
2677    UTL_FILE.FCLOSE_ALL;
2678    RETURN l_return_status;
2679 
2680 WHEN OTHERS THEN
2681   /* -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
2682   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2683   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2684   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2685   UTL_FILE.FCLOSE_ALL;
2686   l_return_status := 'U' ;
2687   RETURN l_return_status;
2688 
2689 END Create_Alloc_Def;
2690 
2691 /*  API start of comments
2692  +==========================================================================+
2693  | PROCEDURE NAME                                                           |
2694  |    Update_Alloc_Def                                                      |
2695  |                                                                          |
2696  | TYPE                                                                     |
2697  |    Public                                                                |
2698  |                                                                          |
2699  | USAGE                                                                    |
2700  |    Update Allocation Definition                                          |
2701  |                                                                          |
2702  | DESCRIPTION                                                              |
2703  |    This is a PL/SQL wrapper procedure to call the                        |
2704  |    Update_Alloc_Def API wrapper function                                 |
2705  |                                                                          |
2706  | PARAMETERS                                                               |
2707  |    p_dir              IN VARCHAR2         - Working directory for input  |
2708  |                                             and output files.            |
2709  |    p_input_file       IN VARCHAR2         - Name of input file           |
2710  |    p_output_file      IN VARCHAR2         - Name of output file          |
2711  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
2712  |                                                                          |
2713  | RETURNS                                                                  |
2714  |    None                                                                  |
2715  |                                                                          |
2716  | HISTORY                                                                  |
2717  |    07-Mar-2001  Uday Moogala    created                                  |
2718  |                                                                          |
2719  +==========================================================================+
2720   Api end of comments
2721 */
2722 PROCEDURE Update_Alloc_Def
2723 ( p_dir          IN VARCHAR2
2724 , p_input_file   IN VARCHAR2
2725 , p_output_file  IN VARCHAR2
2726 , p_delimiter    IN VARCHAR2
2727 )
2728 IS
2729 
2730 l_return_status  VARCHAR2(1);
2731 
2732 BEGIN
2733 
2734  ---- DBMS_OUTPUT.PUT_LINE('in Update_Alloc_Def procedure... ');
2735 l_return_status  :=Update_Alloc_Def( p_dir
2736                                      , p_input_file
2737                                      , p_output_file
2738                                      , p_delimiter
2739                                    );
2740 
2741  -- DBMS_OUTPUT.PUT_LINE('return status := ' || l_return_status);
2742 End Update_Alloc_Def;
2743 
2744 /* +==========================================================================+
2745  | FUNCTION NAME                                                            |
2746  |    Update_Alloc_Def                                                      |
2747  |                                                                          |
2748  | TYPE                                                                     |
2749  |    Public                                                                |
2750  |                                                                          |
2751  | USAGE                                                                    |
2752  |    Update Allocation Definition                                          |
2753  |                                                                          |
2754  | DESCRIPTION                                                              |
2755  |    This is a PL/SQL wrapper function to call the                         |
2756  |    Update_Allocation_definition API.                                     |
2757  |    It reads item data from a flat file and outputs any error             |
2758  |    messages to a second flat file. It also generates a Status            |
2759  |    called gmf_aloc_wrapper<session_id>.log in the temp directory.        |
2760  |                                                                          |
2761  | PARAMETERS                                                               |
2762  |    p_dir              IN VARCHAR2         - Working directory for input  |
2763  |                                             and output files.            |
2764  |    p_input_file       IN VARCHAR2         - Name of input file           |
2765  |    p_output_file      IN VARCHAR2         - Name of output file          |
2766  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
2767  |                                                                          |
2768  | RETURNS                                                                  |
2769  |    VARCHAR2 - 'S' All records processed successfully                     |
2770  |               'E' 1 or more records errored                              |
2771  |               'U' 1 or more record unexpected error                      |
2772  |                                                                          |
2773  | HISTORY                                                                  |
2774  |                                                                          |
2775  +==========================================================================+
2776   Api end of comments
2777 */
2778 FUNCTION Update_Alloc_Def
2779 ( p_dir          IN VARCHAR2
2780 , p_input_file   IN VARCHAR2
2781 , p_output_file  IN VARCHAR2
2782 , p_delimiter    IN VARCHAR2
2783 )
2784 RETURN VARCHAR2
2785 IS
2786 
2787 /* Local variables */
2788 
2789 l_status             VARCHAR2(100);
2790 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
2791 l_count              NUMBER(10)  ;
2792 l_record_count       NUMBER(10)  :=0;
2793 l_loop_cnt           NUMBER(10)  :=0;
2794 l_dummy_cnt          NUMBER(10)  :=0;
2795 l_data               VARCHAR2(2000);
2796 alloc_rec            gmf_allocationdefinition_pub.Allocation_Definition_Rec_Type;
2797 l_p_dir              VARCHAR2(150);
2798 l_output_file        VARCHAR2(120);
2799 l_outfile_handle     UTL_FILE.FILE_TYPE;
2800 l_input_file         VARCHAR2(120);
2801 l_infile_handle      UTL_FILE.FILE_TYPE;
2802 l_line               VARCHAR2(1800);
2803 l_delimiter          VARCHAR(11);
2804 l_log_dir            VARCHAR2(150);
2805 l_log_name           VARCHAR2(120)  :='gmf_api_updalloc_wrapper';
2806 l_log_handle         UTL_FILE.FILE_TYPE;
2807 l_global_file        VARCHAR2(120);
2808 
2809 l_session_id         VARCHAR2(110);
2810 
2811 BEGIN
2812 
2813 /*  Enable The Buffer  */
2814 /*  DBMS_OUTPUT.ENABLE(1000000); */
2815 
2816 -- DBMS_OUTPUT.PUT_LINE('in Update_Alloc_Def function...');
2817 
2818 l_p_dir              :=p_dir;
2819 l_input_file         :=p_input_file;
2820 l_output_file        :=p_output_file;
2821 l_delimiter          :=p_delimiter;
2822 l_global_file        :=l_input_file;
2823 
2824 /*  Obtain The SessionId To Append To wrapper File Name. */
2825 
2826 l_session_id := USERENV('sessionid');
2827 
2828 l_log_name  := CONCAT(l_log_name,l_session_id);
2829 l_log_name  := CONCAT(l_log_name,'.log');
2830 
2831 /*  Directory is now the same same as for the out file */
2832 l_log_dir   := p_dir;
2833 
2834 
2835 /*  Open The Wrapper File For Output And The Input File for Input. */
2836 
2837 l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
2838 l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
2839 
2840 /*  Loop thru flat file and call Inventory Quantities API */
2841 -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2842 -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
2843 -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
2844 -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
2845 -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
2846 
2847 
2848 /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
2849 UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2850 UTL_FILE.NEW_LINE(l_log_handle);
2851 UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
2852 UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
2853 UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
2854 UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
2855 
2856 l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
2857 
2858 
2859 LOOP
2860 l_record_count    :=l_record_count+1;
2861 
2862   BEGIN
2863   UTL_FILE.GET_LINE(l_infile_handle, l_line);
2864   EXCEPTION
2865     WHEN NO_DATA_FOUND THEN
2866 EXIT;
2867   END;
2868 
2869 BEGIN
2870   UTL_FILE.NEW_LINE(l_log_handle);
2871   UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
2872 
2873   alloc_rec.alloc_id            := Get_Field(l_line,l_delimiter,1) ;
2874   alloc_rec.alloc_code          := Get_Field(l_line,l_delimiter,2) ;
2875   alloc_rec.legal_entity_id     := Get_Field(l_line,l_delimiter,3) ;
2876   alloc_rec.alloc_method        := Get_Field(l_line,l_delimiter,4) ;
2877   alloc_rec.line_no             := Get_Field(l_line,l_delimiter,5) ;
2878   alloc_rec.organization_id     := Get_Field(l_line,l_delimiter,6) ;
2879   alloc_rec.organization_code   := Get_Field(l_line,l_delimiter,7) ;
2880   alloc_rec.item_id             := Get_Field(l_line,l_delimiter,8) ;
2881   alloc_rec.item_number         := Get_Field(l_line,l_delimiter,9) ;
2882   alloc_rec.basis_account_id    := Get_Field(l_line,l_delimiter,10) ;
2883   alloc_rec.basis_account_key   := Get_Field(l_line,l_delimiter,11) ;
2884   alloc_rec.balance_type        := Get_Field(l_line,l_delimiter,12) ;
2885   alloc_rec.bas_ytd_ptd         := Get_Field(l_line,l_delimiter,13) ;
2886   alloc_rec.basis_type          := Get_Field(l_line,l_delimiter,14) ;
2887   alloc_rec.fixed_percent       := Get_Field(l_line,l_delimiter,15) ;
2888   alloc_rec.cmpntcls_id         := Get_Field(l_line,l_delimiter,16) ;
2889   alloc_rec.cost_cmpntcls_code  := Get_Field(l_line,l_delimiter,17) ;
2890   alloc_rec.analysis_code       := Get_Field(l_line,l_delimiter,18) ;
2891   alloc_rec.delete_mark         := Get_Field(l_line,l_delimiter,19) ;
2892   alloc_rec.user_name           := Get_Field(l_line,l_delimiter,20) ;
2893 
2894   UTL_FILE.PUT_LINE(l_log_handle, 'alloc_id             = ' || alloc_rec.alloc_id) ;
2895   UTL_FILE.PUT_LINE(l_log_handle, 'alloc_code           = ' || alloc_rec.alloc_code) ;
2896   UTL_FILE.PUT_LINE(l_log_handle, 'legal_entity_id              = ' || alloc_rec.legal_entity_id) ;
2897   UTL_FILE.PUT_LINE(l_log_handle, 'alloc_method         = ' || alloc_rec.alloc_method) ;
2898   UTL_FILE.PUT_LINE(l_log_handle, 'line_no              = ' || alloc_rec.line_no) ;
2899   UTL_FILE.PUT_LINE(l_log_handle, 'item_id              = ' || alloc_rec.item_id) ;
2900   UTL_FILE.PUT_LINE(l_log_handle, 'item_number             = ' || alloc_rec.item_number) ;
2901   UTL_FILE.PUT_LINE(l_log_handle, 'basis_account_key    = ' || alloc_rec.basis_account_key) ;
2902   UTL_FILE.PUT_LINE(l_log_handle, 'balance_type         = ' || alloc_rec.balance_type) ;
2903   UTL_FILE.PUT_LINE(l_log_handle, 'bas_ytd_ptd          = ' || alloc_rec.bas_ytd_ptd) ;
2904   UTL_FILE.PUT_LINE(l_log_handle, 'basis_type           = ' || alloc_rec.basis_type) ;
2905   UTL_FILE.PUT_LINE(l_log_handle, 'fixed_percent        = ' || alloc_rec.fixed_percent) ;
2906   UTL_FILE.PUT_LINE(l_log_handle, 'cmpntcls_id          = ' || alloc_rec.cmpntcls_id) ;
2907   UTL_FILE.PUT_LINE(l_log_handle, 'cost_cmpntcls_code   = ' || alloc_rec.cost_cmpntcls_code) ;
2908   UTL_FILE.PUT_LINE(l_log_handle, 'analysis_code        = ' || alloc_rec.analysis_code) ;
2909   UTL_FILE.PUT_LINE(l_log_handle, 'organization_id      = ' || alloc_rec.organization_id) ;
2910   UTL_FILE.PUT_LINE(l_log_handle, 'organization_code    = ' || alloc_rec.organization_code) ;
2911   UTL_FILE.PUT_LINE(l_log_handle, 'delete_mark          = ' || alloc_rec.delete_mark) ;
2912   UTL_FILE.PUT_LINE(l_log_handle, 'user_name            = ' || alloc_rec.user_name) ;
2913 
2914   -- DBMS_OUTPUT.PUT_LINE('before calling Update API...');
2915   GMF_ALLOCATIONDEFINITION_PUB.Update_Allocation_Definition
2916   ( p_api_version    => 3.0
2917   , p_init_msg_list  => FND_API.G_TRUE
2918   , p_commit         => FND_API.G_TRUE
2919 
2920   , x_return_status  =>l_status
2921   , x_msg_count      =>l_count
2922   , x_msg_data       =>l_data
2923 
2924   , p_allocation_definition_rec => alloc_rec
2925   );
2926 
2927   UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
2928   IF l_count > 0
2929   THEN
2930    l_loop_cnt  :=1;
2931   LOOP
2932 
2933   FND_MSG_PUB.Get(
2934     p_msg_index     => l_loop_cnt,
2935     p_data          => l_data,
2936     p_encoded       => FND_API.G_FALSE,
2937     p_msg_index_out => l_dummy_cnt);
2938 
2939 
2940   -- DBMS_OUTPUT.PUT_LINE(l_data );
2941 
2942   UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
2943   UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
2944   UTL_FILE.NEW_LINE(l_outfile_handle);
2945 
2946 
2947 /*
2948   IF l_status = 'E' OR
2949      l_status = 'U'
2950   THEN
2951     l_data    := CONCAT('ERROR : ',l_data);
2952   END IF;
2953 */
2954 
2955   UTL_FILE.PUT_LINE(l_log_handle, l_data);
2956 
2957   /*  Update error status */
2958     IF (l_status = 'U')
2959     THEN
2960       l_return_status  :=l_status;
2961     ELSIF (l_status = 'E' and l_return_status <> 'U')
2962     THEN
2963       l_return_status  :=l_status;
2964     ELSE
2965       l_return_status  :=l_status;
2966     END IF;
2967 
2968   l_loop_cnt  := l_loop_cnt + 1;
2969   IF l_loop_cnt > l_count
2970   THEN
2971     EXIT;
2972   END IF;
2973 
2974   END LOOP;
2975 
2976  END IF;
2977 
2978 EXCEPTION
2979  WHEN OTHERS THEN
2980   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2981   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
2982   l_return_status := 'U' ;
2983 END ;
2984 
2985 END LOOP;
2986   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2987   UTL_FILE.NEW_LINE(l_log_handle);
2988   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
2989 
2990 /*  Check if any messages generated. If so then decode and */
2991 /*  output to error message flat file */
2992 
2993 UTL_FILE.FCLOSE_ALL;
2994 
2995 RETURN l_return_status;
2996 
2997 EXCEPTION
2998 WHEN UTL_FILE.INVALID_OPERATION THEN
2999    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
3000    UTL_FILE.FCLOSE_ALL;
3001    RETURN l_return_status;
3002 
3003 WHEN UTL_FILE.INVALID_PATH THEN
3004    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
3005    UTL_FILE.FCLOSE_ALL;
3006    RETURN l_return_status;
3007 
3008 WHEN UTL_FILE.INVALID_MODE THEN
3009    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
3010    UTL_FILE.FCLOSE_ALL;
3011    RETURN l_return_status;
3012 
3013 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
3014    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
3015    UTL_FILE.FCLOSE_ALL;
3016    RETURN l_return_status;
3017 
3018 WHEN UTL_FILE.WRITE_ERROR THEN
3019    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
3020    UTL_FILE.FCLOSE_ALL;
3021    RETURN l_return_status;
3022 
3023 WHEN UTL_FILE.READ_ERROR THEN
3024    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
3025    UTL_FILE.FCLOSE_ALL;
3026    RETURN l_return_status;
3027 
3028 WHEN UTL_FILE.INTERNAL_ERROR THEN
3029    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
3030    UTL_FILE.FCLOSE_ALL;
3031    RETURN l_return_status;
3032 
3033 WHEN OTHERS THEN
3034    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
3035   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3036   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3037   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3038    UTL_FILE.FCLOSE_ALL;
3039    l_return_status := 'U' ;
3040    RETURN l_return_status;
3041 
3042 END Update_Alloc_Def;
3043 
3044 /*  API start of comments
3045  +==========================================================================+
3046  | PROCEDURE NAME                                                           |
3047  |    Delete_Alloc_def                                                      |
3048  |                                                                          |
3049  | TYPE                                                                     |
3050  |    Public                                                                |
3051  |                                                                          |
3052  | USAGE                                                                    |
3053  |    Delete Allocation Definition                                          |
3054  |                                                                          |
3055  | DESCRIPTION                                                              |
3056  |    This is a PL/SQL wrapper procedure to call the                        |
3057  |    Delete_Alloc_def API wrapper function                                 |
3058  |                                                                          |
3059  | PARAMETERS                                                               |
3060  |    p_dir              IN VARCHAR2         - Working directory for input  |
3061  |                                             and output files.            |
3062  |    p_input_file       IN VARCHAR2         - Name of input file           |
3063  |    p_output_file      IN VARCHAR2         - Name of output file          |
3064  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
3065  |                                                                          |
3066  | RETURNS                                                                  |
3067  |    None                                                                  |
3068  |                                                                          |
3069  | HISTORY                                                                  |
3070  |    07-Mar-2001  Uday Moogala    created                                  |
3071  |                                                                          |
3072  +==========================================================================+
3073   Api end of comments
3074 */
3075 PROCEDURE Delete_Alloc_def
3076 ( p_dir          IN VARCHAR2
3077 , p_input_file   IN VARCHAR2
3078 , p_output_file  IN VARCHAR2
3079 , p_delimiter    IN VARCHAR2
3080 )
3081 IS
3082 
3083 l_return_status  VARCHAR2(1);
3084 
3085 BEGIN
3086 
3087  ---- DBMS_OUTPUT.PUT_LINE('in Delete_Alloc_def procedure... ');
3088 l_return_status  :=Delete_Alloc_def( p_dir
3089                                      , p_input_file
3090                                      , p_output_file
3091                                      , p_delimiter
3092                                    );
3093 
3094  -- DBMS_OUTPUT.PUT_LINE('return status := ' || l_return_status);
3095 End Delete_Alloc_def;
3096 
3097 /* +==========================================================================+
3098  | FUNCTION NAME                                                            |
3099  |    Delete_Alloc_def                                                      |
3100  |                                                                          |
3101  | TYPE                                                                     |
3102  |    Public                                                                |
3103  |                                                                          |
3104  | USAGE                                                                    |
3105  |    Delete Allocation Definition                                          |
3106  |                                                                          |
3107  | DESCRIPTION                                                              |
3108  |    This is a PL/SQL wrapper function to call the                         |
3109  |    Delete_Allocation_definition API.                                     |
3110  |    It reads item data from a flat file and outputs any error             |
3111  |    messages to a second flat file. It also generates a Status            |
3112  |    called gmf_aloc_wrapper<session_id>.log in the temp directory.        |
3113  |                                                                          |
3114  | PARAMETERS                                                               |
3115  |    p_dir              IN VARCHAR2         - Working directory for input  |
3116  |                                             and output files.            |
3117  |    p_input_file       IN VARCHAR2         - Name of input file           |
3118  |    p_output_file      IN VARCHAR2         - Name of output file          |
3119  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
3120  |                                                                          |
3121  | RETURNS                                                                  |
3122  |    VARCHAR2 - 'S' All records processed successfully                     |
3123  |               'E' 1 or more records errored                              |
3124  |               'U' 1 or more record unexpected error                      |
3125  |                                                                          |
3126  | HISTORY                                                                  |
3127  |                                                                          |
3128  +==========================================================================+
3129   Api end of comments
3130 */
3131 FUNCTION Delete_Alloc_def
3132 ( p_dir          IN VARCHAR2
3133 , p_input_file   IN VARCHAR2
3134 , p_output_file  IN VARCHAR2
3135 , p_delimiter    IN VARCHAR2
3136 )
3137 RETURN VARCHAR2
3138 IS
3139 
3140 /* Local variables */
3141 
3142 l_status             VARCHAR2(100);
3143 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
3144 l_count              NUMBER(10)  ;
3145 l_record_count       NUMBER(10)  :=0;
3146 l_loop_cnt           NUMBER(10)  :=0;
3147 l_dummy_cnt          NUMBER(10)  :=0;
3148 l_data               VARCHAR2(2000);
3149 alloc_rec            gmf_allocationdefinition_pub.Allocation_Definition_Rec_Type;
3150 l_p_dir              VARCHAR2(150);
3151 l_output_file        VARCHAR2(120);
3152 l_outfile_handle     UTL_FILE.FILE_TYPE;
3153 l_input_file         VARCHAR2(120);
3154 l_infile_handle      UTL_FILE.FILE_TYPE;
3155 l_line               VARCHAR2(1800);
3156 l_delimiter          VARCHAR(11);
3157 l_log_dir            VARCHAR2(150);
3158 l_log_name           VARCHAR2(120)  :='gmf_api_delalloc_wrapper';
3159 l_log_handle         UTL_FILE.FILE_TYPE;
3160 l_global_file        VARCHAR2(120);
3161 
3162 l_session_id         VARCHAR2(110);
3163 
3164 BEGIN
3165 
3166 /*  Enable The Buffer  */
3167 /*  DBMS_OUTPUT.ENABLE(1000000); */
3168 
3169 -- DBMS_OUTPUT.PUT_LINE('in Delete_Alloc_def function...');
3170 
3171 l_p_dir              :=p_dir;
3172 l_input_file         :=p_input_file;
3173 l_output_file        :=p_output_file;
3174 l_delimiter          :=p_delimiter;
3175 l_global_file        :=l_input_file;
3176 
3177 /*  Obtain The SessionId To Append To wrapper File Name. */
3178 
3179 l_session_id := USERENV('sessionid');
3180 
3181 l_log_name  := CONCAT(l_log_name,l_session_id);
3182 l_log_name  := CONCAT(l_log_name,'.log');
3183 
3184 /*  Directory is now the same same as for the out file */
3185 l_log_dir   := p_dir;
3186 
3187 
3188 /*  Open The Wrapper File For Output And The Input File for Input. */
3189 
3190 l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
3191 l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
3192 
3193 /*  Loop thru flat file and call Inventory Quantities API */
3194 -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3195 -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
3196 -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
3197 -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
3198 -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
3199 
3200 
3201 /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
3202 UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3203 UTL_FILE.NEW_LINE(l_log_handle);
3204 UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
3205 UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
3206 UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
3207 UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
3208 
3209 l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
3210 
3211 
3212 LOOP
3213 l_record_count    :=l_record_count+1;
3214 
3215   BEGIN
3216   UTL_FILE.GET_LINE(l_infile_handle, l_line);
3217   EXCEPTION
3218     WHEN NO_DATA_FOUND THEN
3219 EXIT;
3220   END;
3221 
3222 BEGIN
3223   UTL_FILE.NEW_LINE(l_log_handle);
3224   UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
3225 
3226   alloc_rec.alloc_id            := Get_Field(l_line,l_delimiter,1) ;
3227   alloc_rec.alloc_code          := Get_Field(l_line,l_delimiter,2) ;
3228   alloc_rec.legal_entity_id     := Get_Field(l_line,l_delimiter,3) ;
3229   alloc_rec.alloc_method        := Get_Field(l_line,l_delimiter,4) ;
3230   alloc_rec.line_no             := Get_Field(l_line,l_delimiter,5) ;
3231   alloc_rec.organization_id     := Get_Field(l_line,l_delimiter,6) ;
3232   alloc_rec.organization_code   := Get_Field(l_line,l_delimiter,7) ;
3233   alloc_rec.item_id             := Get_Field(l_line,l_delimiter,8) ;
3234   alloc_rec.item_number         := Get_Field(l_line,l_delimiter,9) ;
3235   alloc_rec.basis_account_id    := Get_Field(l_line,l_delimiter,10) ;
3236   alloc_rec.basis_account_key   := Get_Field(l_line,l_delimiter,11) ;
3237   alloc_rec.balance_type        := Get_Field(l_line,l_delimiter,12) ;
3238   alloc_rec.bas_ytd_ptd         := Get_Field(l_line,l_delimiter,13) ;
3239   alloc_rec.basis_type          := Get_Field(l_line,l_delimiter,14) ;
3240   alloc_rec.fixed_percent       := Get_Field(l_line,l_delimiter,15) ;
3241   alloc_rec.cmpntcls_id         := Get_Field(l_line,l_delimiter,16) ;
3242   alloc_rec.cost_cmpntcls_code  := Get_Field(l_line,l_delimiter,17) ;
3243   alloc_rec.analysis_code       := Get_Field(l_line,l_delimiter,18) ;
3244   alloc_rec.delete_mark         := Get_Field(l_line,l_delimiter,19) ;
3245   alloc_rec.user_name           := Get_Field(l_line,l_delimiter,20) ;
3246 
3247   UTL_FILE.PUT_LINE(l_log_handle, 'alloc_id             = ' || alloc_rec.alloc_id) ;
3248   UTL_FILE.PUT_LINE(l_log_handle, 'alloc_code           = ' || alloc_rec.alloc_code) ;
3249   UTL_FILE.PUT_LINE(l_log_handle, 'legal_entity_id      = ' || alloc_rec.legal_entity_id) ;
3250   UTL_FILE.PUT_LINE(l_log_handle, 'alloc_method         = ' || alloc_rec.alloc_method) ;
3251   UTL_FILE.PUT_LINE(l_log_handle, 'line_no              = ' || alloc_rec.line_no) ;
3252   UTL_FILE.PUT_LINE(l_log_handle, 'item_id              = ' || alloc_rec.item_id) ;
3253   UTL_FILE.PUT_LINE(l_log_handle, 'item_number          = ' || alloc_rec.item_number) ;
3254   UTL_FILE.PUT_LINE(l_log_handle, 'basis_account_key    = ' || alloc_rec.basis_account_key) ;
3255   UTL_FILE.PUT_LINE(l_log_handle, 'balance_type         = ' || alloc_rec.balance_type) ;
3256   UTL_FILE.PUT_LINE(l_log_handle, 'bas_ytd_ptd          = ' || alloc_rec.bas_ytd_ptd) ;
3257   UTL_FILE.PUT_LINE(l_log_handle, 'basis_type           = ' || alloc_rec.basis_type) ;
3258   UTL_FILE.PUT_LINE(l_log_handle, 'fixed_percent        = ' || alloc_rec.fixed_percent) ;
3259   UTL_FILE.PUT_LINE(l_log_handle, 'cmpntcls_id          = ' || alloc_rec.cmpntcls_id) ;
3260   UTL_FILE.PUT_LINE(l_log_handle, 'cost_cmpntcls_code   = ' || alloc_rec.cost_cmpntcls_code) ;
3261   UTL_FILE.PUT_LINE(l_log_handle, 'analysis_code        = ' || alloc_rec.analysis_code) ;
3262   UTL_FILE.PUT_LINE(l_log_handle, 'organization_id      = ' || alloc_rec.organization_id) ;
3263   UTL_FILE.PUT_LINE(l_log_handle, 'organization_code    = ' || alloc_rec.organization_code) ;
3264   UTL_FILE.PUT_LINE(l_log_handle, 'delete_mark          = ' || alloc_rec.delete_mark) ;
3265   UTL_FILE.PUT_LINE(l_log_handle, 'user_name            = ' || alloc_rec.user_name) ;
3266 
3267   -- DBMS_OUTPUT.PUT_LINE('before calling Delete API...');
3268   GMF_ALLOCATIONDEFINITION_PUB.Delete_Allocation_Definition
3269   ( p_api_version    => 3.0
3270   , p_init_msg_list  => FND_API.G_TRUE
3271   , p_commit         => FND_API.G_TRUE
3272 
3273   , x_return_status  =>l_status
3274   , x_msg_count      =>l_count
3275   , x_msg_data       =>l_data
3276 
3277   , p_allocation_definition_rec => alloc_rec
3278   );
3279 
3280   UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
3281   IF l_count > 0
3282   THEN
3283   l_loop_cnt  :=1;
3284   LOOP
3285 
3286   FND_MSG_PUB.Get(
3287     p_msg_index     => l_loop_cnt,
3288     p_data          => l_data,
3289     p_encoded       => FND_API.G_FALSE,
3290     p_msg_index_out => l_dummy_cnt);
3291 
3292 
3293   -- DBMS_OUTPUT.PUT_LINE(l_data );
3294 
3295   UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
3296   UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
3297   UTL_FILE.NEW_LINE(l_outfile_handle);
3298 
3299   UTL_FILE.PUT_LINE(l_log_handle, l_data);
3300 
3301   /*  Update error status */
3302     IF (l_status = 'U')
3303     THEN
3304       l_return_status  :=l_status;
3305     ELSIF (l_status = 'E' and l_return_status <> 'U')
3306     THEN
3307       l_return_status  :=l_status;
3308     ELSE
3309       l_return_status  :=l_status;
3310     END IF;
3311 
3312   l_loop_cnt  := l_loop_cnt + 1;
3313   IF l_loop_cnt > l_count
3314   THEN
3315     EXIT;
3316   END IF;
3317 
3318   END LOOP;
3319 
3320  END IF;
3321 
3322 EXCEPTION
3323  WHEN OTHERS THEN
3324   -- DBMS_OUTPUT.PUT_LINE('Other Error...1');
3325   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3326   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3327   l_return_status := 'U' ;
3328 END ;
3329 
3330 END LOOP;
3331 
3332   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3333   UTL_FILE.NEW_LINE(l_log_handle);
3334   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3335 
3336 /*  Check if any messages generated. If so then decode and */
3337 /*  output to error message flat file */
3338 
3339 UTL_FILE.FCLOSE_ALL;
3340 
3341 RETURN l_return_status;
3342 
3343 EXCEPTION
3344 WHEN UTL_FILE.INVALID_OPERATION THEN
3345    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
3346    UTL_FILE.FCLOSE_ALL;
3347    RETURN l_return_status;
3348 
3349 WHEN UTL_FILE.INVALID_PATH THEN
3350    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
3351    UTL_FILE.FCLOSE_ALL;
3352    RETURN l_return_status;
3353 
3354 WHEN UTL_FILE.INVALID_MODE THEN
3355    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
3356    UTL_FILE.FCLOSE_ALL;
3357    RETURN l_return_status;
3358 
3359 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
3360    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
3361    UTL_FILE.FCLOSE_ALL;
3362    RETURN l_return_status;
3363 
3364 WHEN UTL_FILE.WRITE_ERROR THEN
3365    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
3366    UTL_FILE.FCLOSE_ALL;
3367    RETURN l_return_status;
3368 
3369 WHEN UTL_FILE.READ_ERROR THEN
3370    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
3371    UTL_FILE.FCLOSE_ALL;
3372    RETURN l_return_status;
3373 
3374 WHEN UTL_FILE.INTERNAL_ERROR THEN
3375    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
3376    UTL_FILE.FCLOSE_ALL;
3377    RETURN l_return_status;
3378 
3379 WHEN OTHERS THEN
3380    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
3381   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3382   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3383   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3384    UTL_FILE.FCLOSE_ALL;
3385    l_return_status := 'U' ;
3386    RETURN l_return_status;
3387 
3388 END Delete_Alloc_def;
3389 
3390 
3391 
3392 --+==========================================================================+
3393 --| PROCEDURE NAME                                                           |
3394 --|    Process_LotCost_Adjustment                                            |
3395 --|                                                                          |
3396 --| TYPE                                                                     |
3397 --|    Public                                                                |
3398 --|                                                                          |
3399 --| USAGE                                                                    |
3400 --|    Create/Insert, Update,Delete Lot Cost Adjustment                      |
3401 --|                                                                          |
3402 --| DESCRIPTION                                                              |
3403 --|    This is a PL/SQL wrapper procedure to call the                        |
3404 --|    Call_LotCost_API wrapper function	   		             |
3405 --|                                                                          |
3406 --| PARAMETERS                                                               |
3407 --|    p_dir              IN VARCHAR2         - Working directory for input  |
3408 --|                                             and output files.            |
3409 --|    p_input_file       IN VARCHAR2         - Name of input file           |
3410 --|    p_output_file      IN VARCHAR2         - Name of output file          |
3411 --|    p_delimiter        IN VARCHAR2         - Delimiter character          |
3412 --|    p_operation	  IN VARCHAR2	      - Operation to be performed    |
3413 --|                                                                          |
3414 --| RETURNS                                                                  |
3415 --|    None                                                                  |
3416 --|                                                                          |
3417 --| HISTORY                                                                  |
3418 --|    30/Mar/2004  Dinesh Vadivel      Created                              |
3419 --|                                                                          |
3420 --+==========================================================================+
3421 
3422 PROCEDURE Process_LotCost_Adjustment
3423 ( p_dir          IN VARCHAR2
3424 , p_input_file   IN VARCHAR2
3425 , p_output_file  IN VARCHAR2
3426 , p_delimiter    IN VARCHAR2
3427 , p_operation    IN VARCHAR2
3428 )
3429 
3430 IS
3431 l_return_status  VARCHAR2(1);
3432 
3433 BEGIN
3434 
3435 --DBMS_OUTPUT.PUT_LINE('in Process_LotCost_Adjustment procedure... ');
3436 l_return_status  :=Process_LotCost_Adjustment( p_dir
3437 			      	                    , p_input_file
3438                                      , p_output_file
3439                                      , p_delimiter
3440 				                        , p_operation
3441                                    );
3442 End Process_LotCost_Adjustment;
3443 
3444 
3445 /* +==========================================================================+
3446  | FUNCTION NAME                                                              |
3447  |    Process_LotCost_Adjustment                                              |
3448  |                                                                            |
3449  | TYPE                                                                       |
3450  |    Public                                                                  |
3451  |                                                                            |
3452  | USAGE                                                                      |
3453  |    Create/Insert, Update or Delete Lot Cost Adjustment                     |
3454  |                                                                            |
3455  | DESCRIPTION                                                                |
3456  |    This is a PL/SQL wrapper function to call the                           |
3457  |    Call_LotCost_API.							      |
3458  |    It reads item data from a flat file and outputs any error               |
3459  |    messages to a second flat file. It also generates a Status              |
3460  |    called gmf_api_<operation>_wrapper<session_id>.log in the /tmp directory|
3461  |                                                                            |
3462  | PARAMETERS                                                                 |
3463  |    p_dir              IN VARCHAR2         - Working directory for input    |
3464  |                                             and output files.              |
3465  |    p_input_file       IN VARCHAR2         - Name of input file             |
3466  |    p_output_file      IN VARCHAR2         - Name of output file            |
3467  |    p_delimiter        IN VARCHAR2         - Delimiter character            |
3468  |    p_operation	  IN VARCHAR2	     - Operation to be performed      |
3469  |									      |
3470  | RETURNS                                                                    |
3471  |    VARCHAR2 - 'S' All records processed successfully                       |
3472  |               'E' 1 or more records errored                                |
3473  |               'U' 1 or more record unexpected error                        |
3474  |                                                                            |
3475  | HISTORY                                                                    |
3476  |                                                                            |
3477  +============================================================================+
3478   Api end of comments
3479 */
3480 FUNCTION Process_LotCost_Adjustment
3481 ( p_dir          IN VARCHAR2
3482 , p_input_file   IN VARCHAR2
3483 , p_output_file  IN VARCHAR2
3484 , p_delimiter    IN VARCHAR2
3485 , p_operation    IN VARCHAR2
3486 )
3487 RETURN VARCHAR2
3488 IS
3489 
3490 /* Local variables */
3491 
3492 
3493 l_status             VARCHAR2(11);
3494 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
3495 l_count              NUMBER(10)  ;
3496 l_record_count       NUMBER(10)  :=0;
3497 l_loop_cnt           NUMBER(10)  :=0;
3498 l_dummy_cnt          NUMBER(10)  :=0;
3499 l_data               VARCHAR2(32767);
3500 
3501 l_header_rec         GMF_LOTCOSTADJUSTMENT_PUB.Lc_Adjustment_Header_Rec_Type;
3502 l_dtl_tbl            GMF_LOTCOSTADJUSTMENT_PUB.Lc_Adjustment_Dtls_Tbl_Type;
3503 
3504 l_p_dir              VARCHAR2(150);
3505 l_output_file        VARCHAR2(120);
3506 l_outfile_handle     UTL_FILE.FILE_TYPE;
3507 l_input_file         VARCHAR2(120);
3508 l_infile_handle      UTL_FILE.FILE_TYPE;
3509 l_line               VARCHAR2(32767);
3510 l_delimiter          VARCHAR(11);
3511 l_log_dir            VARCHAR2(150);
3512 l_log_name           VARCHAR2(120) ;--:='gmf_api_cric_wrapper';
3513 l_log_handle         UTL_FILE.FILE_TYPE;
3514 l_global_file        VARCHAR2(120);
3515 l_idx		     NUMBER(10);
3516 l_idx1		     NUMBER(10);
3517 l_type		     VARCHAR2(32767);
3518 l_continue           VARCHAR2(1) := 'Y' ;
3519 l_skip_details       VARCHAR2(1) := 'N' ;
3520 l_session_id         VARCHAR2(110);
3521 
3522 
3523 BEGIN
3524 
3525   /*  Enable The Buffer  */
3526 --  DBMS_OUTPUT.ENABLE(1000000);
3527 
3528   --DBMS_OUTPUT.PUT_LINE('in Process_LotCost_Adjustment function...');
3529 
3530   l_p_dir              :=p_dir;
3531   l_log_dir	       := p_dir;
3532   l_input_file         :=p_input_file;
3533   l_output_file        :=p_output_file;
3534   l_delimiter          :=p_delimiter;
3535   l_global_file        :=l_input_file;
3536 
3537   IF p_operation = 'INSERT' THEN
3538     l_log_name := 'gmf_api_crtlcadj_wrapper' ;
3539   ELSIF p_operation = 'UPDATE' THEN
3540     l_log_name := 'gmf_api_updlcadj_wrapper' ;
3541   ELSIF p_operation = 'DELETE' THEN
3542     l_log_name := 'gmf_api_dellcadj_wrapper' ;
3543   END IF ;
3544 
3545 
3546   /* Obtain The SessionId To Append To wrapper File Name. */
3547   l_session_id := USERENV('sessionid');
3548 
3549   l_log_name  := CONCAT(l_log_name,l_session_id);
3550   l_log_name  := CONCAT(l_log_name,'.log');
3551 
3552   /*  Directory is now the same same as for the out file */
3553   l_log_dir   := p_dir;
3554 
3555   /* Open The Wrapper File For Output And The Input File for Input. */
3556   l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
3557   l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
3558 
3559   /* Loop thru flat file and call Inventory Quantities API */
3560   /*
3561    DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3562    DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
3563    DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
3564    DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
3565    DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
3566   */
3567 
3568   UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3569   UTL_FILE.NEW_LINE(l_log_handle);
3570   UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
3571   UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
3572   UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
3573   UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
3574 
3575   l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
3576 
3577 
3578   BEGIN
3579    <<TITLE_REPEAT>>
3580     UTL_FILE.GET_LINE(l_infile_handle, l_line);
3581     l_type   := Get_Field(l_line,l_delimiter,1) ;  -- = 10 : header rec, 20 : detail record
3582     IF ( l_type  <> '10' AND l_type <> '20' AND l_type IS NOT NULL) THEN
3583       GOTO TITLE_REPEAT;
3584     END IF;
3585     l_record_count    :=l_record_count+1;
3586 
3587 
3588   EXCEPTION
3589     WHEN NO_DATA_FOUND THEN
3590       raise;
3591   END;
3592 
3593   LOOP
3594     BEGIN
3595       UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || to_char(l_record_count));
3596       UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
3597 
3598        IF l_type = '10' THEN
3599 
3600 	     l_header_rec.adjustment_id			:=	 Get_Field(l_line,l_delimiter,2);
3601         l_header_rec.legal_entity_id             	:=	 Get_Field(l_line,l_delimiter,3);
3602         l_header_rec.cost_type_id			:=	 Get_Field(l_line,l_delimiter,4);
3603         l_header_rec.cost_mthd_code			:=	 Get_Field(l_line,l_delimiter,5);
3604         l_header_rec.organization_id			:=	 Get_Field(l_line,l_delimiter,6);
3605         l_header_rec.organization_code			:=	 Get_Field(l_line,l_delimiter,7);
3606         l_header_rec.item_id				:=	 Get_Field(l_line,l_delimiter,8);
3607         l_header_rec.item_number				:=	 Get_Field(l_line,l_delimiter,9);
3608         l_header_rec.lot_number				:=	 Get_Field(l_line,l_delimiter,10);
3609 
3610 
3611 	-- Bug # 3755374 ANTHIYAG 12-Jul-2004 Start
3612       	BEGIN
3613       		l_header_rec.adjustment_date		:=	 fnd_date.canonical_to_date(Get_Field(l_line,l_delimiter,11));
3614       	EXCEPTION
3615       		WHEN OTHERS THEN
3616       			-- Date set to Sysdate + 1 to disallow errors to be raised in Wrapper.
3617       			-- Error would be handled in Validate procedure of Public API Package
3618       			l_header_rec.adjustment_date	:=	 SYSDATE + 1;
3619       	END;
3620 	-- Bug # 3755374 ANTHIYAG 12-Jul-2004 End
3621 
3622               l_header_rec.reason_code			:=	 Get_Field(l_line,l_delimiter,12);
3623               l_header_rec.delete_mark			:=	 Get_Field(l_line,l_delimiter,13);
3624               l_header_rec.attribute1				:=	 Get_Field(l_line,l_delimiter,14);
3625               l_header_rec.attribute2				:=	 Get_Field(l_line,l_delimiter,15);
3626               l_header_rec.attribute3				:=	 Get_Field(l_line,l_delimiter,16);
3627               l_header_rec.attribute4				:=	 Get_Field(l_line,l_delimiter,17);
3628               l_header_rec.attribute5				:=	 Get_Field(l_line,l_delimiter,18);
3629               l_header_rec.attribute6				:=	 Get_Field(l_line,l_delimiter,19);
3630          	l_header_rec.attribute7				:=	 Get_Field(l_line,l_delimiter,20);
3631          	l_header_rec.attribute8				:=	 Get_Field(l_line,l_delimiter,21);
3632          	l_header_rec.attribute9				:=	 Get_Field(l_line,l_delimiter,22);
3633          	l_header_rec.attribute10			:=	 Get_Field(l_line,l_delimiter,23);
3634          	l_header_rec.attribute11			:=	 Get_Field(l_line,l_delimiter,24);
3635          	l_header_rec.attribute12			:=	 Get_Field(l_line,l_delimiter,25);
3636       	l_header_rec.attribute13			:=	 Get_Field(l_line,l_delimiter,26);
3637       	l_header_rec.attribute14			:=	 Get_Field(l_line,l_delimiter,27);
3638       	l_header_rec.attribute15			:=	 Get_Field(l_line,l_delimiter,28);
3639       	l_header_rec.attribute16			:=	 Get_Field(l_line,l_delimiter,29);
3640       	l_header_rec.attribute17			:=	 Get_Field(l_line,l_delimiter,30);
3641       	l_header_rec.attribute18			:=	 Get_Field(l_line,l_delimiter,31);
3642       	l_header_rec.attribute19			:=	 Get_Field(l_line,l_delimiter,32);
3643       	l_header_rec.attribute20			:=	 Get_Field(l_line,l_delimiter,33);
3644       	l_header_rec.attribute21			:=	 Get_Field(l_line,l_delimiter,34);
3645       	l_header_rec.attribute22			:=	 Get_Field(l_line,l_delimiter,35);
3646       	l_header_rec.attribute23			:=	 Get_Field(l_line,l_delimiter,36);
3647       	l_header_rec.attribute24			:=	 Get_Field(l_line,l_delimiter,37);
3648       	l_header_rec.attribute25			:=	 Get_Field(l_line,l_delimiter,38);
3649       	l_header_rec.attribute26			:=	 Get_Field(l_line,l_delimiter,39);
3650       	l_header_rec.attribute27			:=	 Get_Field(l_line,l_delimiter,40);
3651       	l_header_rec.attribute28			:=	 Get_Field(l_line,l_delimiter,41);
3652       	l_header_rec.attribute29			:=	 Get_Field(l_line,l_delimiter,42);
3653       	l_header_rec.attribute30			:=	 Get_Field(l_line,l_delimiter,43);
3654       	l_header_rec.attribute_category	:=	 Get_Field(l_line,l_delimiter,44);
3655          l_header_rec.user_name				:=	 Get_Field(l_line,l_delimiter,45);
3656       	l_dtl_tbl.DELETE ;
3657          l_skip_details := 'N' ;
3658       	l_idx  := 0 ;
3659 
3660   ELSIF l_type = '20' AND l_skip_details = 'Y' THEN
3661       UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skipping this record...');
3662    ELSIF l_type = '20' AND l_skip_details = 'N' THEN
3663 
3664 	l_idx := l_idx + 1 ;
3665 	l_dtl_tbl(l_idx).adjustment_dtl_id		:=	Get_Field(l_line,l_delimiter,2);
3666 	l_dtl_tbl(l_idx).adjustment_id			:=	Get_Field(l_line,l_delimiter,3);
3667 	l_dtl_tbl(l_idx).cost_cmpntcls_id		:=	Get_Field(l_line,l_delimiter,4);
3668 	l_dtl_tbl(l_idx).cost_cmpntcls_code		:=	Get_Field(l_line,l_delimiter,5);
3669 	l_dtl_tbl(l_idx).cost_analysis_code		:=	Get_Field(l_line,l_delimiter,6);
3670 
3671 	-- Bug # 3755374 ANTHIYAG 12-Jul-2004 Start
3672 	BEGIN
3673 		l_dtl_tbl(l_idx).adjustment_cost	:=	Get_Field(l_line,l_delimiter,7);
3674 	EXCEPTION
3675 		WHEN VALUE_ERROR THEN
3676 			UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : Invalid Adjustment Cost Specified');
3677 			UTL_FILE.PUT_LINE(l_log_handle, 'Error : Invalid Adjustment Cost Specified');
3678 	END;
3679 	-- Bug # 3755374 ANTHIYAG 12-Jul-2004 End
3680 
3681    -- Bug # 3778177 ANTHIYAG 20-Jul-2004 Start
3682    -- l_dtl_tbl(l_idx).delete_mark			:=	Get_Field(l_line,l_delimiter,8);
3683    -- Bug # 3778177 ANTHIYAG 20-Jul-2004 End
3684 
3685         l_dtl_tbl(l_idx).text_code			:=	Get_Field(l_line,l_delimiter,8);
3686 
3687       END IF ;
3688 
3689     EXCEPTION
3690 
3691       WHEN OTHERS THEN
3692 	     UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3693         UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3694         IF l_type = '10' THEN
3695           l_skip_details := 'Y' ;
3696           UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skip detail records.');
3697         ELSIF l_type = '20' THEN
3698           l_dtl_tbl.DELETE(l_idx);
3699           l_idx := l_idx-1;
3700         END IF ;
3701      END ;
3702 
3703     BEGIN
3704 
3705       <<TITLE_REPEAT1>>
3706       UTL_FILE.GET_LINE(l_infile_handle, l_line);
3707       l_type   := Get_Field(l_line,l_delimiter,1) ;  -- 10 : Header Record, 20 : Detail Record
3708        IF ( l_type  <> '10' AND l_type <> '20' AND l_type IS NOT NULL) THEN
3709           GOTO TITLE_REPEAT1;
3710        END IF;
3711       l_record_count    :=l_record_count+1;
3712       UTL_FILE.NEW_LINE(l_log_handle);
3713 
3714     EXCEPTION
3715       WHEN NO_DATA_FOUND THEN
3716         IF l_skip_details = 'N' THEN
3717           UTL_FILE.PUT_LINE(l_log_handle,'Final Call to Call_LotCost_API...');
3718 
3719           /* Call the Call Lot Cost API function */
3720 	  Call_LotCost_API
3721 	  (
3722 	      p_header_rec		=>  l_header_rec
3723             , p_dtl_tbl			=>  l_dtl_tbl
3724             , p_operation    		=>  p_operation
3725             , x_status       		=>  l_status
3726             , x_count    		=>  l_count
3727             , x_data         		=>  l_data
3728           ) ;
3729 
3730           UTL_FILE.PUT_LINE(l_log_handle,'Final After call to Create_LotCost_Adjustment API.status := ' || l_status ||' cnt := ' || l_count );
3731         END IF;
3732         l_continue := 'N' ;
3733         GOTO GET_MSG_STACK ;
3734     END;
3735 
3736     IF (l_type = '10' AND l_record_count <> 1 AND l_skip_details = 'N') THEN
3737       UTL_FILE.PUT_LINE(l_log_handle,'Call to  Create_LotCost_Adjustment API...');
3738 
3739       /* Call the Call Lot Cost API function */ --to change
3740       Call_LotCost_API
3741       (
3742 	  p_header_rec		=>  l_header_rec
3743         , p_dtl_tbl		=>  l_dtl_tbl
3744         , p_operation    	=>  p_operation
3745 	     , x_status       	=>  l_status
3746         , x_count    		=>  l_count
3747         , x_data         	=>  l_data
3748        ) ;
3749 
3750        UTL_FILE.PUT_LINE(l_log_handle,' After call to Create_LotCost_Adjustment API.status := ' ||	l_status ||' cnt := ' || l_count );
3751      END IF;
3752 
3753      <<GET_MSG_STACK>>
3754        null;
3755 
3756     /*  Check if any messages generated. If so then decode and */
3757     /*  output to error message flat file */
3758 
3759       IF l_count > 0 THEN
3760 
3761         l_loop_cnt  :=1;
3762         LOOP
3763           FND_MSG_PUB.Get(
3764           p_msg_index     => l_loop_cnt,
3765           p_data          => l_data,
3766           p_encoded       => FND_API.G_FALSE,
3767           p_msg_index_out => l_dummy_cnt);
3768 
3769           UTL_FILE.PUT_LINE(l_log_handle, l_data);
3770 
3771           /*  Update error status */
3772           IF (l_status = 'U') THEN
3773             l_return_status  :=l_status;
3774           ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
3775             l_return_status  :=l_status;
3776           ELSE
3777             l_return_status  :=l_status;
3778           END IF;
3779 
3780           l_loop_cnt  := l_loop_cnt + 1;
3781           IF l_loop_cnt > l_count THEN
3782             EXIT;
3783           END IF;
3784 
3785         END LOOP; -- msg stack loop
3786         l_count := 0 ;
3787 
3788       END IF;	-- if count of msg stack > 0
3789 
3790       IF l_continue = 'N' THEN
3791         EXIT ;
3792       END IF ;
3793 
3794     END LOOP;
3795 
3796 --    DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3797     UTL_FILE.NEW_LINE(l_log_handle);
3798     UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3799     UTL_FILE.FCLOSE_ALL;
3800 
3801     RETURN l_return_status;
3802 
3803 EXCEPTION
3804 WHEN UTL_FILE.INVALID_OPERATION THEN
3805    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
3806    UTL_FILE.FCLOSE_ALL;
3807    RETURN l_return_status;
3808 
3809 WHEN UTL_FILE.INVALID_PATH THEN
3810    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
3811    UTL_FILE.FCLOSE_ALL;
3812    RETURN l_return_status;
3813 
3814 WHEN UTL_FILE.INVALID_MODE THEN
3815    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
3816    UTL_FILE.FCLOSE_ALL;
3817    RETURN l_return_status;
3818 
3819 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
3820    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
3821    UTL_FILE.FCLOSE_ALL;
3822    RETURN l_return_status;
3823 
3824 WHEN UTL_FILE.WRITE_ERROR THEN
3825    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
3826    UTL_FILE.FCLOSE_ALL;
3827    RETURN l_return_status;
3828 
3829 WHEN UTL_FILE.READ_ERROR THEN
3830    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
3831    UTL_FILE.FCLOSE_ALL;
3832    RETURN l_return_status;
3833 
3834 WHEN UTL_FILE.INTERNAL_ERROR THEN
3835    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
3836    UTL_FILE.FCLOSE_ALL;
3837    RETURN l_return_status;
3838 
3839 WHEN OTHERS THEN
3840    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
3841   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3842   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
3843   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
3844    UTL_FILE.FCLOSE_ALL;
3845    l_return_status := 'U' ;
3846    RETURN l_return_status;
3847 
3848 END Process_LotCost_Adjustment;
3849 
3850 /* +============================================================================+
3851  | PROCEDURE NAME                                                               |
3852  |    Call_LotCost_API							        |
3853  |                                                                              |
3854  | TYPE                                                                         |
3855  |    Public                                                                    |
3856  |										|
3857  | USAGE									|
3858  |    Calls LotCost_Adjsutment APIs based on the operation being performed	|
3859  |										|
3860  | DESCRIPTION									|
3861  |    This is a PL/SQL wrapper function to call the Burden_detail API.		|
3862  |    Data is sent from through the parameters.					|
3863  |										|
3864  | PARAMETERS                                                                   |
3865  |    p_header_rec	    IN VARCHAR2         - Burden Details Header		|
3866  |    p_dtl_tbl             IN VARCHAR2         - Burden Details		|
3867  |    p_operation	    IN VARCHAR2         - Insert/Update/Delete		|
3868  |    x_status              OUT VARCHAR2        - Return Status			|
3869  |    x_count               OUT VARCHAR2        - # of msgs on message stack	|
3870  |    x_data                OUT VARCHAR2        - Actual Message from msg stack	|
3871  |										|
3872  |										|
3873  | HISTORY									|
3874  |     Created by dvadivel on 5-Apr-2004                                        |
3875  +==============================================================================+
3876 */
3877 
3878 PROCEDURE Call_LotCost_API
3879 (
3880   p_header_rec		  IN OUT	NOCOPY GMF_LOTCOSTADJUSTMENT_PUB.Lc_Adjustment_Header_Rec_Type
3881 , p_dtl_tbl		  IN OUT	NOCOPY GMF_LOTCOSTADJUSTMENT_PUB.Lc_Adjustment_Dtls_Tbl_Type
3882 , p_operation             IN			VARCHAR2
3883 , x_status                OUT		NOCOPY	VARCHAR2
3884 , x_count                 OUT		NOCOPY	NUMBER
3885 , x_data                  OUT		NOCOPY	VARCHAR2
3886 )
3887 IS
3888 
3889 BEGIN
3890 
3891  IF p_operation = 'INSERT' THEN
3892    GMF_LotCostAdjustment_PUB.Create_LotCost_Adjustment
3893 	( p_api_version		=>	2.0
3894 	, p_init_msg_list	=>	FND_API.G_TRUE
3895 	, p_commit		=>	FND_API.G_TRUE
3896 	, x_return_status	=>	x_status
3897 	, x_msg_count		=>	x_count
3898 	, x_msg_data		=>	x_data
3899 	, p_header_rec		=>	p_header_rec
3900 	, p_dtl_Tbl		=>	p_dtl_tbl
3901 	);
3902  ELSIF p_operation = 'UPDATE' THEN
3903    GMF_LotCostAdjustment_PUB.Update_LotCost_Adjustment
3904 	( p_api_version		=>	2.0
3905 	, p_init_msg_list	=>	FND_API.G_TRUE
3906 	, p_commit		=>	FND_API.G_TRUE
3907 	, x_return_status	=>	x_status
3908 	, x_msg_count		=>	x_count
3909 	, x_msg_data		=>	x_data
3910 	, p_header_rec		=>	p_header_rec
3911 	, p_dtl_Tbl		=>	p_dtl_tbl
3912 	);
3913  ELSIF p_operation = 'DELETE' THEN
3914    GMF_LotCostAdjustment_PUB.Delete_LotCost_Adjustment
3915 	( p_api_version		=>	2.0
3916 	, p_init_msg_list	=>	FND_API.G_TRUE
3917 	, p_commit		=>	FND_API.G_TRUE
3918 	, x_return_status	=>	x_status
3919 	, x_msg_count		=>	x_count
3920 	, x_msg_data		=>	x_data
3921 	, p_header_rec		=>	p_header_rec
3922 	, p_dtl_Tbl		=>	p_dtl_tbl
3923 	);
3924  END IF ;
3925 
3926 END Call_LotCost_API ;
3927 
3928 /* +========================================================================+
3929  | FUNCTION NAME                                                            |
3930  |    Get_LotCost_Adjsutment                                                   |
3931  |                                                                          |
3932  | TYPE                                                                     |
3933  |    Public                                                                |
3934  |                                                                          |
3935  | USAGE                                                                    |
3936  |    Get Lot Cost Adjustment Details                                                 |
3937  |                                                                          |
3938  | DESCRIPTION                                                              |
3939  |    This is a PL/SQL wrapper function to call the                         |
3940  |    Get_LotCost_Adjustment API.                                               |
3941  |    It reads item data from a flat file and outputs any error             |
3942  |    messages to a second flat file. It also generates a Status            |
3943  |    called gmf_rsrc_wrapper<session_id>.log in the /tmp directory.        |
3944  |                                                                          |
3945  | PARAMETERS                                                               |
3946  |    p_dir              IN VARCHAR2         - Working directory for input  |
3947  |                                             and output files.            |
3948  |    p_input_file       IN VARCHAR2         - Name of input file           |
3949  |    p_output_file      IN VARCHAR2         - Name of output file          |
3950  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
3951  |                                                                          |
3952  | RETURNS                                                                  |
3953  |    VARCHAR2 - 'S' All records processed successfully                     |
3954  |               'E' 1 or more records errored                              |
3955  |               'U' 1 or more record unexpected error                      |
3956  |                                                                          |
3957  | HISTORY                                                                  |
3958  |    Dinesh Vadivel 05-Apr-2004 Created                                    |
3959  |									    |
3960  +==========================================================================+
3961 */
3962 
3963 FUNCTION Get_LotCost_Adjustment
3964 ( p_dir          IN VARCHAR2
3965 , p_input_file   IN VARCHAR2
3966 , p_output_file  IN VARCHAR2
3967 , p_delimiter    IN VARCHAR2
3968 )
3969 RETURN VARCHAR2
3970 IS
3971 
3972 /* Local variables */
3973 
3974 l_status             VARCHAR2(11);
3975 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
3976 l_count              NUMBER(10)  ;
3977 l_record_count       NUMBER(10)  :=0;
3978 l_loop_cnt           NUMBER(10)  :=0;
3979 l_dummy_cnt          NUMBER(10)  :=0;
3980 l_data               VARCHAR2(1000);
3981 
3982 l_header_rec         GMF_LOTCOSTADJUSTMENT_PUB.Lc_Adjustment_Header_Rec_Type;
3983 l_dtl_tbl            GMF_LOTCOSTADJUSTMENT_PUB.Lc_Adjustment_Dtls_Tbl_Type;
3984 
3985 l_p_dir              VARCHAR2(150);
3986 l_output_file        VARCHAR2(120);
3987 l_outfile_handle     UTL_FILE.FILE_TYPE;
3988 l_input_file         VARCHAR2(120);
3989 l_infile_handle      UTL_FILE.FILE_TYPE;
3990 l_line               VARCHAR2(1000);
3991 l_delimiter          VARCHAR(11);
3992 l_log_dir            VARCHAR2(150);
3993 l_log_name           VARCHAR2(120) :='gmf_api_getlotcost_wrapper';
3994 l_log_handle         UTL_FILE.FILE_TYPE;
3995 l_global_file        VARCHAR2(120);
3996 l_idx		     NUMBER(10);
3997 l_idx1		     NUMBER(10);
3998 l_type		     VARCHAR2(32767);
3999 l_continue           VARCHAR2(1) := 'Y' ;
4000 l_skip_details       VARCHAR2(1) := 'N' ;
4001 l_session_id         VARCHAR2(110);
4002 
4003 BEGIN
4004 
4005   /*  Enable The Buffer  */
4006   /*  DBMS_OUTPUT.ENABLE(1000000); */
4007 
4008   -- DBMS_OUTPUT.PUT_LINE('in Get_Burden_details function...');
4009 
4010   l_p_dir              :=p_dir;
4011   l_log_dir	       := p_dir;
4012   l_input_file         :=p_input_file;
4013   l_output_file        :=p_output_file;
4014   l_delimiter          :=p_delimiter;
4015   l_global_file        :=l_input_file;
4016 
4017   /*  Obtain The SessionId To Append To wrapper File Name. */
4018 
4019   l_session_id := USERENV('sessionid');
4020 
4021   l_log_name  := CONCAT(l_log_name,l_session_id);
4022   l_log_name  := CONCAT(l_log_name,'.log');
4023 
4024   /*  Directory is now the same same as for the out file */
4025   l_log_dir   := p_dir;
4026 
4027 
4028   /*  Open The Wrapper File For Output And The Input File for Input. */
4029 
4030   l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
4031   l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
4032 
4033   /*  Loop thru flat file and call Inventory Quantities API */
4034   -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4035   -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
4036   -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
4037   -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
4038   -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
4039 
4040 
4041   /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
4042   UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4043   UTL_FILE.NEW_LINE(l_log_handle);
4044   UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
4045   UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
4046   UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
4047   UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
4048 
4049   l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
4050 
4051 
4052  LOOP
4053   BEGIN
4054      <<TITLE_REPEAT>>
4055     UTL_FILE.GET_LINE(l_infile_handle, l_line);
4056     l_type   := Get_Field(l_line,l_delimiter,1) ;  -- = 10 : header rec, 20 : detail record
4057     IF ( l_type  <> '10' AND l_type IS NOT NULL) THEN
4058       GOTO TITLE_REPEAT;
4059     END IF;
4060     l_record_count    :=l_record_count+1;
4061 
4062   EXCEPTION
4063     WHEN NO_DATA_FOUND THEN
4064       EXIT ;
4065   END;
4066 
4067   BEGIN
4068     UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
4069       -- empty the tables
4070       l_dtl_tbl.delete ;
4071 
4072         l_header_rec.adjustment_id			:=	 Get_Field(l_line,l_delimiter,2);
4073         l_header_rec.legal_entity_id   	:=	 Get_Field(l_line,l_delimiter,3);
4074         l_header_rec.cost_type_id			:=	 Get_Field(l_line,l_delimiter,4);
4075         l_header_rec.cost_mthd_code			:=	 Get_Field(l_line,l_delimiter,5);
4076         l_header_rec.organization_id			:=	 Get_Field(l_line,l_delimiter,6);
4077         l_header_rec.organization_code			:=	 Get_Field(l_line,l_delimiter,7);
4078         l_header_rec.item_id				:=	 Get_Field(l_line,l_delimiter,8);
4079         l_header_rec.item_number				:=	 Get_Field(l_line,l_delimiter,9);
4080         l_header_rec.lot_number				:=	 Get_Field(l_line,l_delimiter,10);
4081 
4082 	-- Bug # 3755374 ANTHIYAG 12-Jul-2004 Start
4083 	BEGIN
4084 		l_header_rec.adjustment_date		:=	 fnd_date.canonical_to_date(Get_Field(l_line,l_delimiter,11));
4085 	EXCEPTION
4086 		WHEN OTHERS THEN
4087 			-- Date set to Sysdate + 1 to disallow errors to be raised in Wrapper.
4088 			-- Error would be handled in Validate procedure of Public API Package
4089 			l_header_rec.adjustment_date	:=	 SYSDATE + 1;
4090 	END;
4091 	-- Bug # 3755374 ANTHIYAG 12-Jul-2004 Start
4092 
4093         l_header_rec.reason_code			:=	 Get_Field(l_line,l_delimiter,12);
4094         l_header_rec.delete_mark			:=	 Get_Field(l_line,l_delimiter,13);
4095         l_header_rec.attribute1				:=	 Get_Field(l_line,l_delimiter,14);
4096         l_header_rec.attribute2				:=	 Get_Field(l_line,l_delimiter,15);
4097         l_header_rec.attribute3				:=	 Get_Field(l_line,l_delimiter,16);
4098         l_header_rec.attribute4				:=	 Get_Field(l_line,l_delimiter,17);
4099         l_header_rec.attribute5				:=	 Get_Field(l_line,l_delimiter,18);
4100         l_header_rec.attribute6				:=	 Get_Field(l_line,l_delimiter,19);
4101 	l_header_rec.attribute7				:=	 Get_Field(l_line,l_delimiter,20);
4102 	l_header_rec.attribute8				:=	 Get_Field(l_line,l_delimiter,21);
4103 	l_header_rec.attribute9				:=	 Get_Field(l_line,l_delimiter,22);
4104 	l_header_rec.attribute10			:=	 Get_Field(l_line,l_delimiter,23);
4105 	l_header_rec.attribute11			:=	 Get_Field(l_line,l_delimiter,24);
4106 	l_header_rec.attribute12			:=	 Get_Field(l_line,l_delimiter,25);
4107 	l_header_rec.attribute13			:=	 Get_Field(l_line,l_delimiter,26);
4108 	l_header_rec.attribute14			:=	 Get_Field(l_line,l_delimiter,27);
4109 	l_header_rec.attribute15			:=	 Get_Field(l_line,l_delimiter,28);
4110 	l_header_rec.attribute16			:=	 Get_Field(l_line,l_delimiter,29);
4111 	l_header_rec.attribute17			:=	 Get_Field(l_line,l_delimiter,30);
4112 	l_header_rec.attribute18			:=	 Get_Field(l_line,l_delimiter,31);
4113 	l_header_rec.attribute19			:=	 Get_Field(l_line,l_delimiter,32);
4114 	l_header_rec.attribute20			:=	 Get_Field(l_line,l_delimiter,33);
4115 	l_header_rec.attribute21			:=	 Get_Field(l_line,l_delimiter,34);
4116 	l_header_rec.attribute22			:=	 Get_Field(l_line,l_delimiter,35);
4117 	l_header_rec.attribute23			:=	 Get_Field(l_line,l_delimiter,36);
4118 	l_header_rec.attribute24			:=	 Get_Field(l_line,l_delimiter,37);
4119 	l_header_rec.attribute25			:=	 Get_Field(l_line,l_delimiter,38);
4120 	l_header_rec.attribute26			:=	 Get_Field(l_line,l_delimiter,39);
4121 	l_header_rec.attribute27			:=	 Get_Field(l_line,l_delimiter,40);
4122 	l_header_rec.attribute28			:=	 Get_Field(l_line,l_delimiter,41);
4123 	l_header_rec.attribute29			:=	 Get_Field(l_line,l_delimiter,42);
4124 	l_header_rec.attribute30			:=	 Get_Field(l_line,l_delimiter,43);
4125 	l_header_rec.attribute_category			:=	 Get_Field(l_line,l_delimiter,44);
4126         l_header_rec.user_name				:=	 Get_Field(l_line,l_delimiter,45);
4127 
4128 
4129 
4130       -- DBMS_OUTPUT.PUT_LINE('Calling Get_Item_Cost API...');
4131 
4132       GMF_LotCostAdjustment_PUB.Get_LotCost_Adjustment
4133       (
4134         p_api_version        =>  2.0
4135       , p_init_msg_list      =>  FND_API.G_TRUE
4136 
4137       , x_return_status      =>  l_status
4138       , x_msg_count          =>  l_count
4139       , x_msg_data           =>  l_data
4140 
4141       , p_header_rec         =>  l_header_rec
4142 
4143       , p_dtl_tbl            =>  l_dtl_tbl
4144       );
4145 
4146       UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
4147 
4148 
4149     /*  Check if any messages generated. If so then decode and */
4150     /*  output to error message flat file */
4151 
4152     IF l_count > 0 THEN
4153 
4154        l_loop_cnt  :=1;
4155        LOOP
4156         FND_MSG_PUB.Get(
4157           p_msg_index     => l_loop_cnt,
4158           p_data          => l_data,
4159           p_encoded       => FND_API.G_FALSE,
4160           p_msg_index_out => l_dummy_cnt);
4161 
4162         ---- DBMS_OUTPUT.PUT_LINE(l_data );
4163         UTL_FILE.PUT_LINE(l_log_handle, l_data);
4164 
4165         /*  Update error status */
4166         IF (l_status = 'U') THEN
4167           l_return_status  :=l_status;
4168         ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
4169           l_return_status  :=l_status;
4170         ELSE
4171           l_return_status  :=l_status;
4172         END IF;
4173 
4174         l_loop_cnt  := l_loop_cnt + 1;
4175         IF l_loop_cnt > l_count THEN
4176           EXIT;
4177         END IF;
4178 
4179       END LOOP; -- msg stack loop
4180       l_count := 0 ;
4181 
4182     END IF;	-- if count of msg stack > 0
4183 
4184     UTL_FILE.NEW_LINE(l_log_handle);
4185     FOR i in 1..l_dtl_tbl.count
4186     LOOP
4187       UTL_FILE.PUT_LINE(l_log_handle,
4188 			' Adjustment Dtl Id : '		||	l_dtl_tbl(i).adjustment_dtl_id	||
4189 			' Adjustment Id	: '		||	l_dtl_tbl(i).adjustment_id	||
4190 			' Cost Cmpntcls Id : '		||	l_dtl_tbl(i).cost_cmpntcls_id	||
4191 			' Cost Cmpntcls Code : '	||	l_dtl_tbl(i).cost_cmpntcls_code	||
4192 			' Cost Anlys Code : '		||	l_dtl_tbl(i).cost_analysis_code ||
4193 			' Adjustment Mark : '		||	l_dtl_tbl(i).adjustment_cost	||
4194 			' Text Code : '			||	l_dtl_tbl(i).text_code
4195 		      );
4196     END LOOP ;
4197     l_dtl_tbl.delete ;
4198     UTL_FILE.NEW_LINE(l_log_handle);
4199     UTL_FILE.NEW_LINE(l_log_handle);
4200 
4201   EXCEPTION
4202    WHEN OTHERS THEN
4203     UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4204     UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4205   END ;
4206 
4207  END LOOP;
4208 
4209   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4210   UTL_FILE.NEW_LINE(l_log_handle);
4211   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4212   UTL_FILE.FCLOSE_ALL;
4213 
4214   RETURN l_return_status;
4215 
4216 EXCEPTION
4217 WHEN UTL_FILE.INVALID_OPERATION THEN
4218    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
4219    UTL_FILE.FCLOSE_ALL;
4220    RETURN l_return_status;
4221 
4222 WHEN UTL_FILE.INVALID_PATH THEN
4223    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
4224    UTL_FILE.FCLOSE_ALL;
4225    RETURN l_return_status;
4226 
4227 WHEN UTL_FILE.INVALID_MODE THEN
4228    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
4229    UTL_FILE.FCLOSE_ALL;
4230    RETURN l_return_status;
4231 
4232 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
4233    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
4234    UTL_FILE.FCLOSE_ALL;
4235    RETURN l_return_status;
4236 
4237 WHEN UTL_FILE.WRITE_ERROR THEN
4238    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
4239    UTL_FILE.FCLOSE_ALL;
4240    RETURN l_return_status;
4241 
4242 WHEN UTL_FILE.READ_ERROR THEN
4243    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
4244    UTL_FILE.FCLOSE_ALL;
4245    RETURN l_return_status;
4246 
4247 WHEN UTL_FILE.INTERNAL_ERROR THEN
4248    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
4249    UTL_FILE.FCLOSE_ALL;
4250    RETURN l_return_status;
4251 
4252 WHEN OTHERS THEN
4253    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
4254   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4255   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4256   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4257    UTL_FILE.FCLOSE_ALL;
4258    l_return_status := 'U' ;
4259    RETURN l_return_status;
4260 
4261 END Get_LotCost_Adjustment;
4262 
4263 
4264 PROCEDURE Process_Burden_details
4265 ( p_dir          IN VARCHAR2
4266 , p_input_file   IN VARCHAR2
4267 , p_output_file  IN VARCHAR2
4268 , p_delimiter    IN VARCHAR2
4269 , p_operation    IN VARCHAR2
4270 )
4271 IS
4272 
4273 l_return_status  VARCHAR2(1);
4274 
4275 BEGIN
4276 
4277 -- DBMS_OUTPUT.PUT_LINE('in Process_Burden_details procedure... ');
4278 l_return_status  :=Process_Burden_details( p_dir
4279 			      	       , p_input_file
4280                                        , p_output_file
4281                                        , p_delimiter
4282                                        , p_operation
4283                                        );
4284 
4285  -- DBMS_OUTPUT.PUT_LINE('return status := ' || l_return_status);
4286 END Process_Burden_details;
4287 
4288 /* +========================================================================+
4289  | FUNCTION NAME                                                            |
4290  |    Process_Burden_details                                                |
4291  |                                                                          |
4292  | TYPE                                                                     |
4293  |    Public                                                                |
4294  |                                                                          |
4295  | USAGE                                                                    |
4296  |    Create burden details                                                 |
4297  |                                                                          |
4298  | DESCRIPTION                                                              |
4299  |    This is a PL/SQL wrapper function to call the                         |
4300  |    Process_Burden_details API.                                           |
4301  |    It reads item data from a flat file and outputs any error             |
4302  |    messages to a second flat file. It also generates a Status            |
4303  |    called gmf_rsrc_wrapper<session_id>.log in the /tmp directory.        |
4304  |                                                                          |
4305  | PARAMETERS                                                               |
4306  |    p_dir              IN VARCHAR2         - Working directory for input  |
4307  |                                             and output files.            |
4308  |    p_input_file       IN VARCHAR2         - Name of input file           |
4309  |    p_output_file      IN VARCHAR2         - Name of output file          |
4310  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
4311  |                                                                          |
4312  | RETURNS                                                                  |
4313  |    VARCHAR2 - 'S' All records processed successfully                     |
4314  |               'E' 1 or more records errored                              |
4315  |               'U' 1 or more record unexpected error                      |
4316  |                                                                          |
4317  | HISTORY                                                                  |
4318  |                                                                          |
4319  +==========================================================================+
4320 */
4321 FUNCTION Process_Burden_details
4322 ( p_dir          IN VARCHAR2
4323 , p_input_file   IN VARCHAR2
4324 , p_output_file  IN VARCHAR2
4325 , p_delimiter    IN VARCHAR2
4326 , p_operation    IN VARCHAR2
4327 )
4328 RETURN VARCHAR2
4329 IS
4330 
4331 /* Local variables */
4332 
4333 l_status             VARCHAR2(11);
4334 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
4335 l_count              NUMBER(10)  ;
4336 l_record_count       NUMBER(10)  :=0;
4337 l_loop_cnt           NUMBER(10)  :=0;
4338 l_dummy_cnt          NUMBER(10)  :=0;
4339 l_data               VARCHAR2(1000);
4340 l_header_rec         GMF_BurdenDetails_PUB.Burden_Header_Rec_Type;
4341 l_dtl_tbl            GMF_BurdenDetails_PUB.Burden_Dtl_Tbl_Type;
4342 l_burdenline_ids     GMF_BurdenDetails_PUB.Burdenline_Ids_Tbl_Type;
4343 l_p_dir              VARCHAR2(150);
4344 l_output_file        VARCHAR2(120);
4345 l_outfile_handle     UTL_FILE.FILE_TYPE;
4346 l_input_file         VARCHAR2(120);
4347 l_infile_handle      UTL_FILE.FILE_TYPE;
4348 l_line               VARCHAR2(1000);
4349 l_delimiter          VARCHAR(11);
4350 l_log_dir            VARCHAR2(150);
4351 l_log_name           VARCHAR2(120) ; -- :='gmf_api_cric_wrapper';
4352 l_log_handle         UTL_FILE.FILE_TYPE;
4353 l_global_file        VARCHAR2(120);
4354 l_idx		     NUMBER(10);
4355 l_idx1		     NUMBER(10);
4356 l_type		     NUMBER(10);
4357 l_continue           VARCHAR2(1) := 'Y' ;
4358 l_skip_details       VARCHAR2(1) := 'N' ;
4359 l_session_id         VARCHAR2(110);
4360 --l_first_rec          VARCHAR2(1) ; -- for the first record it is Y else N.
4361 				   -- to avoid calling API for the first record
4362 
4363 BEGIN
4364 
4365   /*  Enable The Buffer  */
4366   /*  DBMS_OUTPUT.ENABLE(1000000); */
4367 
4368 
4369   l_p_dir              :=p_dir;
4370   l_input_file         :=p_input_file;
4371   l_output_file        :=p_output_file;
4372   l_delimiter          :=p_delimiter;
4373   l_global_file        :=l_input_file;
4374 
4375   IF p_operation = 'INSERT' THEN
4376     l_log_name := 'gmf_api_crbrdn_wrapper' ;
4377   ELSIF p_operation = 'UPDATE' THEN
4378     l_log_name := 'gmf_api_updbrdn_wrapper' ;
4379   ELSIF p_operation = 'DELETE' THEN
4380     l_log_name := 'gmf_api_delbrdn_wrapper' ;
4381   END IF ;
4382 
4383   /*  Obtain The SessionId To Append To wrapper File Name. */
4384 
4385   l_session_id := USERENV('sessionid');
4386 
4387   l_log_name  := CONCAT(l_log_name,l_session_id);
4388   l_log_name  := CONCAT(l_log_name,'.log');
4389 
4390   /*  Directory is now the same same as for the out file */
4391   l_log_dir   := p_dir;
4392 
4393 
4394   /*  Open The Wrapper File For Output And The Input File for Input. */
4395 
4396   l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
4397   l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
4398 
4399   /*  Loop thru flat file and call Inventory Quantities API */
4400   -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4401   -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
4402   -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
4403   -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
4404   -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
4405 
4406   /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
4407   UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4408   UTL_FILE.NEW_LINE(l_log_handle);
4409   UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
4410   UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
4411   UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
4412   UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
4413 
4414   l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
4415 
4416   --zzz
4417   BEGIN
4418     UTL_FILE.GET_LINE(l_infile_handle, l_line);
4419     l_record_count    :=l_record_count+1;
4420     l_type   := Get_Field(l_line,l_delimiter,1) ;  -- = 10 : header rec, 20 : detail record
4421     --l_first_rec := 'Y' ;
4422   EXCEPTION
4423     WHEN NO_DATA_FOUND THEN
4424       raise;
4425   END;
4426 
4427 
4428  LOOP
4429   BEGIN
4430     UTL_FILE.PUT_LINE(l_log_handle, '--');
4431     UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
4432     UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
4433     IF l_type = 10 THEN
4434       -- empty the tables
4435       l_dtl_tbl.delete ;
4436       l_skip_details := 'N' ;
4437       l_header_rec.organization_id   := Get_Field(l_line,l_delimiter,2) ;
4438       l_header_rec.organization_code := Get_Field(l_line,l_delimiter,3) ;
4439       l_header_rec.inventory_item_id := Get_Field(l_line,l_delimiter,4) ;
4440       l_header_rec.item_number       := Get_Field(l_line,l_delimiter,5) ;
4441       l_header_rec.period_id         := Get_Field(l_line,l_delimiter,6) ;
4442       l_header_rec.calendar_code     := Get_Field(l_line,l_delimiter,7) ;
4443       l_header_rec.period_code       := Get_Field(l_line,l_delimiter,8) ;
4444       l_header_rec.cost_type_id      := Get_Field(l_line,l_delimiter,9) ;
4445       l_header_rec.cost_mthd_code    := Get_Field(l_line,l_delimiter,10) ;
4446       l_header_rec.user_name         := Get_Field(l_line,l_delimiter,11) ;
4447       l_idx  := 0 ;
4448       /*
4449       UTL_FILE.PUT_LINE(l_log_handle, 'Type   = ' || l_type) ;
4450       UTL_FILE.PUT_LINE(l_log_handle, 'orgn_code   = ' || l_header_rec.orgn_code) ;
4451       UTL_FILE.PUT_LINE(l_log_handle, 'item_id   = ' || l_header_rec.item_id) ;
4452       UTL_FILE.PUT_LINE(l_log_handle, 'item_no   = ' || l_header_rec.item_no) ;
4453       UTL_FILE.PUT_LINE(l_log_handle, 'whse_code   = ' || l_header_rec.whse_code) ;
4454       UTL_FILE.PUT_LINE(l_log_handle, 'calendar_code   = ' || l_header_rec.calendar_code) ;
4455       UTL_FILE.PUT_LINE(l_log_handle, 'period_code   = ' || l_header_rec.period_code) ;
4456       UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code   = ' || l_header_rec.cost_mthd_code) ;
4457       UTL_FILE.PUT_LINE(l_log_handle, 'user_name   = ' || l_header_rec.user_name) ;
4458       */
4459     ELSIF l_type = 20 AND l_skip_details = 'Y' THEN
4460       UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skipping this record...');
4461     ELSIF l_type = 20 AND l_skip_details = 'N' THEN
4462       l_idx := l_idx + 1 ;
4463       l_dtl_tbl(l_idx).burdenline_id        := Get_Field(l_line,l_delimiter,2) ;
4464       l_dtl_tbl(l_idx).resources            := Get_Field(l_line,l_delimiter,3) ;
4465       l_dtl_tbl(l_idx).cost_cmpntcls_id     := Get_Field(l_line,l_delimiter,4) ;
4466       l_dtl_tbl(l_idx).cost_cmpntcls_code   := Get_Field(l_line,l_delimiter,5) ;
4467       l_dtl_tbl(l_idx).cost_analysis_code   := Get_Field(l_line,l_delimiter,6) ;
4468       l_dtl_tbl(l_idx).burden_usage         := Get_Field(l_line,l_delimiter,7) ;
4469       l_dtl_tbl(l_idx).item_qty             := Get_Field(l_line,l_delimiter,8) ;
4470       l_dtl_tbl(l_idx).item_uom             := Get_Field(l_line,l_delimiter,9) ;
4471       l_dtl_tbl(l_idx).burden_qty           := Get_Field(l_line,l_delimiter,10) ;
4472       l_dtl_tbl(l_idx).burden_uom           := Get_Field(l_line,l_delimiter,11) ;
4473       l_dtl_tbl(l_idx).delete_mark          := Get_Field(l_line,l_delimiter,12) ;
4474       /*
4475       UTL_FILE.PUT_LINE(l_log_handle, 'Populating details level table...' || l_idx ) ;
4476       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: burdenline_id('||l_idx||') = '||l_dtl_tbl(l_idx).burdenline_id) ;
4477       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: resources('||l_idx||') = '||l_dtl_tbl(l_idx).resources) ;
4478       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: cost_cmpntcls_id('||l_idx||') = '||l_dtl_tbl(l_idx).cost_cmpntcls_id) ;
4479       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: cost_cmpntcls_code('||l_idx||') = '||
4480 			l_dtl_tbl(l_idx).cost_cmpntcls_code) ;
4481       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: cost_analysis_code('||l_idx||') = '||
4482 			l_dtl_tbl(l_idx).cost_analysis_code) ;
4483       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: burden_usage('||l_idx||') = '||l_dtl_tbl(l_idx).burden_usage) ;
4484       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: item_qty('||l_idx||') = '||l_dtl_tbl(l_idx).item_qty) ;
4485       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: item_um('||l_idx||') = '||l_dtl_tbl(l_idx).item_um) ;
4486       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: burden_qty('||l_idx||') = '||l_dtl_tbl(l_idx).burden_qty) ;
4487       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: burden_um('||l_idx||') = '||l_dtl_tbl(l_idx).burden_um) ;
4488       UTL_FILE.PUT_LINE(l_log_handle,'DtlRec: delete_mark('||l_idx||') = '||l_dtl_tbl(l_idx).delete_mark) ;
4489       */
4490     END IF ;
4491 
4492   EXCEPTION
4493    WHEN OTHERS THEN
4494     UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4495     UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4496     IF l_type = 10 THEN
4497       l_skip_details := 'Y' ;
4498       UTL_FILE.PUT_LINE(l_log_handle, 'Error : Skip detail records.');
4499     ELSIF l_type = 20 THEN
4500       l_dtl_tbl.delete(l_idx);
4501       l_idx := l_idx-1;
4502     END IF ;
4503   END ;
4504 
4505   BEGIN
4506       --IF l_record_count > 1 THEN	-- to avoid calling API for the first record
4507 	--l_first_rec := 'N' ;
4508       --END IF ;
4509 
4510       UTL_FILE.GET_LINE(l_infile_handle, l_line);
4511       l_record_count    :=l_record_count+1;
4512       UTL_FILE.NEW_LINE(l_log_handle);
4513       l_type   := Get_Field(l_line,l_delimiter,1) ;  -- 10 : header rec, 20 : Detail Record
4514   EXCEPTION
4515    WHEN NO_DATA_FOUND THEN
4516      IF l_skip_details = 'N' THEN
4517       UTL_FILE.PUT_LINE(l_log_handle,'In wrapper exception. Call to Call_Burden_API...');
4518       Call_Burden_API
4519       (
4520 	p_burden_header		=>  l_header_rec
4521       , p_burden_detail		=>  l_dtl_tbl
4522       , p_operation    		=>  p_operation
4523       , x_burdenline_ids	=>  l_burdenline_ids
4524       , x_status       		=>  l_status
4525       , x_count    		=>  l_count
4526       , x_data         		=>  l_data
4527       ) ;
4528 
4529       UTL_FILE.PUT_LINE(l_log_handle,'In wrapper exception. After call to Call_Burden_API.status := ' ||
4530 			l_status ||' cnt := ' || l_count );
4531       l_continue := 'N' ;
4532       goto GET_MSG_STACK ;
4533      END IF ;
4534   END;
4535 
4536     -- DBMS_OUTPUT.PUT_LINE('Check to call Call_Burden_API...type - ' || l_type || ' count = ' || l_record_count);
4537 
4538     IF (l_type = 10 AND l_record_count <> 1 AND l_skip_details = 'N') THEN
4539       UTL_FILE.PUT_LINE(l_log_handle,'In wrapper exception. Call to Call_Burden_API...');
4540       Call_Burden_API
4541       (
4542 	p_burden_header		=>  l_header_rec
4543       , p_burden_detail		=>  l_dtl_tbl
4544       , p_operation    		=>  p_operation
4545       , x_burdenline_ids	=>  l_burdenline_ids
4546       , x_status       		=>  l_status
4547       , x_count    		=>  l_count
4548       , x_data         		=>  l_data
4549       ) ;
4550       UTL_FILE.PUT_LINE(l_log_handle,'In wrapper exception. After call to Call_Burden_API.status := ' ||
4551 			l_status ||' cnt := ' || l_count );
4552     END IF;
4553 
4554    <<GET_MSG_STACK>>
4555      null;
4556 
4557     /*  Check if any messages generated. If so then decode and */
4558     /*  output to error message flat file */
4559 
4560     IF l_count > 0 THEN
4561 
4562        l_loop_cnt  :=1;
4563        LOOP
4564         FND_MSG_PUB.Get(
4565           p_msg_index     => l_loop_cnt,
4566           p_data          => l_data,
4567           p_encoded       => FND_API.G_FALSE,
4568           p_msg_index_out => l_dummy_cnt);
4569 
4570         ---- DBMS_OUTPUT.PUT_LINE(l_data );
4571         UTL_FILE.PUT_LINE(l_log_handle, l_data);
4572 
4573         /*  Update error status */
4574         IF (l_status = 'U') THEN
4575           l_return_status  :=l_status;
4576         ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
4577           l_return_status  :=l_status;
4578         ELSE
4579           l_return_status  :=l_status;
4580         END IF;
4581 
4582         l_loop_cnt  := l_loop_cnt + 1;
4583         IF l_loop_cnt > l_count THEN
4584           EXIT;
4585         END IF;
4586 
4587       END LOOP; -- msg stack loop
4588       l_count := 0 ;
4589 
4590     END IF;	-- if count of msg stack > 0
4591 
4592     IF ((l_type = 10 AND l_record_count <> 1 AND l_skip_details = 'N') OR
4593 	(l_continue = 'N')
4594        ) THEN
4595       FOR i in 1..l_burdenline_ids.count
4596       LOOP
4597         UTL_FILE.PUT_LINE(l_log_handle,'Resource : ' || l_burdenline_ids(i).resources ||
4598 				       ' CmpntClsId : ' || l_burdenline_ids(i).cost_cmpntcls_id ||
4599 				       ' Analysis Code : ' || l_burdenline_ids(i).cost_analysis_code ||
4600 				       ' BurdenLineID : ' || l_burdenline_ids(i).burdenline_id);
4601       END LOOP ;
4602       l_burdenline_ids.delete ;
4603     END IF ;
4604 
4605     IF l_continue = 'N' THEN
4606       EXIT ;
4607     END IF ;
4608 
4609  END LOOP;
4610 
4611   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4612   UTL_FILE.NEW_LINE(l_log_handle);
4613   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4614   UTL_FILE.FCLOSE_ALL;
4615 
4616   RETURN l_return_status;
4617 
4618 EXCEPTION
4619 WHEN UTL_FILE.INVALID_OPERATION THEN
4620    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
4621    UTL_FILE.FCLOSE_ALL;
4622    RETURN l_return_status;
4623 
4624 WHEN UTL_FILE.INVALID_PATH THEN
4625    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
4626    UTL_FILE.FCLOSE_ALL;
4627    RETURN l_return_status;
4628 
4629 WHEN UTL_FILE.INVALID_MODE THEN
4630    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
4631    UTL_FILE.FCLOSE_ALL;
4632    RETURN l_return_status;
4633 
4634 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
4635    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
4636    UTL_FILE.FCLOSE_ALL;
4637    RETURN l_return_status;
4638 
4639 WHEN UTL_FILE.WRITE_ERROR THEN
4640    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
4641    UTL_FILE.FCLOSE_ALL;
4642    RETURN l_return_status;
4643 
4644 WHEN UTL_FILE.READ_ERROR THEN
4645    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
4646    UTL_FILE.FCLOSE_ALL;
4647    RETURN l_return_status;
4648 
4649 WHEN UTL_FILE.INTERNAL_ERROR THEN
4650    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
4651    UTL_FILE.FCLOSE_ALL;
4652    RETURN l_return_status;
4653 
4654 WHEN OTHERS THEN
4655    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
4656   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4657   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4658   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4659    UTL_FILE.FCLOSE_ALL;
4660    l_return_status := 'U' ;
4661    RETURN l_return_status;
4662 
4663 END Process_Burden_details;
4664 
4665 /*  Body start of comments
4666  +==========================================================================+
4667  | PROCEDURE NAME                                                           |
4668  |    Get_Burden_details                                                    |
4669  |                                                                          |
4670  | TYPE                                                                     |
4671  |    Public                                                                |
4672  |                                                                          |
4673  | USAGE                                                                    |
4674  |    Create burden details                                                 |
4675  |                                                                          |
4676  | DESCRIPTION                                                              |
4677  |    This is a PL/SQL wrapper procedure to call the                        |
4678  |    Get_Burden_details API wrapper function                               |
4679  |                                                                          |
4680  | PARAMETERS                                                               |
4681  |    p_dir              IN VARCHAR2         - Working directory for input  |
4682  |                                             and output files.            |
4683  |    p_input_file       IN VARCHAR2         - Name of input file           |
4684  |    p_output_file      IN VARCHAR2         - Name of output file          |
4685  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
4686  |                                                                          |
4687  | RETURNS                                                                  |
4688  |    None                                                                  |
4689  |                                                                          |
4690  | HISTORY                                                                  |
4691  |    27-Apr-2001  Uday Moogala  Created  Bug# 1418689                      |
4692  |    22-Oct-2005  Prasad Marada Modified as per inventory convergence      |
4693  |                               bug 4689137                                |
4694  |                                                                          |
4695  +==========================================================================+
4696   Api end of comments
4697 */
4698 PROCEDURE Get_Burden_details
4699 ( p_dir          IN VARCHAR2
4700 , p_input_file   IN VARCHAR2
4701 , p_output_file  IN VARCHAR2
4702 , p_delimiter    IN VARCHAR2
4703 )
4704 IS
4705 
4706 l_return_status  VARCHAR2(1);
4707 
4708 BEGIN
4709 
4710  DBMS_OUTPUT.PUT_LINE('in Get_Burden_details procedure... ');
4711 l_return_status  :=Get_Burden_details( p_dir
4712 			      	       , p_input_file
4713                                        , p_output_file
4714                                        , p_delimiter
4715                                        );
4716 
4717 -- DBMS_OUTPUT.PUT_LINE('return status := ' || l_return_status);
4718 END Get_Burden_details;
4719 
4720 /* +========================================================================+
4721  | FUNCTION NAME                                                            |
4722  |    Get_Burden_details                                                    |
4723  |                                                                          |
4724  | TYPE                                                                     |
4725  |    Public                                                                |
4726  |                                                                          |
4727  | USAGE                                                                    |
4728  |    Create burden details                                                 |
4729  |                                                                          |
4730  | DESCRIPTION                                                              |
4731  |    This is a PL/SQL wrapper function to call the                         |
4732  |    Get_Burden_details API.                                               |
4733  |    It reads item data from a flat file and outputs any error             |
4734  |    messages to a second flat file. It also generates a Status            |
4735  |    called gmf_rsrc_wrapper<session_id>.log in the /tmp directory.        |
4736  |                                                                          |
4737  | PARAMETERS                                                               |
4738  |    p_dir              IN VARCHAR2         - Working directory for input  |
4739  |                                             and output files.            |
4740  |    p_input_file       IN VARCHAR2         - Name of input file           |
4741  |    p_output_file      IN VARCHAR2         - Name of output file          |
4742  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
4743  |                                                                          |
4744  | RETURNS                                                                  |
4745  |    VARCHAR2 - 'S' All records processed successfully                     |
4746  |               'E' 1 or more records errored                              |
4747  |               'U' 1 or more record unexpected error                      |
4748  |                                                                          |
4749  | HISTORY                                                                  |
4750  |    22-Oct-2005  Prasad Marada Modified as per inventory convergence      |
4751  |                               bug 4689137                                |
4752  |                                                                          |
4753  +==========================================================================+
4754 */
4755 FUNCTION Get_Burden_details
4756 ( p_dir          IN VARCHAR2
4757 , p_input_file   IN VARCHAR2
4758 , p_output_file  IN VARCHAR2
4759 , p_delimiter    IN VARCHAR2
4760 )
4761 RETURN VARCHAR2
4762 IS
4763 
4764 /* Local variables */
4765 
4766 l_status             VARCHAR2(11);
4767 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
4768 l_count              NUMBER(10)  ;
4769 l_record_count       NUMBER(10)  :=0;
4770 l_loop_cnt           NUMBER(10)  :=0;
4771 l_dummy_cnt          NUMBER(10)  :=0;
4772 l_data               VARCHAR2(1000);
4773 l_header_rec         GMF_BurdenDetails_PUB.Burden_Header_Rec_Type;
4774 l_dtl_tbl            GMF_BurdenDetails_PUB.Burden_Dtl_Tbl_Type;
4775 l_p_dir              VARCHAR2(150);
4776 l_output_file        VARCHAR2(120);
4777 l_outfile_handle     UTL_FILE.FILE_TYPE;
4778 l_input_file         VARCHAR2(120);
4779 l_infile_handle      UTL_FILE.FILE_TYPE;
4780 l_line               VARCHAR2(1000);
4781 l_delimiter          VARCHAR(11);
4782 l_log_dir            VARCHAR2(150);
4783 l_log_name           VARCHAR2(120) :='gmf_api_getbrdn_wrapper';
4784 l_log_handle         UTL_FILE.FILE_TYPE;
4785 l_global_file        VARCHAR2(120);
4786 l_idx		     NUMBER(10);
4787 l_idx1		     NUMBER(10);
4788 l_type		     NUMBER(10);
4789 l_continue           VARCHAR2(1) := 'Y' ;
4790 l_skip_details       VARCHAR2(1) := 'N' ;
4791 l_session_id         VARCHAR2(110);
4792 
4793 BEGIN
4794 
4795   /*  Enable The Buffer  */
4796   /*  DBMS_OUTPUT.ENABLE(1000000); */
4797 
4798   -- DBMS_OUTPUT.PUT_LINE('in Get_Burden_details function...');
4799 
4800   l_p_dir              :=p_dir;
4801   l_input_file         :=p_input_file;
4802   l_output_file        :=p_output_file;
4803   l_delimiter          :=p_delimiter;
4804   l_global_file        :=l_input_file;
4805 
4806   /*  Obtain The SessionId To Append To wrapper File Name. */
4807 
4808   l_session_id := USERENV('sessionid');
4809 
4810   l_log_name  := CONCAT(l_log_name,l_session_id);
4811   l_log_name  := CONCAT(l_log_name,'.log');
4812 
4813   /*  Directory is now the same same as for the out file */
4814   l_log_dir   := p_dir;
4815 
4816   /*  Open The Wrapper File For Output And The Input File for Input. */
4817 
4818   l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
4819   l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
4820 
4821   /*  Loop thru flat file and call Inventory Quantities API */
4822   -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4823   -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
4824   -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
4825   -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
4826   -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
4827 
4828 
4829   /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
4830   UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4831   UTL_FILE.NEW_LINE(l_log_handle);
4832   UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
4833   UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
4834   UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
4835   UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
4836 
4837   l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
4838 
4839  LOOP
4840   BEGIN
4841     UTL_FILE.GET_LINE(l_infile_handle, l_line);
4842     l_record_count    :=l_record_count+1;
4843   EXCEPTION
4844     WHEN NO_DATA_FOUND THEN
4845       EXIT ;
4846   END;
4847 
4848   BEGIN
4849     UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
4850       -- empty the tables
4851       l_dtl_tbl.delete ;
4852 
4853       l_header_rec.organization_id   := Get_Field(l_line,l_delimiter,1) ;
4854       l_header_rec.organization_code := Get_Field(l_line,l_delimiter,2) ;
4855       l_header_rec.inventory_item_id := Get_Field(l_line,l_delimiter,3) ;
4856       l_header_rec.item_number       := Get_Field(l_line,l_delimiter,4) ;
4857       l_header_rec.period_id         := Get_Field(l_line,l_delimiter,5) ;
4858       l_header_rec.calendar_code     := Get_Field(l_line,l_delimiter,6) ;
4859       l_header_rec.period_code       := Get_Field(l_line,l_delimiter,7) ;
4860       l_header_rec.cost_type_id      := Get_Field(l_line,l_delimiter,8) ;
4861       l_header_rec.cost_mthd_code    := Get_Field(l_line,l_delimiter,9) ;
4862       l_header_rec.user_name         := Get_Field(l_line,l_delimiter,10) ;
4863 
4864       UTL_FILE.PUT_LINE(l_log_handle, 'organization_id   = ' || l_header_rec.organization_id) ;
4865       UTL_FILE.PUT_LINE(l_log_handle, 'organization_code = ' || l_header_rec.organization_code) ;
4866       UTL_FILE.PUT_LINE(l_log_handle, 'inventory_item_id = ' || l_header_rec.inventory_item_id) ;
4867       UTL_FILE.PUT_LINE(l_log_handle, 'item_number  = '      || l_header_rec.item_number) ;
4868       UTL_FILE.PUT_LINE(l_log_handle, 'period_id   = '     || l_header_rec.period_id) ;
4869       UTL_FILE.PUT_LINE(l_log_handle, 'calendar_code   = ' || l_header_rec.calendar_code) ;
4870       UTL_FILE.PUT_LINE(l_log_handle, 'period_code   = '   || l_header_rec.period_code) ;
4871       UTL_FILE.PUT_LINE(l_log_handle, 'cost_type_id   = '  || l_header_rec.cost_type_id) ;
4872       UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code  = ' || l_header_rec.cost_mthd_code) ;
4873       UTL_FILE.PUT_LINE(l_log_handle, 'user_name   = '     || l_header_rec.user_name) ;
4874 
4875        -- Invoke public get burden details
4876       GMF_BurdenDetails_PUB.Get_Burden_Details
4877       (
4878         p_api_version        =>  2.0
4879       , p_init_msg_list      =>  FND_API.G_TRUE
4880 
4881       , x_return_status      =>  l_status
4882       , x_msg_count          =>  l_count
4883       , x_msg_data           =>  l_data
4884 
4885       , p_header_rec         =>  l_header_rec
4886 
4887       , x_dtl_tbl            =>  l_dtl_tbl
4888       );
4889 
4890       UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
4891 
4892     /*  Check if any messages generated. If so then decode and */
4893     /*  output to error message flat file */
4894 
4895     IF l_count > 0 THEN
4896 
4897        l_loop_cnt  :=1;
4898        LOOP
4899         FND_MSG_PUB.Get(
4900           p_msg_index     => l_loop_cnt,
4901           p_data          => l_data,
4902           p_encoded       => FND_API.G_FALSE,
4903           p_msg_index_out => l_dummy_cnt);
4904 
4905         ---- DBMS_OUTPUT.PUT_LINE(l_data );
4906         UTL_FILE.PUT_LINE(l_log_handle, l_data);
4907 
4908         /*  Update error status */
4909         IF (l_status = 'U') THEN
4910           l_return_status  :=l_status;
4911         ELSIF (l_status = 'E' and l_return_status <> 'U') THEN
4912           l_return_status  :=l_status;
4913         ELSE
4914           l_return_status  :=l_status;
4915         END IF;
4916 
4917         l_loop_cnt  := l_loop_cnt + 1;
4918         IF l_loop_cnt > l_count THEN
4919           EXIT;
4920         END IF;
4921 
4922       END LOOP; -- msg stack loop
4923       l_count := 0 ;
4924 
4925     END IF;	-- if count of msg stack > 0
4926 
4927     UTL_FILE.NEW_LINE(l_log_handle);
4928     FOR i in 1..l_dtl_tbl.count
4929     LOOP
4930       UTL_FILE.PUT_LINE(l_log_handle,
4931 			'Burdenline_Id : ' || l_dtl_tbl(i).Burdenline_Id ||
4932 			' resources : ' || l_dtl_tbl(i).resources ||
4933 			' Cmpntcls Id : ' || l_dtl_tbl(i).cost_cmpntcls_id ||
4934 			' Cmpntcls Code : ' || l_dtl_tbl(i).cost_cmpntcls_id ||
4935 			' Alys Code : ' || l_dtl_tbl(i).cost_analysis_code
4936 		       );
4937       UTL_FILE.PUT_LINE(l_log_handle,
4938 			' Burden Usage : ' || l_dtl_tbl(i).Burden_Usage ||
4939 			' Item Qty : ' || l_dtl_tbl(i).item_qty ||
4940 			' Item UOM : ' || l_dtl_tbl(i).Item_UOM ||
4941 			' Burden Qty : ' || l_dtl_tbl(i).Burden_Qty ||
4942 			' Burden UOM : ' || l_dtl_tbl(i).Burden_UOM ||
4943 			' Burden Factor : ' || l_dtl_tbl(i).Burden_Factor ||
4944 			' Delete Mark : ' || l_dtl_tbl(i).Delete_Mark
4945                        );
4946     END LOOP ;
4947     l_dtl_tbl.delete ;
4948     UTL_FILE.NEW_LINE(l_log_handle);
4949     UTL_FILE.NEW_LINE(l_log_handle);
4950 
4951   EXCEPTION
4952    WHEN OTHERS THEN
4953     UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4954     UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
4955   END ;
4956 
4957  END LOOP;
4958 
4959   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4960   UTL_FILE.NEW_LINE(l_log_handle);
4961   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
4962   UTL_FILE.FCLOSE_ALL;
4963 
4964   RETURN l_return_status;
4965 
4966 EXCEPTION
4967 WHEN UTL_FILE.INVALID_OPERATION THEN
4968    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
4969    UTL_FILE.FCLOSE_ALL;
4970    RETURN l_return_status;
4971 
4972 WHEN UTL_FILE.INVALID_PATH THEN
4973    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
4974    UTL_FILE.FCLOSE_ALL;
4975    RETURN l_return_status;
4976 
4977 WHEN UTL_FILE.INVALID_MODE THEN
4978    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
4979    UTL_FILE.FCLOSE_ALL;
4980    RETURN l_return_status;
4981 
4982 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
4983    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
4984    UTL_FILE.FCLOSE_ALL;
4985    RETURN l_return_status;
4986 
4987 WHEN UTL_FILE.WRITE_ERROR THEN
4988    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
4989    UTL_FILE.FCLOSE_ALL;
4990    RETURN l_return_status;
4991 
4992 WHEN UTL_FILE.READ_ERROR THEN
4993    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
4994    UTL_FILE.FCLOSE_ALL;
4995    RETURN l_return_status;
4996 
4997 WHEN UTL_FILE.INTERNAL_ERROR THEN
4998    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
4999    UTL_FILE.FCLOSE_ALL;
5000    RETURN l_return_status;
5001 
5002 WHEN OTHERS THEN
5003    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
5004   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5005   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5006   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5007    UTL_FILE.FCLOSE_ALL;
5008    l_return_status := 'U' ;
5009    RETURN l_return_status;
5010 
5011 END Get_Burden_details;
5012 
5013 /* +========================================================================+
5014  | FUNCTION NAME                                                            |
5015  |    Call_Burden_API                                                 |
5016  |                                                                          |
5017  | TYPE                                                                     |
5018  |    Public                                                                |
5019  |                                                                          |
5020  | USAGE                                                                    |
5021  |    Calls burden APIs based on the operation being performed              |
5022  |                                                                          |
5023  | DESCRIPTION                                                              |
5024  |    This is a PL/SQL wrapper function to call the Burden_detail API.      |
5025  |    Data is sent from through the parameters.                             |
5026  |                                                                          |
5027  | PARAMETERS                                                               |
5028  |    p_burden_header    IN VARCHAR2         - Burden Details Header        |
5029  |    p_burden_detail    IN VARCHAR2         - Burden Details               |
5030  |    p_operation        IN VARCHAR2         - Insert/Update/Delete         |
5031  |    x_burdenline_ids   OUT VARCHAR2        - Inserted burdenline_ids      |
5032  |    x_status           OUT VARCHAR2        - Return Status                |
5033  |    x_count            OUT VARCHAR2        - # of msgs on message stack   |
5034  |    x_data             OUT VARCHAR2        - Actual Message from msg stack|
5035  |                                                                          |
5036  | RETURNS                                                                  |
5037  |    VARCHAR2 - 'S' All records processed successfully                     |
5038  |               'E' 1 or more records errored                              |
5039  |               'U' 1 or more record unexpected error                      |
5040  |                                                                          |
5041  | HISTORY                                                                  |
5042  |                                                                          |
5043  +==========================================================================+
5044 */
5045 PROCEDURE Call_Burden_API
5046 (
5047   p_burden_header    IN  GMF_BurdenDetails_PUB.Burden_Header_Rec_Type
5048 , p_burden_detail    IN  GMF_BurdenDetails_PUB.Burden_Dtl_Tbl_Type
5049 , p_operation        IN  VARCHAR2
5050 , x_burdenline_ids   OUT NOCOPY GMF_BurdenDetails_PUB.Burdenline_Ids_Tbl_Type
5051 , x_status           OUT NOCOPY VARCHAR2
5052 , x_count            OUT NOCOPY NUMBER
5053 , x_data             OUT NOCOPY VARCHAR2
5054 )
5055 IS
5056 
5057 BEGIN
5058 
5059  IF p_operation = 'INSERT' THEN
5060    GMF_BurdenDetails_PUB.Create_Burden_Details
5061    (
5062      p_api_version        =>  2.0
5063    , p_init_msg_list      =>  FND_API.G_TRUE
5064    , p_commit             =>  FND_API.G_TRUE
5065 
5066    , x_return_status      =>  x_status
5067    , x_msg_count          =>  x_count
5068    , x_msg_data           =>  x_data
5069 
5070    , p_header_rec         =>  p_burden_header
5071    , p_dtl_tbl            =>  p_burden_detail
5072 
5073    , x_burdenline_ids     =>  x_burdenline_ids
5074    );
5075  ELSIF p_operation = 'UPDATE' THEN
5076    GMF_BurdenDetails_PUB.Update_Burden_Details
5077    (
5078      p_api_version        =>  2.0
5079    , p_init_msg_list      =>  FND_API.G_TRUE
5080    , p_commit             =>  FND_API.G_TRUE
5081 
5082    , x_return_status      =>  x_status
5083    , x_msg_count          =>  x_count
5084    , x_msg_data           =>  x_data
5085 
5086    , p_header_rec         =>  p_burden_header
5087    , p_dtl_tbl            =>  p_burden_detail
5088    );
5089  ELSIF p_operation = 'DELETE' THEN
5090    GMF_BurdenDetails_PUB.Delete_Burden_Details
5091    (
5092      p_api_version        =>  2.0
5093    , p_init_msg_list      =>  FND_API.G_TRUE
5094    , p_commit             =>  FND_API.G_TRUE
5095 
5096    , x_return_status      =>  x_status
5097    , x_msg_count          =>  x_count
5098    , x_msg_data           =>  x_data
5099 
5100    , p_header_rec         =>  p_burden_header
5101    , p_dtl_tbl            =>  p_burden_detail
5102    );
5103  END IF ;
5104 
5105 END Call_Burden_API ;
5106 
5107 
5108 
5109 /*  Body start of comments
5110  +==========================================================================+
5111  | PROCEDURE NAME                                                           |
5112  |    Create_resource_cost                                                  |
5113  |                                                                          |
5114  | TYPE                                                                     |
5115  |    Public                                                                |
5116  |                                                                          |
5117  | USAGE                                                                    |
5118  |    Create Resource Cost                                                  |
5119  |                                                                          |
5120  | DESCRIPTION                                                              |
5121  |    This is a PL/SQL wrapper procedure to call the                        |
5122  |    Create_Resource_Cost API wrapper function                             |
5123  |                                                                          |
5124  | PARAMETERS                                                               |
5125  |    p_dir              IN VARCHAR2         - Working directory for input  |
5126  |                                             and output files.            |
5127  |    p_input_file       IN VARCHAR2         - Name of input file           |
5128  |    p_output_file      IN VARCHAR2         - Name of output file          |
5129  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
5130  |                                                                          |
5131  | RETURNS                                                                  |
5132  |    None                                                                  |
5133  |                                                                          |
5134  | HISTORY                                                                  |
5135  | 27-Feb-2001  Uday Moogala  Created  Bug# 1418689                         |
5136  | 21-Oct-2005  Prasad marada Modified the procedure as per the record type |
5137  |              changes in resource cost public packages                    |
5138  |                                                                          |
5139  +==========================================================================+
5140   Api end of comments
5141 */
5142 PROCEDURE Create_resource_cost
5143 ( p_dir          IN VARCHAR2
5144 , p_input_file   IN VARCHAR2
5145 , p_output_file  IN VARCHAR2
5146 , p_delimiter    IN VARCHAR2
5147 )
5148 IS
5149 
5150 l_return_status  VARCHAR2(1);
5151 
5152 BEGIN
5153 
5154 -- DBMS_OUTPUT.PUT_LINE('in Create_resource_cost procedure... ');
5155 l_return_status  :=Create_resource_cost( p_dir
5156 			      	       , p_input_file
5157                                        , p_output_file
5158                                        , p_delimiter
5159                                        );
5160 
5161  -- DBMS_OUTPUT.PUT_LINE('return status := ' || l_return_status);
5162 END Create_resource_cost;
5163 
5164 /* +========================================================================+
5165  | FUNCTION NAME                                                            |
5166  |    Create_resource_cost                                                  |
5167  |                                                                          |
5168  | TYPE                                                                     |
5169  |    Public                                                                |
5170  |                                                                          |
5171  | USAGE                                                                    |
5172  |    Create Resource Cost                                                  |
5173  |                                                                          |
5174  | DESCRIPTION                                                              |
5175  |    This is a PL/SQL wrapper function to call the                         |
5176  |    Create_Resource_Cost API.                                             |
5177  |    It reads item data from a flat file and outputs any error             |
5178  |    messages to a second flat file. It also generates a Status            |
5179  |    called gmf_rsrc_wrapper<session_id>.log in the /tmp directory.        |
5180  |                                                                          |
5181  | PARAMETERS                                                               |
5182  |    p_dir              IN VARCHAR2         - Working directory for input  |
5183  |                                             and output files.            |
5184  |    p_input_file       IN VARCHAR2         - Name of input file           |
5185  |    p_output_file      IN VARCHAR2         - Name of output file          |
5186  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
5187  |                                                                          |
5188  | RETURNS                                                                  |
5189  |    VARCHAR2 - 'S' All records processed successfully                     |
5190  |               'E' 1 or more records errored                              |
5191  |               'U' 1 or more record unexpected error                      |
5192  |                                                                          |
5193  | HISTORY                                                                  |
5194  | 21-Oct-2005  Prasad marada Modified the procedure as per the record type |
5195  |              changes in resource cost public packages                    |
5196  |                                                                          |
5197  +==========================================================================+
5198   Api end of comments
5199 */
5200 FUNCTION Create_resource_cost
5201 ( p_dir          IN VARCHAR2
5202 , p_input_file   IN VARCHAR2
5203 , p_output_file  IN VARCHAR2
5204 , p_delimiter    IN VARCHAR2
5205 )
5206 RETURN VARCHAR2
5207 IS
5208 
5209 /* Local variables */
5210 
5211 l_status             VARCHAR2(11);
5212 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
5213 l_count              NUMBER(10)  ;
5214 l_record_count       NUMBER(10)  :=0;
5215 l_loop_cnt           NUMBER(10)  :=0;
5216 l_dummy_cnt          NUMBER(10)  :=0;
5217 l_data               VARCHAR2(1000);
5218 rsrc_rec             GMF_ResourceCost_PUB.Resource_Cost_Rec_Type;
5219 l_p_dir              VARCHAR2(150);
5220 l_output_file        VARCHAR2(120);
5221 l_outfile_handle     UTL_FILE.FILE_TYPE;
5222 l_input_file         VARCHAR2(120);
5223 l_infile_handle      UTL_FILE.FILE_TYPE;
5224 l_line               VARCHAR2(1000);
5225 l_delimiter          VARCHAR(11);
5226 l_log_dir            VARCHAR2(150);
5227 l_log_name           VARCHAR2(120)  :='gmf_api_crrc_wrapper';
5228 l_log_handle         UTL_FILE.FILE_TYPE;
5229 l_global_file        VARCHAR2(120);
5230 
5231 l_session_id         VARCHAR2(110);
5232 
5233 BEGIN
5234 
5235 /*  Enable The Buffer  */
5236 /*  DBMS_OUTPUT.ENABLE(1000000); */
5237 
5238 -- DBMS_OUTPUT.PUT_LINE('in Create_resource_cost function...');
5239 
5240 l_p_dir              :=p_dir;
5241 l_input_file         :=p_input_file;
5242 l_output_file        :=p_output_file;
5243 l_delimiter          :=p_delimiter;
5244 l_global_file        :=l_input_file;
5245 
5246 /*  Obtain The SessionId To Append To wrapper File Name. */
5247 l_session_id := USERENV('sessionid');
5248 l_log_name  := CONCAT(l_log_name,l_session_id);
5249 l_log_name  := CONCAT(l_log_name,'.log');
5250 
5251 /*  Directory is now the same same as for the out file */
5252 l_log_dir   := p_dir;
5253 
5254 /*  Open The Wrapper File For Output And The Input File for Input. */
5255 
5256 l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
5257 l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
5258 
5259 /*  Loop thru flat file and call Inventory Quantities API */
5260 -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5261 -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
5262 -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
5263 -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
5264 -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
5265 
5266 /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
5267 UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5268 UTL_FILE.NEW_LINE(l_log_handle);
5269 UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
5270 UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
5271 UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
5272 UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
5273 
5274 l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
5275 
5276 
5277 LOOP
5278   l_record_count    :=l_record_count+1;
5279   BEGIN
5280   UTL_FILE.GET_LINE(l_infile_handle, l_line);
5281   EXCEPTION
5282     WHEN NO_DATA_FOUND THEN
5283       EXIT;
5284   END;
5285 
5286 BEGIN
5287   UTL_FILE.NEW_LINE(l_log_handle);
5288   UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
5289 
5290   rsrc_rec.resources           := Get_Field(l_line,l_delimiter,1) ;
5291   rsrc_rec.legal_entity_id     := Get_Field(l_line,l_delimiter,2) ;
5292   rsrc_rec.organization_id     := Get_Field(l_line,l_delimiter,3) ;
5293   rsrc_rec.organization_code   := Get_Field(l_line,l_delimiter,4) ;
5294   rsrc_rec.period_id           := Get_Field(l_line,l_delimiter,5) ;
5295   rsrc_rec.calendar_code       := Get_Field(l_line,l_delimiter,6) ;
5296   rsrc_rec.period_code         := Get_Field(l_line,l_delimiter,7) ;
5297   rsrc_rec.cost_type_id        := Get_Field(l_line,l_delimiter,8) ;
5298   rsrc_rec.cost_mthd_code      := Get_Field(l_line,l_delimiter,9) ;
5299   rsrc_rec.usage_uom           := Get_Field(l_line,l_delimiter,10) ;
5300   rsrc_rec.nominal_cost        := Get_Field(l_line,l_delimiter,11) ;
5301   rsrc_rec.delete_mark         := Get_Field(l_line,l_delimiter,12) ;
5302   rsrc_rec.user_name           := Get_Field(l_line,l_delimiter,13) ;
5303 
5304   UTL_FILE.PUT_LINE(l_log_handle, 'resources     = ' || rsrc_rec.resources);
5305   UTL_FILE.PUT_LINE(l_log_handle, 'legal_entity_id= ' || rsrc_rec.legal_entity_id);
5306   UTL_FILE.PUT_LINE(l_log_handle, 'organization_id= ' || rsrc_rec.organization_id);
5307   UTL_FILE.PUT_LINE(l_log_handle, 'organization_code= ' || rsrc_rec.organization_code);
5308   UTL_FILE.PUT_LINE(l_log_handle, 'period_id     = ' || rsrc_rec.period_id);
5309   UTL_FILE.PUT_LINE(l_log_handle, 'calendar_code = ' || rsrc_rec.calendar_code);
5310   UTL_FILE.PUT_LINE(l_log_handle, 'period_code   = ' || rsrc_rec.period_code);
5311   UTL_FILE.PUT_LINE(l_log_handle, 'cost_type_id= '   || rsrc_rec.cost_type_id);
5312   UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code= ' || rsrc_rec.cost_mthd_code);
5313   UTL_FILE.PUT_LINE(l_log_handle, 'usage_uom     = ' || rsrc_rec.usage_uom);
5314   UTL_FILE.PUT_LINE(l_log_handle, 'nominal_cost  = ' || rsrc_rec.nominal_cost);
5315   UTL_FILE.PUT_LINE(l_log_handle, 'delete_mark   = ' || rsrc_rec.delete_mark);
5316   UTL_FILE.PUT_LINE(l_log_handle, 'user_name     = ' || rsrc_rec.user_name);
5317 
5318   GMF_ResourceCost_PUB.Create_Resource_Cost
5319   ( p_api_version    => 2.0
5320   , p_init_msg_list  => FND_API.G_TRUE
5321   , p_commit         => FND_API.G_TRUE
5322 
5323   , x_return_status  =>l_status
5324   , x_msg_count      =>l_count
5325   , x_msg_data       =>l_data
5326 
5327   , p_Resource_Cost_rec => rsrc_rec
5328   );
5329 
5330   UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
5331   IF l_count > 0
5332   THEN
5333     l_loop_cnt  :=1;
5334     LOOP
5335 
5336     FND_MSG_PUB.Get(
5337       p_msg_index     => l_loop_cnt,
5338       p_data          => l_data,
5339       p_encoded       => FND_API.G_FALSE,
5340       p_msg_index_out => l_dummy_cnt);
5341 
5342 
5343     -- DBMS_OUTPUT.PUT_LINE(l_data );
5344 
5345     UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
5346     UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
5347     UTL_FILE.NEW_LINE(l_outfile_handle);
5348 
5349   /*
5350     IF l_status = 'E' OR
5351        l_status = 'U'
5352     THEN
5353       l_data    := CONCAT('ERROR : ',l_data);
5354     END IF;
5355   */
5356 
5357     UTL_FILE.PUT_LINE(l_log_handle, l_data);
5358 
5359     /*  Update error status */
5360       IF (l_status = 'U')
5361       THEN
5362         l_return_status  :=l_status;
5363       ELSIF (l_status = 'E' and l_return_status <> 'U')
5364       THEN
5365         l_return_status  :=l_status;
5366       ELSE
5367         l_return_status  :=l_status;
5368       END IF;
5369 
5370     l_loop_cnt  := l_loop_cnt + 1;
5371     IF l_loop_cnt > l_count
5372     THEN
5373       EXIT;
5374     END IF;
5375 
5376     END LOOP;
5377 
5378   END IF;
5379 
5380 EXCEPTION
5381  WHEN OTHERS THEN
5382   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5383   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5384   l_return_status := 'U' ;
5385 END ;
5386 
5387 
5388 END LOOP;
5389   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5390   UTL_FILE.NEW_LINE(l_log_handle);
5391   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5392 
5393 /*  Check if any messages generated. If so then decode and */
5394 /*  output to error message flat file */
5395 
5396 UTL_FILE.FCLOSE_ALL;
5397 
5398 RETURN l_return_status;
5399 
5400 EXCEPTION
5401 WHEN UTL_FILE.INVALID_OPERATION THEN
5402    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
5403    UTL_FILE.FCLOSE_ALL;
5404    RETURN l_return_status;
5405 
5406 WHEN UTL_FILE.INVALID_PATH THEN
5407    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
5408    UTL_FILE.FCLOSE_ALL;
5409    RETURN l_return_status;
5410 
5411 WHEN UTL_FILE.INVALID_MODE THEN
5412    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
5413    UTL_FILE.FCLOSE_ALL;
5414    RETURN l_return_status;
5415 
5416 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
5417    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
5418    UTL_FILE.FCLOSE_ALL;
5419    RETURN l_return_status;
5420 
5421 WHEN UTL_FILE.WRITE_ERROR THEN
5422    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
5423    UTL_FILE.FCLOSE_ALL;
5424    RETURN l_return_status;
5425 
5426 WHEN UTL_FILE.READ_ERROR THEN
5427    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
5428    UTL_FILE.FCLOSE_ALL;
5429    RETURN l_return_status;
5430 
5431 WHEN UTL_FILE.INTERNAL_ERROR THEN
5432    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
5433    UTL_FILE.FCLOSE_ALL;
5434    RETURN l_return_status;
5435 
5436 WHEN OTHERS THEN
5437    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
5438   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5439   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5440   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5441    UTL_FILE.FCLOSE_ALL;
5442    l_return_status := 'U' ;
5443    RETURN l_return_status;
5444 
5445 END Create_resource_cost;
5446 
5447 /*  API start of comments
5448  +==========================================================================+
5449  | PROCEDURE NAME                                                           |
5450  |    Update_resource_cost                                                  |
5451  |                                                                          |
5452  | TYPE                                                                     |
5453  |    Public                                                                |
5454  |                                                                          |
5455  | USAGE                                                                    |
5456  |    Update Resource Cost                                                  |
5457  |                                                                          |
5458  | DESCRIPTION                                                              |
5459  |    This is a PL/SQL wrapper procedure to call the                        |
5460  |    Update_resource_cost API wrapper function                             |
5461  |                                                                          |
5462  | PARAMETERS                                                               |
5463  |    p_dir              IN VARCHAR2         - Working directory for input  |
5464  |                                             and output files.            |
5465  |    p_input_file       IN VARCHAR2         - Name of input file           |
5466  |    p_output_file      IN VARCHAR2         - Name of output file          |
5467  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
5468  |                                                                          |
5469  | RETURNS                                                                  |
5470  |    None                                                                  |
5471  |                                                                          |
5472  | HISTORY                                                                  |
5473  |    07-Mar-2001  Uday Moogala    created                                  |
5474 
5475  |                                                                          |
5476  +==========================================================================+
5477   Api end of comments
5478 */
5479 PROCEDURE Update_resource_cost
5480 ( p_dir          IN VARCHAR2
5481 , p_input_file   IN VARCHAR2
5482 , p_output_file  IN VARCHAR2
5483 , p_delimiter    IN VARCHAR2
5484 )
5485 IS
5486 
5487 l_return_status  VARCHAR2(1);
5488 
5489 BEGIN
5490 
5491  ---- DBMS_OUTPUT.PUT_LINE('in Update_resource_cost procedure... ');
5492 l_return_status  :=Update_resource_cost( p_dir
5493                                      , p_input_file
5494                                      , p_output_file
5495                                      , p_delimiter
5496                                    );
5497 
5498  -- DBMS_OUTPUT.PUT_LINE('return status := ' || l_return_status);
5499 END Update_resource_cost;
5500 
5501 /* +==========================================================================+
5502  | FUNCTION NAME                                                            |
5503  |    Update_resource_cost                                                  |
5504  |                                                                          |
5505  | TYPE                                                                     |
5506  |    Public                                                                |
5507  |                                                                          |
5508  | USAGE                                                                    |
5509  |    Update Resource Cost                                                  |
5510  |                                                                          |
5511  | DESCRIPTION                                                              |
5512  |    This is a PL/SQL wrapper function to call the                         |
5513  |    Update_Resource_Cost API.                                             |
5514  |    It reads item data from a flat file and outputs any error             |
5515  |    messages to a second flat file. It also generates a Status            |
5516  |    called gmf_aloc_wrapper<session_id>.log in the temp directory.        |
5517  |                                                                          |
5518  | PARAMETERS                                                               |
5519  |    p_dir              IN VARCHAR2         - Working directory for input  |
5520  |                                             and output files.            |
5521  |    p_input_file       IN VARCHAR2         - Name of input file           |
5522  |    p_output_file      IN VARCHAR2         - Name of output file          |
5523  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
5524  |                                                                          |
5525  | RETURNS                                                                  |
5526  |    VARCHAR2 - 'S' All records processed successfully                     |
5527  |               'E' 1 or more records errored                              |
5528  |               'U' 1 or more record unexpected error                      |
5529  |                                                                          |
5530  | HISTORY                                                                  |
5531  | 21-Oct-2005 Prasad marada Modified the procedure as per the record type  |
5532  |                           changes in resource cost public packages       |
5533  |                                                                          |
5534  +==========================================================================+
5535   Api end of comments
5536 */
5537 FUNCTION Update_resource_cost
5538 ( p_dir          IN VARCHAR2
5539 , p_input_file   IN VARCHAR2
5540 , p_output_file  IN VARCHAR2
5541 , p_delimiter    IN VARCHAR2
5542 )
5543 RETURN VARCHAR2
5544 IS
5545 
5546 /* Local variables */
5547 
5548 l_status             VARCHAR2(100);
5549 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
5550 l_count              NUMBER(10)  ;
5551 l_record_count       NUMBER(10)  :=0;
5552 l_loop_cnt           NUMBER(10)  :=0;
5553 l_dummy_cnt          NUMBER(10)  :=0;
5554 l_data               VARCHAR2(2000);
5555 rsrc_rec             GMF_ResourceCost_PUB.Resource_Cost_Rec_Type;
5556 l_p_dir              VARCHAR2(150);
5557 l_output_file        VARCHAR2(120);
5558 l_outfile_handle     UTL_FILE.FILE_TYPE;
5559 l_input_file         VARCHAR2(120);
5560 l_infile_handle      UTL_FILE.FILE_TYPE;
5561 l_line               VARCHAR2(1800);
5562 l_delimiter          VARCHAR(11);
5563 l_log_dir            VARCHAR2(150);
5564 l_log_name           VARCHAR2(120)  :='gmf_api_updrc_wrapper';
5565 l_log_handle         UTL_FILE.FILE_TYPE;
5566 l_global_file        VARCHAR2(120);
5567 
5568 l_session_id         VARCHAR2(110);
5569 
5570 BEGIN
5571 
5572 /*  Enable The Buffer  */
5573 /*  DBMS_OUTPUT.ENABLE(1000000); */
5574 
5575 -- DBMS_OUTPUT.PUT_LINE('in Update_resource_cost function...');
5576 
5577 l_p_dir              :=p_dir;
5578 l_input_file         :=p_input_file;
5579 l_output_file        :=p_output_file;
5580 l_delimiter          :=p_delimiter;
5581 l_global_file        :=l_input_file;
5582 
5583 /*  Obtain The SessionId To Append To wrapper File Name. */
5584 
5585 l_session_id := USERENV('sessionid');
5586 
5587 l_log_name  := CONCAT(l_log_name,l_session_id);
5588 l_log_name  := CONCAT(l_log_name,'.log');
5589 
5590 /*  Directory is now the same same as for the out file */
5591 l_log_dir   := p_dir;
5592 
5593 
5594 /*  Open The Wrapper File For Output And The Input File for Input. */
5595 
5596 l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
5597 l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
5598 
5599 /*  Loop thru flat file and call Inventory Quantities API */
5600 -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5601 -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
5602 -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
5603 -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
5604 -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
5605 
5606 
5607 /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
5608 UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5609 UTL_FILE.NEW_LINE(l_log_handle);
5610 UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
5611 UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
5612 UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
5613 UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
5614 
5615 l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
5616 
5617 LOOP
5618   l_record_count    :=l_record_count+1;
5619   BEGIN
5620     BEGIN
5621       UTL_FILE.NEW_LINE(l_log_handle);
5622       UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
5623       UTL_FILE.GET_LINE(l_infile_handle, l_line);
5624     EXCEPTION
5625       WHEN NO_DATA_FOUND THEN
5626         EXIT;
5627     END;
5628     IF l_line IS NULL THEN
5629       EXIT;
5630     ELSE
5631       rsrc_rec.resources           := Get_Field(l_line,l_delimiter,1) ;
5632       rsrc_rec.legal_entity_id     := Get_Field(l_line,l_delimiter,2) ;
5633       rsrc_rec.organization_id     := Get_Field(l_line,l_delimiter,3) ;
5634       rsrc_rec.organization_code   := Get_Field(l_line,l_delimiter,4) ;
5635       rsrc_rec.period_id           := Get_Field(l_line,l_delimiter,5) ;
5636       rsrc_rec.calendar_code       := Get_Field(l_line,l_delimiter,6) ;
5637       rsrc_rec.period_code         := Get_Field(l_line,l_delimiter,7) ;
5638       rsrc_rec.cost_type_id        := Get_Field(l_line,l_delimiter,8) ;
5639       rsrc_rec.cost_mthd_code      := Get_Field(l_line,l_delimiter,9) ;
5640       rsrc_rec.usage_uom           := Get_Field(l_line,l_delimiter,10) ;
5641       rsrc_rec.nominal_cost        := Get_Field(l_line,l_delimiter,11) ;
5642       rsrc_rec.delete_mark         := Get_Field(l_line,l_delimiter,12) ;
5643       rsrc_rec.user_name           := Get_Field(l_line,l_delimiter,13) ;
5644 
5645       UTL_FILE.PUT_LINE(l_log_handle, 'resources     = ' || rsrc_rec.resources);
5646       UTL_FILE.PUT_LINE(l_log_handle, 'legal_entity_id= ' || rsrc_rec.legal_entity_id);
5647       UTL_FILE.PUT_LINE(l_log_handle, 'organization_id= ' || rsrc_rec.organization_id);
5648       UTL_FILE.PUT_LINE(l_log_handle, 'organization_code= ' || rsrc_rec.organization_code);
5649       UTL_FILE.PUT_LINE(l_log_handle, 'period_id     = ' || rsrc_rec.period_id);
5650       UTL_FILE.PUT_LINE(l_log_handle, 'calendar_code = ' || rsrc_rec.calendar_code);
5651       UTL_FILE.PUT_LINE(l_log_handle, 'period_code   = ' || rsrc_rec.period_code);
5652       UTL_FILE.PUT_LINE(l_log_handle, 'cost_type_id= '   || rsrc_rec.cost_type_id);
5653       UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code= ' || rsrc_rec.cost_mthd_code);
5654       UTL_FILE.PUT_LINE(l_log_handle, 'usage_uom     = ' || rsrc_rec.usage_uom);
5655       UTL_FILE.PUT_LINE(l_log_handle, 'nominal_cost  = ' || rsrc_rec.nominal_cost);
5656       UTL_FILE.PUT_LINE(l_log_handle, 'delete_mark   = ' || rsrc_rec.delete_mark);
5657       UTL_FILE.PUT_LINE(l_log_handle, 'user_name     = ' || rsrc_rec.user_name);
5658 
5659   -- DBMS_OUTPUT.PUT_LINE('before calling Update API...');
5660   GMF_ResourceCost_PUB.Update_Resource_Cost
5661   ( p_api_version    => 2.0
5662   , p_init_msg_list  => FND_API.G_TRUE
5663   , p_commit         => FND_API.G_TRUE
5664 
5665   , x_return_status  =>l_status
5666   , x_msg_count      =>l_count
5667   , x_msg_data       =>l_data
5668 
5669   , p_Resource_Cost_rec => rsrc_rec
5670   );
5671 
5672     UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
5673   IF l_count > 0
5674   THEN
5675     l_loop_cnt  :=1;
5676     LOOP
5677 
5678     FND_MSG_PUB.Get(
5679       p_msg_index     => l_loop_cnt,
5680       p_data          => l_data,
5681       p_encoded       => FND_API.G_FALSE,
5682       p_msg_index_out => l_dummy_cnt);
5683 
5684 
5685     -- DBMS_OUTPUT.PUT_LINE(l_data );
5686 
5687     UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
5688     UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
5689     UTL_FILE.NEW_LINE(l_outfile_handle);
5690 
5691 
5692   /*
5693     IF l_status = 'E' OR
5694        l_status = 'U'
5695     THEN
5696       l_data    := CONCAT('ERROR : ',l_data);
5697     END IF;
5698   */
5699 
5700     UTL_FILE.PUT_LINE(l_log_handle, l_data);
5701 
5702     /*  Update error status */
5703       IF (l_status = 'U')
5704       THEN
5705         l_return_status  :=l_status;
5706       ELSIF (l_status = 'E' and l_return_status <> 'U')
5707       THEN
5708         l_return_status  :=l_status;
5709       ELSE
5710         l_return_status  :=l_status;
5711       END IF;
5712 
5713     l_loop_cnt  := l_loop_cnt + 1;
5714     IF l_loop_cnt > l_count
5715     THEN
5716       EXIT;
5717     END IF;
5718 
5719     END LOOP;
5720 
5721   END IF;
5722   END IF;
5723 
5724 
5725 EXCEPTION
5726  WHEN OTHERS THEN
5727   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5728   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5729   l_return_status := 'U' ;
5730 END ;
5731 
5732 END LOOP;
5733   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5734   UTL_FILE.NEW_LINE(l_log_handle);
5735   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5736 
5737 /*  Check if any messages generated. If so then decode and */
5738 /*  output to error message flat file */
5739 
5740 UTL_FILE.FCLOSE_ALL;
5741 
5742 RETURN l_return_status;
5743 
5744 EXCEPTION
5745 WHEN UTL_FILE.INVALID_OPERATION THEN
5746    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
5747    UTL_FILE.FCLOSE_ALL;
5748    RETURN l_return_status;
5749 
5750 WHEN UTL_FILE.INVALID_PATH THEN
5751    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
5752    UTL_FILE.FCLOSE_ALL;
5753    RETURN l_return_status;
5754 
5755 WHEN UTL_FILE.INVALID_MODE THEN
5756    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
5757    UTL_FILE.FCLOSE_ALL;
5758    RETURN l_return_status;
5759 
5760 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
5761    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
5762    UTL_FILE.FCLOSE_ALL;
5763    RETURN l_return_status;
5764 
5765 WHEN UTL_FILE.WRITE_ERROR THEN
5766    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
5767    UTL_FILE.FCLOSE_ALL;
5768    RETURN l_return_status;
5769 
5770 WHEN UTL_FILE.READ_ERROR THEN
5771    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
5772    UTL_FILE.FCLOSE_ALL;
5773    RETURN l_return_status;
5774 
5775 WHEN UTL_FILE.INTERNAL_ERROR THEN
5776    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
5777    UTL_FILE.FCLOSE_ALL;
5778    RETURN l_return_status;
5779 
5780 WHEN OTHERS THEN
5781    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
5782   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5783   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
5784   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5785    UTL_FILE.FCLOSE_ALL;
5786    l_return_status := 'U' ;
5787    RETURN l_return_status;
5788 
5789 END Update_resource_cost;
5790 
5791 /*  API start of comments
5792  +==========================================================================+
5793  | PROCEDURE NAME                                                           |
5794  |    Delete_resource_cost                                                  |
5795  |                                                                          |
5796  | TYPE                                                                     |
5797  |    Public                                                                |
5798  |                                                                          |
5799  | USAGE                                                                    |
5800  |    Delete Resource Cost                                                  |
5801  |                                                                          |
5802  | DESCRIPTION                                                              |
5803  |    This is a PL/SQL wrapper procedure to call the                        |
5804  |    Delete_resource_cost API wrapper function                             |
5805  |                                                                          |
5806  | PARAMETERS                                                               |
5807  |    p_dir              IN VARCHAR2         - Working directory for input  |
5808  |                                             and output files.            |
5809  |    p_input_file       IN VARCHAR2         - Name of input file           |
5810  |    p_output_file      IN VARCHAR2         - Name of output file          |
5811  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
5812  |                                                                          |
5813  | RETURNS                                                                  |
5814  |    None                                                                  |
5815  |                                                                          |
5816  | HISTORY                                                                  |
5817  |    07-Mar-2001  Uday Moogala    created                                  |
5818  |                                                                          |
5819  +==========================================================================+
5820   Api end of comments
5821 */
5822 PROCEDURE Delete_resource_cost
5823 ( p_dir          IN VARCHAR2
5824 , p_input_file   IN VARCHAR2
5825 , p_output_file  IN VARCHAR2
5826 , p_delimiter    IN VARCHAR2
5827 )
5828 IS
5829 
5830 l_return_status  VARCHAR2(1);
5831 
5832 BEGIN
5833 
5834  ---- DBMS_OUTPUT.PUT_LINE('in Delete_resource_cost procedure... ');
5835 l_return_status  :=Delete_resource_cost( p_dir
5836                                      , p_input_file
5837                                      , p_output_file
5838                                      , p_delimiter
5839                                    );
5840 
5841  -- DBMS_OUTPUT.PUT_LINE('return status := ' || l_return_status);
5842 END Delete_resource_cost;
5843 
5844 /* +==========================================================================+
5845  | FUNCTION NAME                                                            |
5846  |    Delete_resource_cost                                                  |
5847  |                                                                          |
5848  | TYPE                                                                     |
5849  |    Public                                                                |
5850  |                                                                          |
5851  | USAGE                                                                    |
5852  |    Delete Resource Cost                                                  |
5853  |                                                                          |
5854  | DESCRIPTION                                                              |
5855  |    This is a PL/SQL wrapper function to call the                         |
5856  |    Delete_Resource_Cost API.                                             |
5857  |    It reads item data from a flat file and outputs any error             |
5858  |    messages to a second flat file. It also generates a Status            |
5859  |    called gmf_rsrc_wrapper<session_id>.log in the temp directory.        |
5860  |                                                                          |
5861  | PARAMETERS                                                               |
5862  |    p_dir              IN VARCHAR2         - Working directory for input  |
5863  |                                             and output files.            |
5864  |    p_input_file       IN VARCHAR2         - Name of input file           |
5865  |    p_output_file      IN VARCHAR2         - Name of output file          |
5866  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
5867  |                                                                          |
5868  | RETURNS                                                                  |
5869  |    VARCHAR2 - 'S' All records processed successfully                     |
5870  |               'E' 1 or more records errored                              |
5871  |               'U' 1 or more record unexpected error                      |
5872  |                                                                          |
5873  | HISTORY                                                                  |
5874  | 21-Oct-2005 Prasad marada Modified the procedure as per the record type  |
5875  |                           changes in resource cost public packages       |
5876  |                                                                          |
5877  +==========================================================================+
5878   Api end of comments
5879 */
5880 FUNCTION Delete_resource_cost
5881 ( p_dir          IN VARCHAR2
5882 , p_input_file   IN VARCHAR2
5883 , p_output_file  IN VARCHAR2
5884 , p_delimiter    IN VARCHAR2
5885 )
5886 RETURN VARCHAR2
5887 IS
5888 
5889 /* Local variables */
5890 
5891 l_status             VARCHAR2(100);
5892 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
5893 l_count              NUMBER(10)  ;
5894 l_record_count       NUMBER(10)  :=0;
5895 l_loop_cnt           NUMBER(10)  :=0;
5896 l_dummy_cnt          NUMBER(10)  :=0;
5897 l_data               VARCHAR2(2000);
5898 rsrc_rec             GMF_ResourceCost_PUB.Resource_Cost_Rec_Type;
5899 l_p_dir              VARCHAR2(150);
5900 l_output_file        VARCHAR2(120);
5901 l_outfile_handle     UTL_FILE.FILE_TYPE;
5902 l_input_file         VARCHAR2(120);
5903 l_infile_handle      UTL_FILE.FILE_TYPE;
5904 l_line               VARCHAR2(1800);
5905 l_delimiter          VARCHAR(11);
5906 l_log_dir            VARCHAR2(150);
5907 l_log_name           VARCHAR2(120)  :='gmf_api_delrc_wrapper';
5908 l_log_handle         UTL_FILE.FILE_TYPE;
5909 l_global_file        VARCHAR2(120);
5910 
5911 l_session_id         VARCHAR2(110);
5912 
5913 BEGIN
5914 
5915 /*  Enable The Buffer  */
5916 /*  DBMS_OUTPUT.ENABLE(1000000); */
5917 
5918 -- DBMS_OUTPUT.PUT_LINE('in Delete_resource_cost function...');
5919 
5920 l_p_dir              :=p_dir;
5921 l_input_file         :=p_input_file;
5922 l_output_file        :=p_output_file;
5923 l_delimiter          :=p_delimiter;
5924 l_global_file        :=l_input_file;
5925 
5926 /*  Obtain The SessionId To Append To wrapper File Name. */
5927 
5928 l_session_id := USERENV('sessionid');
5929 
5930 l_log_name  := CONCAT(l_log_name,l_session_id);
5931 l_log_name  := CONCAT(l_log_name,'.log');
5932 
5933 /*  Directory is now the same same as for the out file */
5934 l_log_dir   := p_dir;
5935 
5936 
5937 /*  Open The Wrapper File For Output And The Input File for Input. */
5938 
5939 l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
5940 l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
5941 
5942 /*  Loop thru flat file and call Inventory Quantities API */
5943 -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5944 -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
5945 -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
5946 -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
5947 -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
5948 
5949 
5950 /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
5951 UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
5952 UTL_FILE.NEW_LINE(l_log_handle);
5953 UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
5954 UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
5955 UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
5956 UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
5957 
5958 l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
5959 
5960 
5961 LOOP
5962 l_record_count    :=l_record_count+1;
5963 
5964   BEGIN
5965   UTL_FILE.GET_LINE(l_infile_handle, l_line);
5966   EXCEPTION
5967     WHEN NO_DATA_FOUND THEN
5968 EXIT;
5969   END;
5970 
5971 BEGIN
5972   UTL_FILE.NEW_LINE(l_log_handle);
5973   UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
5974 
5975   rsrc_rec.resources           := Get_Field(l_line,l_delimiter,1) ;
5976   rsrc_rec.legal_entity_id     := Get_Field(l_line,l_delimiter,2) ;
5977   rsrc_rec.organization_id     := Get_Field(l_line,l_delimiter,3) ;
5978   rsrc_rec.organization_code   := Get_Field(l_line,l_delimiter,4) ;
5979   rsrc_rec.period_id           := Get_Field(l_line,l_delimiter,5) ;
5980   rsrc_rec.calendar_code       := Get_Field(l_line,l_delimiter,6) ;
5981   rsrc_rec.period_code         := Get_Field(l_line,l_delimiter,7) ;
5982   rsrc_rec.cost_type_id        := Get_Field(l_line,l_delimiter,8) ;
5983   rsrc_rec.cost_mthd_code      := Get_Field(l_line,l_delimiter,9) ;
5984   rsrc_rec.usage_uom           := Get_Field(l_line,l_delimiter,10) ;
5985   rsrc_rec.nominal_cost        := Get_Field(l_line,l_delimiter,11) ;
5986   rsrc_rec.delete_mark         := Get_Field(l_line,l_delimiter,12) ;
5987   rsrc_rec.user_name           := Get_Field(l_line,l_delimiter,13) ;
5988 
5989   UTL_FILE.PUT_LINE(l_log_handle, 'resources     = ' || rsrc_rec.resources);
5990   UTL_FILE.PUT_LINE(l_log_handle, 'legal_entity_id= ' || rsrc_rec.legal_entity_id);
5991   UTL_FILE.PUT_LINE(l_log_handle, 'organization_id= ' || rsrc_rec.organization_id);
5992   UTL_FILE.PUT_LINE(l_log_handle, 'organization_code= ' || rsrc_rec.organization_code);
5993   UTL_FILE.PUT_LINE(l_log_handle, 'period_id     = ' || rsrc_rec.period_id);
5994   UTL_FILE.PUT_LINE(l_log_handle, 'calendar_code = ' || rsrc_rec.calendar_code);
5995   UTL_FILE.PUT_LINE(l_log_handle, 'period_code   = ' || rsrc_rec.period_code);
5996   UTL_FILE.PUT_LINE(l_log_handle, 'cost_type_id= '   || rsrc_rec.cost_type_id);
5997   UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code= ' || rsrc_rec.cost_mthd_code);
5998   UTL_FILE.PUT_LINE(l_log_handle, 'usage_uom     = ' || rsrc_rec.usage_uom);
5999   UTL_FILE.PUT_LINE(l_log_handle, 'nominal_cost  = ' || rsrc_rec.nominal_cost);
6000   UTL_FILE.PUT_LINE(l_log_handle, 'delete_mark   = ' || rsrc_rec.delete_mark);
6001   UTL_FILE.PUT_LINE(l_log_handle, 'user_name     = ' || rsrc_rec.user_name);
6002 
6003   -- DBMS_OUTPUT.PUT_LINE('before calling Delete API...');
6004   GMF_ResourceCost_PUB.Delete_Resource_Cost
6005   ( p_api_version    => 2.0
6006   , p_init_msg_list  => FND_API.G_TRUE
6007   , p_commit         => FND_API.G_TRUE
6008 
6009   , x_return_status  =>l_status
6010   , x_msg_count      =>l_count
6011   , x_msg_data       =>l_data
6012 
6013   , p_Resource_Cost_rec => rsrc_rec
6014   );
6015 
6016     UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
6017   IF l_count > 0
6018   THEN
6019     l_loop_cnt  :=1;
6020     LOOP
6021 
6022     FND_MSG_PUB.Get(
6023       p_msg_index     => l_loop_cnt,
6024       p_data          => l_data,
6025       p_encoded       => FND_API.G_FALSE,
6026       p_msg_index_out => l_dummy_cnt);
6027 
6028 
6029     -- DBMS_OUTPUT.PUT_LINE(l_data );
6030 
6031     UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
6032     UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
6033     UTL_FILE.NEW_LINE(l_outfile_handle);
6034 
6035     UTL_FILE.PUT_LINE(l_log_handle, l_data);
6036 
6037     /*  Update error status */
6038       IF (l_status = 'U')
6039       THEN
6040         l_return_status  :=l_status;
6041       ELSIF (l_status = 'E' and l_return_status <> 'U')
6042       THEN
6043         l_return_status  :=l_status;
6044       ELSE
6045         l_return_status  :=l_status;
6046       END IF;
6047 
6048     l_loop_cnt  := l_loop_cnt + 1;
6049     IF l_loop_cnt > l_count
6050     THEN
6051       EXIT;
6052     END IF;
6053 
6054     END LOOP;
6055 
6056   END IF;
6057 
6058 EXCEPTION
6059  WHEN OTHERS THEN
6060   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
6061   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
6062   l_return_status := 'U' ;
6063 END ;
6064 
6065 
6066 END LOOP;
6067   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
6068   UTL_FILE.NEW_LINE(l_log_handle);
6069   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
6070 
6071 /*  Check if any messages generated. If so then decode and */
6072 /*  output to error message flat file */
6073 
6074 UTL_FILE.FCLOSE_ALL;
6075 
6076 RETURN l_return_status;
6077 
6078 EXCEPTION
6079 WHEN UTL_FILE.INVALID_OPERATION THEN
6080    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
6081    UTL_FILE.FCLOSE_ALL;
6082    RETURN l_return_status;
6083 
6084 WHEN UTL_FILE.INVALID_PATH THEN
6085    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
6086    UTL_FILE.FCLOSE_ALL;
6087    RETURN l_return_status;
6088 
6089 WHEN UTL_FILE.INVALID_MODE THEN
6090    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
6091    UTL_FILE.FCLOSE_ALL;
6092    RETURN l_return_status;
6093 
6094 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
6095    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
6096    UTL_FILE.FCLOSE_ALL;
6097    RETURN l_return_status;
6098 
6099 WHEN UTL_FILE.WRITE_ERROR THEN
6100    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
6101    UTL_FILE.FCLOSE_ALL;
6102    RETURN l_return_status;
6103 
6104 WHEN UTL_FILE.READ_ERROR THEN
6105    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
6106    UTL_FILE.FCLOSE_ALL;
6107    RETURN l_return_status;
6108 
6109 WHEN UTL_FILE.INTERNAL_ERROR THEN
6110    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
6111    UTL_FILE.FCLOSE_ALL;
6112    RETURN l_return_status;
6113 
6114 WHEN OTHERS THEN
6115    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
6116   UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
6117   UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
6118   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
6119    UTL_FILE.FCLOSE_ALL;
6120    l_return_status := 'U' ;
6121    RETURN l_return_status;
6122 
6123 END Delete_resource_cost;
6124 
6125 /*  Body start of comments
6126  +==========================================================================+
6127  | PROCEDURE NAME                                                           |
6128  |    Get_Resource_Cost                                                     |
6129  |                                                                          |
6130  | TYPE                                                                     |
6131  |    Public                                                                |
6132  |                                                                          |
6133  | USAGE                                                                    |
6134  |    Get Item Cost                                                         |
6135  |                                                                          |
6136  | DESCRIPTION                                                              |
6137  |    This is a PL/SQL wrapper procedure to call the                        |
6138  |    Get_Resource_Cost API wrapper function                                |
6139  |                                                                          |
6140  | PARAMETERS                                                               |
6141  |    p_dir              IN VARCHAR2         - Working directory for input  |
6142  |                                             and output files.            |
6143  |    p_input_file       IN VARCHAR2         - Name of input file           |
6144  |    p_output_file      IN VARCHAR2         - Name of output file          |
6145  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
6146  |                                                                          |
6147  | RETURNS                                                                  |
6148  |    None                                                                  |
6149  |                                                                          |
6150  | HISTORY                                                                  |
6151  |    27/Feb/2001  Uday Moogala  Created  Bug# 1418689                      |
6152  |                                                                          |
6153  +==========================================================================+
6154   Api end of comments
6155 */
6156 PROCEDURE Get_Resource_Cost
6157 ( p_dir          IN VARCHAR2
6158 , p_input_file   IN VARCHAR2
6159 , p_output_file  IN VARCHAR2
6160 , p_delimiter    IN VARCHAR2
6161 )
6162 IS
6163 
6164 l_return_status  VARCHAR2(1);
6165 
6166 BEGIN
6167 
6168 -- DBMS_OUTPUT.PUT_LINE('in Get_Resource_Cost procedure... ');
6169 l_return_status  :=Get_Resource_Cost( p_dir
6170 			      	, p_input_file
6171                                 , p_output_file
6172                                 , p_delimiter
6173                                 );
6174 
6175  -- DBMS_OUTPUT.PUT_LINE('return status := ' || l_return_status);
6176 END Get_Resource_Cost;
6177 
6178 /* +========================================================================+
6179  | FUNCTION NAME                                                            |
6180  |    Get_Resource_Cost                                                     |
6181  |                                                                          |
6182  | TYPE                                                                     |
6183  |    Public                                                                |
6184  |                                                                          |
6185  | USAGE                                                                    |
6186  |    Get Item Cost                                                         |
6187  |                                                                          |
6188  | DESCRIPTION                                                              |
6189  |    This is a PL/SQL wrapper function to call the                         |
6190  |    Get_Resource_Cost API.                                                |
6191  |    It reads item data from a flat file and outputs any error             |
6192  |    messages to a second flat file. It also generates a Status            |
6193  |    called gmf_rsrc_wrapper<session_id>.log in the /tmp directory.        |
6194  |                                                                          |
6195  | PARAMETERS                                                               |
6196  |    p_dir              IN VARCHAR2         - Working directory for input  |
6197  |                                             and output files.            |
6198  |    p_input_file       IN VARCHAR2         - Name of input file           |
6199  |    p_output_file      IN VARCHAR2         - Name of output file          |
6200  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
6201  |                                                                          |
6202  | RETURNS                                                                  |
6203  |    VARCHAR2 - 'S' All records processed successfully                     |
6204  |               'E' 1 or more records errored                              |
6205  |               'U' 1 or more record unexpected error                      |
6206  |                                                                          |
6207  | HISTORY                                                                  |
6208  |                                                                          |
6209  +==========================================================================+
6210   Api end of comments
6211 */
6212 
6213 FUNCTION Get_Resource_Cost
6214 ( p_dir          IN VARCHAR2
6215 , p_input_file   IN VARCHAR2
6216 , p_output_file  IN VARCHAR2
6217 , p_delimiter    IN VARCHAR2
6218 )
6219 RETURN VARCHAR2
6220 IS
6221 
6222 /* Local variables */
6223 
6224 l_status             VARCHAR2(100);
6225 l_return_status      VARCHAR2(11) :=FND_API.G_RET_STS_SUCCESS;
6226 l_count              NUMBER(10)  ;
6227 l_record_count       NUMBER(10)  :=0;
6228 l_loop_cnt           NUMBER(10)  :=0;
6229 l_dummy_cnt          NUMBER(10)  :=0;
6230 l_data               VARCHAR2(2000);
6231 rsrc_rec             GMF_ResourceCost_PUB.Resource_Cost_Rec_Type;
6232 x_rsrc_rec           GMF_ResourceCost_PUB.Resource_Cost_Rec_Type;
6233 l_p_dir              VARCHAR2(150);
6234 l_output_file        VARCHAR2(120);
6235 l_outfile_handle     UTL_FILE.FILE_TYPE;
6236 l_input_file         VARCHAR2(120);
6237 l_infile_handle      UTL_FILE.FILE_TYPE;
6238 l_line               VARCHAR2(1800);
6239 l_delimiter          VARCHAR(11);
6240 l_log_dir            VARCHAR2(150);
6241 l_log_name           VARCHAR2(120)  :='gmf_api_getrc_wrapper';
6242 l_log_handle         UTL_FILE.FILE_TYPE;
6243 l_global_file        VARCHAR2(120);
6244 
6245 l_session_id         VARCHAR2(110);
6246 
6247 BEGIN
6248 
6249 /*  Enable The Buffer  */
6250 /*  DBMS_OUTPUT.ENABLE(1000000); */
6251 
6252 -- DBMS_OUTPUT.PUT_LINE('in Get_resource_cost function...');
6253 
6254 l_p_dir              :=p_dir;
6255 l_input_file         :=p_input_file;
6256 l_output_file        :=p_output_file;
6257 l_delimiter          :=p_delimiter;
6258 l_global_file        :=l_input_file;
6259 
6260 /*  Obtain The SessionId To Append To wrapper File Name. */
6261 
6262 l_session_id := USERENV('sessionid');
6263 
6264 l_log_name  := CONCAT(l_log_name,l_session_id);
6265 l_log_name  := CONCAT(l_log_name,'.log');
6266 
6267 /*  Directory is now the same same as for the out file */
6268 l_log_dir   := p_dir;
6269 
6270 
6271 /*  Open The Wrapper File For Output And The Input File for Input. */
6272 
6273 l_log_handle      :=UTL_FILE.FOPEN(l_log_dir, l_log_name, 'w');
6274 l_infile_handle   :=UTL_FILE.FOPEN(l_p_dir, l_input_file, 'r');
6275 
6276 /*  Loop thru flat file and call Inventory Quantities API */
6277 -- DBMS_OUTPUT.PUT_LINE('Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
6278 -- DBMS_OUTPUT.PUT_LINE('Input Directory  ' || l_p_dir );
6279 -- DBMS_OUTPUT.PUT_LINE('Input File       ' || l_input_file );
6280 -- DBMS_OUTPUT.PUT_LINE('Delimiter        ' || l_delimiter );
6281 -- DBMS_OUTPUT.PUT_LINE('Output File      ' || l_output_file );
6282 
6283 
6284 /*  -- DBMS_OUTPUT.PUT_LINE('Start Processing'); */
6285 UTL_FILE.PUT_LINE(l_log_handle, 'Process Started at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
6286 UTL_FILE.NEW_LINE(l_log_handle);
6287 UTL_FILE.PUT_LINE(l_log_handle, 'Input Directory  ' || l_p_dir );
6288 UTL_FILE.PUT_LINE(l_log_handle, 'Input File       ' || l_input_file );
6289 UTL_FILE.PUT_LINE(l_log_handle, 'Record Type      ' || l_delimiter );
6290 UTL_FILE.PUT_LINE(l_log_handle, 'Output File      ' || l_output_file );
6291 
6292 l_outfile_handle  :=UTL_FILE.FOPEN(l_p_dir, l_output_file, 'w');
6293 
6294 
6295 LOOP
6296   l_record_count    :=l_record_count+1;
6297 
6298   BEGIN
6299   UTL_FILE.GET_LINE(l_infile_handle, l_line);
6300   EXCEPTION
6301     WHEN NO_DATA_FOUND THEN
6302     EXIT;
6303   END;
6304 
6305   BEGIN
6306     UTL_FILE.NEW_LINE(l_log_handle);
6307     UTL_FILE.PUT_LINE(l_log_handle, 'Reading Record...' || l_record_count );
6308 
6309     rsrc_rec.resources           := Get_Field(l_line,l_delimiter,1) ;
6310     rsrc_rec.legal_entity_id     := Get_Field(l_line,l_delimiter,2) ;
6311     rsrc_rec.organization_id     := Get_Field(l_line,l_delimiter,3) ;
6312     rsrc_rec.organization_code   := Get_Field(l_line,l_delimiter,4) ;
6313     rsrc_rec.period_id           := Get_Field(l_line,l_delimiter,5) ;
6314     rsrc_rec.calendar_code       := Get_Field(l_line,l_delimiter,6) ;
6315     rsrc_rec.period_code         := Get_Field(l_line,l_delimiter,7) ;
6316     rsrc_rec.cost_type_id        := Get_Field(l_line,l_delimiter,8) ;
6317     rsrc_rec.cost_mthd_code      := Get_Field(l_line,l_delimiter,9) ;
6318     rsrc_rec.usage_uom           := Get_Field(l_line,l_delimiter,10) ;
6319     rsrc_rec.nominal_cost        := Get_Field(l_line,l_delimiter,11) ;
6320     rsrc_rec.delete_mark         := Get_Field(l_line,l_delimiter,12) ;
6321     rsrc_rec.user_name           := Get_Field(l_line,l_delimiter,13) ;
6322 
6323     UTL_FILE.PUT_LINE(l_log_handle, 'resources     = ' || rsrc_rec.resources);
6324     UTL_FILE.PUT_LINE(l_log_handle, 'legal_entity_id= ' || rsrc_rec.legal_entity_id);
6325     UTL_FILE.PUT_LINE(l_log_handle, 'organization_id= ' || rsrc_rec.organization_id);
6326     UTL_FILE.PUT_LINE(l_log_handle, 'organization_code= ' || rsrc_rec.organization_code);
6327     UTL_FILE.PUT_LINE(l_log_handle, 'period_id     = ' || rsrc_rec.period_id);
6328     UTL_FILE.PUT_LINE(l_log_handle, 'calendar_code = ' || rsrc_rec.calendar_code);
6329     UTL_FILE.PUT_LINE(l_log_handle, 'period_code   = ' || rsrc_rec.period_code);
6330     UTL_FILE.PUT_LINE(l_log_handle, 'cost_type_id= '   || rsrc_rec.cost_type_id);
6331     UTL_FILE.PUT_LINE(l_log_handle, 'cost_mthd_code= ' || rsrc_rec.cost_mthd_code);
6332     UTL_FILE.PUT_LINE(l_log_handle, 'usage_uom     = ' || rsrc_rec.usage_uom);
6333     UTL_FILE.PUT_LINE(l_log_handle, 'nominal_cost  = ' || rsrc_rec.nominal_cost);
6334     UTL_FILE.PUT_LINE(l_log_handle, 'delete_mark   = ' || rsrc_rec.delete_mark);
6335     UTL_FILE.PUT_LINE(l_log_handle, 'user_name     = ' || rsrc_rec.user_name);
6336 
6337     -- DBMS_OUTPUT.PUT_LINE('before calling Get Resource Cost Public API...');
6338     GMF_ResourceCost_PUB.Get_Resource_Cost
6339     ( p_api_version    => 2.0
6340     , p_init_msg_list  => FND_API.G_TRUE
6341 
6342     , x_return_status  =>l_status
6343     , x_msg_count      =>l_count
6344     , x_msg_data       =>l_data
6345 
6346     , p_Resource_Cost_rec => rsrc_rec
6347     , x_Resource_Cost_rec => x_rsrc_rec
6348     );
6349 
6350     UTL_FILE.PUT_LINE(l_log_handle, 'after API call. status := ' || l_status ||' cnt := ' || l_count );
6351     IF l_count > 0
6352     THEN
6353       l_loop_cnt  :=1;
6354       LOOP
6355 
6356         FND_MSG_PUB.Get(
6357           p_msg_index     => l_loop_cnt,
6358           p_data          => l_data,
6359           p_encoded       => FND_API.G_FALSE,
6360           p_msg_index_out => l_dummy_cnt);
6361 
6362 
6363         -- DBMS_OUTPUT.PUT_LINE(l_data );
6364         --UTL_FILE.PUT_LINE(l_outfile_handle, 'Record = ' ||l_record_count );
6365         --UTL_FILE.PUT_LINE(l_outfile_handle, l_data);
6366         --UTL_FILE.NEW_LINE(l_outfile_handle);
6367 
6368         UTL_FILE.PUT_LINE(l_log_handle, l_data);
6369 
6370         /*  Update error status */
6371           IF (l_status = 'U')
6372           THEN
6373             l_return_status  :=l_status;
6374           ELSIF (l_status = 'E' and l_return_status <> 'U')
6375           THEN
6376             l_return_status  :=l_status;
6377           ELSE
6378             l_return_status  :=l_status;
6379           END IF;
6380 
6381         l_loop_cnt  := l_loop_cnt + 1;
6382         IF l_loop_cnt > l_count
6383         THEN
6384           EXIT;
6385         END IF;
6386 
6387       END LOOP;
6388     END IF;	-- message count
6389 
6390     IF (x_rsrc_rec.usage_uom <> FND_API.G_MISS_CHAR) OR
6391        (x_rsrc_rec.nominal_cost <> FND_API.G_MISS_NUM) THEN
6392 
6393       UTL_FILE.PUT_LINE( l_log_handle,
6394                        'Usage_uom : '         || x_rsrc_rec.usage_uom ||
6395                        ' Nominal Cost : '    || x_rsrc_rec.nominal_cost ||
6396                        ' Delete Mark : '     || x_rsrc_rec.delete_mark ||
6397                        ' User Name : '       || x_rsrc_rec.user_name
6398                        ) ;
6399     END IF ;
6400 
6401   EXCEPTION
6402    WHEN OTHERS THEN
6403     UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
6404     UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
6405     l_return_status := 'U' ;
6406   END ;
6407 
6408 END LOOP ;
6409 
6410   -- DBMS_OUTPUT.PUT_LINE('Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
6411   UTL_FILE.NEW_LINE(l_log_handle);
6412   UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
6413   UTL_FILE.FCLOSE_ALL;
6414 
6415   RETURN l_return_status;
6416 
6417 EXCEPTION
6418 WHEN UTL_FILE.INVALID_OPERATION THEN
6419    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Operation For '|| l_global_file); */
6420    UTL_FILE.FCLOSE_ALL;
6421    RETURN l_return_status;
6422 
6423 WHEN UTL_FILE.INVALID_PATH THEN
6424    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Path For      '|| l_global_file); */
6425    UTL_FILE.FCLOSE_ALL;
6426    RETURN l_return_status;
6427 
6428 WHEN UTL_FILE.INVALID_MODE THEN
6429    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Mode For      '|| l_global_file); */
6430    UTL_FILE.FCLOSE_ALL;
6431    RETURN l_return_status;
6432 
6433 WHEN UTL_FILE.INVALID_FILEHANDLE THEN
6434    /* -- DBMS_OUTPUT.PUT_LINE('Invalid File Handle   '|| l_global_file); */
6435    UTL_FILE.FCLOSE_ALL;
6436    RETURN l_return_status;
6437 
6438 WHEN UTL_FILE.WRITE_ERROR THEN
6439    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Write Error   '|| l_global_file); */
6440    UTL_FILE.FCLOSE_ALL;
6441    RETURN l_return_status;
6442 
6443 WHEN UTL_FILE.READ_ERROR THEN
6444    /*  -- DBMS_OUTPUT.PUT_LINE('Invalid Read  Error   '|| l_global_file); */
6445    UTL_FILE.FCLOSE_ALL;
6446    RETURN l_return_status;
6447 
6448 WHEN UTL_FILE.INTERNAL_ERROR THEN
6449    /*  -- DBMS_OUTPUT.PUT_LINE('Internal Error'); */
6450    UTL_FILE.FCLOSE_ALL;
6451    RETURN l_return_status;
6452 
6453 WHEN OTHERS THEN
6454    /*  -- DBMS_OUTPUT.PUT_LINE('Other Error'); */
6455    UTL_FILE.PUT_LINE(l_outfile_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
6456    UTL_FILE.PUT_LINE(l_log_handle, 'Error : ' || to_char(SQLCODE) || ' ' || SQLERRM);
6457    UTL_FILE.PUT_LINE(l_log_handle, 'Process Completed at ' || to_char(SYSDATE,'DD-MON-YY HH24:MI:SS'));
6458    UTL_FILE.FCLOSE_ALL;
6459    l_return_status := 'U' ;
6460    RETURN l_return_status;
6461 
6462 END Get_Resource_Cost;
6463 
6464 
6465 
6466 
6467 /* +==========================================================================+
6468  | FUNCTION NAME                                                            |
6469  |    Get_Field                                                             |
6470  |                                                                          |
6471  | TYPE                                                                     |
6472  |    Public                                                                |
6473  |                                                                          |
6474  | USAGE                                                                    |
6475  |    Get value of field n from a delimited line of ASCII data              |
6476  |                                                                          |
6477  | DESCRIPTION                                                              |
6478  |    This utility function will return the value of a field from           |
6479  |    a delimited line of ASCII text                                        |
6480  |                                                                          |
6481  | PARAMETERS                                                               |
6482  |    p_line             IN VARCHAR2         - line of data                 |
6483  |    p_delimiter        IN VARCHAR2         - Delimiter character          |
6484  |    p_field_no         IN NUMBER           - Field occurance to be        |
6485  |                                             returned                     |
6486  |                                                                          |
6487  | RETURNS                                                                  |
6488  |    VARCHAR2                               - Value of field               |
6489  |                                                                          |
6490  | HISTORY                                                                  |
6491  |                                                                          |
6492  +==========================================================================+
6493   Api end of comments
6494 */
6495 FUNCTION Get_Field
6496 ( p_line         IN VARCHAR2
6497 , p_delimiter    IN VARCHAR2
6498 , p_field_no     IN NUMBER
6499 )
6500 RETURN VARCHAR2
6501 IS
6502 /*  Local variables */
6503 l_start         NUMBER  :=0;
6504 l_end           NUMBER  :=0;
6505 l_string   VARCHAR2(2000);
6506 
6507 BEGIN
6508 
6509 /* Determine start position */
6510 IF p_field_no = 1
6511 THEN
6512   l_start       :=0;
6513 ELSE
6514   l_start       :=INSTR(p_line,p_delimiter,1,(p_field_no - 1));
6515   IF l_start    = 0
6516   THEN
6517     RETURN NULL;
6518   END IF;
6519 END IF;
6520 
6521 /*  Determine end position */
6522 l_end           :=INSTR(p_line,p_delimiter,1,p_field_no);
6523 IF l_end        = 0
6524 THEN
6525   l_end         := LENGTH(p_line) + 1;
6526 END IF;
6527 
6528 /*  Extract the field data */
6529 IF (l_end - l_start) = 1
6530 THEN
6531   RETURN NULL;
6532 ELSE
6533   -- RETURN SUBSTR(p_line,(l_start + 1),((l_end - l_start) - 1));
6534   l_string := SUBSTR(p_line,(l_start + 1),((l_end - l_start) - 1));
6535 
6536   IF l_string IS NULL THEN
6537 	RETURN NULL;
6538   ELSIF l_string = 'G_MISS_CHAR' THEN
6539 	RETURN FND_API.G_MISS_CHAR;
6540   ELSIF l_string = 'G_MISS_NUM' THEN
6541 	RETURN FND_API.G_MISS_NUM;
6542   ELSIF l_string = 'G_MISS_DATE' THEN
6543 	RETURN FND_API.G_MISS_DATE;
6544   ELSE
6545 	RETURN l_string;
6546   END IF;
6547 
6548 END IF;
6549 
6550 EXCEPTION
6551   WHEN OTHERS
6552   THEN
6553     RETURN NULL;
6554 
6555 END Get_Field;
6556 
6557 /* +==========================================================================+
6558  | FUNCTION NAME                                                            |
6559  |    Get_Substring                                                         |
6560  |                                                                          |
6561  | TYPE                                                                     |
6562  |    Public                                                                |
6563  |                                                                          |
6564  | USAGE                                                                    |
6565  |    Get value of Sub-string from formatted ASCII data file record         |
6566  |                                                                          |
6567  | DESCRIPTION                                                              |
6568  |    This utility function will return the value of a passed sub-string    |
6569  |    of a formatted ASCII data file record                                 |
6570  |                                                                          |
6571  | PARAMETERS                                                               |
6572  |    p_substring        IN VARCHAR2         - substring data               |
6573  |                                                                          |
6574  | RETURNS                                                                  |
6575  |    VARCHAR2                               - Value of field               |
6576  |                                                                          |
6577  | HISTORY                                                                  |
6578  |                                                                          |
6579  +==========================================================================+
6580   Api end of comments
6581 */
6582 FUNCTION Get_Substring
6583 ( p_substring    IN VARCHAR2
6584 )
6585 RETURN VARCHAR2
6586 IS
6587 /*  Local variables */
6588 l_string_value   VARCHAR2(200)  :=' ';
6589 
6590 BEGIN
6591 
6592 /*  Determine start position */
6593 l_string_value  :=NVL(RTRIM(LTRIM(p_substring)),' ');
6594 
6595 RETURN l_string_value;
6596 EXCEPTION
6597   WHEN OTHERS
6598   THEN
6599     RETURN ' ';
6600 
6601 END Get_Substring;
6602 
6603 
6604 END GMF_API_WRP;