Operating the RFC/BOR Generator

Objectives

After completing this lesson, you will be able to:
  • Define a data model based on an RFC/BOR interface
  • Map Operations to an RFC/BOR implementation

RFC/BOR Interface Import

Development flow: RFC/BOR generator

With code mapping, you can generate source code for OData operations by establishing a relationship between the interface parameters of a reuse unit and the properties of an entity set. This is done with the built-in mapping tool of the SAP Gateway Service Builder.

  • For a function module or BAPI (Business Application Programming Interface), you can map the create, read, update, delete, and query operations separately for each entity set of your data model.
  • For a search help, you can map the read and query operation for each entity set.
  • For a CDS view, you map the whole entity set generating code for the read and query operations.

For a smooth mapping experience it is recommended to use the interface of the reuse unit as template for the entity types of the entity sets, which should be mapped. For a function module, these are the importing, exporting, and changing parameters in its interface.

Development steps: RFC/BOR generator

The implementation process starts with the import of the interface of a function module. In contrast to code-based service implementation, service implementation via mapping can already be started prior to generating the runtime artifacts.

You usually start with mapping of the read and query methods, then the service is registered and tested. If the test is successful, you can then implement the CUD methods via mapping of appropriate function modules. The reason is that you usually test the CUD methods by reusing successful HTTP responses of read requests as input.

Screenshot flow about importing an RFC/BOR interface in SEGW

To import a function module interface, right-click Data Model and choose ImportRFC/BOR Interface. This opens the first step of the Create Entity Type from Data Source Wizard.

A function module usually provides only the functionality for one CRUD method. So you will use distinct function modules to map each CRUD method. But you can only choose one function module as template for the entity type. Therefore, the interface of this function module should provide a parameter as template for the entity type that is suitable to be reused for the other function modules.

Note

It is quite common that function modules defined as BAPIs in the Business Object Repository (BOR) or included in other data models reuse the same data dictionary types in their interfaces.
Screenshot flow about the Create Entity Type from Data Source wizard in SEGW

The Create Entity Type from Data Source Wizard consists of the following steps:

  1. In the first screen, you enter a name and select if you want to use a local or remote data source. For a remote data source, an RFC destination must be provided.
  2. Using the value help, you select the data source to be imported.
  3. When the option Create Default Entity Set is selected, the wizard creates an entity set called <Name of entity type>Set, for example, ProductSet.
  4. In the next screen, you select the fields of at least one parameter, which should become properties of the entity type. It is also possible to assign the selected fields as a structure to one property of the entity type. This will result in a complex type based on the selected fields of the parameter.
  5. Finally you choose the key field(s). Every entity type in OData must have at least one key field. It is also possible to rename the properties of the entity type since the proposed values are generated based on the ABAP field names: The underscores in the field names are removed and the name segments are merged in a camel case notation.

    Caution

    Only properties based on primitive types can be selected as key, not the ones based on complex types.

This wizard has some parallels with the Import from DDIC Structure Wizard. One of the major differences is that interface parameters can be assigned as structure to entity type properties. This might get handy in complex data models but could also be solved in other ways.

More important is the second major difference: You can choose remote-enabled function modules of other ABAP systems as data source. If you implement your OData service in one system and for any reason want to get data from another system, there is no better way than using RFC. By using this wizard, you can actually use the technical definition of DDIC types of another system to generate identical local types in your system. Remember that the DDIC itself is not remote-enabled, but the function modules are.

Hint

If you want to map a local function module, it is also fine to call the Import from DDIC Structure Wizard selecting the DDIC type used for the parameter in the function module interface.

RFC/BOR Query Mapping

Screenshot flow about mapping GetEntitySet (Query) in SEGW – Select RFC

To map the query operation to a data source, expand the entity set under Service Implementation, right-click the GetEntitySet (Query) method, and choose Map to Data Source. In the Map to Data Source popup, select if you want to map a local or remote data source.

To map a function module, select Remote Function Module as Type and enter the name of the function module. A value help is available to ease finding the right function module.

Screenshot flow about mapping GetEntitySet (Query) in SEGW – Propose Mapping

