SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Replace Wrapper by Released API

Learn how to replace the wrapper for the `BAPI_PR_CREATE` function module with the released API `I_PurchaseRequisitionTp` business object interface and maintain the related authorization defaults.

Overview

🎓 intermediate 20 min. ABAP ExtensibilityIntermediateSAP S 4hanaABAP Development

You will learn

  • How to replace the wrapper integration with an EML call to the released API.
  • How to consequently adapt the action implementation as well as the unmanaged save implementation.
  • How to change the BO to strict(2) mode.
  • How to maintain the corresponding authorization defaults as indicated by the released API.
Matthäus Schüle M Matthäus Schüle July 24, 2026
Created by May 6, 2024
Contributors

Prerequisites

Prerequisites

  • You have completed the previous tutorial in this group, integrated your wrapper in your RAP BO and provided authorizations to users for non-released authorization objects.

Steps

Intro

The complete scenario showing how to create a RAP BO and integrate a released purchase requisition API is presented in the tutorial group Develop an SAP Fiori App to Trigger Purchase Requisitions API. This tutorial specifically focuses on the transition from using the wrapper to using the released API.

In the previous tutorials of this group you learnt how to mitigate the case of a missing released API to create purchase requisitions, by creating a wrapper and integrating it into your shopping cart RAP business object (RAP BO).

When SAP provides a released API, then it is recommended to use that one.

Therefore, in this tutorial you will learn how to replace the wrapper for the BAPI_PR_CREATE function module with the released I_PurchaseRequisitionTp business object interface.

Throughout this tutorial, wherever ### appears, use a number (e.g. 000). This tutorial is done with the placeholder 000.

Step 1 Adapt the Behavior Implementation

As explained in the previous tutorial of this series Integrate the Wrapper into the Shopping Cart Business Object the logic works as follows:

When the createpurchrqnbapisave action is used, the shopping cart orders are marked (similar to a checkbox) using the OverallStatus field, and then the actual purchase requisition creation is handled in the unmanaged save implementation in thesave_modified method.

Since in this tutorial we want to use the released API to create purchase requisitions (rather than the BAPI) you will now adapt the createpurchrqnbapisave method and thesave_modified method to replace the call to the BAPI wrapper with an EML call to the released API.

Connect to the system via ADT and navigate to the package Z_PURCHASE_REQ_### containing the RAP BO.

You will first declare some new needed data types and then you will modify the createpurchrqnbapisave method to handle the creation of a purchase requisition for a given shopping cart item using the released purchase requisition API.

Open the global class of the behavior implementation ZBP_SHOPCARTTP_### and add the following code snippet in thepublic section:

ABAP
TYPES: BEGIN OF ty_pr_details,
         pid        TYPE abp_behv_pid,
         cid        TYPE abp_behv_cid,
         pur_req    TYPE zashopcart_###-purchase_requisition,
         order_uuid TYPE zashopcart_###-order_uuid,
       END OF ty_pr_details.
CLASS-DATA purchase_requisition_details TYPE TABLE OF ty_pr_details.

You just defined a new table type, which will be used in the behavior implementation to store information on the purchase requisition of a given shopping cart entry. This information consist of a pid, or preliminary key (the released API uses late numbering, so when being called by the application it will only return this preliminary key which is converted into the final key in a later step), a cid (which is needed in the case in which the purchase requisition gets updated), a pur_req (which will store the actual purchase requisition number that will be created), and the order_uuid (which is the id of the given shopping cart entry for a which a purchase requisition number will be created).

Your global class should now look as follows:

Global Class
Global Class

Save it. Do NOT activate it yet.

The data type you just created will be used in the behavior implementation.

Open the lhc_shopcart class of the behavior implementation and navigate to the createpurchrqnbapisave method. Add the following code snippet after the first READ entities statement.

ABAP
DATA: purchase_requisitions      TYPE TABLE FOR CREATE I_PurchaserequisitionTP,
      purchase_requisition       TYPE STRUCTURE FOR CREATE I_PurchaserequisitionTP,
      purchase_requisition_items TYPE TABLE FOR CREATE i_purchaserequisitionTP\_PurchaseRequisitionItem,
      purchase_requisition_item  TYPE STRUCTURE FOR CREATE i_purchaserequisitiontp\\purchaserequisition\_purchaserequisitionitem,
      delivery_date              TYPE I_PurchaseReqnItemTP-DeliveryDate,
      n                          TYPE i.
LOOP AT onlineorders INTO DATA(onlineorder) WHERE OverallStatus = c_overall_status-new .

  delivery_date = cl_abap_context_info=>get_system_date( ) + 14.

  n += 1.
  "purchase requisition
  DATA(cid) = onlineorder-OrderID && '_' && n.
  purchase_requisition = VALUE #( %cid = cid
  purchaserequisitiontype = 'NB' ) .
  APPEND purchase_requisition TO purchase_requisitions.

  "purchase requisition item
  purchase_requisition_item = VALUE #(
  %cid_ref = cid
  %target = VALUE #( (
  %cid = |My%ItemCID_{ n }|
  plant = '1010' "Plant 01 (DE)
  accountassignmentcategory = 'U' "unknown
