1 PACKAGE BODY OE_Order_Context_GRP AS
2 /* $Header: OEXGCTXB.pls 120.2 2005/06/21 21:57:48 appldev ship $ */
3
4 -- Global constant holding the package name
5 G_PKG_NAME CONSTANT VARCHAR2(30) := 'OE_Order_Context_GRP';
6
7
8 -- Start of Comments
9 -- API name Set_Created_By_Context
10 -- Type Group
11 --
12 -- Function This API may be used when group callers in an operating
13 -- unit need to update orders in a DIFFERENT operating unit.
14 --
15 -- Used to re-initialize application context based on user, resp
16 -- and application combination for user who created the order or line.
17 -- This would ensure that operating unit is re-set to operating
18 -- unit in which order or line was created.
19 --
20 -- Please NOTE that order processing will then run in the context of
21 -- created by and NOT the caller i.e. user, responsibility level
22 -- profiles and other user/resp specific functions (e.g. OM
23 -- security constraints) will be evaluated for the order created by.
24 --
25 -- IMPORTANT: After calling this API and calling respective OM API
26 -- to process this update (e.g. Process_Order), you should re-set to
27 -- your original context using FND_GLOBAL.Apps_Initialize with
28 -- original user, resp,application returned by this function.
29 --
30 -- Parameters Pass p_header_id if the context should be set using
31 -- created by for the order.
32 -- Pass p_line_id if the context should be set using
33 -- created by for the line.
34 -- If you pass both p_line_id and p_header_id, context will be set
35 -- using created_by for the line.
36 -- Original application context values for the API caller are returned
37 -- in : x_orig_user_id, x_orig_resp_id, x_orig_resp_appl_id
38 --
39 -- Examples 1. If you are updating/deleting only one line and/or only the child
40 -- entities of this line e.g. price adjustments, sales credits
41 -- - pass p_line_id.
42 -- 2. When you are CREATING/UPDATING lines, you can pass p_header_id.
43 -- If lines being processed are under ONE model, you can pass
44 -- top_model_line_id in the p_line_id parameter.
45 -- 3. For all other operations spanning multiple lines or multiple
46 -- child entities of one order, pass p_header_id.
47 --
48 -- The earlier logic of setting the CREATED BY context stored in the WF
49 -- tables was removed for the MOAC project in R12
50 --
51 -- End of Comments
52
53 PROCEDURE Set_Created_By_Context
54 (p_header_id IN NUMBER DEFAULT NULL
55 ,p_line_id IN NUMBER DEFAULT NULL
56 ,x_orig_user_id OUT NOCOPY /* file.sql.39 change */ NUMBER
57 ,x_orig_resp_id OUT NOCOPY /* file.sql.39 change */ NUMBER
58 ,x_orig_resp_appl_id OUT NOCOPY /* file.sql.39 change */ NUMBER
59 ,x_return_status OUT NOCOPY /* file.sql.39 change */ VARCHAR2
60 ,x_msg_count OUT NOCOPY /* file.sql.39 change */ NUMBER
61 ,x_msg_data OUT NOCOPY /* file.sql.39 change */ VARCHAR2
62 )
63 IS
64 l_user_id NUMBER;
65 /* MOAC
66 l_resp_id NUMBER;
67 l_resp_appl_id NUMBER;
68 l_itemtype VARCHAR2(8);
69 l_itemkey VARCHAR2(30);
70 */
71 l_org_id NUMBER;
72 --
73 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
74 --
75 BEGIN
76
77 IF l_debug_level > 0 THEN
78 oe_debug_pub.add( 'ENTER SET_CREATED_BY_CONTEXT' , 1 ) ;
79 END IF;
80
81 x_return_status := FND_API.G_RET_STS_SUCCESS;
82
83 -- Return the original context values
84 x_orig_user_id := FND_GLOBAL.USER_ID;
85 x_orig_resp_id := FND_GLOBAL.RESP_ID;
86 x_orig_resp_appl_id := FND_GLOBAL.RESP_APPL_ID;
87 -- MOAC changes starts
88 IF p_line_id IS NOT NULL THEN
89 SELECT org_id
90 INTO l_org_id
91 FROM oe_order_lines_all
92 WHERE line_id = p_line_id;
93 ELSIF p_header_id IS NOT NULL THEN
94 SELECT org_id
95 INTO l_org_id
96 FROM oe_order_headers_all
97 WHERE header_id = p_header_id;
98 END IF;
99
100 IF l_org_id IS NOT NULL THEN
101 IF l_debug_level > 0 THEN
102 oe_debug_pub.add( 'OEXGCTXB.pls - setting single org context to '||l_org_id , 1 );
103 END IF;
104 MO_GLOBAL.Set_Policy_Context('S', l_org_id);
105 END IF;
106
107 /* commented for MOAC
108 IF p_line_id IS NOT NULL THEN
109 l_itemtype := 'OEOL';
110 l_itemkey := to_char(p_line_id);
111 ELSIF p_header_id IS NOT NULL THEN
112 l_itemtype := 'OEOH';
113 l_itemkey := to_char(p_header_id);
114 END IF;
115
116 IF l_itemkey IS NOT NULL THEN
117 IF l_debug_level > 0 THEN
118 oe_debug_pub.add( 'SET CONTEXT' , 2 ) ;
119 END IF;
120
121 l_user_id := WF_Engine.GetItemAttrNumber
122 (itemtype => l_itemtype
123 ,itemkey => l_itemkey
124 ,aname => 'USER_ID');
125 l_resp_id := WF_Engine.GetItemAttrNumber
126 (itemtype => l_itemtype
127 ,itemkey => l_itemkey
128 ,aname => 'RESPONSIBILITY_ID');
129 l_resp_appl_id := WF_Engine.GetItemAttrNumber
130 (itemtype => l_itemtype
131 ,itemkey => l_itemkey
132 ,aname => 'APPLICATION_ID');
133
134 IF l_user_id IS NULL
135 OR l_resp_id IS NULL
136 OR l_resp_appl_id IS NULL
137 THEN
138 IF l_debug_level > 0 THEN
139 oe_debug_pub.add( 'SET CONTEXT: NO DATA FOUND' , 2 ) ;
140 END IF;
141 RAISE NO_DATA_FOUND;
142 END IF;
143
144 FND_GLOBAL.Apps_Initialize
145 (user_id => l_user_id
146 ,resp_id => l_resp_id
147 ,resp_appl_id => l_resp_appl_id);
148
149 END IF; */
150
151 IF l_debug_level > 0 THEN
152 oe_debug_pub.add( 'EXIT SET_CREATED_BY_CONTEXT' , 1 ) ;
153 END IF;
154
155 EXCEPTION
156 WHEN OTHERS THEN
157 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
158 IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
159 THEN
160 OE_MSG_PUB.Add_Exc_Msg
161 ( G_PKG_NAME
162 , 'Set_Created_By_Context'
163 );
164 END IF;
165 -- Get message count and data
166 OE_MSG_PUB.Count_And_Get
167 ( p_count => x_msg_count
168 , p_data => x_msg_data
169 );
170 END Set_Created_By_Context;
171
172 END OE_Order_Context_GRP;