API Using

Post on 30-Oct-2014

152 views 12 download

Tags:

transcript

1© 2009 Oracle Corporation – Proprietary and Confidential

2© 2009 Oracle Corporation – Proprietary and Confidential

Day, Date, 2004

time p.m. ET

Teleconference Access:

North America: xxxx

International: xxxx

Password: Advisor

Understand and Build Custom Code for

using APIs

Oracle Product Information

Management / Product Lifecycle Management

Features

Wednesday October 27

1:00 PM Eastern10:00 AM Pacific

Document 1185694.1

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

Upcoming Webcasts

3© 2010 Oracle Corporation – Proprietary and Confidential

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 Oracle‟s products

remains at the sole discretion of Oracle.

Safe Harbor Statement

4

Agenda

• Oracle Integration Repository

• Introduction to PL/SQL APIs

• Understand API Definition

• Code Flow & Demonstration

• Troubleshooting

• Best Practices

• References

• Question / Answer

5

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

6© 2010 Oracle Corporation – Proprietary and Confidential

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 Oracle‟s products

remains at the sole discretion of Oracle.

Safe Harbor Statement

<Insert Picture Here>

Understand and Build Custom Code for using APIs

Anthony Shahen, Suhasini Rayadurgam, Richard Coleman – Oracle Support

8

Agenda

• Oracle Integration Repository

• Introduction to PL/SQL APIs

• Understand API Definition

• Code Flow & Demonstration

• Troubleshooting

• Best Practices

• References

• Question / Answer

9

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)

10

Oracle Integration Repository (R12)

11

Agenda

• Oracle Integration Repository

• Introduction to PL/SQL APIs

• Understand API Definition

• Code Flow & Demonstration

• Troubleshooting

• Best Practices

• References

• Question / Answer

12

APIs

Why APIs ?

• Migrate data from legacy systems to Oracle EBS

• Perform custom processing before data loads

• Perform bulk load into Oracle EBS

E-Business Suite

External Source API

13

Agenda

• Oracle Integration Repository

• Introduction to PL/SQL APIs

• Understand API Definition

• Code Flow & Demonstration

• Troubleshooting

• Best Practices

• References

• Question / Answer

14

Understand API Definition

• Intended purpose, Input parameters, Output

parameters, Input / Output parameters, Default values

for parameters

• Map inputs from source table (user‟s data) to the

input parameters

• Use debugging information to detect and diagnose

errors

15

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.

16

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

17

API Packaging – Cont’d

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

18

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

API Naming Conventions

19

Sample API Definition

-- sample API signature

EGO_ITEM_PUB.PROCESS_ITEMS

(

P_API_VERSION IN NUMBER,

P_INIT_MSG_LIST IN VARCHAR2 := G_FALSE,

P_COMMIT IN VARCHAR2 := G_FALSE,

P_ITEM_TBL IN EGO_ITEM_PUB.ITEM_TBL_TYPE,

P_ROLE_GRANT_TBL IN EGO_ITEM_PUB.ROLE_GRANT_TBL_TYPE,

X_ITEM_TBL OUT EGO_ITEM_PUB.ITEM_TBL_TYPE,

X_RETURN_STATUS OUT VARCHAR2,

X_MSG_COUNT OUT NUMBER

);

20

Agenda

• Oracle Integration Repository

• Introduction to PL/SQL APIs

• Understand API Definition

• Code Flow & Demonstration

• Troubleshooting

• Best Practices

• References

• Question / Answer

21

API InputsDefault Values

User’s data source

P_API_VERSION

P_INIT_MSG_LIST

P_COMMIT

P_ITEM_TBL

P_ROLE_GRANT_TBLITEM_NUMBER

DESCRIPTION

PRIMARY_UOM

SECONDARY_UOM

ITEM_TEMPLATE

ROLE_NAME

GRANTEE_PARTY_TYPE

GRANTEE_PARTY_NAME

START_DATE

END_DATE

Mapping inputs to API

1.0

FND_API.G_TRUE

FND_API.G_FALSE

22

Code Flow

Initialize Applications

Context

Load data from external system

Call the API

Print return status / error messages

Handle exceptions

23

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 user‟s table, and call the API>

<Print output information, and errors, if any>

EXCEPTION

<Handle exceptions, if multi-level API calls are made>

END;

24

Initialize Application Information-- Declarations

l_user_id fnd_user.user_id%TYPE;

l_user_name fnd_user.user_name%TYPE;

l_application_id fnd_responsibility.application_id%TYPE;

l_resp_id fnd_responsibility.responsibility_id%TYPE;

l_resp_name 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 );

25

Load data from user’s 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;

26

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('=====================================');

27

-- Declarations

x_message_list Error_Handler.Error_Tbl_Type;

x_return_status VARCHAR2(2);

x_msg_count 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('====================================='); =

Print output information and errors

28

Exception Handling

EXCEPTION

WHEN OTHERS THEN

dbms_output.put_line('Exception Occured :„||SQLCODE ||':'||SQLERRM);

END;

29

Demonstration

30

Agenda

• Oracle Integration Repository

• Introduction to PL/SQL APIs

• Understand API Definition

• Code Flow & Demonstration

• Troubleshooting

• Best Practices

• References

• Question / Answer

31

Troubleshooting

32

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

33

Troubleshooting – Cont’d

For PLM / PIM,

Input parameters - p_debug_level (>0)

* Note: Not all PIM APIs support this parameter.

34

Troubleshooting – Cont’d

• 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';

35

Troubleshooting – Cont’d

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>

36

Agenda

• Oracle Integration Repository

• Understand API Definition

• Code Flow

• Demonstration

• Troubleshooting

• Best Practices

• References

• Question / Answer

37

Best Practices

Ensure that …

• p_commit is set to TRUE only when implicit COMMIT is required

• x_return_status is printed to the user’s 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

38

Agenda

• Oracle Integration Repository

• Understand API Definition

• Code Flow

• Demonstration

• Troubleshooting

• Best Practices

• References

• Question / Answer

39

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.

40

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 ?

41

<Insert Picture Here>

Q&A

42© 2009 Oracle Corporation – Proprietary and Confidential

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

43© 2010 Oracle Corporation – Proprietary and Confidential

THANK YOU

44© 2009 Oracle Corporation – Proprietary and Confidential