Use Propose Mapping to automatically generate available mapping relations between the properties of the entity set and the parameters of the data source. If the entity type of the entity set was created based on the type of the parameter, the properties are completely mapped. You may generate the runtime artifacts and start testing the query operation.

If the entity type of the entity set differs from the type of the parameters, you may add missing mappings by dragging and dropping the parameter fields of the data source to the suitable entity set properties in the mapping table.

Export parameters are mapped as output showing an arrow pointing from the data source on the right to the entity set on the left. Changing parameters are also mapped as output but can be changed to input by choosing the arrows in the table. This is done if you want to provide data from the OData request to the function module.

Screenshot flow about mapping GetEntitySet (Query) in SEGW – Max Rows and Log

Depending on the function module interface, additional features can be implemented by mapping suitable parameters. Many function modules offer a parameter to limit the number of selected data sets. This corresponds to the query option $top.

In our example, to map $top in the Data Source Parameter view on the right, expand the MAX_ROWS node. Select BAPIMAXROW and choose Set/Unset Max Hits.

BAPIs do not throw any errors but use a parameter called RETURN of type BAPIRET2 to inform the caller about errors. The mapping tool recognizes this parameter automatically and flags it as log. All messages provided via this parameter are now handled as errors in the generated code. If you want to change this or flag another parameter as log, you can use the Set/Unset Log button.

Screenshot flow about mapping GetEntitySet (Query) in SEGW – Filter

Function modules providing a list of data sets often define parameters to apply filters on the list in their interface. If such a parameter is defined as a range table, then the mapping tool automatically recognizes this and flags it as a range. If you want to change this or flag another parameter as range, you can use the Set/Unset Range button.

To map $filter, you must add the property of the entity set, which should be filtered, and map it to the filter parameter of the data source. In our example, you do this by following these steps:

  1. Choose Append Row.
  2. In the Entity Set property field, enter BuyerName by using the value help.
  3. Drag and drop the data source parameter SELPARAMBUYERNAME from the right to the Data Source Parameter table field on the left.
  4. Confirm the mapping of the range table n the popup.

This creates an input mapping showing an arrow pointing from the entity set on the left to the data source on the right.

RFC/BOR Read Mapping

Mapping GetEntity (Read)

Screenshot flow about mapping GetEntity (Read) in SEGW – Select RFC

To map the read operation to a data source, expand the entity set under Service Implementation, right-click the GetEntity (Read) method, and choose Map to Data Source. In the Map to Data Source popup, select if you want to map a local or remote data source.

To map a function module, select Remote Function Module as Type and enter the name of the function module. A value help is available to ease finding the right function module.

Screenshot flow about mapping GetEntity (Read) in SEGW – Propose Mapping

Use Propose Mapping to automatically generate available mapping relations between the properties of the entity set and the parameters of the data source. Please note that the mapping is not complete because to retrieve a single entity, you still need to specify the key field(s). In addition, the function module defines a parameter as mandatory. Luckily this is the key we must map anyway.

Screenshot flow about mapping GetEntity (Read) in SEGW – Key Field(s)

For the key field(s), one or more lines must be added and mapped (here: SoId):

  1. Choose Append Row.
  2. In the Entity Set property field, enter SoId by using the value help.
  3. Drag and drop the data source parameter SO_IDSO_ID from the right to the Data Source Parameter table field on the left.

This creates an input mapping showing an arrow pointing from the entity set on the left to the data source on the right. Now you may generate the runtime artifacts and start testing the read operation.

RFC/BOR CUD Mapping

Map Create Operation

Mapping CUD operations to a data source follows the same principle as mapping read. First, expand the entity set under Service Implementation, right-click the method you want to map, and choose Map to Data Source. In the Map to Data Source popup, select if you want to map a local or remote data source.

To map a function module, select Remote Function Module as Type and enter the name of the function module. A value help is available to ease finding the right function module.

Screenshot about mapping create operation in SEGW

Use Propose Mapping to automatically generate available mapping relations between the properties of the entity set and the parameters of the data source. If the entity type of the entity set was created based on the type of the parameter, the properties are completely mapped as input.

