API for Closing/Finally Closing PO Using po_actions.close_po


API for closing or finally closing the POs. In this API, there is a parameter "p_action" which we need to set as either CLOSE (if we want to close the PO) or FINALLY CLOSE (If we want to Finally Close) the PO. Another Parameter which needs to set properly is "p_auto_close". This parameter should be set to 'N'.

/*oracle R12 : PO - Script to Close / Finally Close PO using PO_ACTIONS CLOSE_PO API.sql*/

DECLARE

x_action constant varchar2(20) := 'CLOSE'; -- Change this parameter as per requirement
x_calling_mode constant varchar2(2) := 'PO';
x_conc_flag constant varchar2(1) := 'N';
x_return_code_h varchar2(100);
x_auto_close constant varchar2(1) := 'N';
x_origin_doc_id number;
x_returned boolean;

CURSOR c_po_details IS

SELECT
pha.po_header_id,
pha.org_id,
pha.segment1,
pha.agent_id,
pdt.document_subtype,
pdt.document_type_code,
pha.closed_code,
pha.closed_date
FROM apps.po_headers_all pha, apps. pdt
WHERE pha.type_lookup_code = pdt.document_subtype
AND pha.org_id = pdt.org_id
AND pdt.document_type_code = 'PO'
AND authorization_status = 'APPROVED'
AND pha.closed_code <> 'CLOSED'
AND segment1 = 'P_PO_Number'; -- Enter the PO Number if only one PO needs to be finally closed/Closed

begin

fnd_global.apps_initialize (user_id => P_user_id,
resp_id => P_resp_id,
resp_appl_id => P_resp_appl_id);

/*For more details on how to Initialize the session oracle Apps R-12 visit Initializing The Session Oracle Apps R-12
*/
for po_head in c_po_details

LOOP

mo_global.init (po_head.document_type_code);
mo_global.set_policy_context ('S', po_head.org_id);

DBMS_OUTPUT.PUT_LINE ('Calling PO_Actions.close_po for Closing/Finally Closing PO =>' po_head.segment1);

x_returned :=
po_actions.close_po(
p_docid => po_head.po_header_id,
p_doctyp => po_head.document_type_code,
p_docsubtyp => po_head.document_subtype,
p_lineid => NULL,
p_shipid => NULL,
p_action => x_action,
p_reason => NULL,
p_calling_mode => x_calling_mode,
p_conc_flag => x_conc_flag,
p_return_code => x_return_code_h,
p_auto_close => x_auto_close,
p_action_date => SYSDATE,
p_origin_doc_id => NULL);

IF x_returned = TRUE THEN

DBMS_OUTPUT.PUT_LINE ('Purchase Order which just got Closed/Finally Closed is ' po_head.segment1);

COMMIT;

ELSE

DBMS_OUTPUT.PUT_LINE ('API Failed to Close/Finally Close the Purchase Order');

END IF;

END LOOP;

END;



/**Note : You can change document_type_code to close others type also for eg. PA,RFQ,REQUISITION etc. */

Initializing the session oracle Apps R-12

FND_GLOBAL.APPS_INITIALIZE is used for initializing the session before calling any public or private API’s in Oracle EBusiness suite. Its not required for all the API’s but its recommended that you set this profile before making any calls to either private or public API. 


Listed below is a sample call to FND_GLOBAL.APPS_INITIALIZE function


fnd_global.APPS_INITIALIZE(user_id=>l_user_id, 
                           resp_id=>l_resp_id, 
                           resp_appl_id=>l_resp_appl_id);


l_user_id : fnd user ID which will be utilized during the call. 
l_resp_id : responsibility ID 
l_resp_appl_id : responsibility application ID. 

You can use either sysadmin or use some user who has all the above listed responsibilities or you can use your username.


You can get user id,responsibility_id and application_id from below query:

select fnd.user_id , 
          fresp.responsibility_id, 
          fresp.application_id 
from   fnd_user fnd,
       fnd_responsibility_tl fresp 
where  fnd.user_name = 'P_user_name' 
and    fresp.responsibility_name = 'P_Responsibility_name';


Another option to get the values from oracle front-end, login and open java forms and then go to below path :
Help > Diagnostics > Examine 

and get the values from $profile session values.

 Query to find concurrent request,requester,parameter and completion time


Sharing query to find all the information while running concurrent program like its parameter, who have run the program,actual start and completion time,current status and responsibility etc.

SELECT   REQUEST_ID,
                 PHASE_CODE,
                STATUS_CODE,
               RESPONSIBILITY_ID,
               ACTUAL_START_DATE,
              ACTUAL_COMPLETION_DATE,
              COMPLETION_TEXT,
              ARGUMENT_TEXT,
              PROGRAM_SHORT_NAME,
            REQUESTOR
  FROM APPS.FND_CONC_REQ_SUMMARY_V
 WHERE PROGRAM_SHORT_NAME LIKE 'P_CONCURRENT_PROGRAM_SHORT_NAME'
 ORDER BY REQUEST_ID DESC;

              Query to find Employee details,location and user

Sharing query to find employee details based on its location.You can get user name,employee id etc.


SELECT DISTINCT PER.FULL_NAME,
                PER.EMAIL_ADDRESS,
                FU.USER_NAME,
                PER.NATIONAL_IDENTIFIER,
                HL.DESCRIPTION,
                PT.SYSTEM_NAME,
                HO.NAME BU_NAME,
                PS.ORGANIZATION_ID OU
  FROM APPS.FND_USER                FU,
       APPS.PER_ALL_PEOPLE_F        PER,
       APPS.HR_LOCATIONS_ALL        HL,
       APPS.PER_PERSON_TYPES_V      PT,
       APPS.PER_ALL_ASSIGNMENTS_F   PS,
       HR.HR_ALL_ORGANIZATION_UNITS HO
 WHERE PS.LOCATION_ID = HL.LOCATION_ID
 AND PER.PERSON_TYPE_ID = PT.PERSON_TYPE_ID
 AND FU.EMPLOYEE_ID = PER.PERSON_ID
 AND PS.PERSON_ID = PER.PERSON_ID
 AND PS.ORGANIZATION_ID = HO.ORGANIZATION_ID
 AND TRUNC(SYSDATE) BETWEEN TRUNC(PER.EFFECTIVE_START_DATE) AND
 (PER.EFFECTIVE_END_DATE)
 AND TRUNC(SYSDATE) BETWEEN TRUNC(PS.EFFECTIVE_START_DATE) AND
 (PS.EFFECTIVE_END_DATE)
 AND (FU.END_DATE >= SYSDATE OR FU.END_DATE IS NULL)
 AND HL.location_id = P_location_id
 ORDER BY PER.FULL_NAME;