DBA Data[Home] [Help]

PACKAGE BODY: APPS.MRP_CANCEL_PO

Source


1 PACKAGE BODY mrp_cancel_po AS
2 /*$Header: MRPCNPOB.pls 120.1.12010000.1 2008/07/28 04:47:23 appldev ship $ */
3 -- -------------------------------------------------
4 -- Bug#4013684 - 16-dec-2004.
5 -- Added new parameters p_doc_type and p_doc_subtype
6 -- Which will be passed to PO api.
7 -- -------------------------------------------------
8 PROCEDURE cancel_po_program
9 (
10 p_po_header_id IN NUMBER,
11 p_po_line_id IN NUMBER,
12 p_po_number IN VARCHAR2,
13 p_po_ship_num IN NUMBER,
14 p_doc_type    IN VARCHAR2,
15 p_doc_subtype IN VARCHAR2
16 ) IS
17 
18 l_original_org_context  VARCHAR2(10);
19 l_document_org_id       NUMBER;
20 l_release_number NUMBER;
21 l_po_line_id NUMBER;
22 l_pos_lbrace NUMBER;
23 l_pos_rbrace NUMBER;
24 x_return_status VARCHAR2(1);
25 l_access_mode VARCHAR2(1);
26 l_current_org_id NUMBER;
27 
28 BEGIN
29         BEGIN
30 			-- Remember the current org context.
31 			l_original_org_context := SUBSTRB(USERENV('CLIENT_INFO'),1,10);
32 
33 			-- Before calling the PO Cancel API (which uses org-striped views),
34 			-- We need to retrieve and set the org context to the document's operating unit.
35 			SELECT org_id
36 			INTO l_document_org_id
37 			FROM po_headers_all
38 			WHERE po_header_id = p_po_header_id;
39 
40             l_access_mode := mo_global.Get_access_mode();
41             l_current_org_id := mo_global.get_current_org_id();
42 
43 			--FND_CLIENT_INFO.set_org_context(to_char(l_document_org_id));
44 			mo_global.set_policy_context('S',l_document_org_id);--MOAC changes
45 
46             l_po_line_id := p_po_line_id;
47             IF p_doc_type = 'RELEASE' THEN
48                 l_pos_lbrace := instr(p_po_number,'(');
49                 l_pos_rbrace := instr(p_po_number,')');
50                 l_release_number := substr(p_po_number, l_pos_lbrace +1,(l_pos_rbrace -(l_pos_lbrace+1)));
51                 l_po_line_id := NULL;
52             END IF;
53 			--call the Cancel API
54 			PO_Document_Control_GRP.control_document(
55 				p_api_version  => 1.0,
56 				p_init_msg_list => FND_API.G_TRUE,
57 				p_commit     => FND_API.G_TRUE,
58 				x_return_status  => x_return_status,
59 				p_doc_type    =>  p_doc_type,
60 				p_doc_subtype  => p_doc_subtype,
61 				p_doc_id    => p_po_header_id,
62 				p_doc_num    => null,
63 				p_release_id  => null,
64 				p_release_num  => l_release_number,
65 				p_doc_line_id  => l_po_line_id,
66 				p_doc_line_num  => null,
67 				p_doc_line_loc_id  => NULL,
68 				p_doc_shipment_num => p_po_ship_num ,
69 				p_source     => null,
70 				p_action      => 'CANCEL',
71 				p_action_date   => SYSDATE,
72 				p_cancel_reason  => null,
73 				p_cancel_reqs_flag  => null,
74 				p_print_flag     => null,
75 				p_note_to_vendor  =>null);
76 
77 	 -- Set the org context back to the original operating unit.
78 	  --FND_CLIENT_INFO.set_org_context(l_original_org_context);
79 
80 	  Mo_Global.Set_Policy_Context (p_access_mode => l_access_mode,
81 	                                p_org_id => l_current_org_id);
82 
83 	  EXCEPTION
84               WHEN OTHERS THEN
85                   --FND_CLIENT_INFO.set_org_context(l_original_org_context);
86 
87                   Mo_Global.Set_Policy_Context (p_access_mode => l_access_mode,
88 	                                            p_org_id => l_current_org_id);
89 	  END;
90 
91           IF (x_return_status = FND_API.G_RET_STS_SUCCESS) THEN
92              FND_FILE.PUT_LINE(FND_FILE.LOG,'cancellation succeeds');
93           else
94              FND_FILE.PUT_LINE(FND_FILE.LOG,'cancellation fails');
95           end if;
96 
97           FND_FILE.PUT_LINE(FND_FILE.LOG,'header: '||p_po_header_id);
98           FND_FILE.PUT_LINE(FND_FILE.LOG,'line: '||p_po_line_id);
99           FND_FILE.PUT_LINE(FND_FILE.LOG,'po number: '||p_po_number);
100           FND_FILE.PUT_LINE(FND_FILE.LOG,'shipment number: '||p_po_ship_num);
101 
102 END cancel_po_program;
103 
104 END mrp_cancel_po;