NoteThe following image contains links to more information.
The Open Data Protocol (OData) includes standard CRUD (Create, Retrieve, Update, and
Delete) operations that map to the HTTP methods POST, GET, PUT/MERGE, and DELETE. In
addition, OData supports further service operations (function imports) that can be invoked
by the HTTP methods GET or POST for anything that cannot be mapped to the standard CRUD
operations. You can implement such additional service operations in the Service Builder by
creating function imports within your data model.
For example, you could create function
imports for the following custom operations:
- Confirm Work Item
- Check Flight Availability
While it is simple to create new function imports to invoke custom operations, if
the operation you want to use can be invoked using a standard CRUD operation, you should
not create a function import. That is, you should only create function imports for
custom operations that cannot be invoked using a standard operation.
Procedure
To create a function import for a custom operation, proceed
as follows:
- Right click the Data Model folder, and select
Create and then select Function Import.
Create Function Import dialog opens.
- In Return Type Kind column select the kind of return
type (if any) you want the function import to return data at runtime.
- In the Return Type column, enter the name of the
complex type or entity type you want the function import to return. You can use
the input help to select an existing complex or entity type from your project.
If the input help is empty, you must first create the relevant complex type or
entity type in your project. If you selected No Return
this field is non-editable.
- In Return Cardinality column, select the cardinality
using input help.
Note If return type of function import is an Entity Type
and:
- If the key properties of entity type are of Core Type
Edm.DateTime, Edm.DateTimeoffset or
Edm.Guid, Return Cardinality 0..1 is not
allowed because, for these Core Types initial ABAP value is not a
valid edm value and it can cause runtime exception. If you select
0..1, an error message is displayed.
- If the key properties of entity type is other than
Edm.DateTime, or
Edm.DateTimeoffset, or
Edm.Guid, and Return Cardinality 0..1 is
selected, a warning message is displayed as cardinality 0..1 is not
recommended for any Core Type as per OData standards.
While upgrading if your project contains Function Import and it's
return type is an entity type having key fields of core type
Edm.DateTime, Edm.DateTimeoffset or
Edm.Guid, you get an error message.
- If you have set the Return Cardinality 0..1 or 1..n , you must enter the
entity set that has to be used in the Return Entity Set
column. In other cases, this column is non-editable.
- Select the HTTP method to invoke the function import. If you do not select an
HTTP method, you have to invoke the function import using the GET or POST
method.
- In Action for Entity Type column select the entity type
to which the function import applies semantically as an action. While this
setting has no effect at runtime, it can help you to determine which function
import belong to a particular entity type.
- In the Label column, you can enter a label for the new
function import. You can enter a free-text label directly or use the
Label Text Reference Editor to enter the reference
type (program, data element, or class). The reference type you select
influences the other input fields (Object Name, Key, and
Label) you have to edit.
- Specify the Function Import name. Function Imports opens in mass maintenance view.
Do the following in mass maintenance view:
You can create a subsequent function
import when you right click Function Import folder and select Create and follow
above procedure.
Alternatively, In the mass maintenance view of Function
Imports, click (Display<->Change) and then (Insert Row) to add new Function Import.
Note To delete a function
import select the relevant function import row from the mass maintenance view and
click
(Delete Row)
- Click Save to save the changes and invoke the custom operation
at runtime.