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

Integrate released purchase requisition API into Shopping Cart Business Object

Integrate released purchase requisition API into shopping cart business object with SAP S/4HANA Cloud, ABAP Environment or SAP S/4HANA on-premise.

Overview

🎓 beginner 25 min. SAP S 4hana Cloud ABAP EnvironmentBeginnerABAP DevelopmentABAP Extensibility

You will learn

  • โœ”How to enhance the behavior definition of a data model
  • โœ”How to enhance the behavior definition of a projection view
  • โœ”How to enhance metadata extensions
  • โœ”How to implement the unmanaged save and save_modified
  • โœ”How to enhance a behavior implementation
  • โœ”How to run the SAP Fiori Elements Preview
  • โœ”How to check purchase requisitions
Merve Temel M Merve Temel March 22, 2024
Created by August 15, 2023
Contributors

Prerequisites

Prerequisites

  • This tutorial can be used in both SAP S/4HANA Cloud, private edition system and SAP S/4HANA on-premise system with release 2022 FPS01. We suggest using a Fully-Activated Appliance in SAP Cloud Appliance Library for an easy start without the need for system setup.
  • For SAP S/4HANA on-premise, create developer user with full development authorization
  • You have installed the latest Eclipse with ADT.
  • Business role SAP_BR_PURCHASER needs to be assigned to your business user
  • Use Starter Development Tenant in S/4HANA Cloud for the tutorial to have necessary sample data in place. See 3-System Landscape and Transport Management.

Steps

In the shopping cart, customers can order various items. Once an item is ordered, a new purchase requisition is created via purchase requisitions API.

EML can be used to trigger purchase requisitions API, which is released for cloud development.

Intro

In this tutorial, wherever ### appears, use a number (e.g. 000).


Step 1 Enhance behavior definition of data model
โ€”

Hint: In case of S/4HANA 2022 FPS01, strict(1) mode must be used.

  1. Add the following action statement for createPurchaseRequisitionItem to your behavior definition ZR_SHOPCARTTP_###.
```ABAP
validation checkPurchaseRequisition on save { field OverallStatus; }
action ( features : instance ) createPurchaseRequisitionItem result [1] $self;
```

 ![projection](https://raw.githubusercontent.com/sap-tutorials/abap-core-development/main/tutorials/abap-s4hanacloud-purchasereq-integrate-api/bdef5.png)

 **Hint:** Please replace **`###`** with your ID. 
  1. Check your behavior definition:
```ABAP
managed implementation in class ZBP_SHOPCARTTP_### unique;
strict ( 2 );
with draft;

define behavior for ZR_SHOPCARTTP_### alias ShoppingCart
persistent table zashopcart_###
draft table ZDSHOPCART_###
etag master LocalLastChangedAt
lock master total etag LastChangedAt
authorization master( global )

{
  field ( readonly )
  OrderUUID,
  CreatedAt,
  CreatedBy,
  LastChangedAt,
  LastChangedBy,
  LocalLastChangedAt,
  PurchaseRequisition,
  PrCreationDate,
  DeliveryDate;

  field ( numbering : managed )
  OrderUUID;

  create;
  update(features: instance) ;
  delete;

  draft action(features: instance) Edit;
  draft action Activate;
  draft action Discard;
  draft action Resume;
  draft determine action Prepare { validation checkOrderedQuantity;  validation checkDeliveryDate;}
    determination setInitialOrderValues on modify { create; }
    determination calculateTotalPrice on modify { create; field Price; }
  validation checkOrderedQuantity on save { create; field OrderQuantity; }
  validation checkDeliveryDate on save { create; field DeliveryDate; }

  validation checkPurchaseRequisition on save { field OverallStatus; }
  action ( features : instance ) createPurchaseRequisitionItem result [1] $self;

  mapping for ZASHOPCART_###
  {
    OrderUUID = order_uuid;
    OrderID = order_id;
    OrderedItem = ordered_item;
    Price = price;
    TotalPrice = total_price;
    Currency = currency;
    OrderQuantity = order_quantity;
    DeliveryDate = delivery_date;
    OverallStatus = overall_status;
    Notes = notes;
    CreatedBy = created_by;
    CreatedAt = created_at;
    LastChangedBy = last_changed_by;
    LastChangedAt = last_changed_at;
    LocalLastChangedAt = local_last_changed_at;
    PurchaseRequisition = purchase_requisition;
    PrCreationDate = pr_creation_date;
  }
}
```
  1. Save and activate.
Step 2 Enhance behavior definition of projection view
+
Step 3 Enhance metadata extension
+
Step 4 Implement unmanaged save and save_modified
+
Step 5 Enhance behavior implementation
+
Step 6 Open documentation
+
Step 7 Run SAP Fiori Elements preview
+
Step 8 Check purchase requisition
+
Step 9 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 9
1. Enhance behavior definition of data model 2. Enhance behavior definition of projection view 3. Enhance metadata extension 4. Implement unmanaged save and save_modified 5. Enhance behavior implementation 6. Open documentation 7. Run SAP Fiori Elements preview 8. Check purchase requisition 9. Test yourself

Learn more →