You are on page 1of 5

18 Declare

19 ld_effective_date date := to_date('01-JAN-1951','DD-MON-


YYYY');
20 ld_effective_end_date date;
21 ld_effective_start_date date;
22 ln_BALANCE_NAME number;
23 ln_business_group_id number;
24 ln_COLUMN_NAME number;
25 ln_DIMENSION number;
26 ln_KUBE_TYPE number;
27 ln_maxrows number := 0;
28 ln_myitems number := 0;
29 ln_row_id number;
30 ln_row_ovn number;
31 ln_row_sequence number;
32 ln_sequence number := 0;
33 ln_user_column_instance_id number;
34 ln_user_row_id number;
35 ln_user_table_id number;
36 ln_value_ovn number;
37 lv_COLUMN_NAME varchar2(150);
38 lv_leg_code varchar2(2);
39 lv_myBusiness_group_name varchar2(240) := 'Kinetic Concepts, Inc.';
40 lv_myTag varchar2(30) := '/401k Audit/';
41 --
42 cursor c_existing_udt_content(p_business_group_id in number) IS
43 select cinst1.value as KUBE_TYPE,
44 bt.balance_name as BALANCE_NAME,
45 bt.balance_type_id as BALANCE_TYPE_ID,
46 cinst3.value as COLUMN_NAME,
47 cinst4.value as DIMENSION,
48 to_number(substr(r.row_low_range_or_name,2)) as SEQUENCE
49 from pay_user_tables t
50 ,pay_user_rows_f r
51 ,pay_user_columns c1
52 ,pay_user_columns c2
53 ,pay_user_columns c3
54 ,pay_user_columns c4
55 ,pay_user_column_instances_f cinst1
56 ,pay_user_column_instances_f cinst2
57 ,pay_user_column_instances_f cinst3
58 ,pay_user_column_instances_f cinst4
59 ,pay_balance_types bt
60 ,per_business_groups pbg
61 where pbg.business_group_id = p_business_group_id
62 and nvl(bt.business_group_id, pbg.business_group_id) =
pbg.business_group_id
63 and nvl(bt.legislation_code, pbg.legislation_code) = pbg.legislation_code
64 and t.user_table_name = 'KBDX_EBDW_BALANCE_SUM_SOURCE'
65 and t.business_group_id = pbg.business_group_id
66 and t.user_table_id = r.user_table_id
67 and r.user_row_id = cinst1.user_row_id and t.user_table_id =
c1.user_table_id
68 and c1.user_column_name = 'KUBE_TYPE' and c1.user_column_id =
cinst1.user_column_id
69 and r.user_row_id = cinst2.user_row_id and t.user_table_id =
c2.user_table_id
70 and c2.user_column_name = 'BALANCE_NAME' and c2.user_column_id =
cinst2.user_column_id
71 and r.user_row_id = cinst3.user_row_id and t.user_table_id =
c3.user_table_id
72 and c3.user_column_name = 'COLUMN_NAME' and c3.user_column_id =
cinst3.user_column_id
73 and r.user_row_id = cinst4.user_row_id and t.user_table_id =
c4.user_table_id
74 and c4.user_column_name = 'DIMENSION' and c4.user_column_id =
cinst4.user_column_id
75 and upper(cinst2.value) = upper(bt.balance_name)
76 AND trunc(sysdate) BETWEEN r.effective_start_date
77 AND r.effective_end_date
78 AND trunc(sysdate) BETWEEN cinst1.effective_start_date
79 AND cinst1.effective_end_date
80 AND trunc(sysdate) BETWEEN cinst2.effective_start_date
81 AND cinst2.effective_end_date
82 AND trunc(sysdate) BETWEEN cinst3.effective_start_date
83 AND cinst3.effective_end_date
84 AND trunc(sysdate) BETWEEN cinst4.effective_start_date
85 AND cinst4.effective_end_date;
86 --
87 cursor c_column_id(p_user_table_id in number) IS
88 select user_column_name,user_column_id from pay_user_columns
89 where user_table_id = p_user_table_id and user_column_name in
('KUBE_TYPE','BALANCE_NAME','COLUMN_NAME','DIMENSION');
90 --
91 cursor c_row_id(p_user_table_id in number) IS
92 select user_row_id from hr.pay_user_rows_f where user_table_id =
p_user_table_id;
93 --
94 cursor myTAG IS
95 select lv_myTag KUBE_TYPE,bt.balance_name,'Balances' COLUMN_NAME,'X'
DIMENSION
96 from pay_balance_types bt, per_business_groups pbg
97 where pbg.business_group_id = ln_business_group_id
98 and nvl(bt.business_group_id,pbg.business_group_id) = pbg.business_group_id
99 and nvl(bt.legislation_code,pbg.legislation_code) = pbg.legislation_code
100 and bt.balance_name in (
101 'Gross Earnings',
102 'Pre Tax Deductions',
103 'Adjust 401k Contribution',
104 'KCI 401k Roth',
105 'KCI 401k Roth Catchup',
106 'KCI 401k Roth ER',
107 'Loan 1 401k',
108 'Pretax 401k',
109 'Pretax 401k Catchup',
110 'Pretax 401k ER',
111 'Puerto Rico 401K',
112 'Puerto Rico 401K Catchup',
113 'Puerto Rico 401K ER',
114 'Puerto Rico 401K Loan',
115 'Puerto Rico 401K Total ER'
116 )
117 UNION ALL
118 select * from kbdx_gtt_balance_sum_source
119 ORDER BY 1,3,2;
120 --
121 Begin
122 select business_group_id into ln_business_group_id from per_business_groups
where upper(name) = upper(lv_myBusiness_group_name);
123 select legislation_code into lv_leg_code from per_business_groups where
business_group_id = ln_business_group_id;
124 --
125 select user_table_id into ln_user_table_id from pay_user_tables
126 where user_table_name = 'KBDX_EBDW_BALANCE_SUM_SOURCE' and
business_group_id = ln_business_group_id;
127 --
128 select max(display_sequence) into ln_maxrows from pay_user_rows_f where
user_table_id = ln_user_table_id;
129 --
130 For i in c_column_id(ln_user_table_id) LOOP
131 CASE i.user_column_name
132 WHEN 'KUBE_TYPE' THEN ln_KUBE_TYPE := i.user_column_id;
133 WHEN 'BALANCE_NAME' THEN ln_BALANCE_NAME := i.user_column_id;
134 WHEN 'COLUMN_NAME' THEN ln_COLUMN_NAME := i.user_column_id;
135 WHEN 'DIMENSION' THEN ln_DIMENSION := i.user_column_id;
136 END CASE;
137 End Loop;
138 --
139 -- copy only the other TAGS content of 'KBDX_EPBDM_BALANCE_SUM_SOURCE' UDT
so we can restore after lv_myTag refresh
140 --
141 kbdx_kube_utilities.truncate_gtt_table('KBDX_GTT_BALANCE_SUM_SOURCE',TRUE);
142 For i in c_existing_udt_content(ln_business_group_id) LOOP
143 If i.kube_type <> lv_myTag THEN
144 insert into
kbdx_gtt_balance_sum_source(KUBE_TYPE,BALANCE_NAME,COLUMN_NAME,DIMENSION)
145 values (i.kube_type,i.balance_name,i.column_name,i.dimension);
146 End If;
147 End Loop;
148
kbdx_kube_api_pkg.gather_kbace_table_stats('KBDX_GTT_BALANCE_SUM_SOURCE',TRUE);
149 --
150 -- Remove the values from our UDT
151 --
152 delete from pay_user_column_instances_f where user_column_instance_id in (
153 select user_column_instance_id from pay_user_column_instances_f where
user_row_id in (
154 select user_row_id from pay_user_rows_f where user_table_id =
ln_user_table_id)
155 and user_column_id in (select user_column_id from pay_user_columns where
user_table_id = ln_user_table_id));
156 --
157 -- count needed UDT rows
158 --
159 For i in myTAG LOOP
160 ln_myitems := ln_myitems + 1;
161 End Loop;
162 --
163 -- add additional UDT rows if needed
164 --
165 If ln_maxrows < ln_myitems THEN
166 FOR row IN ln_maxrows+1..ln_myitems LOOP
167 ln_row_sequence := row;
168 pay_user_row_api.create_user_row
169 (p_validate => false
170 ,p_effective_date => ld_effective_date
171 ,p_user_table_id => ln_user_table_id
172 ,p_row_low_range_or_name => 'R'||to_char(ln_row_sequence)
173 ,p_display_sequence => ln_row_sequence
174 ,p_business_group_id => ln_business_group_id
175 ,p_user_row_id => ln_row_id
176 ,p_object_version_number => ln_row_ovn
177 ,p_effective_start_date => ld_effective_start_date
178 ,p_effective_end_date => ld_effective_end_date
179 );
180 End Loop;
181 End If;
182 --
183 -- populate lv_myTag, the RPM '/RPM 401K/' TAG
184 --
185 For i in myTAG LOOP
186 --
187 ln_sequence := ln_sequence + 1;
188 select pur.user_row_id into ln_user_row_id from pay_user_rows_f pur
189 where pur.user_table_id = ln_user_table_id and pur.row_low_range_or_name
= 'R'||to_char(ln_sequence);
190 --
191 -- force COLUMN_NAME here if required
192 --
193 lv_COLUMN_NAME := i.COLUMN_NAME;
194 --
195 pay_user_column_instance_api.create_user_column_instance
196 (p_validate => false
197 ,p_effective_date => ld_effective_date
198 ,p_user_row_id => ln_user_row_id
199 ,p_user_column_id => ln_KUBE_TYPE
200 ,p_value => i.KUBE_TYPE
201 ,p_business_group_id => ln_business_group_id
202 ,p_user_column_instance_id => ln_user_column_instance_id
203 ,p_object_version_number => ln_value_ovn
204 ,p_effective_start_date => ld_effective_start_date
205 ,p_effective_end_date => ld_effective_end_date
206 );
207 --
208 pay_user_column_instance_api.create_user_column_instance
209 (p_validate => false
210 ,p_effective_date => ld_effective_date
211 ,p_user_row_id => ln_user_row_id
212 ,p_user_column_id => ln_BALANCE_NAME
213 ,p_value => i.BALANCE_NAME
214 ,p_business_group_id => ln_business_group_id
215 ,p_user_column_instance_id => ln_user_column_instance_id
216 ,p_object_version_number => ln_value_ovn
217 ,p_effective_start_date => ld_effective_start_date
218 ,p_effective_end_date => ld_effective_end_date
219 );
220 --
221 pay_user_column_instance_api.create_user_column_instance
222 (p_validate => false
223 ,p_effective_date => ld_effective_date
224 ,p_user_row_id => ln_user_row_id
225 ,p_user_column_id => ln_COLUMN_NAME
226 ,p_value => lv_COLUMN_NAME
227 ,p_business_group_id => ln_business_group_id
228 ,p_user_column_instance_id => ln_user_column_instance_id
229 ,p_object_version_number => ln_value_ovn
230 ,p_effective_start_date => ld_effective_start_date
231 ,p_effective_end_date => ld_effective_end_date
232 );
233 --
234 pay_user_column_instance_api.create_user_column_instance
235 (p_validate => false
236 ,p_effective_date => ld_effective_date
237 ,p_user_row_id => ln_user_row_id
238 ,p_user_column_id => ln_DIMENSION
239 ,p_value => i.DIMENSION
240 ,p_business_group_id => ln_business_group_id
241 ,p_user_column_instance_id => ln_user_column_instance_id
242 ,p_object_version_number => ln_value_ovn
243 ,p_effective_start_date => ld_effective_start_date
244 ,p_effective_end_date => ld_effective_end_date
245 );
246 --
247 End Loop;
248 --
249 End;
250 /
251* commit;
SQL> spool off;

You might also like