Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
 

A step-by-step guide to understanding your SAP BTP sub-account costs and facilitating cross-allocation across your business units.



Introduction


Many customers take advantage of the consumption-based pricing model of SAP BTP. In doing so, customer teams need to organize their account structure to distribute consumption across different units, departments, and regions within their organization. While SAP bills customers for each Global Account, customers often want to cross-charge these units according to their usage. To achieve this, customer account teams require transparency of usage patterns per sub-account and an easy way to cross-charge their internal units accordingly. This article outlines a solution to this problem.



Solution Approach


The solution is broken down into four steps:




  1. Configure labels in the BTP Cockpit for each sub-account – to mark sub-accounts to exclude in subscription data.

  2. Create entitlements for "Cloud Management Service" and "Usage Data Management."

  3. Create instances of "Cloud Management Service" and "Usage Data Management" services.

  4. Use simple code to extract the metering data using a Resource Consumption API.


 

Step 1 – Configure Labels in the BTP Cockpit for Each Sub Account


The first step is to define labels for your sub-account. You need to use a specific label name called “EXCLUDE”. This is important because the code which you will see in later steps uses the hard-coded label called “EXCLUDE”.  This is needed for all subaccounts which you want to be “excluded” from the metering calculations.

  • Go to your subaccount edit page and add a new label. No need to add any values for this label.



EXCLUDE Label





  • After creating the label, you can view it in your Global Account – Account Explorer.





Step 2 - Create entitlements for “Cloud Management Service” and “Usage Data Management


Next, create entitlements for the two services used in extracting usage data for all your sub-accounts in your global account. In the BTP Cockpit, go to "Service Assignments" to check the Quota Assignments of the two services. Then, go to Entity Assignments, select your sub-account in "Select Entities," and provide an entitlement for the Cloud Management Service and Usage Data Management service.




 

  1. In BTP Cockpit, go to “Service Assignments“ to check the Quota Assignments of the two service




  1. Go to Entity Assignments, select your subaccount in “Select Entities”



Entity Assignments




  1. Give entitlement to the Cloud Management Service





    • Click Add Service Plan

    • Click Configure Entitlements

    • Search for “Cloud Management Service”

    • Select the “central” option

    • “Add 1 Service Plan”

    • Click Save





Add CMS Entitlement



Cloud Management Service




  1. Repeat the same for the “Usage Data Management” service





    • Click Configure Entitlements

    • Click Add Service Plan

    • Search for “Usage Data Management”

    • Select the “reporting-ga-admin” option

    • “Add 1 Service Plan”

    • Click Save






Step 3 - Create an instance of “Cloud Management Service” and “Usage Data Management” services


 

Create instances of the two services, and then create service keys and bindings for each service. Remember to save the JSON data for each service key and binding as this will be used in the next step.




  • Go to Service Market Place, Select Cloud Management Service, and click “Create”



Create Service instances




  • Enter an Instance Name – ex “TEST_CMS” and make sure you select “Other” in the runtime environment



Create CMS Instance




  • Instantiate the Usage Data Management service in any subaccount as this service reports usage data for the whole of the Global Account

  • Go to Service Market Place, Select Usage Data Management, and click “Create

  • Enter an Instance Name – ex “TEST_UDM” and make sure you select “Cloud Foundry” in the runtime environment



Create UDM Instance




  • Check and make sure instances are created under “instances and subscriptions”



Check Instances




  • Select the Usage Data Management service and click on Create Service Key

  • Enter the Service Key name – ex “Test_UDM”

  • Enter the X509 Json:


{
"credential-type": "x509",
"x509": {
"key-length": 2048,
"validity": 7,
"validity-type": "DAYS"
}
}



  • Once the key is created, keep a copy of the service key. This will help in binding the application in GitHub to the User Data Management service.





  • Create Service Binding for “Cloud Management Service” Service



CMS Binding




  • Enter the Binding Name – Ex CMS-Key.


{
"credential-type": "x509",
"x509": {
"key-length": 2048,
"validity": 7,
"validity-type": "DAYS"
}
}


  • Click “Create”


 


CMS Key




  • Once the binding is created, you can view the same




  • Download it or copy JSON and keep it



View CMS Key



Step 4 -Sample application to extract the Metering Data


Create a simple application to extract the metering data. A sample application has been provided for your reference: Link

  1. Open your Command Line Interface (CLI) and enter the following command to clone the git project: Link

    1. This will allow you to download a copy of the project to your local machine.



  2. Inside the demo.js file, you will need to make some changes to two properties:

    1. In the udmMtlsCreds section, replace the asterisks with your own JSON for Usage Data Management - Service Key.

    2. In the cisMtlsCreds section, replace the asterisks with your own JSON for Cloud Management Service - Service Key





mTLS Credentials


It is important to ensure that you use the correct JSON data for each section so that the application will run smoothly and without errors.

  1. After you have made the necessary changes to the demo.js file, you can run the Sample application. To do this, go back to your CLI and enter the following command: "node demo.js".
    This will initiate the application and allow you to test its functionality. If there are any errors or issues, you may need to go back and make adjustments to the code or JSON data.


Once the Sample application is running, you can begin using it to retrieve calculated subaccount data. To do this, you will need to use a specific URL structure:

http://localhost:3000/getCalculatedConsumption?startDate={startDate}&toDate={toDate}

In this URL, you will need to replace {startDate} with the start date of the Billing and {toDate} with the last date for the Billing. It is important to note that the parameters for these dates are in Year-Month format (YYYYMM).

For example, if you want to retrieve all the billings between January 2021 and May 2022, you would use the following URL:

http://localhost:3000/getCalculatedConsumption?startDate=202101&toDate=202205

There are two ways to use this URL:

Using Postman:

  1. Open Postman and create a new request.

  2. Set the request type to "GET".

  3. In the request URL field, enter the URL: http://localhost:3000/getCalculatedConsumption?startDate={startDate}&toDate={toDate}

  4. Replace the {startDate} and {toDate} parameters in the URL with the desired start and end dates of the billing range you want to retrieve.

  5. Press Send to execute the request and retrieve the Calculated Subaccount Data.

  6. The results will be displayed in the Postman response window.



Using Postman


Using Curl:

  1. Open your terminal or command prompt.

  2. Type the following command, replacing the {startDate} and {toDate} parameters with the desired start and end dates of the billing range you want to retrieve:curl "http://localhost:3000/getCalculatedConsumption?startDate={startDate}&toDate={toDate}"

  3. Press Enter to execute the request and retrieve the Calculated Subaccount Data.

  4. The results will be displayed in your terminal window.


Conclusion


By following these four steps, you can gain transparency into your SAP BTP sub-account costs and simplify cross-allocation across your business units. This solution will enable your customer account teams to efficiently manage their internal units and provide accurate billing information for each department or region.