Thursday, March 8, 2012

Launch DRP Supply Chain Planning Processes

Procedure to Submits Concurrent Program Launch DRP Supply Chain Planning Processes (MRPSLPPS3).
---------------------
PROCEDURE submit_program (p_plan_name IN VARCHAR2, p_org_id IN NUMBER)
IS
-- Variables for Request submition
v_validate_request_id NUMBER;
v_wait_status BOOLEAN;
v_phase VARCHAR2 (240);
v_status VARCHAR2 (240);
v_dev_phase VARCHAR2 (240);
v_dev_status VARCHAR2 (240);
v_message VARCHAR2 (240);
v_error NUMBER := 0;
BEGIN
v_validate_request_id := NULL;
v_validate_request_id :=
fnd_request.submit_request ('MRP',
'MRPSLPPS3',
'',
'',
FALSE,
TO_CHAR (p_org_id),
p_plan_name,
1 -- Yes
,
1 , -- Yes
to_char(trunc(SYSDATE),'YYYY/MM/DD hh24:mi:ss'),
to_char(trunc(SYSDATE+365),'YYYY/MM/DD hh24:mi:ss')
);
put_log ('Program submitted with request id: ' || v_validate_request_id);
COMMIT;

IF v_validate_request_id > 0
THEN
v_wait_status :=
fnd_concurrent.wait_for_request
(request_id => v_validate_request_id,
INTERVAL => 10,
max_wait => 5400,
phase => v_phase,
status => v_status,
dev_phase => v_dev_phase,
dev_status => v_dev_status,
MESSAGE => v_message
);
END IF;

IF (v_dev_status = 'ERROR')
THEN
raise_application_error (-20000,
'Request '
|| v_validate_request_id
|| ' failed: '
|| v_message
);
END IF;

COMMIT;
END submit_program;

Procedure to Update Item Number in Oracle Inventory

ego_item_pub API to update Item Number.
--------------------------------------------
CREATE OR REPLACE
PACKAGE xx_item_num_update
AS
PROCEDURE item_update (
errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_old_item_name IN VARCHAR2,
p_new_item_name IN VARCHAR2
);

END xx_item_num_update;
/
SHOW ERRORS PACKAGE xx_item_num_update;

CREATE OR REPLACE
PACKAGE BODY xx_item_num_update
AS

/******************************************************************************
Procedure: put_log()
Description: Writes a line to the log file.
+- Required/Optional
| Name Description
- ----------------------------- -----------------------------------------------
R p_string String to write to the log file
******************************************************************************/
PROCEDURE put_log (p_string IN VARCHAR2)
IS
BEGIN
fnd_file.put_line (fnd_file.LOG, p_string);
END put_log;

/******************************************************************************
Procedure: item_update()
Description: Procedure to update Item Number.
+- Required/Optional
| Name Description
- ----------------------------------------------------------------------------
R p_old_item_name Old Item Number
R p_new_item_name New Item Number
******************************************************************************/
PROCEDURE item_update (
errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_old_item_name IN VARCHAR2,
p_new_item_name IN VARCHAR2
)
IS

CURSOR c_items (p_item_id NUMBER) IS
SELECT organization_id
FROM mtl_system_items_kfv
WHERE inventory_item_id = p_item_id;

e_abort EXCEPTION;
e_skip EXCEPTION;
l_inventory_item_id NUMBER;
l_organization_id NUMBER;
x_inventory_item_id NUMBER;
x_organization_id NUMBER;
x_return_status VARCHAR2(300);
x_msg_count NUMBER;
x_msg_data VARCHAR2 (4000);
x_message_list Error_Handler.Error_Tbl_Type;

BEGIN

BEGIN
SELECT inventory_item_id
INTO l_inventory_item_id
FROM mtl_system_items_kfv
WHERE organization_id = 82
AND concatenated_segments = p_old_item_name;
EXCEPTION
WHEN OTHERS THEN
put_log ('Error While fetching inventory item id'||SQLERRM);
RAISE e_abort;
END;

