Skip to Content
Personal Insights
Author's profile photo Uladzislau Pralat

Real-Time Open Order Calculation with S/4HANA CDS Views

Real-time open order calculation was always a challenge in R/3 due to slow DB. Developers had no choice but do calculations in ABAP layer with endless loops, if statements and interim tables / variables. With S/4HANA ABAP CDS Views game changing technology it is time to use set based SQL calculations and push calculations to HANA DB where they belong.

In my blog I will explain open order requested not goods issued scenario e.g.  open order = requested – goods issued. All calculations are done in CDS view table function using SQL. Table function is very simple and all complexity is inside implementing ABAP Class.

Let me walk you thought set base calculations inside the table function.

  1. Select order requested information on schedule line level
  2. Calculate order requested quantity totals and running totals for each order item
  3. Calculate goods issued quantity on order item level
  4. Calculate open quantity e.g. open = requested – goods issued
  5. Calculate open order schedule line value and eliminate order schedule lines that are not open

Select Order Requested Information on Schedule Line Level

 

Calculate Order Requested Quantity Totals and Running Totals for Each Order Item

 

Calculate Goods Issued Quantity on Order Item Level

 

Calculate Open Quantity e.g. Open = Requested – Goods Issued

Note: CASE statement is where open quantity is calculated.

1st when statement is when schedule line is not open e.g. fully goods issued

2nd when statement current schedule line is partially open  e.g. partially goods issued

else statement for schedule lines that are open e.g not goods issued

 

Calculate Open Order Schedule Line Value and Eliminate Order Schedule Lines That are Not Open

Note: open order schedule line value is calculated prorating order line value. Not open schedule lines are eliminated checking open quantity

 

 

Assigned tags

      16 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo DANISH ABDUL MUNAF KAZI
      DANISH ABDUL MUNAF KAZI

      Thanks a ton! Can you please share the source code (downloadable version) if possible?

      Author's profile photo Uladzislau Pralat
      Uladzislau Pralat
      Blog Post Author

      Hi Danish,

      Open Order business rules differs from client to client. That is why I kept my explanation shot, simple and client agnostic.

      Explaining complete scenario goes beyond the scope of the blog. I am planning to write a functional blog to explain logic in more details.

      Regards, Uladzislau

      Regards,

      Author's profile photo Robert Forster
      Robert Forster

      Hi,

      wondering if there is not a standard CDS for this

       

      Best Regards

      Author's profile photo Uladzislau Pralat
      Uladzislau Pralat
      Blog Post Author

      Hi Robert,

      there are standard Open Order CDS Views, but their business rules much different from what my client needs.

      Regards, Uladzislau

      Author's profile photo abhijeet kankani
      abhijeet kankani

      Indeed a good concept to use AMDP classes by using table function in CDS view and which will be executed in HANA DB directly instead of application layer.

      But in CDS view itself there are so many basic things which we can use like if/else, regular expressions and case statement, and once artefacts are generated code will be pushed inside the HANA DB only.

      So is there is any advantage in performance if we are using simple things like if/else or case or any basic expression in cds itself VS Table function( AMDP class) ?

      Because same functionality we can achieve using cds view without AMDP(Table function).

      Regards,

      Abhijeet Kankani

      Author's profile photo Uladzislau Pralat
      Uladzislau Pralat
      Blog Post Author

      Hi Abhijeet,

      in my case I need window function which is only available in table function AMDP.

      Regards, Uladzislau

      Author's profile photo abhijeet kankani
      abhijeet kankani

      Oo Got it, for me I achieved most of functinality using VDM concepts in CDS itself.

      Author's profile photo Aleksandrs Frolovs
      Aleksandrs Frolovs

      Dear Uladzislau Pralat,

      Lets assume this article is a Christmas gift for all SAPers. Thanks a lot.

      Question :

      Can I use existing ABAP classes in conjunction with ABAP CDS ot table functions?

      Thanks

       

      Author's profile photo Uladzislau Pralat
      Uladzislau Pralat
      Blog Post Author

      Hi Aleksandrs,

      if you mean consume CDS View in ABAP class, then answer is yes.

      Regards, Uladzislau

      Author's profile photo Aleksandrs Frolovs
      Aleksandrs Frolovs

      Thanks

       

      I mean call existing ABAP class from CDS view.

      We have a very complex authorization process that is enabled via several ABAP classes and customization tables.

       

      Thanks

      Author's profile photo Uladzislau Pralat
      Uladzislau Pralat
      Blog Post Author

      Please consider using CDS access control instead

      Author's profile photo Aleksandrs Kerauts
      Aleksandrs Kerauts

      Does this solution deliver list of open items at any selected date or date is hardcoded?

      Author's profile photo Uladzislau Pralat
      Uladzislau Pralat
      Blog Post Author

      Hi Aleksandrs,

      the CDS view retrieves a list of open items as of current date (no hardcoding).

      Regards, Uladzislau

       

      Author's profile photo Aleksandrs Kerauts
      Aleksandrs Kerauts

      Thanks, Can this query be enabled for the list of open items per key date (parameter)?

      Author's profile photo Aleksandrs Kerauts
      Aleksandrs Kerauts

      Thanks, Can this query enable the list of open items per key date (parameter)?

      Author's profile photo Uladzislau Pralat
      Uladzislau Pralat
      Blog Post Author

      Unfortunately, SAP data model does not support this requirement