Skip to Content
author's profile photo Former Member
Former Member

How to get the latest Records from Table

Hi Experts,

We are querying on a table CDPOS(Change Log). Our query requiredment is to get the latest change record for any sales Order / Customer / etc from CDPOS table.

Could some one please guide me how can I get this done in HANA?

As of i know i could sort the table based on Time stamp and get the latest record. But this is a cost effective as the table contains huge amount of data.

Please suggest if any other alternative.

Best regards,


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on May 06, 2015 at 08:57 AM

    try leveraging $trex_udiv$ (order by desc).

    (as I find it influences default sorting)

    caveat: this is an internal column, and likely not supported for the productive usage.

    what is the context here (in business sense), that translates in this requirement?

    how do you expect get timestamp in CDPOS (it doesn't exist by default)?

    can you explain more?


    Add a comment
    10|10000 characters needed characters exceeded

    • And again: there is no default sorting of a table.

      The remark about UDIV affecting the "default order" doesn't make sense therefore.

      Also: besides the factual behavior of the UDIV column, there is no API contract for this column.

      Any solution build on that will only work by chance.

      Just as you didn't realize before that the values aren't monotonously increasing every aspect of this column (data type, content, availability) can (and likely will) be changed in future versions.

      So, no, the approach is not usable at all. It's a partly working hack at best that is not sufficient for enterprise applications.

      Relying on this internal, undocumented, non-supported column is a bug.

  • author's profile photo Former Member
    Former Member
    Posted on May 11, 2015 at 05:30 PM

    Krishna, can you shed a little more light on your requirement? Are you simply wanting to read into the table for a single document and retrieve the last change OR are you trying to use this in some type of join on a very large set of data?



    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 12, 2015 at 12:13 PM

    I think you could try an simple approach to adress this problem:

    When we talk about SQL, SQL Script and XSJS, you should give variables a try.

    In detail:

    Write a Procedure with executes following steps:

    1, Make a projection of time stamps, key

    2, If time stamp exists (from step 4) cut the table like where timestamps > time stamp

    3, Sort time stamps

    4, Save latest time stamp for further usage

    5, Retrieve resulting objects by key

    I don`t know if this works with the Database only or if you need some other server side scripting.

    But in my view this should be a comman programming problem which should be already adressed by someone.


    In conclusion this isn`t a sap specific problem, so i recommend to search also other sites like stackoverflow in order to adjust a solution to sap enviroment.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.