You are on page 1of 44

2009 Oracle Corporation Proprietary and Confidential

Understand and Build Custom Code for using APIs


Day, Date, 2004 Upcoming Webcasts time p.m. ET Teleconference Access:

Join us for Upcoming Logistics and Master Data Management Community Webcasts. For complete details on all upcoming Oracle Advisor Webcast Events, please review: Document 740966.1, Oracle Advisor Webcast Schedule in MOS Do you have any suggestions for future Inventory Management or Product Lifecycle Management webcasts? Please email your suggestions to: oracle-inv-news_WW@oracle.com

Oracle Product North America: xxxx Information International: xxxx Features Wednesday October 27 1:00 PM Eastern 10:00 AM Pacific Document 1185694.1
Password: Advisor Lifecycle Management

Management / Product

2009 Oracle Corporation Proprietary and Confidential

Safe Harbor Statement


The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decision. The development, release, and timing of any features or functionality described for Oracles products remains at the sole discretion of Oracle.

2010 Oracle Corporation Proprietary and Confidential

Agenda
Oracle Integration Repository Introduction to PL/SQL APIs Understand API Definition Code Flow & Demonstration Troubleshooting Best Practices References Question / Answer

Webcast Information
Presentation will be recorded and available from:
Note 740964.1 And linked from MOS Logistics and Master Data Management Communities

We will have some polling questions for you.


The Polls will appear on the right side of your screen

Question and Answer will be at the end of the presentation and will be via WebEx Chat functionality
Send your chat question to All Panelists Refrain from including any proprietary information in your chat question We may not have opportunity to respond to all questions during live session Question responses will also be posted to MOS Logistics and Master Data Management Communities

2010 Oracle Corporation Proprietary and Confidential

Safe Harbor Statement


The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decision. The development, release, and timing of any features or functionality described for Oracles products remains at the sole discretion of Oracle.

2010 Oracle Corporation Proprietary and Confidential

<Insert Picture Here>

Understand and Build Custom Code for using APIs


Anthony Shahen, Suhasini Rayadurgam, Richard Coleman Oracle Support

Agenda
Oracle Integration Repository Introduction to PL/SQL APIs Understand API Definition Code Flow & Demonstration Troubleshooting Best Practices References Question / Answer

Oracle Integration Repository


Public APIs Business interfaces View of the interface mechanisms

In Release 12, the Oracle Integration Repository is shipped as part of the E-Business Suite. (Responsibility: Integrated SOA Gateway)

Oracle Integration Repository (R12)

10

Agenda
Oracle Integration Repository Introduction to PL/SQL APIs Understand API Definition Code Flow & Demonstration Troubleshooting Best Practices References Question / Answer

11

APIs
External Source

API

E-Business Suite

Why APIs ?
Migrate data from legacy systems to Oracle EBS Perform custom processing before data loads

Perform bulk load into Oracle EBS

12

Agenda
Oracle Integration Repository Introduction to PL/SQL APIs Understand API Definition Code Flow & Demonstration Troubleshooting Best Practices References Question / Answer

13

Understand API Definition


Intended purpose, Input parameters, Output parameters, Input / Output parameters, Default values for parameters Map inputs from source table (users data) to the input parameters Use debugging information to detect and diagnose errors

14

PL/SQL APIs
PL/SQL Packages The Application Programming Interface or API is a PL/SQL packaged procedure that can be used as an alternative to Application online forms for data entry and manipulation.

15

API Packaging
Package: A package bundles logically related types, variables, cursors and subprograms(procedures and functions)
A package has two parts Specification and Body: Package Specification: The specification declares the types, constants, variables, exceptions, cursors and sub programs

Package Body: The body defines the code for subprograms

16

API Packaging Contd


Types of subprograms:

Procedure: Subprogram without a return value, uses OUT parameters to return values
Function: Subprogram with a return value Note: All public packages that expose the APIs are named as <Product Prefix>_<Pkg Name>_PUB. Ex: EGO_ITEM_PUB Both the specification and body are packaged as two separate files, specification as <File Name>S.pls Ex: EGOPITMS.pls body as <File Name>B.pls Ex: EGOPITMB.pls
17

API Naming Conventions


Parameters: p_<name> : IN Parameters (used for input) x_<name> : OUT / IN OUT Parameters (used for input / output)

