ABAP Open SQL 分页查询

让人意外的是,google搜索abap paging query,查到的结果似乎都指出需要使用native SQL来实现相关功能;使用百度搜索 abap分页查询,不仅查不到解决方案,甚至可以看到有人提出分页查询非常影响效率,不应使用。我想这是没有道理的。经过对文档的查询,我发现Open SQL拥有这方面的能力。

 

本文链接:

原创内容,转载请注明。

 

OFFSET 关键字实现

从ABAP 7.51开始,Open SQL中引入了关键字OFFSET可以指定查询的开始位置。以下这是官方文档中的一个小例子,通过UP TO n ROWS指定一次查询的条目数,通过OFFSET指定开始行:

SELECT - UP TO, OFFSET:

REPORT demo_select_up_to_offset. CLASS demo DEFINITION. PUBLIC SECTION. CLASS-METHODS main. PRIVATE SECTION. CLASS-DATA: o TYPE int8, n TYPE int8. CLASS-METHODS setup. ENDCLASS. CLASS demo IMPLEMENTATION. METHOD main. setup( ). SELECT FROM demo_expressions FIELDS id, num1 AS number, numlong1 AS result ORDER BY id, num1 INTO TABLE @DATA(itab) OFFSET @o UP TO @n ROWS. cl_demo_output=>display( itab ). DELETE FROM demo_expressions. ENDMETHOD. METHOD setup. cl_demo_input=>new( )->add_field( CHANGING field = o )->request( CHANGING field = n ). IF NOT ( ( o BETWEEN 0 AND 2147483646 ) AND ( n BETWEEN 0 AND 2147483646 ) ). cl_demo_output=>display( `Input not in allowed interval!` ). LEAVE PROGRAM. ENDIF. DELETE FROM demo_expressions. DO strlen( sy-abcde ) TIMES. INSERT demo_expressions FROM @( VALUE #( id = substring( val = sy-abcde off = sy-index - 1 len = 1 ) num1 = sy-index numlong1 = ipow( base = 2 exp = sy-index ) ) ). ENDDO. ENDMETHOD. ENDCLASS. START-OF-SELECTION. demo=>main( ).

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpsjdf.html