put_log ('Inventory Item Id: '||l_inventory_item_id);
put_log ('Old Item Name: '||p_old_item_name);
put_log ('New Item Name: '||p_new_item_name);

FOR rec_items IN c_items(l_inventory_item_id)
LOOP

apps.ego_item_pub.process_item
(p_api_version => 1.0,
p_init_msg_list => 'T',
p_commit => FND_API.G_FALSE,--'F',--'T',
p_transaction_type => 'UPDATE',
p_inventory_item_id => l_inventory_item_id,
p_organization_id => rec_items.organization_id,
p_Item_Number => p_new_item_name,
x_inventory_item_id => x_inventory_item_id,
x_organization_id => x_organization_id,
x_return_status => x_return_status,
x_msg_count => x_msg_count,
x_msg_data => x_msg_data
);

IF (x_return_status <> apps.fnd_api.g_ret_sts_success) THEN
ROLLBACK;
put_log( 'Item Number Update API Error '|| x_return_status );
put_log('Error Messages :');
Error_Handler.GET_MESSAGE_LIST(x_message_list=>x_message_list);
FOR i IN 1..x_message_list.COUNT LOOP
put_log(x_message_list(i).message_text);
END LOOP;
RAISE e_abort;
ELSE
COMMIT;
put_log('Item Number Update API Success: ' || x_return_status || ' Org Id: '||rec_items.organization_id);
END IF;
END LOOP;

EXCEPTION
WHEN e_abort THEN
put_log ('Unexpected Error Occured in item_update(). Aborting the Program');
retcode := 2;
WHEN OTHERS THEN
put_log ('Error in item_update(): ' || SQLERRM);
errbuf := SQLERRM;
retcode := 2;
END item_update;
END xx_item_num_update;
/
SHOW ERRORS PACKAGE BODY xx_item_num_update;

Update PO Line Price -- Oracle Apps

po_change_api1_s API/Package to update PO Line Price. Noticed that Price gets changed when launch_approvals_flag is set to 'Y'
----------------------------
CREATE OR REPLACE
PACKAGE xx_po_price_update
AS
PROCEDURE price_update (
errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_po_num IN VARCHAR2,
p_line_num IN VARCHAR2,
p_new_price IN VARCHAR2
);

END xx_po_price_update;
/
SHOW ERRORS PACKAGE xx_po_price_update;

CREATE OR REPLACE
PACKAGE BODY xx_po_price_update
AS

/******************************************************************************
Procedure: put_log()
Description: Writes a line to the log file.
+- Required/Optional
| Name Description
- ----------------------------- -----------------------------------------------
R p_string String to write to the log file
******************************************************************************/
PROCEDURE put_log (p_string IN VARCHAR2)
IS
BEGIN
fnd_file.put_line (fnd_file.LOG, p_string);
END put_log;

/******************************************************************************
Procedure: price_update()
Description: Procedure to update PO Line Price.
+- Required/Optional
| Name Description
- ----------------------------------------------------------------------------
R p_po_num PO Number
R p_line_num PO Line Number
R p_new_price New PO Line Price
******************************************************************************/
PROCEDURE price_update (
errbuf OUT VARCHAR2,
retcode OUT VARCHAR2,
p_po_num IN VARCHAR2,
p_line_num IN VARCHAR2,
p_new_price IN VARCHAR2
)
IS


e_abort EXCEPTION;
e_skip EXCEPTION;
l_po_num po_headers_all.segment1%TYPE;
l_api_errors po_api_errors_rec_type;
l_revision_num NUMBER;
l_result NUMBER;
l_price po_lines_all.unit_price%TYPE;
l_org_id NUMBER := fnd_profile.value ('ORG_ID');

BEGIN

l_po_num := NULL;
l_revision_num := NULL;
l_result := NULL;

BEGIN
SELECT segment1, revision_num
INTO l_po_num, l_revision_num
FROM po_headers_all
WHERE org_id = l_org_id
AND segment1 = p_po_num;
EXCEPTION
WHEN NO_DATA_FOUND THEN
put_log ('No matching PO Number found for the value entered '||SQLERRM);
RAISE e_abort;
WHEN OTHERS THEN
put_log ('Error While fetching PO Number '||SQLERRM);
RAISE e_abort;
END;