Default Values:
FND_API Boolean Values, Return Status Values {or} Package Spec API specific pre-defined constants Data Input: Process Single Record p_<var_name>_rec

{or}
Process Multiple Records p_<var_name>_tbl
18

Sample API Definition


-- sample API signature
EGO_ITEM_PUB.PROCESS_ITEMS ( P_API_VERSION IN NUMBER,

P_INIT_MSG_LIST
P_COMMIT P_ITEM_TBL

IN
IN IN

VARCHAR2 := G_FALSE,
VARCHAR2 := G_FALSE, EGO_ITEM_PUB.ITEM_TBL_TYPE, EGO_ITEM_PUB.ROLE_GRANT_TBL_TYPE,

P_ROLE_GRANT_TBL IN X_ITEM_TBL X_RETURN_STATUS X_MSG_COUNT );

OUT EGO_ITEM_PUB.ITEM_TBL_TYPE, OUT VARCHAR2, OUT NUMBER

19

Agenda
Oracle Integration Repository Introduction to PL/SQL APIs Understand API Definition Code Flow & Demonstration Troubleshooting Best Practices References Question / Answer

20

Mapping inputs to API


Default Values

API Inputs

1.0 FND_API.G_TRUE FND_API.G_FALSE

P_API_VERSION P_INIT_MSG_LIST P_COMMIT P_ITEM_TBL

Users data source

ITEM_NUMBER DESCRIPTION PRIMARY_UOM SECONDARY_UOM ITEM_TEMPLATE ROLE_NAME GRANTEE_PARTY_TYPE GRANTEE_PARTY_NAME START_DATE END_DATE

P_ROLE_GRANT_TBL

21

Code Flow
Initialize Applications Context Load data from external system Call the API

Print return status / error messages Handle exceptions

22

Code Flow
CREATE OR REPLACE PROCEDURE <proc_name> (parameter_list) <declare required variables and cursors> BEGIN <Initialize Applications Information>

<Loop through the cursor / Load data from the users table, and call the API>
<Print output information, and errors, if any> EXCEPTION <Handle exceptions, if multi-level API calls are made> END;

23

Initialize Application Information


-- Declarations l_user_id l_user_name l_application_id l_resp_id l_resp_name fnd_user.user_id%TYPE; fnd_user.user_name%TYPE; fnd_responsibility.application_id%TYPE; fnd_responsibility.responsibility_id%TYPE; fnd_responsibility.responsibility_key%TYPE;

-- Get the user_id SELECT user_id INTO l_user_id FROM fnd_user WHERE user_name = l_user_name; -- Get the application_id and responsibility_id SELECT application_id, responsibility_id INTO l_application_id, l_resp_id FROM fnd_responsibility WHERE responsibility_key = l_resp_name;

-- Print message to user FND_GLOBAL.APPS_INITIALIZE(l_user_id, l_resp_id, l_application_id); dbms_output.put_line('Initialized applications context:'|| l_user_id ||' '|| l_resp_id ||' '|| l_application_id );
24

Load data from users table into cursor


-- Cursor declaration CURSOR <cursor_name>(parameter_list ) IS SELECT <col1, col2, > FROM <user_table_name> WHERE <filter_criteria> -- Load data from cursor to be provided as input to API FOR <cursor_var> IN <cursor_name>(parameter_list ) LOOP <for each record retrieved from the cursor, load the input variables to the API> {OR} <call the API for each record retrieved from the cursor> END LOOP;

25

Call the API


-- call the API with <package_name>.<api_name>(parameter_list..) dbms_output.put_line('====================================='); dbms_output.put_line('Calling EGO_ITEM_PUB.Process_Items API'); EGO_ITEM_PUB.PROCESS_ITEMS( p_api_version => l_api_version ,p_init_msg_list => l_init_msg_list ,p_commit => l_commit ,p_item_tbl => l_item_tbl ,p_role_grant_tbl => l_role_grant_tbl ,x_item_tbl => x_item_tbl ,x_return_status => x_return_status ,x_msg_count => x_msg_count); dbms_output.put_line('=====================================');

26

Print output information and errors


-- Declarations x_message_list x_return_status x_msg_count Error_Handler.Error_Tbl_Type; VARCHAR2(2); NUMBER := 0;

