Democratising Data: How SAP CAP Empowers Business Users in Application Development

Qazi Murtaza
Qazi Murtaza
Senior Consultant - DevOps

Table of Contents

Introduction

Is “Data Democratisation” just another buzzword, or does it truly hold significance? I found this blog by Arpit Choudhury who defines Data Democratisation as “the ongoing process of enabling everybody in an organisation, irrespective of their technical know-how, to work with data comfortably, to feel confident talking about it, and as a result, make data-informed decisions and build customer experiences powered by data.“, but he hilariously points out that it’s not as simple as handing over your company’s relational database to your team and proclaiming, “We’re all about Data Democratisation!” That’s like saying you’re an open book while the book is in a foreign language.

Let’s face it; real Data Democratisation goes way beyond just granting access. It’s about empowering teams with the right tools and knowledge to make data-driven decisions. So, as tempting as it might be to toss around buzzwords, let’s focus on embracing the real essence of Data Democratisation and unlocking its true potential!

To achieve this, we need to constantly seek ways to streamline our processes and make data-driven decisions.  We need to empower our teams to be data literate, ask questions based on the data, enable technologies that make it easier for everybody to work with data, and there is no better example of that than SAP CAP.

SAP Cloud Application Programming Model (CAP) is a powerful framework that allows business users to participate in application development actively, simplifying data modelling and service creation. In this blog, we will explore how SAP CAP empowers business users to become key players in application development through examples and code excerpts.

What is the SAP Cloud Application Programming Model (CAP)?

SAP Cloud Application Programming Model (CAP) is an open-source, multi-cloud framework that enables the rapid development of enterprise-grade applications. It leverages popular technologies like Node.js, TypeScript, and OData to provide a comprehensive solution for data modelling, service generation and application development.

CAP embraces the principles of domain-driven design and promotes a clear separation of concerns, allowing developers and business users to focus on their respective areas of expertise. With CAP, business users can take charge of data modelling and service definitions, while developers can concentrate on implementing business logic and user interfaces.

				
					codenamespace my.app;

entity Customer {
  key ID   : UUID;
  name    : String;
  email   : String;
  age     : Integer;
  address : Association to my.app.Address;
  preferences: Association to many my.app.Preference;
}

entity Preference {
  key ID     : UUID;
  type      : String;
  value     : String;
  customer  : Association to my.app.Customer;
}

entity Campaign {
  key ID     : UUID;
  name      : String;
  startDate : DateTime;
  endDate   : DateTime;
  description: String;
}

entity Interaction {
  key ID          : UUID;
  timestamp     : DateTime;
  type          : String;
  description   : String;
  customer      : Association to my.app.Customer;
  campaign      : Association to my.app.Campaign;
}

entity Lead {
  key ID          : UUID;
  firstName     : String;
  lastName      : String;
  email         : String;
  status        : String; // e.g., New, Contacted, Qualified, Lost
  source        : String; // e.g., Website, Event, Referral
  campaign      : Association to my.app.Campaign;
}
				
			

In the above example, we define a Core Data Services (CDS) entity called “Customer” and its extensions; by using simple annotations, business users can define key properties, data types and associations between entities. This abstract representation allows developers to map the CDS model to different database systems easily.

Service Generation with CAP

Once the data model is defined using CDS, CAP can automatically generate powerful OData and RESTful services based on that model. Business users don’t have to worry about writing boilerplate code or dealing with low-level service implementations. Let’s see how CAP automatically generates an OData service for the “Customer” and other entities we defined earlier:

				
					const cds = require('@sap/cds');