It is often the case that the key is generated during creation of a data set. To provide this key to the requester, you must map the key field(s) as output (here: SoId):

  1. Choose Append Row.
  2. In the Entity Set property field, enter SoId by using the value help.
  3. Drag and drop the data source parameter SALESORDERIDSO_ID from the right to the Data Source Parameter table field on the left.

Now you may generate the runtime artifacts and start testing the create operation.

Map Update Operation

Screenshot about mapping update operation in SEGW

Also for the update operation, use Propose Mapping to automatically generate available mapping relations between the properties of the entity set and the parameters of the data source. If the entity type of the entity set was created based on the type of the parameter, the properties are completely mapped as input.

To call an update module in ABAP, you must provide additional parameters with mappings. In our example, the SoId property must be mapped to three input parameters:

  • Identify data set via SO_IDSO_ID
  • Pass data via SOHEADERDATASO_ID
  • Document transfer via SOHEADERDATAXSO_ID

The SOHEADERDATAX import structure is a convention for BAPIs. You tell the BAPI by passing an "X" in its components, which component of the SOHEADERDATA import structure is transferred. Not all fields are transferred because they are calculated by the function module.

Hint

If the function module offers additional parameters as a kind of flag to control the behavior of the function module, you may supply these by mapping suitable constant values to the parameters.

Map Delete Operation

Screenshot about mapping delete operation in SEGW

For the delete operation, only the key field(s) must be mapped as input. Propose Mapping can be used or just drag and drop. The only output are the status messages in the RETURN parameter, which is automatically flagged as log.

Create an SAP Gateway Service with the BOR/RFC Generator

Business Example

You are a developer or solution architect in your company. You need to import and map BOR/RFC function modules to read and query operations of an SAP Gateway service.

Template:
GW100_S_CUD (SAP Gateway Project)
Solution:
GW100_S_BORRFC (SAP Gateway Project)

Note

This exercise requires an SAP Learning system. Login information are provided by your system setup guide.

Note

You may continue with your solution of the previous exercise or copy the template to ZGW100_##_BORRFC. Whenever the values or object names in this exercise include ##, replace ## with the number of your user.

Prerequisites

The data model for business partner was defined in exercise Add an Additional Entity to a Data Model.

Task 1: Define the Entity SalesOrder based on a Function Module

Steps

  1. In the SAP Gateway Service Builder of your SAP S/4HANA (S4H) system, import the parameter HEADERDATA of the RFC/BOR interface BAPI_EPM_SO_GET_DETAIL as entity SalesOrder. Select the following fields and define SO_ID as key:

    StructureComponent
    HEADERDATASO_ID
    HEADERDATANOTE
    HEADERDATABUYER_ID
    HEADERDATABUYER_NAME
    HEADERDATACURRENCY_CODE
    HEADERDATAGROSS_AMOUNT
    HEADERDATANET_AMOUNT
    HEADERDATATAX_AMOUNT
    HEADERDATALIFECYCLE_STATUS
    HEADERDATABILLING_STATUS
    HEADERDATADELIVERY_STATUS
    1. In the SAP Easy Access of your S4H, search for SAP Gateway Service Builder or start transaction SEGW.

    2. In the SAP Gateway Service Builder, in the context menu of Data Model, choose ImportRFC/BOR Interface.

    3. In the Create Entity Type from Data Source popup, enter the following values:

      FieldValue
      Entity Type NameSalesOrder
      Type (Data Source Attributes)Remote Function Call
      Name (Data Source Attributes)BAPI_EPM_SO_GET_DETAIL
    4. Choose Next.

    5. Expand the tree node HEADERDATA.

    6. Select the checkbox for the following components:

      StructureComponent
      HEADERDATASO_ID
      HEADERDATANOTE
      HEADERDATABUYER_ID
      HEADERDATABUYER_NAME
      HEADERDATACURRENCY_CODE
      HEADERDATAGROSS_AMOUNT
      HEADERDATANET_AMOUNT
      HEADERDATATAX_AMOUNT
      HEADERDATALIFECYCLE_STATUS
      HEADERDATABILLING_STATUS
      HEADERDATADELIVERY_STATUS
    7. Choose Next.

    8. Select the Is Key checkbox for the field SO_ID.

    9. Choose Finish.

      Note

      Don't worry about the Potential loss of data; ABAP type is more restrictive warnings . This should just remind you to check the system customizing for amount fields. There is no such customizing active in the learning system.
    10. Choose Save.

