DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKL_VENDOR_AGREEMENT_PUB

Source


1 PACKAGE BODY OKL_VENDOR_AGREEMENT_PUB AS
2 /*$Header: OKLPVAGB.pls 120.4 2009/05/27 22:29:30 sechawla ship $*/
3 /*
4 *  Following is the generic program flow
5 *  -------------------------------------
6 *  Create Vendor Agreement Header - First Step
7 *  Create Party Role - Second Step
8 *  Create Contact Role - Third Step
9 *  Create Rule Group - Fourth Step
10 *  Create Terms and Conditions - Fifth Step
11 *  Create Articles - Sixth Step
12 */
13 
14 
15 PROCEDURE create_vendor_agreement (
16 				          p_api_version     	    IN NUMBER,
17                           p_init_msg_list           IN VARCHAR2 DEFAULT OKL_API.G_FALSE,
18                           p_hdr_rec                 IN program_header_rec,
19                           p_parent_agreement_number IN VARCHAR2 DEFAULT NULL,
20                           p_party_role_contact_tbl  IN party_role_contact_tbl,
21 			              p_vendor_billing_rec	    IN VENDOR_BILLING_REC,
22                           p_terms_n_conditions_tbl  IN TERMS_AND_CONDITIONS_TBL,
23                           p_article_tbl	          IN article_tbl,
24                           x_return_status           OUT NOCOPY VARCHAR2,
25                           x_msg_count               OUT NOCOPY NUMBER,
26                           x_msg_data                OUT NOCOPY VARCHAR2
27 					)
28 AS
29 
30   l_api_name    	VARCHAR2(35)    := 'CREATE_VENDOR_AGREEMENT';
31   lx_header_rec	chrv_rec_type;
32   lx_k_header_rec khrv_rec_type;
33   l_chr_id      	NUMBER := NULL;
34   l_line_id     	NUMBER := NULL;
35   l_cpl_id      	NUMBER := NULL;
36   l_rrd_id      	NUMBER := NULL;
37   l_cplv_tbl    	cplv_tbl_type;
38   lx_cplv_tbl   	cplv_tbl_type;
39   l_cplv_rec    	cplv_rec_type;
40   lx_cplv_rec    	cplv_rec_type;
41   l_ctcv_tbl    	ctcv_tbl_type;
42   lx_ctcv_tbl   	ctcv_tbl_type;
43   l_jtot_object1_code OKC_K_PARTY_ROLES_V.jtot_object1_code%TYPE;
44   l_jtot_object1_code_contact OKC_CONTACTS_V.jtot_object1_code%TYPE;
45   l_rgpv_tbl    	rgpv_tbl_type;
46   lx_rgpv_tbl   	rgpv_tbl_type;
47   l_rgr_tbl     	rgr_tbl_type;
48   l_catv_tbl    	catv_tbl_type;
49   lx_catv_tbl    	catv_tbl_type;
50 
51   j NUMBER := 0;
52   k NUMBER := 0;
53 
54   l_msg_index_out number;
55   l_dummy NUMBER;
56 
57 -- Get Party  Type
58 CURSOR get_party_role_jtot (p_rle_code IN VARCHAR2, p_category IN VARCHAR2) IS
59 	SELECT rso.jtot_object_code
60       FROM   okc_subclass_roles sre,
61              okc_role_sources rso
62       WHERE  sre.scs_code = p_category
63       AND    rso.rle_code = sre.rle_code
64       AND    rso.rle_code = p_rle_code
65       AND    rso.buy_or_sell = 'S';
66 
67 -- Get Contact Type
68 CURSOR get_contact_role_jtot (p_party_role_code IN VARCHAR2,
69                               p_contact_role_code IN VARCHAR2) IS
70 	SELECT jtot_object_code
71 	FROM   okc_contact_sources
72 	WHERE  rle_code = p_party_role_code
73 	AND    buy_or_sell = 'S'
74 	AND    CRO_CODE = p_contact_role_code;
75 
76 -- Get CPL ID
77 CURSOR get_party_role_id (p_party_role_code IN VARCHAR2,
78 				  p_party_role_id IN NUMBER,
79 				  p_chr_id IN NUMBER) IS
80 	SELECT id
81 	FROM   OKC_K_PARTY_ROLES_B
82 	WHERE  chr_id = p_chr_id
83 	AND    object1_id1 = p_party_role_id
84 	AND    rle_code = p_party_role_code;
85 
86 -- Get RRD ID for Vendor Billing association
87 CURSOR get_rrd_id IS
88     select id
89     from okc_rg_role_defs
90     where sre_id = (select id
91                     from okc_subclass_roles
92                     where scs_code = 'PROGRAM' and rle_code = 'OKL_VENDOR')
93     and srd_id = (  select id
94                     from okc_subclass_rg_defs
95                     where scs_code = 'PROGRAM' and rgd_code = 'LAVENB');
96 
97 -- Get Article ID and Release
98 l_sae_id NUMBER := NULL;
99 
100 CURSOR get_article (p_name IN VARCHAR2, p_version IN VARCHAR2) IS
101 	select sar.id
102 	from   okc_std_articles_v sar,
103 	       okc_std_art_versions_v svr
104 	where  sar.id = svr.sae_id
105 	and    sar.name = p_name
106 	and    svr.sav_release = p_version;
107 
108 --27-May-2009 sechawla 6826580 : added
109 CURSOR l_invoice_formats(cp_inv_fmt_name IN VARCHAR2) IS
110    SELECT ID
111    FROM   okl_invoice_formats_v
112    WHERE  name = cp_inv_fmt_name;
113 
114    l_inv_fmt_id  NUMBER;
115 
116 BEGIN
117   x_return_status := FND_API.G_RET_STS_SUCCESS;
118   x_return_status := OKL_API.START_ACTIVITY(p_api_name      => l_api_name
119                                             ,p_init_msg_list => p_init_msg_list
120                                             ,p_api_type      => '_PUB'
121                                             ,x_return_status => x_return_status);
122   IF x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR THEN
123     RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
124   ELSIF x_return_status = OKL_API.G_RET_STS_ERROR THEN
125     RAISE OKL_API.G_EXCEPTION_ERROR;
126   END IF;
127 
128   /* Agreement Header */
129   OKL_VENDOR_PROGRAM_PUB.create_program (p_api_version 			=> p_api_version,
130                                          p_init_msg_list 		=> p_init_msg_list,
131                                          x_return_status 		=> x_return_status,
132                                          x_msg_count			=> x_msg_count,
133                                          x_msg_data             => x_msg_data,
134                                          p_hdr_rec             	=> p_hdr_rec,
135                                          p_parent_agreement_number 	=> p_parent_agreement_number,
136                                          x_header_rec			=> lx_header_rec,
137                                          x_k_header_rec         => lx_k_header_rec);
138   IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
139     RAISE OKC_API.G_EXCEPTION_ERROR;
140   END IF;
141 
142   /* Party Role */
143   IF (p_party_role_contact_tbl.count > 0) THEN
144 	k := 1;
145 	FOR i IN p_party_role_contact_tbl.FIRST..p_party_role_contact_tbl.LAST
146 	LOOP
147       -- Following check avoids calling party API because lease vendor is
148       -- created as part of header in the previous step, but creates additional
149       -- parties.
150       IF (p_party_role_contact_tbl(i).party_role_code = 'OKL_VENDOR' AND
151 	      p_party_role_contact_tbl(i).contact_role_code IS NOT NULL AND
152 	      p_party_role_contact_tbl(i).contact_role_id IS NOT NULL) THEN
153 		  NULL;
154 	  ELSE
155         -- Following check avoids same party being created twice,
156         -- but allows for more contacts for the same party in the
157         -- next step for 'party contact' creation
158         l_dummy := 0;
159         FOR z IN 1..k-1
160         LOOP
161           IF (l_cplv_tbl(z).rle_code = p_party_role_contact_tbl(i).party_role_code AND
162               l_cplv_tbl(z).object1_id1 = p_party_role_contact_tbl(i).party_role_id) THEN
163               l_dummy := 1;
164           END IF;
165         END LOOP;
166 
167         IF (l_dummy = 0) THEN
168             l_cplv_tbl(k).chr_id      := lx_header_rec.id;
169             l_cplv_tbl(k).dnz_chr_id  := lx_header_rec.id;
170       	    l_cplv_tbl(k).rle_code    := p_party_role_contact_tbl(i).party_role_code;
171             l_cplv_tbl(k).object1_id1 := p_party_role_contact_tbl(i).party_role_id;
172   	        l_cplv_tbl(k).object1_id2 := '#';
173        	    -- Get Party Type 'OKX_PARTY', 'OKX_VENDOR' etc.
174    	        OPEN  get_party_role_jtot ( p_party_role_contact_tbl(i).party_role_code,
175                                        lx_header_rec.scs_code);
176    	        FETCH get_party_role_jtot INTO l_jtot_object1_code;
177    	        CLOSE get_party_role_jtot;
178 
179             l_cplv_tbl(k).jtot_object1_code   := l_jtot_object1_code;
180    			k := k+1;
181         END IF;
182       END IF;
183     END LOOP;
184 	OKL_CONTRACT_PARTY_PUB.create_k_party_role(p_api_version	=> p_api_version,
185                                                p_init_msg_list	=> p_init_msg_list,
186                                                x_return_status	=> x_return_status,
187                                                x_msg_count	=> x_msg_count,
188                                                x_msg_data	=> x_msg_data,
189                                                p_cplv_tbl	=> l_cplv_tbl,
190                                                x_cplv_tbl	=> lx_cplv_tbl);
191 	IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
192 	  RAISE OKC_API.G_EXCEPTION_ERROR;
193 	END IF;
194   END IF;
195 
196   /* Party Contact */
197   IF(p_party_role_contact_tbl.count > 0) THEN
198     k := 0;
199     FOR i IN p_party_role_contact_tbl.FIRST..p_party_role_contact_tbl.LAST
200     LOOP
201       -- rabhupat BUG#4574673/#4593854 start
202       -- populate the contact table only when the contact information is provided
203       IF(p_party_role_contact_tbl(i).contact_role_code IS NOT NULL AND p_party_role_contact_tbl(i).contact_role_code <> OKL_API.G_MISS_CHAR AND
204          p_party_role_contact_tbl(i).contact_role_id IS NOT NULL AND p_party_role_contact_tbl(i).contact_role_id <> OKL_API.G_MISS_NUM) THEN
205       -- rabhupat BUG#4574673/#4593854 end
206          -- Get Party Role ID
207          OPEN get_party_role_id (p_party_role_contact_tbl(i).party_role_code,
208                                  p_party_role_contact_tbl(i).party_role_id,
209                                  lx_header_rec.id);
210          FETCH get_party_role_id INTO l_cpl_id;
211          CLOSE get_party_role_id;
212          -- Get Contact Type 'OKX_SALEPERS' etc.
213          OPEN get_contact_role_jtot (p_party_role_contact_tbl(i).party_role_code,
214                                      p_party_role_contact_tbl(i).contact_role_code);
215          FETCH get_contact_role_jtot INTO l_jtot_object1_code_contact;
216          CLOSE get_contact_role_jtot;
217          k := k+1;
218          l_ctcv_tbl(k).dnz_chr_id := lx_header_rec.id;
219          l_ctcv_tbl(k).cpl_id := l_cpl_id;
220          l_ctcv_tbl(k).cro_code := p_party_role_contact_tbl(i).contact_role_code;
221          l_ctcv_tbl(k).object1_id1 := p_party_role_contact_tbl(i).contact_role_id;
222          l_ctcv_tbl(k).object1_id2 := '#';
223          l_ctcv_tbl(k).jtot_object1_code := l_jtot_object1_code_contact;
224        END IF;
225     END LOOP;
226     OKL_CONTRACT_PARTY_PUB.create_contact(p_api_version   => p_api_version,
227                                           p_init_msg_list => p_init_msg_list,
228                                           x_return_status => x_return_status,
229                                           x_msg_count     => x_msg_count,
230                                           x_msg_data      => x_msg_data,
231                                           p_ctcv_tbl      => l_ctcv_tbl,
232                                           x_ctcv_tbl      => lx_ctcv_tbl);
233     IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
234  	  RAISE OKC_API.G_EXCEPTION_ERROR;
235 	END IF;
236   END IF;
237   /* Terms and Conditions */
238   IF (p_terms_n_conditions_tbl.count > 0) THEN
239     FOR i IN p_terms_n_conditions_tbl.FIRST..p_terms_n_conditions_tbl.LAST
240     LOOP
241       l_rgr_tbl(i).rgd_code	:= p_terms_n_conditions_tbl(i).rule_group_code;
242       l_rgr_tbl(i).RULE_INFORMATION_CATEGORY  := p_terms_n_conditions_tbl(i).rule_code;
243       l_rgr_tbl(i).object1_id1:= p_terms_n_conditions_tbl(i).object1_id1;
244       l_rgr_tbl(i).object2_id1:= p_terms_n_conditions_tbl(i).object2_id1;
245       l_rgr_tbl(i).object3_id1:= p_terms_n_conditions_tbl(i).object3_id1;
246       l_rgr_tbl(i).object1_id2:= p_terms_n_conditions_tbl(i).object1_id2;
247       l_rgr_tbl(i).object2_id2:= p_terms_n_conditions_tbl(i).object2_id2;
248       l_rgr_tbl(i).object3_id2:= p_terms_n_conditions_tbl(i).object3_id2;
249       l_rgr_tbl(i).jtot_object1_code:= p_terms_n_conditions_tbl(i).jtot_object1_code;
250       l_rgr_tbl(i).jtot_object2_code:= p_terms_n_conditions_tbl(i).jtot_object2_code;
251       l_rgr_tbl(i).jtot_object3_code:= p_terms_n_conditions_tbl(i).jtot_object3_code;
252       l_rgr_tbl(i).std_template_yn := 'N';
253       l_rgr_tbl(i).warn_yn := 'N';
254       l_rgr_tbl(i).rule_information1 := p_terms_n_conditions_tbl(i).rule_information1;
255       l_rgr_tbl(i).rule_information2 := p_terms_n_conditions_tbl(i).rule_information2;
256       l_rgr_tbl(i).rule_information3 := p_terms_n_conditions_tbl(i).rule_information3;
257       l_rgr_tbl(i).rule_information4 := p_terms_n_conditions_tbl(i).rule_information4;
258       l_rgr_tbl(i).rule_information5 := p_terms_n_conditions_tbl(i).rule_information5;
259       l_rgr_tbl(i).rule_information6 := p_terms_n_conditions_tbl(i).rule_information6;
260       l_rgr_tbl(i).rule_information7 := p_terms_n_conditions_tbl(i).rule_information7;
261       l_rgr_tbl(i).rule_information8 := p_terms_n_conditions_tbl(i).rule_information8;
262       l_rgr_tbl(i).rule_information9 := p_terms_n_conditions_tbl(i).rule_information9;
263       l_rgr_tbl(i).rule_information10 := p_terms_n_conditions_tbl(i).rule_information10;
264       l_rgr_tbl(i).rule_information11 := p_terms_n_conditions_tbl(i).rule_information11;
265       l_rgr_tbl(i).rule_information12 := p_terms_n_conditions_tbl(i).rule_information12;
266       l_rgr_tbl(i).rule_information13 := p_terms_n_conditions_tbl(i).rule_information13;
267       l_rgr_tbl(i).rule_information14 := p_terms_n_conditions_tbl(i).rule_information14;
268       l_rgr_tbl(i).rule_information15 := p_terms_n_conditions_tbl(i).rule_information15;
269       l_rgr_tbl(i).template_yn := 'N';
270     END LOOP;
271     l_line_id := NULL;
272     l_cpl_id:= NULL;
273     l_rrd_id:= NULL;
274 
275     OKL_RGRP_RULES_PROCESS_PUB.process_rule_group_rules(p_api_version	=> p_api_version,
276                                                         p_init_msg_list   => p_init_msg_list,
277                                                         x_return_status   => x_return_status,
278                                                         x_msg_count       => x_msg_count,
279                                                         x_msg_data        => x_msg_data,
280                                                         p_chr_id          => lx_header_rec.id,
281                                                         p_line_id         => l_line_id,
282                                                         p_cpl_id          => l_cpl_id,
283                                                         p_rrd_id          => l_rrd_id,
284                                                         p_rgr_tbl         => l_rgr_tbl);
285     IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
286       RAISE OKC_API.G_EXCEPTION_ERROR;
287     END IF;
288   END IF;
289 
290   /* Vendor Billing */
291   -- rabhupat bug#4520143/#4530455 added G_MISS check
292   IF (p_vendor_billing_rec.customer_id IS NOT NULL AND p_vendor_billing_rec.customer_id <> OKL_API.G_MISS_NUM AND
293       p_vendor_billing_rec.cust_acct_id IS NOT NULL AND p_vendor_billing_rec.cust_acct_id <> OKL_API.G_MISS_NUM AND
294       p_vendor_billing_rec.bill_to_site_use_id IS NOT NULL AND p_vendor_billing_rec.bill_to_site_use_id <> OKL_API.G_MISS_NUM) THEN
295 
296       l_cplv_rec.cust_acct_id        := p_vendor_billing_rec.cust_acct_id;
297       l_cplv_rec.bill_to_site_use_id := p_vendor_billing_rec.bill_to_site_use_id;
298       -- Get Party Role Record ID
299       OPEN  get_party_role_id('OKL_VENDOR', to_number(p_hdr_rec.P_OBJECT1_ID1),lx_header_rec.id );
300       FETCH get_party_role_id INTO l_cpl_id;
301       CLOSE get_party_role_id;
302       l_cplv_rec.id := l_cpl_id;
303       OKL_CONTRACT_PARTY_PUB.update_k_party_role(
304                     p_api_version	=> p_api_version,
305                     p_init_msg_list	=> p_init_msg_list,
306                     x_return_status	=> x_return_status,
307                     x_msg_count	=> x_msg_count,
308                     x_msg_data	=> x_msg_data,
309                     p_cplv_rec	=> l_cplv_rec,
310                     x_cplv_rec	=> lx_cplv_rec);
311       IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
312         RAISE OKC_API.G_EXCEPTION_ERROR;
313       END IF;
314       l_rgr_tbl.DELETE;
315       -- Process Customer ID
316       -- rabhupat bug#4520143 removed the redundent condition
317       j := 1;
318       l_rgr_tbl(j).rgd_code	:= 'LAVENB';
319       l_rgr_tbl(j).RULE_INFORMATION_CATEGORY := 'LAVENC';
320       l_rgr_tbl(j).object1_id1:= to_char(p_vendor_billing_rec.customer_id);
321       l_rgr_tbl(j).object1_id2:= NULL;
322       l_rgr_tbl(j).jtot_object1_code:= 'OKX_PARTY';
323       l_rgr_tbl(j).std_template_yn := 'N';
324       l_rgr_tbl(j).warn_yn := 'N';
325       l_rgr_tbl(j).rule_information1 := NULL;
326       l_rgr_tbl(j).rule_information2 := NULL;
327       l_rgr_tbl(j).rule_information3 := NULL;
328       l_rgr_tbl(j).rule_information4 := NULL;
329       l_rgr_tbl(j).template_yn := 'N';
330       -- Get RRD ID
331       OPEN get_rrd_id ;
332       FETCH get_rrd_id INTO l_rrd_id;
333       CLOSE get_rrd_id ;
334       -- Line ID is NULL
335       l_line_id := NULL;
336       -- Process Payment Method
337       j := j+1;
338       l_rgr_tbl(j).rgd_code	:= 'LAVENB';
339       l_rgr_tbl(j).RULE_INFORMATION_CATEGORY := 'LAPMTH';
340       -- rabhupat BUG#4574673 start
341       -- populate the information if payment method is passed
342       IF(p_vendor_billing_rec.PAYMENT_METHOD IS NOT NULL AND p_vendor_billing_rec.PAYMENT_METHOD <> OKL_API.G_MISS_NUM) THEN
343          l_rgr_tbl(j).object1_id1:= p_vendor_billing_rec.PAYMENT_METHOD;
344          l_rgr_tbl(j).object1_id2:= '#';
345          l_rgr_tbl(j).jtot_object1_code:= 'OKX_RCPTMTH';
346       END IF;
347       l_rgr_tbl(j).std_template_yn := 'N';
348       l_rgr_tbl(j).warn_yn := 'N';
349       l_rgr_tbl(j).template_yn := 'N';
350       -- Process Bank Account
351       j := j+1;
352       l_rgr_tbl(j).rgd_code	:= 'LAVENB';
353       l_rgr_tbl(j).RULE_INFORMATION_CATEGORY := 'LABACC';
354       -- rabhupat BUG#4574673 start
355       -- populate the information if bank account is passed
356       IF(p_vendor_billing_rec.bank_account IS NOT NULL AND p_vendor_billing_rec.bank_account <> OKL_API.G_MISS_NUM) THEN
357         l_rgr_tbl(j).object1_id1:= p_vendor_billing_rec.bank_account;
358         l_rgr_tbl(j).object1_id2:= '#';
359         l_rgr_tbl(j).jtot_object1_code:= 'OKX_CUSTBKAC';
360       END IF;
361       l_rgr_tbl(j).std_template_yn := 'N';
362       l_rgr_tbl(j).warn_yn := 'N';
363       l_rgr_tbl(j).template_yn := 'N';
364       -- Process Invoice Format
365       j := j+1;
366       l_rgr_tbl(j).rgd_code	:= 'LAVENB';
367       l_rgr_tbl(j).RULE_INFORMATION_CATEGORY := 'LAINVD';
368       l_rgr_tbl(j).object1_id1:= NULL;
369       l_rgr_tbl(j).object1_id2:= NULL;
370       l_rgr_tbl(j).jtot_object1_code:= NULL;
371       l_rgr_tbl(j).std_template_yn := 'N';
372       l_rgr_tbl(j).warn_yn := 'N';
373 
374       --27-May-2009 sechawla 6826580 : added
375       OPEN   l_invoice_formats(p_vendor_billing_rec.invoice_format);
376       FETCH  l_invoice_formats INTO l_inv_fmt_id;
377       CLOSE  l_invoice_formats;
378 
379       --27-May-2009 sechawla 6826580 : store ID instead of Name
380       l_rgr_tbl(j).rule_information1 := to_char(l_inv_fmt_id); --p_vendor_billing_rec.invoice_format;
381 
382       l_rgr_tbl(j).template_yn := 'N';
383       -- Process Review Invoice flag
384       -- rabhupat BUG#4574673 start
385       -- if review invoice falg is not checked passing 'N'
386       IF(p_vendor_billing_rec.review_invoice IS NOT NULL AND p_vendor_billing_rec.review_invoice <> OKL_API.G_MISS_CHAR) THEN
387         l_rgr_tbl(j).rule_information4 := p_vendor_billing_rec.review_invoice;
388       ELSE
389         l_rgr_tbl(j).rule_information4 := 'N';
390       END IF;
391       -- Process Review Invoice reason
392       j := j+1;
393       l_rgr_tbl(j).rgd_code	:= 'LAVENB';
394       l_rgr_tbl(j).RULE_INFORMATION_CATEGORY := 'LAINPR';
395       l_rgr_tbl(j).object1_id1:= NULL;
396       l_rgr_tbl(j).object1_id2:= NULL;
397       l_rgr_tbl(j).jtot_object1_code:= NULL;
398       l_rgr_tbl(j).std_template_yn := 'N';
399       l_rgr_tbl(j).warn_yn := 'N';
400       l_rgr_tbl(j).rule_information1 := p_vendor_billing_rec.review_reason;
401       l_rgr_tbl(j).template_yn := 'N';
402       -- Process Review Invoice Date
403       -- rabhupat BUG#4574673 start
404       -- populate the information if review until date is passed
405       IF(p_vendor_billing_rec.review_until_date IS NOT NULL AND p_vendor_billing_rec.review_until_date <> OKL_API.G_MISS_DATE) THEN
406         l_rgr_tbl(j).rule_information2 := p_vendor_billing_rec.review_until_date;
407       END IF;
408       -- Process Rule Groups and Rules for vendor billing
409       -- and associate it with the vendor party role
410       OKL_RGRP_RULES_PROCESS_PUB.process_rule_group_rules(
411 	      p_api_version	=> p_api_version,
412 	      p_init_msg_list   => p_init_msg_list,
413 	      x_return_status   => x_return_status,
414 	      x_msg_count       => x_msg_count,
415 	      x_msg_data        => x_msg_data,
416 	      p_chr_id          => lx_header_rec.id,
417 	      p_line_id         => l_line_id,
418 	      p_cpl_id          => l_cpl_id,
419 	      p_rrd_id          => l_rrd_id,
420 	      p_rgr_tbl         => l_rgr_tbl);
421       IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
422          RAISE OKC_API.G_EXCEPTION_ERROR;
423       END IF;
424   END IF;
425   /* Article */
426   IF (p_article_tbl.count > 0) THEN
427     FOR i IN p_article_tbl.FIRST..p_article_tbl.LAST
428     LOOP
429       l_catv_tbl(i).cat_type := 'STA';
430       l_catv_tbl(i).fulltext_yn := 'Y';
431       OPEN get_article (p_article_tbl(i).article_name, p_article_tbl(i).version);
432       FETCH get_article INTO l_sae_id;
433       CLOSE get_article;
434       l_catv_tbl(i).SAV_SAE_ID := l_sae_id;
435       l_catv_tbl(i).SAV_SAV_RELEASE := p_article_tbl(i).version;
436       l_catv_tbl(i).chr_id := lx_header_rec.id;
437       l_catv_tbl(i).dnz_chr_id := lx_header_rec.id;
438       l_catv_tbl(i).name := p_article_tbl(i).article_name;
439     END LOOP;
440     OKL_VP_K_ARTICLE_PUB.create_k_article(
441 				   p_api_version		=> p_api_version,
442                            p_init_msg_list	=> p_init_msg_list,
443                            x_return_status	=> x_return_status,
444                            x_msg_count		=> x_msg_count,
445                            x_msg_data		=> x_msg_data,
446                            p_catv_tbl		=> l_catv_tbl,
447                            x_catv_tbl		=> lx_catv_tbl);
448     IF (x_return_status <> OKC_API.G_RET_STS_SUCCESS) THEN
449        RAISE OKC_API.G_EXCEPTION_ERROR;
450     END IF;
451   END IF;
452 
453 OKL_API.END_ACTIVITY(x_msg_count     => x_msg_count
454                       ,x_msg_data      => x_msg_data );
455 
456   EXCEPTION
457      WHEN OKC_API.G_EXCEPTION_ERROR THEN
458 
459      --27-May-2009 sechawla 6826580
460      IF l_invoice_formats%ISOPEN THEN
461         CLOSE l_invoice_formats;
462      END IF;
463 
464        x_return_status := OKC_API.HANDLE_EXCEPTIONS
465        (substr(l_api_name,1,26),
466         G_PKG_NAME,
467         'OKC_API.G_RET_STS_ERROR',
468         x_msg_count,
469         x_msg_data,
470         '_PUB');
471      WHEN OKC_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
472 
473      --27-May-2009 sechawla 6826580
474      IF l_invoice_formats%ISOPEN THEN
475         CLOSE l_invoice_formats;
476      END IF;
477 
478        x_return_status := OKC_API.HANDLE_EXCEPTIONS
479        (substr(l_api_name,1,26),
480         G_PKG_NAME,
481         'OKC_API.G_RET_STS_UNEXP_ERROR',
482         x_msg_count,
483         x_msg_data,
484         '_PUB');
485      WHEN OTHERS THEN
486 
487      --27-May-2009 sechawla 6826580
488      IF l_invoice_formats%ISOPEN THEN
489         CLOSE l_invoice_formats;
490      END IF;
491 
492        x_return_status := OKC_API.HANDLE_EXCEPTIONS
493        (substr(l_api_name,1,26),
494         G_PKG_NAME,
495         'OTHERS',
496         x_msg_count,
497         x_msg_data,
498         '_PUB');
499 
500 END create_vendor_agreement;
501 
502 END;