Quantcast
Channel: SCN : Discussion List - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 5653

HANA pagination - Navigate forward and backward through result set

$
0
0

Hi folks,

 

Suppose I have a query that returns a potentially large result set, such as

 

SELECT * FROM BUT000;

 

or

 

SELECT

    OPBEL,

    VKONT,

    VTREF,

    HVORG,

    TVORG,

    SUM ( BETRH ) AS BETRH

FROM DFKKOP

GROUP BY OPBEL, VKONT, VTREF, HVORG, TVORG;

 

I don't want to overwhelm the client (front-end, service consumer, ABAP application using a secondary database connection, whatever) with the entire results set but retrieve and display it in chunks of 100. I want to allow forward and backward navigation in the result set: Show me the first 100, then the second 100, the third 100, then back to the second 100, and so on.

 

I've found two things that come close to what I want:

 

1) SELECT ... LIMIT ... OFFSET

 

SELECT * FROM BUT000 -- 1st 100

  LIMIT 100;

SELECT * FROM BUT000 -- 2nd 100

  LIMIT 100 OFFSET 100;

SELECT * FROM BUT000 -- 3rd 100

  LIMIT 100 OFFSET 200;

SELECT * FROM BUT000 -- 2nd 100 again

  LIMIT 100 OFFSET 100;

 

Disadvantage: Each time I want to retrieve a package, the query is executed again.

 

2) ADBC package handling

 

  DATA:

    lr_sql      TYPE REF TO cl_sql_statement,

    lr_result   TYPE REF TO cl_sql_result_set,

    lr_results  TYPE REF TO data.

 

  CREATE OBJECT lr_sql

    EXPORTING

      con_ref = cl_sql_connection=>get_connection( 'SECONDARY' ).

 

  lr_result = lr_sql->execute_query( |SELECT * FROM SAPDAT.BUT000| ).

  GET REFERENCE OF lt_results INTO lr_results.

 

  lr_result->set_param_table( lr_results ).

 

  DO 3 TIMES.

    CLEAR lt_results.

    lr_result->next_package( 100 ).

  ENDDO.

 

  lr_result->close( ).

 

Disadvantage: can only navigate forward to the next package, no backward navigation or free positioning available.

 

I'd be happy with solutions that solve the problem at the HANA/SQL Script level or at the ABAP level. Who can help?

 

Thanks,

 

Thorsten


Viewing all articles
Browse latest Browse all 5653

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>