Task 2: Model a Navigation between BusinessPartner and SalesOrder

Steps

  1. Model navigation BusinessPartner_SalesOrders between the entities BusinessPartner and SalesOrder connecting one BusinessPartnerID to many BuyerId. Create the navigation properties SalesOrders and Buyer in the according entity types.

    1. In the SAP Gateway Service Builder of your S4H, expand the node Data ModelEntity Types.

    2. In the context menu of Associations, choose Create.

    3. In the Create Association popup, in the Association Name field, enter BusinessPartner_SalesOrders.

    4. For the Principal Entity, enter the following values:

      FieldValue
      Entity type nameBusinessPartner
      Cardinality1
      Navigation PropertySalesOrders
    5. Select the Create related Navigation Property checkbox for the Dependent Entity.

    6. For the Dependent Entity, enter the following values:

      FieldValue
      Entity type nameSalesOrder
      Cardinality1..n
      Navigation PropertyBuyer
    7. Click Next.

    8. In the Dependent Property field, enter BuyerId by using the value help.

    9. Click Next.

    10. Click Finish.

    11. Choose Save.

Task 3: Map the Query and Read Operations of SalesOrder to a Function Module

Steps

  1. In the SAP Gateway Service Builder of your S4H, map the read operation of entity set SalesOrderSet to the function module BAPI_EPM_SO_GET_DETAIL.

    1. In the SAP Gateway Service Builder of your S4H, expand the node Service ImplementationSalesOrderSet.

    2. In the context menu of GetEntity (Read), choose Map to Data Source.

    3. In the Map to Data Source popup, enter the following values:

      FieldValue
      TypeRemote Function Call
      NameBAPI_EPM_SO_GET_DETAIL
    4. Choose Continue.

    5. Choose Propose Mapping.

    6. Choose Append Row.

    7. In the Entity Set property field, enter SoId by using the value help.

    8. In the Data Source Parameter view on the right, expand the node SO_ID.

    9. Drag and drop the Data Source ParameterSO_ID from the right to the Data Source Parameter field of the new table entry to the left.

    10. Choose Check Project Consistency.

    11. Choose Save.

  2. Map the query operation of entity set SalesOrderSet to the function module BAPI_EPM_SO_GET_LIST. Set the maximum hits and map filters for SoId and BuyerName.

    1. Expand the node Service ImplementationSalesOrderSet.

    2. In the context menu of GetEntitySet (Query), choose Map to Data Source.

    3. In the Map to Data Source popup, enter the following values:

      FieldValue
      TypeRemote Function Call
      NameBAPI_EPM_SO_GET_LIST
    4. Choose Continue.

    5. Choose Propose Mapping.

    6. In the Data Source Parameter view on the right, expand the node MAX_ROWS.

    7. Select BAPIMAXROW and choose Set/Unset Max Hits.

    8. Choose Append Row.

    9. In the field Entity Set property, enter SoId by using the value help.

    10. Drag and drop the Data Source ParameterSELPARAMSOID from the right to the Data Source Parameter field of the new table entry to the left.

    11. In the Map Range popup, choose Continue.

    12. Choose Append Row.

    13. In the field Entity Set property, enter BuyerName by using the value help.

    14. Drag and drop the Data Source ParameterSELPARAMBUYERNAME from the right to the Data Source Parameter field of the new table entry to the left.

    15. In the Map Range popup, choose Continue.

    16. Choose Generate Runtime Objects.

    17. For every popup, choose the transport request provided to you.

Task 4: Test the Query and Read Operations of SalesOrder

