DBA Data[Home] [Help]

PACKAGE BODY: APPS.AK_UPLOAD_GRP

Source


1 package body AK_UPLOAD_GRP as
2 /* $Header: akgulodb.pls 120.2 2005/09/15 22:27:08 tshort ship $ */
3 
4 procedure UPLOAD (
5   p_update_mode       IN   varchar2,
6   p_return_status     OUT NOCOPY varchar2
7   ) is
8 
9   l_api_name          VARCHAR2(30) := 'Upload';
10   l_buffer_tbl        AK_ON_OBJECTS_PUB.Buffer_Tbl_Type;
11   l_filename          varchar2(128);
12   l_index             number := 0;
13   l_log_directory     varchar2(128);
14   l_log_filename      varchar2(128);
15   l_msg_count         number;
16   l_msg_data          varchar2(2000);
17   l_return_status     VARCHAR2(1);
18   l_string_pos        number;
19   l_table_index       number;
20   l_session_id        number := -1;
21 begin
22 
23   --FND_MSG_PUB.G_MSG_LEVEL_THRESHOLD := FND_MSG_PUB.G_MSG_LVL_SUCCESS;
24   FND_MSG_PUB.G_MSG_LEVEL_THRESHOLD := FND_MSG_PUB.G_MSG_LVL_ERROR;
25 
26   FND_PROGRAM.set_session_mode('seed_data');
27 
28   -- set current process mode to UPLOAD
29   AK_ON_OBJECTS_PUB.G_LOAD_MODE := 'UPLOAD';
30 
31   -- Check Update mode
32   if (p_update_mode = 'UPDATE') then
33     G_UPDATE_MODE := TRUE;
34 	-- update everything
35 	G_NO_CUSTOM_UPDATE := FALSE;
36 	G_COMPARE_UPDATE := FALSE;
37   elsif (p_update_mode = 'NCUPDATE') then
38 	-- update non-customized data only
39     G_NO_CUSTOM_UPDATE := TRUE;
40 	G_UPDATE_MODE := FALSE;
41 	G_COMPARE_UPDATE := TRUE;
42   elsif (p_update_mode = 'NON_SEED_DATA') then
43         -- update non-customized data only
44     G_NO_CUSTOM_UPDATE := TRUE;
45         G_UPDATE_MODE := FALSE;
46         G_COMPARE_UPDATE := TRUE;
47   elsif (p_update_mode = 'COMPAREUPDATE') then
48 	-- update everything, but compare date
49 	G_UPDATE_MODE := TRUE;
50 	G_NO_CUSTOM_UPDATE := FALSE;
51 	G_COMPARE_UPDATE := TRUE;
52   else
53     G_UPDATE_MODE := FALSE;
54 	G_NO_CUSTOM_UPDATE := FALSE;
55 	G_COMPARE_UPDATE := FALSE;
56   end if;
57   --
58   -- Load buffer table with log file heading info to be written
59   -- to the log file
60   --
61   l_index := 1;
62   l_buffer_tbl(l_index) := '**********';
63 
64   l_index := l_index + 1;
65   FND_MESSAGE.SET_NAME('AK','AK_START_UPLOAD_SESSION');
66   l_buffer_tbl(l_index) := FND_MESSAGE.GET;
67 
68   l_index := l_index + 1;
69   l_buffer_tbl(l_index) := to_char(sysdate, 'DY MM DD YYYY HH24:MI:SS');
70   l_index := l_index + 1;
71   l_buffer_tbl(l_index) := '**********';
72   l_index := l_index + 1;
73   l_buffer_tbl(l_index) := ' ';
74   if (G_NON_SEED_DATA) then
75 	l_index := l_index + 1;
76   	l_buffer_tbl(l_index) := 'Uploading in Non Seed Data mode.';
77         l_index := l_index + 1;
78         l_buffer_tbl(l_index) := 'All WHO columns, in records normally updated depending on update mode, will be updated with the information from the jlt file.';
79   	l_index := l_index + 1;
80   	l_buffer_tbl(l_index) := ' ';
81   end if;
82 
83   --dbms_output.put_line('Begin upload at:' ||
84   --                     to_char(sysdate, 'MM-DD HH24:MI:SS'));
85   --
86   -- Write heading info to a log file
87   --
88   AK_ON_OBJECTS_PVT.WRITE_LOG_FILE (
89     p_return_status => l_return_status,
90     p_buffer_tbl => l_buffer_tbl,
91     p_write_mode => AK_ON_OBJECTS_PUB.G_OVERWRITE
92   );
93 
94   /** commit the inserts in ak_loader_temp that's done by akload **/
95   commit;
96 
97   /** retreive the sessio id **/
98   select sid into l_session_id
99   from v$session
100   where AUDSID = userenv('SESSIONID');
101 
102   AK_ON_OBJECTS_PVT.G_SESSION_ID := l_session_id;
103 
104   --
105   -- Clean up buffer table for use by other messages later
106   --
107   -- l_buffer_tbl.delete;
108 
109   --
110   -- Upload data from data file to the database
111   --
112   AK_ON_OBJECTS_GRP.UPLOAD (
113 --    p_validation_level => FND_API.G_VALID_LEVEL_NONE,
114     p_api_version_number => 1.0,
115     p_init_msg_tbl => TRUE,
116     p_msg_count => l_msg_count,
117     p_msg_data => l_msg_data,
118     p_return_status => l_return_status
119   );
120 
121   p_return_status := l_return_status;
122 
123   --dbms_output.put_line('Finish uploading at:' ||
124   --                     to_char(sysdate, 'MM-DD HH24:MI:SS'));
125 
126   --dbms_output.put_line('Return status is: ' || l_return_status);
127   --dbms_output.put_line('Return message: ' || l_msg_data);
128 
129   if FND_MSG_PUB.Count_Msg > 0 then
130     FND_MSG_PUB.Reset;
131     --dbms_output.put_line('Messages: ');
132     for i in 1 .. FND_MSG_PUB.Count_Msg loop
133       l_buffer_tbl(i + l_index) := FND_MSG_PUB.GET(p_encoded=>FND_API.G_FALSE);
134       --dbms_output.put_line(to_char(i) || substr(l_buffer_tbl(i),1,256) );
135     end loop;
136     FND_MSG_PUB.Initialize;
137   end if;
138   --
139   -- Add ending to log file
140   --
141   l_index := nvl(l_buffer_tbl.last,0) + 1;
142   l_buffer_tbl(l_index) := '**********';
143   l_index := l_index + 1;
144   l_buffer_tbl(l_index) := to_char(sysdate, 'DY MM DD YYYY HH24:MI:SS');
145   l_index := l_index + 1;
146   FND_MESSAGE.SET_NAME('AK','AK_END_UPLOAD_SESSION');
147   l_buffer_tbl(l_index) := FND_MESSAGE.GET;
148   --
149   -- Write all messages to a log file
150   --
151   AK_ON_OBJECTS_PVT.WRITE_LOG_FILE (
152     p_return_status => l_return_status,
153     p_buffer_tbl => l_buffer_tbl,
154     p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
155   );
156   if (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) or
157      (l_return_status = FND_API.G_RET_STS_ERROR) then
158     RAISE FND_API.G_EXC_ERROR;
159   end if;
160 
161 EXCEPTION
162   WHEN FND_API.G_EXC_ERROR THEN
163     p_return_status := FND_API.G_RET_STS_ERROR;
164   WHEN OTHERS THEN
165     p_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
166     FND_MSG_PUB.Build_Exc_Msg( G_PKG_NAME, l_api_name,
167                            SUBSTR (SQLERRM, 1, 240) );
168     FND_MSG_PUB.Add;
169   if FND_MSG_PUB.Count_Msg > 0 then
170     FND_MSG_PUB.Reset;
171     if ( l_index is null ) then l_index := 0; end if;
172     for i in 1 .. FND_MSG_PUB.Count_Msg loop
173       l_buffer_tbl(i + l_index) := FND_MSG_PUB.GET(p_encoded=>FND_API.G_FALSE);
174       --dbms_output.put_line(to_char(i) || substr(l_buffer_tbl(i),1,256) );
175     end loop;
176     FND_MSG_PUB.Initialize;
177   end if;
178   --
179   -- Add ending to log file
180   --
181   l_index := nvl(l_buffer_tbl.last,0) + 1;
182   l_buffer_tbl(l_index) := '**********';
183   l_index := l_index + 1;
184   l_buffer_tbl(l_index) := to_char(sysdate, 'DY MM DD YYYY HH24:MI:SS');
185   l_index := l_index + 1;
186   FND_MESSAGE.SET_NAME('AK','AK_END_UPLOAD_SESSION');
187   l_buffer_tbl(l_index) := FND_MESSAGE.GET;
188   --
189   -- Write all messages to a log file
190   --
191   AK_ON_OBJECTS_PVT.WRITE_LOG_FILE (
192     p_return_status => l_return_status,
193     p_buffer_tbl => l_buffer_tbl,
194     p_write_mode => AK_ON_OBJECTS_PUB.G_APPEND
195   );
196 
197 end UPLOAD;
198 end AK_UPLOAD_GRP;