* PurchaseRequisitionItemText = . "retrieved automatically from maintained MaterialInfo
  requestedquantity = '1'
  purchaserequisitionprice = '100'
  purreqnitemcurrency = 'EUR'
  Material = 'D001'
  materialgroup = 'A001'
  purchasinggroup = '001'
  purchasingorganization = '1010'
  DeliveryDate = delivery_date "delivery_date "yyyy-mm-dd (at least 10 days)
  CreatedByUser = OnlineOrder-CreatedBy
  ) ) ).
  APPEND purchase_requisition_item TO purchase_requisition_items.
ENDLOOP.
IF keys IS NOT INITIAL .
  "purchase reqn
  MODIFY ENTITIES OF i_purchaserequisitiontp
  ENTITY purchaserequisition
  CREATE FIELDS ( purchaserequisitiontype )
  WITH purchase_requisitions
  "purchase reqn item
  CREATE BY \_purchaserequisitionitem
  FIELDS ( plant
* purchaserequisitionitemtext
  accountassignmentcategory
  requestedquantity
  baseunit
  purchaserequisitionprice
  purreqnitemcurrency
  Material
  materialgroup
  purchasinggroup
  purchasingorganization
  DeliveryDate

  )
  WITH purchase_requisition_items
  REPORTED DATA(reported_create_pr)
  MAPPED DATA(mapped_create_pr)
  FAILED DATA(failed_create_pr).
ENDIF.

IF mapped_create_pr IS NOT INITIAL.
  LOOP AT onlineorders INTO DATA(onlineorder1) WHERE OverallStatus = c_overall_status-new.
    LOOP AT mapped_create_pr-purchaserequisition INTO DATA(purchaserequisition_details) .
      IF onlineorder1-OrderID = substring_before( val = purchaserequisition_details-%cid sub = '_' ).

        APPEND VALUE #( cid = purchaserequisition_details-%cid
        pid = purchaserequisition_details-%pid
        order_uuid = onlineorder1-OrderuuID ) TO zbp_shopcarttp_###=>purchase_requisition_details .
        DELETE ADJACENT DUPLICATES FROM zbp_shopcarttp_###=>purchase_requisition_details COMPARING pid.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
ENDIF.

The createpurchrqnbapisave method handles the creation of a purchase requisition for a given shopping cart entry via released API. In the case of mass creation of multiple purchase requisitions, the purchaserequisition_details table handles the mapping between purchase requisition number and its corresponding shopping cart entry.

The createpurchrqnbapisave method should now look like this:

Implementation Code
Implementation Code

You will now navigate to the save_modified method, remove the call to the BAPI wrapper and insert the following code snippet with an EML call to the released API:

ABAP
METHOD save_modified.
    IF create-ShoppingCart IS NOT INITIAL.
      INSERT zashopcart_### FROM TABLE @create-ShoppingCart MAPPING FROM ENTITY.
    ENDIF.

    IF update IS NOT INITIAL.
      DATA(creation_date) = cl_abap_context_info=>get_system_date( ).

      LOOP AT update-ShoppingCart INTO DATA(OnlineOrder1) WHERE %control-OverallStatus = if_abap_behv=>mk-on.
        LOOP AT zbp_shopcarttp_###=>purchase_requisition_details INTO DATA(purchase_reqn_via_eml) WHERE pid IS NOT INITIAL AND order_uuid = onlineorder1-OrderUUID.
          CONVERT KEY OF i_purchaserequisitiontp FROM purchase_reqn_via_eml-pid TO DATA(ls_pr_key1).
          UPDATE zashopcart_### SET purchase_requisition = @ls_pr_key1-PurchaseRequisition,
          overall_status = 'Submitted / Approved',
          pr_creation_date = @creation_date
          WHERE order_uuid = @purchase_reqn_via_eml-Order_UUID.
        ENDLOOP.
      ENDLOOP.
    ENDIF.

    LOOP AT delete-ShoppingCart INTO DATA(shoppingcart_delete) WHERE OrderUUID IS NOT INITIAL.
      DELETE FROM zashopcart_### WHERE order_uuid = @shoppingcart_delete-OrderUUID.
      DELETE FROM zdshopcart_### WHERE orderuuid = @shoppingcart_delete-OrderUUID.
    ENDLOOP.
ENDMETHOD.

As previously explained, the released API I_PurchaserequisitionTP uses late numbering and so, when being called by the application, it will only return a preliminary key %pid. In order to retrieve the final key you have to use the CONVERT KEY keyword.

The save_modified method should now look as follows:

save_modified implementation
save_modified implementation

Save and activate it.

Step 2 Remove `checkPurchaseRequisition` method
+
Step 3 Switch to strict(2) mode
+
Step 4 Run SAP Fiori Elements Preview
+
Step 5 Maintain Authorization Defaults
+
Step 6 Test yourself
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 6
1. Adapt the Behavior Implementation 2. Remove `checkPurchaseRequisition` method 3. Switch to strict(2) mode 4. Run SAP Fiori Elements Preview 5. Maintain Authorization Defaults 6. Test yourself

Learn more →