Technology Blog Posts by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
ChaitanyaG
Explorer
514

SAP's CDS9 Parser: The Next Generation of Cloud Application Development

Introduction

SAP's Cloud Application Programming Model (CAP) continues to evolve, with the latest leap being the introduction of the CDS9 Parser—a major upgrade to the Core Data Services (CDS) framework. Designed to enhance performance, developer experience, and processing capabilities, this parser lays the groundwork for next-generation SAP BTP applications.

Whether you're a seasoned SAP developer or just getting started, this guide breaks down everything you need to know about CDS9—from benefits and configuration to migration best practices and future steps.

Release Timeline and Transition Plan

The rollout of the CDS9 parser is designed to be gradual, offering developers ample time to test and adapt:

  • February 2025: CDS9 is released as an opt-in feature.
  • May 2025: CDS9 becomes the default parser, with the legacy version being phased out permanently.

This phased approach helps teams prepare for the switch while ensuring backward compatibility during the transition period.

Key Improvements in CDS9

ChaitanyaG_2-1744128602121.png

 

1. Architectural and Performance Enhancements

  • Faster Processing: 40% speed improvement in model compilation.
  • Memory Efficiency: Optimized usage, especially in large-scale projects.
  • Smaller Installation Size: Reduced from ~2MB to ~200KB by removing external dependencies like ANTLR4.
  • Quicker Startup: 15–20% faster for large models with over 100 entities.

2. Advanced Processing Capabilities

  • Support for nested projections and optimized WHERE clauses.
  • Improved AST (Abstract Syntax Tree) for deeper code analysis and IDE support.
  • Multi-stage compilation via compile.for.runtime and compile.to.dbx.

3. Developer Experience Boosts

  • Intelligent code completion: Up to 60% more accurate suggestions.
  • Real-time validation: Especially for @restrict clauses and auth annotations.
  • Enum default values: Cleaner syntax and improved readability.

-----------------------------------------------------------------------------------------------------------------------------------------------

How to Configure the CDS9 Parser

ChaitanyaG_4-1744129110364.png

Step 1: Update Your Dependencies

Make sure your project is using the latest versions of required packages:

npm install -g @sap/cds-dk
cds version

Step 2: Enable the New Parser

Activate the new parser in your project configuration by modifying the .cdsrc.json:

{
  "cdsc": {
    "newparser": true
  }
}

Step 3: Customize Compilation Settings

{
  "cdsc": {
    "newparser": true,
    "flavor": "parsed",
    "min": true,
    "docs": true,
    "locations": true
  }
}

Step 4: Compatibility Testing

Test your project using hybrid configurations to check for compatibility:

CDS_FEATURES=new_parser cds test
cds compile.to.hana --flavor parsed

Step 5: Use REPL for Debugging

You can use the cds repl command for debugging and validating your models:

cds repl
> let csn = cds.parse.cdl(`entity Foo { bar : String }`)

Step 6: Gradual Rollout with Fallback

If transitioning from an older parser, you can enable fallback mechanisms:

{
  "cdsc": {
    "newparser": true,
    "legacyFallback": true
  }
}

Step 7: Final Deployment

Once testing is complete, remove fallback settings and deploy with full adoption of the new parser:

cds deploy --to hana --parser new

-----------------------------------------------------------------------------------------------------------------------------------------------

Known Issues & Considerations

1. Complex SQL Parsing

  • CDS9 may struggle with CASE in SUM expressions.
  • Workaround: Use db.run() for complex native queries.

2. Stricter Validation

  • Older syntax and annotations may fail due to stricter validation rules.
  • Fix: Refactor models to comply with the new validation standards.

3. OData V2 Limitations

  • Structured and arrayed types may be incompatible with OData V2.
  • Fix: Migrate to OData V4 or avoid these constructs.

4. Ignored Filters on Function Outputs

  • Filters may not work as expected on function return values.
  • Fix: Refactor logic into separate queries or calculated fields.

5. No Fallback Post-May 2025

  • After May 2025, there will be no fallback to the old parser. Test thoroughly before then.

6. Early Release Bugs

  • Some early versions had issues like missing authentication for certain headers.
  • Fix: Track updates in the changelog and apply fixes as necessary.

-----------------------------------------------------------------------------------------------------------------------------------------------

Leveraging New CDS9 Features

Enum Defaults

type Status : String enum { open = 'O'; closed = 'C'; inProgress = 'P' };
entity Orders {
  key id : Integer;
  status : Status default #open;
}

@assert.range Enhancements

entity Products {
  key id : Integer;
  quantity : Integer @assert.range: [(0), 100];
  price : Decimal @assert.range: [0, _]; // _ = infinity
}

Type Projections

type Address {
  street : String;
  city : String;
  zipCode : String;
  country : String;
}
type ShortAddress : projection on Address {
  street,
  city
};

-----------------------------------------------------------------------------------------------------------------------------------------------

Best Practices for Migration

ChaitanyaG_5-1744129287039.png

1. Prepare Environment

Upgrade @SAP/cds to v9+ and install the test package:

npm add -D @cap-js/cds-test

Update ESLint to v9.

2. Test Extensively

Use hybrid configurations for testing both old and new parsers:

cds migrate "*" --dry --profile hybrid,production --resolve-bindings

Validate with parsed flavor:

cds compile.to.hana --flavor parsed

3. Fix Known Issues

  • Ensure your code adheres to the stricter validation rules.
  • Refactor any complex SQL queries or use native database queries.

-----------------------------------------------------------------------------------------------------------------------------------------------

Post-Adoption Checklist

  • Remove old settings:
    Delete "cdsc.newParser": true from your .cdsrc.json file. It's no longer needed.

  • Update your tools:
    Upgrade all relevant dependencies like @SAP/cds, ESLint, and @cap-js/cds-test.

  • Use the new features:
    Start using enums, projections, and improved validation rules for cleaner, more efficient code.

  • Test everything:
    Run full tests to make sure all models and annotations work correctly with the new parser.

  • Update CI/CD pipelines:
    Add the new parser to your CI/CD setup for automated testing and deployment.

  • Fix OData V2 compatibility:
    If you're using OData V2, install the compatibility adapter with:

npm add @cap-js-community/odata-v2-adapter

-----------------------------------------------------------------------------------------------------------------------------------------------

Conclusion

CDS9 marks a significant leap in SAP CAP development with its enhanced performance, new features, and improved developer experience. By following the outlined steps and best practices, developers can smoothly transition to this new parser and take full advantage of its capabilities.
-----------------------------------------------------------------------------------------------------------------------------------------------

References

  1. SAP Cloud Application Programming Model (CAP) Official Documentation - https://cap.cloud.sap/
  2. SAP BTP Developer Guide - https://developers.sap.com/topics/business-technology-platform.html
  3. Core Data Services (CDS) Documentation - https://cap.cloud.sap/docs/cds/
  4. SAP CDS9 Parser Release Notes - https://cap.cloud.sap/docs/releases/
  5. SAP Developer Community - https://community.sap.com/topics/cloud-application-programming-model
  6. OData V2 Adapter for CAP - https://www.npmjs.com/package/@cap-js-community/odata-v2-adapter
  7. SAP CAP Node.js SDK - https://www.npmjs.com/package/@sap/cds
  8. SAP CAP Testing Tools - https://www.npmjs.com/package/@cap-js/cds-test