module.exports = cds.service.impl(async (srv) => {
  const { Customer, Preference, Interaction, Campaign, Lead, MarketingAnalytics } = srv.entities;

  srv.on('READ', Customer, async () => {
    const customers = await SELECT.from(Customer);
    return customers;
  });
				
			

In the above code excerpt, we use the @sap/cds Node.js module to implement an OData service for the Customer & other entities. The framework automatically handles incoming read requests for the entities and fetches the data from the underlying database.

				
					  srv.on('CREATE', async (req) => {
    if (req.target === Lead) {
      // Custom logic for lead creation, e.g., lead source tracking
      const lead = await INSERT.into(Lead).entries(req.data);
      return lead;
    } else if (req.target === Campaign) {
      // Custom logic for campaign creation, e.g., setting default start and end dates
      const campaign = await INSERT.into(Campaign).entries(req.data);
      return campaign;
    } else {
      // For other entities, use default create behavior
      return srv.create(req);
    }
  });
				
			

Business users can define similar handlers for other CRUD (Create, Read, Update, Delete) operations on the entities they model, example below

				
					 srv.on('UPDATE', async (req) => {
    // For certain entities, we can add update-specific logic here
    if (req.target === Customer && req.data.segment) {
      // Custom logic for updating customer segment, e.g., validation or triggering events
      const customer = await UPDATE(Customer, req.data).where({ ID: req.data.ID });
      return customer;
    } else {
      // For other entities, use default update behavior
      return srv.update(req);
    }
  });
				
			
				
					
  srv.on('DELETE', async (req) => {
    // For certain entities, we can add delete-specific logic here
    if (req.target === Interaction) {
      // Custom logic for deleting interactions, e.g., updating related analytics
      const deletedInteraction = await DELETE.from(Interaction).where({ ID: req.data.ID });
      // Custom logic to update related analytics based on the deleted interaction
      // ...
      return deletedInteraction;
    } else {
      // For other entities, use default delete behavior
      return srv.delete(req);
    }
  });

  // Custom Actions and Functions can be defined here
});
				
			

This code defines a server-side function that handles DELETE requests, executing custom logic for interactions and default behaviour for other entities.

Extending Services with Business Logic

While SAP CAP empowers business users to define data models and basic service operations, it also allows developers to step in and extend these services with complex business logic. This collaboration ensures that the application development process is seamless and efficient.

For example, let’s say we want to add a custom operation to our “Customer” entity service to fetch all customers who are above a certain age. We can easily extend the existing service with the following code:

				
					// ...
srv.on('READ', Customer, async (req) => {
  if (req.query.AboveAge) {
    const age = parseInt(req.query.AboveAge);
    const customers = await SELECT.from(Customer).where({ age: { '>=': age } });
    return customers;
  } else {
    const customers = await SELECT.from(Customer);
    return customers;
  }
});
// ...

				
			

In this example, we extended the “READ” operation for the “Customer” entity to accept an additional query parameter called “AboveAge.” If the parameter is provided, the service fetches all customers with an age greater than or equal to the specified value. This kind of flexibility allows developers to add complex filtering, aggregation and validation logic to the services modelled by business users.

One of the fundamentals of “Democratising Data” is to empower those with domain expertise, and empowering business users to participate in application development actively is crucial for modern businesses’ success. SAP Cloud Application Programming Model (CAP) simplifies data modelling and service creation, allowing business users to define data structures and basic service operations. At the same time, developers can focus on adding business logic and extending these services to meet specific requirements.

Conclusion

With the power of SAP CAP, organisations can accelerate application development, improve collaboration between business and IT teams, and ultimately deliver innovative, data-driven applications to the market faster than ever before. Embracing CAP opens up new possibilities for businesses, fostering a culture of agility, adaptability and constant innovation. So why wait? Start democratising data with SAP CAP and unlock the true potential of your business. Now that SAP has released the “SAP Build Code”, this could potentially help business users dive in deep. SAP Build Code – “Use code generation with Joule to generate application logic, data models and sample data conforming to app extensions and test scripts“ it can also illustrate the whole model visually, which is always an appreciated feature.

SAP Build Code – Model Illustration

Remember, this blog only scratches the surface of what SAP CAP can achieve. To fully explore its capabilities and harness its potential, it’s essential to dive deeper into the framework’s documentation and tutorials.

Happy coding and democratising data with the SAP Cloud Application Programming Model!

Share the article with your peers!

Facebook
Twitter
LinkedIn