put_log ('PO Number: ' || p_po_num);
put_log ('PO Line Number : '|| p_line_num);
put_log ('New Price: ' || p_new_price);

l_result :=
po_change_api1_s.update_po
(x_po_number => p_po_num, --Enter the PO Number
x_release_number => NULL, --Enter the Release Num
x_revision_number => l_revision_num, --Enter the Revision Number
x_line_number => TO_NUMBER(p_line_num), --Enter the Line Number
x_shipment_number => NULL, --Enter the Shipment Number
new_quantity => NULL, --Enter the new quantity
new_price => TO_NUMBER(p_new_price), --Enter the new price,
new_promised_date => NULL, --Enter the new promised date,
new_need_by_date => NULL, --Enter the new need by date,
launch_approvals_flag => 'Y',
update_source => NULL,
version => '1.0',
x_override_date => NULL,
x_api_errors => l_api_errors,
p_buyer_name => NULL,
p_secondary_quantity => NULL,
p_preferred_grade => NULL,
p_org_id => l_org_id);

IF (l_result = 1) THEN
put_log('Successfully updated the PO => ' || p_po_num);
END IF;

IF (l_result <> 1) THEN
put_log ('Failed to update the PO Due to Following Reasons');

-- Display the errors
FOR i IN 1 .. l_api_errors.message_text.COUNT
LOOP
put_log (l_api_errors.message_text (i));
END LOOP;
retcode := 2;
END IF;
EXCEPTION
WHEN e_abort THEN
put_log ('Unexpected Error Occured in price_update(). Aborting the Program');
retcode := 2;
WHEN OTHERS THEN
put_log ('Error in price_update(): ' || SQLERRM);
errbuf := SQLERRM;
retcode := 2;
END price_update;
END xx_po_price_update;
/
SHOW ERRORS PACKAGE BODY xx_po_price_update;

Wednesday, December 7, 2011

Oracle Applications Interview Questions

1. Are you familiar with User exits in Reports?

User Exists are 9 Types.

• FND SRWINIT: Fetches concurrent request information and sets up the profile options, in Before Report Trigger

• FND SRWEXIT: Ensures that all the memory allocated for Oracle AOL user exits has been freed up properly- After Report Trigger

• FND FORMAT_CURRENCY: This is used for MULTIPLE REPORTING CURRNECY.

• FND FLEXSQL: Before Report Trigger - these user exits allow you to use flex fields in your reports

• FND FLEXIDVAL: used to display flex field information like prompt, value etc

User exit, when called from Report triggers, moves the control from report to the outside program, there it performs the action programmed, and returns back to report environment. The program makes USER to EXIT from ongoing environment to perform certain.

2. Do you know what are User Profiles in Apps? Any e.g.

User Profile: It is a set of changeable options through which your application runs. User profile can be defined at various levels. They are

1. System 2. Application 3. Responsibility 4. User

2.1. What is the difference between AFTER PARAMETER TRIGGER and BEFORE REPORT TRIGGER?

After parameter Trigger: It will fire after the parameter form is displayed. Here we can do validation on parameter values

Before Report Trigger: It will fire before the report is executed and after the query is parsed and data is fetched.

2.2. How are text files read and written in Oracle PL/SQL?

Yes there is a facility UTL_FILE , using this package you can read and write data into text files.

Or TEXT_IO package also there. UTL_FILE is for backend procedures and this writes and reads from DB server, while TEXT_IO package is used in forms to read and write from Client machine

2.3 What are the types of exceptions you face in utl_file ?

UTL_FILE.INVALID_PATH -- Specified path does not exist or is not visible to Oracle

UTL_FILE.FILE_OPEN -- File is already open

invalid_filename -- A file with the specified name does not exist in the path

access_denied -- Access to the file has been denied by the operating system

Path is defined in v$parameter where name = 'utl_file_dir'

A

Append Text

AB

Append Byte Mode

R

Read Text

RB

Read Byte Mode

W

Write Text

