Creating SAP CAPM Demo Project and Custom Functions Your Complete Hands On Tutorial

Posted on August 11, 2025 by Laeeq Siddique

Creating SAP CAPM

Introduction:

Understanding SAP CAPM Custom Functions

SAP CAPM Custom Functions. This is about the capability to define and use your logic in the SAP Cloud Application Programming Model (CAPM). CAPM itself is a great platform offering an easy way to create enterprise-level services in SAP, end-to-end.

This blog covers :

  • Creating a CAPM demo project
  • Bound and Unbound Custom Functions Specification and Implementation of Bound and Unbound Custom Functions
  • Inject flexible business logic with JavaScript
  • Developing SAP API and corresponding real-world service endpoints

This guide by Cremencing is the perfect resource for both SAP beginners and seasoned professionals. As a premier provider of SAP custom development, Cremencing helps you go beyond the basics—offering expert insights into what you need to know during the development process. With best practices and real-world examples, this book will show you how to take your application to the next level.

What is SAP CAPM?

SAP Cloud Application Programming Model (CAPM) is a development framework designed for building full-stack applications within the SAP ecosystem. It supports Node.js and Java runtimes and is used to develop multi-target applications (MTAs) across the following layers:

LayerDescription
DB LayerRuns in SAP HANA
Service LayerRuns in Node.js or Java
UI LayerRuns in the browser (Fiori, SAPUI5, etc.)

Steps to Create a CAPM Demo Project

You can create a CAPM project either through the CLI in VS Code or via the wizard in SAP Business Application Studio (BAS).

Option 1: Using Command Line Interface (CLI)

cds init my-capm-project

cd my-capm-project

npm install

Option 2: Using SAP BAS Wizard

  1. Log in to SAP BAS
  2. Start a new project from the template: “Basic CAP Project”
  3. Include sample data (optional)
  4. Wait for the project scaffolding to be completed

Project Structure Overview

Folder/FilesPurpose
db/Data model definitions (e.g., data-model.cds)
srv/Service definitions & logic (.cds, .js files)
app/Optional UI layer
package.jsonProject metadata and dependencies
cdsrc.jsonCAPM configurations
gen/Auto-generated content for builds

After initializing, use cds watch to start the server and auto-refresh upon changes. Your CAPM application will be live on http://localhost:4004.

Implementing SAP CAPM Custom Functions

What Are Custom Functions?

Custom functions in SAP CAPM are used to encapsulate reusable business logic that goes beyond standard CRUD operations. They can be either Bound to specific entities or Unbound and globally accessible across the service.

Bound Functions

Bound functions are directly linked to a data entity and are often used for entity-specific computations or logic.

Step 1: Define the Function in .cds

File: srv/custservice.cds

entity Customer {

  ID: UUID;

  name: String;

}

function boundedFunction(msg: String): String;

Step 2: Implement the Function in .js

File: srv/custservice.js

module.exports = (srv) => {

  srv.on(‘boundedFunction’, async (req) => {

    const { msg } = req.data;

    return `Bound Function Response: ${msg}`;

  });

};

Step 3: Call the Function via URL

http://localhost:4004/api/customer/CustService.boundedFunction(msg=’Welcome’)

Unbound Functions

Unbound functions are service-level operations that do not rely on specific entities.

Step 1: Define the Function in .cds

function greetUser(name: String): String;

Step 2: Implement the Function in the .js

module.exports = (srv) => {

  srv.on(‘greetUser’, async (req) => {

    return `Hello, ${req.data.name}`;

  });

};

Step 3: Call the Function via URL

http://localhost:4004/api/greetUser(name=’SAP Developer’)

Running & Testing the CAPM Project

Use the following command to run and observe your custom functions:

cds watch

Visit http://localhost:4004 to view available services. Each custom function you’ve defined will be exposed as an endpoint and can be tested using any REST client (like Postman) or directly from the browser.

Key Differences: Functions vs. Actions in CAPM

FeatureFunctionsActions
Side EffectsNo (read-only)Yes (can update data)
Input ParamsSupportedSupported
ReturnA single response valueCan trigger workflow or process
Example UseCalculations, read-only queriesApprove Order, Cancel Subscription

Use functions when you need to return a value without modifying data. Use actions when your logic causes data changes or business events.

Competitive Comparison

FeatureCremencing BlogCompetitor 1Competitor 2Competitor 3
Full CAPM setup guideYesYesYesYes
Custom function implementationYes (detailed)NoPartialYes
Service structure explainedYesNoYesYes
CLI and BAS wizard both coveredYesYesNoYes

Cremencing.com offers deeper, practical steps, real-world function implementations, and structural-level clarity that competitors often skip.

Resources

Official SAP Documentation

Community Articles and Code Examples

Need custom help with SAP? Explore Cremencing’s expert SAP Custom Development Services.

Conclusion

Knowing how to create and use SAP CAPM Custom Functions is a powerful capability that allows you to create customized solutions in the SAP landscape. Whether you’re describing bound functions for entity-level operations or unbound functions for general-purpose use, CAPM empowers you to scale and tame your service layer in a way that wasn’t possible before.

You now know:

  • How to create a CAPM demo project
  • The folder organization and function locations
  • Writing and calling custom logic with JS
  • What are the best use cases for bound vs unbound functions

For companies that want to inject additional intelligence, automation, or custom processes into their SAP systems, custom development with CAPM is the way forward.

Call to Action

If you are interested in building powerful and custom applications in SAP with CAPM, Cremencing Solution is here to help!

We are an SAP Custom Development services company, offering industrial-strength, scalable SAP-based solutions designed to fit your business like a glove.

Ready to discuss your next project?
Visit our Contact Page or explore our SAP Custom Development Services to learn more.

FAQs

1. What are the steps involved in creating a demo project using SAP Cloud Application Programming Model (CAPM)?
Start by running cds init, define your data and service layers, install dependencies using npm install, and use cds watch to launch the application.

2. How can you define and use custom functions in a CAPM service layer?
You define the function in a .cds file and implement the logic in a .js file of the same name within the srv/ folder.

3. What is the role of the srv folder in an SAP CAPM project?
The srv folder houses your service definitions and business logic, including custom functions and actions.

4. How does the CAPM framework support the implementation of custom business logic?
CAPM allows the use of JavaScript or Node.js modules for service handlers via the srv.on() method, offering flexibility and async handling.

5. What is the difference between actions and functions in CAPM?
Functions are read-only and return data, while actions can modify data or trigger workflows. Use functions for calculations and actions for processing.