[Home] [Help]
PACKAGE BODY: APPS.PO_REQ_DOCUMENT_CANCEL_PVT
Source
1 PACKAGE BODY PO_REQ_DOCUMENT_CANCEL_PVT AS
2 /* $Header: POXVRCAB.pls 120.1 2005/06/29 18:50:19 shsiung noship $*/
3
4 --CONSTANTS
5
6 G_PKG_NAME CONSTANT varchar2(30) := 'PO_REQ_DOCUMENT_CANCEL_PVT';
7
8 c_log_head CONSTANT VARCHAR2(50) := 'po.plsql.'|| G_PKG_NAME || '.';
9
10 -- Read the profile option that enables/disables the debug log
11 g_fnd_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
12
13 -------------------------------------------------------------------------------
14 --Start of Comments
15 --Name: cancel_requisition
16 --Pre-reqs:
17 -- None.
18 --Modifies:
19 -- None.
20 --Locks:
21 -- None.
22 --Function:
23 -- Cancels a Requisition by calling the C code through Doc Manager.
24 -- This API can process requisitions from multiple operating units.
25 --Parameters:
26 --IN:
27 --p_api_version
28 -- Specifies API version.
29 --p_req_header_id
30 -- Specifies Requisition Header ID.
31 --p_req_line_id
32 -- Specifies Requisition Line ID.
33 --OUT:
34 --x_return_status
35 -- Indicates API return status as 'S', 'E' or 'U'.
36 --x_msg_count
37 -- The number of messages put into FND Message Stack by this API
38 --x_msg_data
39 -- First message put into FND Message Stack by this API
40 --Testing:
41 -- All the input table parameters should have the exact same length.
42 -- They may have null values at some indexes, but need to identify an entity uniquely
43 -- Call the API when only Requisition Exist, PO/Release Exist
44 -- and for all the combinations of attributes.
45 --End of Comments
46 -------------------------------------------------------------------------------
47
48 PROCEDURE cancel_requisition (
49 p_api_version IN NUMBER,
50 p_req_header_id IN PO_TBL_NUMBER,
51 p_req_line_id IN PO_TBL_NUMBER,
52 p_cancel_date IN DATE,
53 p_cancel_reason IN VARCHAR2,
54 p_source IN VARCHAR2,
55 x_return_status OUT NOCOPY VARCHAR2,
56 x_msg_count OUT NOCOPY NUMBER,
57 x_msg_data OUT NOCOPY VARCHAR2
58 ) IS
59
60 l_api_name CONSTANT VARCHAR(30) := 'cancel_requisition';
61 l_api_version CONSTANT NUMBER := 1.0;
62 l_progress VARCHAR2(3) := '000';
63
64 l_encumbrance_flag VARCHAR2(1);
65 l_oe_installed_flag VARCHAR2(1) := 'Y';
66 l_req_subtype PO_REQUISITION_HEADERS_ALL.TYPE_LOOKUP_CODE%TYPE;
67
68 l_po_return_code VARCHAR2(25);
69 l_online_report_id NUMBER;
70 l_req_control_error_rc VARCHAR2(1);
71
72 -- Bug 3362534 START
73 l_document_org_id PO_REQUISITION_HEADERS_ALL.org_id%TYPE;
74 l_original_org_id NUMBER := PO_MOAC_UTILS_PVT.GET_CURRENT_ORG_ID ; -- <R12 MOAC> added
75 -- Bug 3362534 END
76
77 BEGIN
78
79 IF g_fnd_debug = 'Y' THEN
80 IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
81 FND_LOG.string(FND_LOG.LEVEL_STATEMENT, c_log_head || '.'||l_api_name||'.'
82 || l_progress, 'Entering Procedure '||l_api_name);
83 END IF;
84 END IF;
85
86 -- Standard call to check for call compatibility
87 l_progress := '010';
88 IF NOT FND_API.Compatible_API_Call(l_api_version, p_api_version, l_api_name, G_PKG_NAME) THEN
89 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
90 END IF;
91
92 FOR i IN 1..p_req_line_id.count LOOP
93
94 SELECT type_lookup_code,
95 org_id -- Bug 3362534
96 INTO l_req_subtype,
97 l_document_org_id
98 FROM PO_REQUISITION_HEADERS_ALL
99 WHERE requisition_header_id = p_req_header_id(i);
100
101 -- Bug 3362534 START
102 -- Set the org context to the operating unit of the document.
103 PO_MOAC_UTILS_PVT.set_org_context(l_document_org_id) ; -- <R12 MOAC>
104
105 -- Check whether req encumbrance is enabled for this operating unit.
106 IF PO_CORE_S.is_encumbrance_on (
107 p_doc_type => PO_CORE_S.g_doc_type_REQUISITION,
108 p_org_id => l_document_org_id )
109 THEN
110 l_encumbrance_flag := 'Y';
111 ELSE
112 l_encumbrance_flag := 'N';
113 END IF;
114 -- Bug 3362534 END
115
116 l_progress := '020';
117 IF po_reqs_control_sv.val_reqs_action(
118 x_req_header_id => p_req_header_id(i),
119 x_req_line_id => p_req_line_id(i),
120 x_agent_id => null,
121 x_req_doc_type => 'REQUISITION',
122 x_req_doc_subtype => l_req_subtype,
123 x_req_control_action => 'CANCEL REQUISITION',
124 x_req_control_reason => p_cancel_reason,
125 x_req_action_date => p_cancel_date,
126 x_encumbrance_flag => l_encumbrance_flag,
127 x_oe_installed_flag => l_oe_installed_flag) = FALSE
128 THEN
129 FND_MESSAGE.set_name('PO', 'PO_REQ_CANCEL_ERROR');
130 FND_MSG_PUB.add;
131 RAISE FND_API.G_EXC_ERROR;
132 END IF;
133
134 IF l_encumbrance_flag = 'Y' THEN
135
136 l_progress := '030';
137 PO_DOCUMENT_FUNDS_PVT.do_cancel(
138 x_return_status => x_return_status,
139 p_doc_type => 'REQUISITION',
140 p_doc_subtype => l_req_subtype,
141 p_doc_level => 'LINE',
142 p_doc_level_id => p_req_line_id(i),
143 p_use_enc_gt_flag=> PO_DOCUMENT_FUNDS_PVT.g_parameter_NO,
144 p_override_funds => PO_DOCUMENT_FUNDS_PVT.g_parameter_USE_PROFILE,
145 p_use_gl_date => PO_DOCUMENT_FUNDS_PVT.g_parameter_USE_PROFILE,
146 p_override_date => p_cancel_date,
147 x_po_return_code => l_po_return_code,
148 x_online_report_id=> l_online_report_id);
149
150 IF l_po_return_code <> PO_DOCUMENT_FUNDS_PVT.g_return_SUCCESS THEN
151 RAISE FND_API.G_EXC_ERROR;
152 END IF;
153
154 l_progress := '040';
155 po_reqs_control_sv.update_reqs_status(
156 x_req_header_id => p_req_header_id(i),
157 x_req_line_id => p_req_line_id(i),
158 x_agent_id => null,
159 x_req_doc_type => 'REQUISITION',
160 x_req_doc_subtype => l_req_subtype,
161 x_req_control_action => 'CANCEL REQUISITION',
162 x_req_control_reason => p_cancel_reason,
163 x_req_action_date => p_cancel_date,
164 x_encumbrance_flag => l_encumbrance_flag,
165 x_oe_installed_flag => l_oe_installed_flag,
166 x_req_control_error_rc => l_req_control_error_rc);
167
168 IF l_req_control_error_rc = 'Y' THEN
169 FND_MESSAGE.set_name('PO', 'PO_REQ_CANCEL_ERROR');
170 FND_MSG_PUB.add;
171 RAISE FND_API.G_EXC_ERROR;
172 END IF;
173
174 END IF; --End of IF l_encumbrance_flag = 'Y'
175
176 END LOOP;
177
178 l_progress := '050';
179 x_return_status := FND_API.G_RET_STS_SUCCESS;
180
181 -- Bug 3362534 Set the org context back to the original operating unit.
182 PO_MOAC_UTILS_PVT.set_org_context(l_original_org_id) ; -- <R12 MOAC>
183
184 EXCEPTION
185 WHEN FND_API.G_EXC_ERROR THEN
186 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
187 x_return_status := FND_API.G_RET_STS_ERROR;
188 -- Bug 3362534 Set the org context back to the original operating unit.
189 PO_MOAC_UTILS_PVT.set_org_context(l_original_org_id) ; -- <R12 MOAC>
190 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
191 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
192 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
193 -- Bug 3362534 Set the org context back to the original operating unit.
194 PO_MOAC_UTILS_PVT.set_org_context(l_original_org_id) ; -- <R12 MOAC>
195 WHEN OTHERS THEN
196 FND_MSG_PUB.add_exc_msg(G_PKG_NAME, l_api_name || '.' || l_progress);
197 FND_MSG_PUB.Count_And_Get(p_count => x_msg_count, p_data => x_msg_data);
198 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
199 -- Bug 3362534 Set the org context back to the original operating unit.
200 PO_MOAC_UTILS_PVT.set_org_context(l_original_org_id) ; -- <R12 MOAC>
201
202 END cancel_requisition;
203
204 END PO_REQ_DOCUMENT_CANCEL_PVT;