WB

Write Byte Mode


*** How do i force to use an index? – Using concept of Oracle HINTS

2.4 Bulk Collect with PL/SQL

In PL/SQL, using bulk collect, it is possible to select the values from mutliple rows in one go.

Friday, December 2, 2011

Query to find trace file in Oracle Apps.

SELECT 'Request id: '||request_id ,
'Trace id: '||oracle_Process_id,
'Trace Flag: '||req.enable_trace,
'Trace Name: '||dest.value||'/'||lower(dbnm.value)||'_ora_'||oracle_process_id||'.trc',
--'Prog. Name: '||prog.user_concurrent_program_name,
'File Name: '||execname.execution_file_name|| execname.subroutine_name ,
'Status : '||decode(phase_code,'R','Running') ||'-'||decode(status_code,'R','Normal'),
'SID Serial: '||ses.sid||','|| ses.serial#, 'Module : '||ses.module
from
fnd_concurrent_requests req,
v$session ses,
v$process proc,
v$parameter dest,
v$parameter dbnm,
fnd_concurrent_programs_vl prog,
fnd_executables execname where req.request_id = &request
and req.oracle_process_id=proc.spid(+)
and proc.addr = ses.paddr(+)
and dest.name='user_dump_dest'
and dbnm.name='db_name'
and req.concurrent_program_id = prog.concurrent_program_id
and req.program_application_id = prog.application_id
and prog.application_id = execname.application_id
and prog.executable_id=execname.executable_id;

Find Current Query for a Concurrent Program.

Following query gives us the current running query for a concurrent program in Oracle Applications:

SELECT a.request_id, d.sid, d.serial# ,d.osuser,d.process
FROM apps.fnd_concurrent_requests a,
apps.fnd_concurrent_processes b,
v$process c,
v$session d
WHERE a.controlling_manager = b.concurrent_process_id
AND c.pid = b.oracle_process_id
AND b.session_id=d.audsid
AND a.request_id = 30600658
AND a.phase_code = 'R'

select /*+ ORDERED */ sql_text
from v$session s, v$sqltext t
where t.address = s.sql_address
and s.sid = 2348
order by piece

SQL Query to get Responsibility Name for Concurrent Program




SELECT DISTINCT
  FCPL.USER_CONCURRENT_PROGRAM_NAME
, FCP.CONCURRENT_PROGRAM_NAME
, FAPP.APPLICATION_NAME
, FRG.REQUEST_GROUP_NAME
, FNRTL.RESPONSIBILITY_NAME
FROM
  APPS.FND_REQUEST_GROUPS FRG
, APPS.FND_APPLICATION_TL FAPP
, APPS.FND_REQUEST_GROUP_UNITS FRGU
, APPS.FND_CONCURRENT_PROGRAMS FCP
, APPS.FND_CONCURRENT_PROGRAMS_TL FCPL
, APPS.FND_RESPONSIBILITY FNR
, APPS.FND_RESPONSIBILITY_TL FNRTL
WHERE
    FRG.APPLICATION_ID=fapp.APPLICATION_ID
AND FRG.APPLICATION_ID = FRGU.APPLICATION_ID
AND FRG.REQUEST_GROUP_ID = FRGU.REQUEST_GROUP_ID
AND FRG.REQUEST_GROUP_ID = FNR.REQUEST_GROUP_ID
AND FRG.APPLICATION_ID = FNR.APPLICATION_ID
AND FNR.RESPONSIBILITY_ID = FNRTL.RESPONSIBILITY_ID
AND FRGU.REQUEST_UNIT_ID = FCP.CONCURRENT_PROGRAM_ID
AND FRGU.UNIT_APPLICATION_ID = FCP.APPLICATION_ID
AND FCP.CONCURRENT_PROGRAM_ID = FCPL.CONCURRENT_PROGRAM_ID
AND FCPL.USER_CONCURRENT_PROGRAM_NAME LIKE 'Conc Prog Name'
AND FNRTL.LANGUAGE = 'US'
AND FAPP.LANGUAGE = 'US';

Cellular Phones

Online Store