Steps

  1. In the SAP Gateway Client of your S4H, test the paging operation for sales orders in your service. Query the first two sales orders.

    1. In the SAP Gateway Service Builder of your S4H, double-click Service Maintenance.

    2. Choose SAP Gateway Client.

    3. In the SAP Gateway Client, select HTTPS as Protocol.

    4. Choose Entity Set.

    5. In the Entity Sets popup, double-click SalesOrderSet.

    6. Choose Add URI Option.

    7. In the Add URI Option popup, double-click $top=2.

      Example

      /sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/SalesOrderSet?$top=2
    8. Choose Execute.

      Result

      The HTTP Response displays the first two sales orders.
  2. Test the filter operation for sales orders in your service. Filter the sales orders with the buyer name "SAP".

    1. In the Request URI field, add &$filter=BuyerName eq 'SAP' to the URI.

      Example

      /sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/SalesOrderSet?$top=2&$filter=BuyerName eq 'SAP'
    2. Choose Execute.

      Result

      The HTTP Response displays the first two sales orders of the buyer "SAP".
  3. Test the read operation for sales orders in your service. Read a single sales order.

    1. In the Request URI field, replace ?$top=3&$filter=BuyerName eq 'SAP' with the key of a sales order.

      Example

      /sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/SalesOrderSet('500000000')
    2. Choose Execute.

      Result

      The HTTP Response displays the sales order.
    3. Memorize the sales order ID.

Task 5: Define the Entity SalesOrderItem based on a Function Module

Steps

  1. In the SAP Gateway Service Builder of your S4H, import the parameter ITEMDATA[] of the RFC/BOR interface BAPI_EPM_SO_GET_DETAIL as entity SalesOrderItem. Select the following fields and define SO_ID and SO_ITEM_POS as key:

    StructureComponent
    ITEMDATA[]SO_ID
    ITEMDATA[]SO_ITEM_POS
    ITEMDATA[]PRODUCT_ID
    ITEMDATA[]NOTE
    ITEMDATA[]CURRENCY_CODE
    ITEMDATA[]GROSS_AMOUNT
    ITEMDATA[]NET_AMOUNT
    ITEMDATA[]TAX_AMOUNT
    ITEMDATA[]DELIVERY_DATE
    ITEMDATA[]QUANTITY
    ITEMDATA[]QUANTITY_UNIT
    1. In the SAP Gateway Service Builder of your S4H, in the context menu of Data Model, choose ImportRFC/BOR Interface.

    2. In the Create Entity Type from Data Source popup, enter the following values:

      FieldValue
      Entity Type NameSalesOrderItem
      Type (Data Source Attributes)Remote Function Call
      Name (Data Source Attributes)BAPI_EPM_SO_GET_DETAIL
    3. Choose Next.

    4. Expand the tree node ITEMDATA[].

    5. Select the checkbox for the following components:

      StructureComponent
      ITEMDATA[]SO_ID
      ITEMDATA[]SO_ITEM_POS
      ITEMDATA[]PRODUCT_ID
      ITEMDATA[]NOTE
      ITEMDATA[]CURRENCY_CODE
      ITEMDATA[]GROSS_AMOUNT
      ITEMDATA[]NET_AMOUNT
      ITEMDATA[]TAX_AMOUNT
      ITEMDATA[]DELIVERY_DATE
      ITEMDATA[]QUANTITY
      ITEMDATA[]QUANTITY_UNIT
    6. Choose Next.

    7. Select the Is Key checkbox for the fields SO_ID and SO_ITEM_POS.

    8. Choose Finish.

      Note

      Don't worry about the Potential loss of data; ABAP type is more restrictive warnings . This should just remind you to check the system customizing for amount fields. There is no such customizing active in the learning system.
    9. Choose Save.

Task 6: Model a Navigation between SalesOrder and SalesOrderItem

