DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMI_VALIDATE_ALLOCATION_PVT

Source


1 PACKAGE BODY GMI_VALIDATE_ALLOCATION_PVT AS
2 /*  $Header: GMIVALVB.pls 115.8 2002/11/06 21:59:53 hwahdani ship $  */
3 
4 /*  Global variables */
5 G_PKG_NAME  CONSTANT  VARCHAR2(30):='GMI_VALIDATE_ALLOCATION_PVT';
6 
7 
8 /*  Proc start of comments
9  +=========================================================================+
10  | PROCEDURE NAME                                                          |
11  |    Validate_Input_Parameters                                            |
12  |                                                                         |
13  | DESCRIPTION                                                             |
14  |    Used to ensure that mandatory input parameters have been supplied    |
15  |                                                                         |
16  | PARAMETERS                                                              |
17  |  p_allocation_rec     IN  GMI_AUTO_ALLOCATE_PUB.gmi_allocation_rec      |
18  |  x_ic_item_mst_rec    OUT ic_item_mst%ROWTYPE                           |
19  |  x_ic_whse_mst_rec    OUT ic_whse_mst%ROWTYPE                           |
20  |  x_allocation_rec     OUT GMI_AUTO_ALLOCATE_PUB.gmi_allocation_rec      |
21  |  x_return_status      OUT VARCHAR2                                      |
22  |  x_msg_count          OUT NUMBER                                        |
23  |  x_msg_data           OUT VARCHAR2                                      |
24  |                                                                         |
25  | HISTORY                                                                 |
26  |    15-DEC-1999      K.Y.Hunt      Created                               |
27  +=========================================================================+
28   Proc end of comments
29 */
30 PROCEDURE VALIDATE_INPUT_PARMS
31 ( p_allocation_rec     IN  GMI_AUTO_ALLOCATE_PUB.gmi_allocation_rec
32 , x_ic_item_mst_rec    OUT NOCOPY ic_item_mst%ROWTYPE
33 , x_ic_whse_mst_rec    OUT NOCOPY ic_whse_mst%ROWTYPE
34 , x_allocation_rec     OUT NOCOPY GMI_AUTO_ALLOCATE_PUB.gmi_allocation_rec
35 , x_return_status      OUT NOCOPY VARCHAR2
36 , x_msg_count          OUT NOCOPY NUMBER
37 , x_msg_data           OUT NOCOPY VARCHAR2
38 )
39 IS
40 l_api_name           CONSTANT VARCHAR2 (30) := 'VALIDATE_INPUT_PARMS';
41 l_user_id            FND_USER.USER_ID%TYPE;
42 l_msg_count          NUMBER  :=0;
43 l_msg_data           VARCHAR2(2000);
44 l_return_status      VARCHAR2(1);
45 
46 CURSOR ic_item_mst_c1 IS
47 SELECT *
48 FROM
49   ic_item_mst
50 WHERE
51     item_no     = p_allocation_rec.item_no;
52 
53 
54 CURSOR ic_whse_mst_c1 IS
55 SELECT *
56 FROM
57   ic_whse_mst
58 WHERE
59     whse_code   = p_allocation_rec.whse_code and delete_mark=0;
60 BEGIN
61 
62   /*Initialize API return status to sucess
63   =======================================*/
64   x_return_status := FND_API.G_RET_STS_SUCCESS;
65 
66   /* Move input rec to local variable
67   ==================================*/
68   x_allocation_rec := p_allocation_rec;
69 
70   /*Check user
71   ===========*/
72   l_user_id := p_allocation_rec.user_id;
73 
74   /*Either ID or NAME must be supplied.  If both are blank then error.
75   ===================================================================*/
76   IF NOT GMI_VALIDATE_ALLOCATION_PVT.Validate_who(p_allocation_rec.user_id
77                                                  ,p_allocation_rec.user_name)
78   THEN
79     oe_debug_pub.add('OPM ALLOCATION - Validation fail on user',1);
80     FND_MESSAGE.SET_NAME('GML','GML_USER_ID_REQUIRED');
81     FND_MSG_PUB.Add;
82     RAISE FND_API.G_EXC_ERROR;
83   END IF;
84 
85   /*If USER_ID not supplied, retrieve it
86   =====================================*/
87   /* NC - 11/13/01 user_id 0 is a valid one( for sysadmin) . Removing the OR condition. */
88   IF (p_allocation_rec.user_id IS NULL )
89   THEN
90     GMA_GLOBAL_GRP.Get_who( p_user_name  => p_allocation_rec.user_name
91                           , x_user_id    => l_user_id
92                           );
93 
94     --IF l_user_id = 0   /* 0 user_id is a valid value */
95 
96     IF l_user_id is NULL
97     THEN
98       FND_MESSAGE.SET_NAME('GMI','SY_API_INVALID_USER_NAME');
99       FND_MESSAGE.SET_TOKEN('USER_NAME',p_allocation_rec.user_name);
100       FND_MSG_PUB.Add;
101       RAISE FND_API.G_EXC_ERROR;
102     END IF;
103   ELSE
104     l_user_id := p_allocation_rec.user_id;
105   END IF;
106 
107   x_allocation_rec.user_id := l_user_id;
108 
109   /* Check doc_id
110   ==============*/
111 /* dbms_output.put_line('Now do doc_id'); */
112   IF (p_allocation_rec.doc_id IS NULL)
113   THEN
114     oe_debug_pub.add('KYH ALLOCATION - Validation fail on doc id',1);
115     FND_MESSAGE.SET_NAME('GML','GML_DOC_ID_REQUIRED');
116     FND_MESSAGE.SET_TOKEN('ITEM_NO',p_allocation_rec.item_no);
117     FND_MSG_PUB.Add;
118     RAISE FND_API.G_EXC_ERROR;
119   END IF;
120 
121   /* Check line_id
122   ===============*/
123 /* dbms_output.put_line('Now check line_id'); */
124   IF (p_allocation_rec.line_id IS NULL)
125   THEN
126     oe_debug_pub.add('KYH ALLOCATION - Validation fail on line id',1);
127     FND_MESSAGE.SET_NAME('GML','GML_LINE_ID_REQUIRED');
128     FND_MESSAGE.SET_TOKEN('ITEM_NO',p_allocation_rec.item_no);
129     FND_MSG_PUB.Add;
130     RAISE FND_API.G_EXC_ERROR;
131   END IF;
132 
133   /* Check item_no
134   ===============*/
135   IF (p_allocation_rec.item_no = ' ' OR p_allocation_rec.item_no IS NULL)
136   THEN
137     oe_debug_pub.add('KYH ALLOCATION - Validation fail on item',1);
138     FND_MESSAGE.SET_NAME('GML','SO_E_ITM_REQUIRED');
139     FND_MSG_PUB.Add;
140     RAISE FND_API.G_EXC_ERROR;
141   END IF;
142 
143   /* Retrieve item attributes
144   ==========================*/
145   OPEN ic_item_mst_c1;
146   FETCH ic_item_mst_c1 INTO x_ic_item_mst_rec;
147   IF (ic_item_mst_c1%NOTFOUND)
148   THEN
149     CLOSE ic_item_mst_c1;
150     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
151   ELSE
152     CLOSE ic_item_mst_c1;
153   END IF;
154 
155   /*If errors found, then raise exception
156   ======================================*/
157   IF (x_ic_item_mst_rec.item_id = 0) OR
158         (x_ic_item_mst_rec.delete_mark = 1)
159   THEN
160     FND_MESSAGE.SET_NAME('GMI','IC_API_INVALID_ITEM_NO');
161     FND_MESSAGE.SET_TOKEN('ITEM_NO',p_allocation_rec.item_no);
162     FND_MSG_PUB.Add;
163     RAISE FND_API.G_EXC_ERROR;
164   ELSIF (x_ic_item_mst_rec.noninv_ind = 1)
165   THEN
166     oe_debug_pub.add('KYH ALLOCATION - noninv item',1);
167     FND_MESSAGE.SET_NAME('GMI','IC_API_NONINV_ITEM_NO');
168     FND_MESSAGE.SET_TOKEN('ITEM_NO',p_allocation_rec.item_no);
169     FND_MSG_PUB.Add;
170     RAISE FND_API.G_EXC_ERROR;
171   ELSIF (x_ic_item_mst_rec.inactive_ind = 1)
172   THEN
173     oe_debug_pub.add('KYH ALLOCATION - inactive item',1);
174     FND_MESSAGE.SET_NAME('GMI','IC_API_INACTIVE_ITEM_NO');
175     FND_MESSAGE.SET_TOKEN('ITEM_NO',p_allocation_rec.item_no);
176     FND_MSG_PUB.Add;
177     RAISE FND_API.G_EXC_ERROR;
178   ELSIF (x_ic_item_mst_rec.alloc_class IS NULL)
179   THEN
180     oe_debug_pub.add('KYH ALLOCATION - missing allocation class',1);
181     FND_MESSAGE.SET_NAME('GML','GML_API_MISSING_ALLOC_CLASS');
182     FND_MESSAGE.SET_TOKEN('ITEM_NO',p_allocation_rec.item_no);
183     FND_MSG_PUB.Add;
184     RAISE FND_API.G_EXC_ERROR;
185   END IF;
186 
187 
188   /* Check whse_code
189   =================*/
190   IF (p_allocation_rec.whse_code = ' ' OR p_allocation_rec.whse_code IS NULL)
191   THEN
192     oe_debug_pub.add('KYH ALLOCATION - missing whse code',1);
193     FND_MESSAGE.SET_NAME('GML','SO_E_WHSE_REQUIRED');
194     FND_MSG_PUB.Add;
195     RAISE FND_API.G_EXC_ERROR;
196   END IF;
197 
198   /*Retrieve warehouse attributes
199   ==============================*/
200   OPEN ic_whse_mst_c1;
201   FETCH ic_whse_mst_c1 INTO x_ic_whse_mst_rec;
202   IF (ic_whse_mst_c1%NOTFOUND)
203   THEN
204     CLOSE ic_whse_mst_c1;
205     FND_MESSAGE.SET_NAME('GMI','IC_API_INVALID_WHSE_CODE');
206     FND_MESSAGE.SET_TOKEN('WHSE_CODE', p_allocation_rec.whse_code);
207     FND_MSG_PUB.Add;
208     RAISE FND_API.G_EXC_ERROR;
209   ELSE
210     CLOSE ic_whse_mst_c1;
211   END IF;
212 
213 /*  Check co_code    */
214   IF (p_allocation_rec.co_code = ' ' OR p_allocation_rec.co_code IS NULL)
215   THEN
216     oe_debug_pub.add('KYH ALLOCATION - missing CO CODE',1);
217     FND_MESSAGE.SET_NAME('GML','GML_CO_CODE_REQUIRED');
218     FND_MSG_PUB.Add;
219     RAISE FND_API.G_EXC_ERROR;
220   END IF;
221 
222 /*  not needed for bug 2245351 Check cust_no */
223   /*IF (p_allocation_rec.cust_no = ' ' OR p_allocation_rec.cust_no IS NULL)
224   THEN
225     oe_debug_pub.add('KYH ALLOCATION - missing CUST NO',1);
226     FND_MESSAGE.SET_NAME('GML','SO_E_CUST_NO_REQUIRED');
227     FND_MSG_PUB.Add;
228     RAISE FND_API.G_EXC_ERROR;
229   END IF;                                                                       */
230 
231 /*  Check order_qty   */
232   IF (p_allocation_rec.order_qty1 <= 0 OR p_allocation_rec.order_qty1 IS NULL)
233   THEN
234     oe_debug_pub.add('KYH ALLOCATION - missing order qty',1);
235     FND_MESSAGE.SET_NAME('GML','PO_NONZERO_VAL');
236     FND_MSG_PUB.Add;
237     RAISE FND_API.G_EXC_ERROR;
238   END IF;
239 
240 /*  Check order_qty2 */
241   IF x_ic_item_mst_rec.dualum_ind in (1,2,3) AND
242      (p_allocation_rec.order_qty2 <= 0 OR p_allocation_rec.order_qty2 IS NULL)
243   THEN
244     oe_debug_pub.add('KYH ALLOCATION - missing order qty2',1);
245     FND_MESSAGE.SET_NAME('GML','GML_ORDER_QTY2_REQUIRED');
246     FND_MESSAGE.SET_TOKEN('ITEM_NO',p_allocation_rec.item_no);
247     FND_MSG_PUB.Add;
248     RAISE FND_API.G_EXC_ERROR;
249   END IF;
250 
251 /*  Check order_um1 */
252   IF (p_allocation_rec.order_um1 = ' ' OR p_allocation_rec.order_um1 IS NULL)
253   THEN
254     oe_debug_pub.add('KYH ALLOCATION - missing order UM',1);
255     FND_MESSAGE.SET_NAME('GML','SO_E_UOM1_REQUIRED');
256     FND_MSG_PUB.Add;
257     RAISE FND_API.G_EXC_ERROR;
258   END IF;
259 
260 /*  Check order_um2   */
261   IF x_ic_item_mst_rec.dualum_ind in (1,2,3) AND
262      (p_allocation_rec.order_um2 = ' '  OR p_allocation_rec.order_um2 IS NULL)
263   THEN
264     oe_debug_pub.add('KYH ALLOCATION - missing order UM2',1);
265     FND_MESSAGE.SET_NAME('GML','GML_ORDER_UM2_REQUIRED');
266     FND_MESSAGE.SET_TOKEN('ITEM_NO',p_allocation_rec.item_no);
267     FND_MSG_PUB.Add;
268     RAISE FND_API.G_EXC_ERROR;
269   END IF;
270 
271 /*  Check Trans_date   */
272   IF (p_allocation_rec.trans_date IS NULL)
273   THEN
274     oe_debug_pub.add('KYH ALLOCATION - missing trans date',1);
275     FND_MESSAGE.SET_NAME('GML','SO_E_DATE_REQUIRED');
276     FND_MSG_PUB.Add;
277     RAISE FND_API.G_EXC_ERROR;
278   END IF;
279 
280 
281 /*  Validation OK */
282   RETURN;
283 
284 /*  Exception Handling */
285 
286   EXCEPTION
287     WHEN FND_API.G_EXC_ERROR THEN
288       x_return_status := FND_API.G_RET_STS_ERROR;
289       FND_MSG_PUB.Count_AND_GET (  p_count =>  x_msg_count
290                                  , p_data  =>  x_msg_data
291                                 );
292 
293     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
294       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
295       FND_MSG_PUB.Count_AND_GET (  p_count =>  x_msg_count
296                                  , p_data  =>  x_msg_data
297                                 );
298     WHEN OTHERS THEN
299       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
300       FND_MSG_PUB.Add_Exc_Msg (  G_PKG_NAME
301                                , l_api_name
302                               );
303       FND_MSG_PUB.Count_AND_GET (  p_count =>  x_msg_count
304                                  , p_data  =>  x_msg_data
305                                 );
306 
307 END Validate_Input_Parms;
308 
309 /*  Func start of comments
310  +==========================================================================+
311  |  FUNCTION NAME                                                           |
312  |       Validate_who                                                       |
313  |  USAGE                                                                   |
314  |       Ensure that a user identifier has been supplied.                   |
315  |       This can be either the user_name OR user_id.                       |
316  |  DESCRIPTION                                                             |
317  |       This function validates that one of the 2 parameters has a         |
318  |       value.                                                             |
319  |                                                                          |
320  |  PARAMETERS                                                              |
321  |       p_user_id    IN User Identifier                                    |
322  |       p_user_name  IN User Name                                          |
323  |  RETURNS                                                                 |
324  |       TRUE  - If one or both parameters supplied                         |
325  |       FALSE - If both parameters are empty                               |
326  |                                                                          |
327  |  HISTORY                                                                 |
328  |       04/JAN/2000   Karen Hunt                                           |
329  |                                                                          |
330  +==========================================================================+
331   Func end of comments
332 */
333 FUNCTION Validate_who
334 ( p_user_id     IN FND_USER.USER_ID%TYPE
335 , p_user_name   IN FND_USER.USER_NAME%TYPE
336 )
337 RETURN BOOLEAN
338 IS
339 BEGIN
340 
341 /* dbms_output.put_line('This is validate who'); */
342   IF (p_user_id IS NULL) AND
343      (p_user_name = ' ' OR p_user_name IS NULL)
344   THEN
345 /*    dbms_output.put_line('Return FALSE'); */
346      RETURN FALSE;
347   ELSE
348 /*    dbms_output.put_line('Return TRUE'); */
349      RETURN TRUE;
350   END IF;
351 
352 EXCEPTION
353   WHEN OTHERS THEN
354     RAISE;
355 END Validate_who;
356 
357 END GMI_VALIDATE_ALLOCATION_PVT;