-- Code to print errors using the error_handler package dbms_output.put_line('====================================='); dbms_output.put_line('Return Status: '||x_return_status); IF (x_return_status <> FND_API.G_RET_STS_SUCCESS) THEN dbms_output.put_line('Error Messages :'); Error_Handler.GET_MESSAGE_LIST(x_message_list); FOR i IN 1..x_message_list.COUNT LOOP dbms_output.put_line(x_message_list(i).message_text);

END LOOP;
END IF; dbms_output.put_line('====================================='); =

27

Exception Handling

EXCEPTION WHEN OTHERS THEN dbms_output.put_line('Exception Occured :||SQLCODE ||':'||SQLERRM); END;

28

Demonstration

29

Agenda
Oracle Integration Repository Introduction to PL/SQL APIs Understand API Definition Code Flow & Demonstration Troubleshooting Best Practices References Question / Answer

30

Troubleshooting

31

Troubleshooting
Get the debug log file to see additional messages For Inventory, INV: Debug level to 15 INV: Debug Trace to YES INV: Debug file to a directory that is defined in the utl_file_dir parameter value
SELECT value FROM v$parameter WHERE name = utl_file_dir;

For BOM & ENG, Input parameters - p_debug, p_output_dir, p_debug_filename

32

Troubleshooting Contd
For PLM / PIM, Input parameters - p_debug_level (>0)
* Note: Not all PIM APIs support this parameter.

33

Troubleshooting Contd
Get the trace and tkprof files for looking at the internal queries
To generate the trace file:
ALTER SESSION SET EVENTS '10046 trace name context forever, level 12';

ALTER SESSION SET TRACEFILE_IDENTIFIER = 'API_TRACE_05_17';


EXEC XX_PROCESS_ITEMS('TEST_API_ITEM2','V1',15015);

ALTER SESSION SET EVENTS '10046 trace name context off';

34

Troubleshooting Contd
To locate the trace file:
SELECT VALUE FROM V$PARAMETER WHERE NAME = user_dump_dest'

To generate the tkprof:


tkprof <*trace_file_identifier*>.trc <tkprof>.out sys=no explain=apps/<apps pwd>

35

Agenda
Oracle Integration Repository Understand API Definition Code Flow Demonstration Troubleshooting Best Practices References Question / Answer

36

Best Practices
Ensure that
p_commit is set to TRUE only when implicit COMMIT is required x_return_status is printed to the users output: (S Success, E Error, U Unexpected Error) Print all Error Messages from FND stack in case of errors Handle exceptions appropriately, when calling multiple APIs

Debugging is turned on (p_debug_level := 0 - 3) for the Erro stack messages


Turn product related debugging profiles on as appropriate for the API for viewing additional messages in the debug log Avoid use of DDL statements (Create / Alter / Drop / Truncate) while calling multiple APIs in the same session
37

Agenda
Oracle Integration Repository Understand API Definition Code Flow Demonstration Troubleshooting Best Practices References Question / Answer

38

Where to find public APIs


Users Guide
Oracle Supply Chain Management APIs and Open Interfaces

To find APIs that are supported


In Releases 12 and above, - The Oracle Integration Repository ships as part of the E-Business Suite. - As your instance is patched, the repository will automatically be updated with content appropriate for the precise revisions of interfaces in your environment. - Add the responsibility - Integrated SOA Gateway, and you can browse all the interfaces. - You can view by product family, interface type, standard.

39

Notes for Reference


Note: 729513.1 API specifics, custom code to use APIs, debugging guidelines Inventory: Note: 729998.1 (8 APIs related to Move Orders and Reservations) PLM / PIM: Note: 730164.1 (8 APIs related to Item and User-Defined Attribute Management) Debugging: Note 869386.1 - How to Enable Trace or Debug for Inventory APIs executed as SQL Script Outside of the Applications ?
40

<Insert Picture Here>

Q&A

41

Continue the discussion


If you would like to ask additional questions or continue the discussion with other attendees, please submit discussion threads via the My Oracle Support Logistics Community.
1. Login to My Oracle Support

2. Click on Community tab


3. Enter Logistics in Find a Community box 4. Click on the Logistics Community

5. Start a Discussion or comment on an existing thread The recorded version of this webcast will be available on the Advisor Webcast Archive in MOS:
Document ID 740964.1 Look under Oracle EBS Community Webcasts > Manufacturing

2009 Oracle Corporation Proprietary and Confidential

42

THANK YOU

2010 Oracle Corporation Proprietary and Confidential

43

2009 Oracle Corporation Proprietary and Confidential

44

You might also like