Steps

  1. Model navigation SalesOrder_SalesOrderItems between the entities SalesOrder and SalesOrderItem connecting one SoId of sales order to many SoId of sales order items. Create the navigation properties Items and SalesOrder in the according entity types.

    1. In the SAP Gateway Service Builder of your S4H, expand the node Data ModelEntity Types.

    2. In the context menu of Associations, choose Create.

    3. In the Create Association popup, in the field Association Name, enter SalesOrder_SalesOrderItems.

    4. For the Principal Entity, enter the following values:

      FieldValue
      Entity Type NameSalesOrder
      Cardinality1
      Navigation PropertyItems
    5. Select the Create related Navigation Property checkbox for the Dependent Entity.

    6. For the Dependent Entity, enter the following values:

      FieldValue
      Entity Type NameSalesOrderItem
      Cardinality1..n
      Navigation PropertySalesOrder
    7. Choose Next.

    8. In the Dependent Property field, enter SoId by using the value help.

    9. Choose Next.

    10. Choose Finish.

    11. Choose Save.

Task 7: Map the Query Operation of SalesOrderItem to a Function Module

Steps

  1. In the SAP Gateway Service Builder of your S4H, map the query operation of entity set SalesOrderItemSet to the function module BAPI_EPM_SO_GET_DETAIL including the filter for SoId

    1. In the SAP Gateway Service Builder of your S4H, expand the node Service ImplementationSalesOrderItemSet.

    2. In the context menu of GetEntitySet (Query), choose Map to Data Source.

    3. In the Map to Data Source popup, enter the following values:

      FieldValue
      TypeRemote Function Call
      NameBAPI_EPM_SO_GET_DETAIL
    4. Choose Continue.

    5. Choose Propose Mapping.

    6. Choose Append Row.

    7. In the Entity Set property field, enter SoId by using the value help.

    8. In the Data Source Parameter view on the right, expand the node SO_ID.

    9. Drag and drop the Data Source ParameterSO_ID from the right to the Data Source Parameter field of the new table entry to the left.

    10. Choose Generate Runtime Objects.

Task 8: Test the Query and Operation of SalesOrderItem

Steps

  1. In the SAP Gateway Client of your S4H, test the navigation between sales order and sales order items in your service. Query the items of the sales order you read before.

    1. In the SAP Gateway Service Builder of your S4H, double-click Service Maintenance.

    2. Choose SAP Gateway Client.

    3. In the SAP Gateway Client, select HTTPS as Protocol.

    4. Choose Entity Set.

    5. In the Entity Sets popup, double-click SalesOrderSet.

    6. In the Request URI field, add the memorized key of the sales order you read before to the URI.

    7. In the Request URI field, add /Items to the URI.

      Example

      /sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/SalesOrderSet('500000000')/Items
    8. Choose Execute.

      Result

      The HTTP Response displays the items of the sales order.
  2. Test the expand operation for sales order and sales order items in your service. Read the sales order you read before including its items.

    1. In the Request URI field, replace the / in front of Items with ?$expand=.

      Example

      /sap/opu/odata/SAP/ZGW100_##_STUDENT_SRV/SalesOrderSet('500000000')?$expand=Items
    2. Choose Execute.

      Result

      The HTTP Response displays the sales order and its items.

Task 9: Document the Query Options Generated via BOR/RFC Generator in the Metadata

Steps

  1. In the SAP Gateway Service Builder of your S4H, set the entity set SalesOrderSet to be Pageable and set the entity set SalesOrderItemSet to be Pageable and RequiresFilter.

    1. In the SAP Gateway Service Builder of your S4H, expand Data Model.

    2. Double-click Entity Sets.

    3. For of the SalesOrderSet, set the Pageable checkbox.

    4. For of the SalesOrderItemSet, set the Pageable and RequiresFilter checkbox.

  2. Set the properties SoId and BuyerName of the entity type SalesOrder to be Filterable. Set the property SoId of the entity type SalesOrderItem to be Filterable.

    1. Expand Data ModelEntity TypesSalesOrder.

    2. Double-click Properties.

    3. For the properties SoId and BuyerName, set the Filterable checkbox.

    4. Expand SalesOrderItem.

    5. Double-click Properties.

    6. For the property SoId, set the Filterable checkbox.

    7. Choose Generate Runtime Objects.

Log in to track your progress & complete quizzes