Technology Blogs 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: 
dave_price
Participant
0 Kudos
Hello, if like me you find yourself writing nearly all your own custom data provider class extension methods (in lieu of having SEGW generate them via RFC mapping or etc), you might find this class useful -- it will provide skip/top/count functions for any custom DPC GET_ENTITYSET class, with no modifications, simply add the below method call to the end of any such method, no additional coding needed!
 *skip/top/inline
zcl_segw_utilities=>skiptopinlinecount( exporting io_tech_request_context = io_tech_request_context changing ct_entityset = et_entityset cs_response_context = es_response_context ).

One caveat -- this might not be the best route if you need to do some expensive processing within the initial result set and (for performance) only want to do that processing for the subset of results specified by skip/top, but 90% of the time this works like a Charm.

There might be a more elegant way to accomplish this (suggestions welcome!) but so far it's been a great little timesaver.





   method skiptopinlinecount.
*----------------------------------------------------------------------*
* Author: Dave Price
* Date: 1/27/2017
* Purpose: Skip/top/inlinecount logic for any DPC ENTITYSET call
*----------------------------------------------------------------------*
* MODIFICATION LOG *
*----------------------------------------------------------------------*
* Author Date Transport Description
* ------- ---------- ---------- -----------
*
*----------------------------------------------------------------------*
*******NOTES
*skip=5 means start results from the 6th row
*top=3 means show the first three results after skipping
*so skip=5 and top=3 means return results 6,7,8

data:
lt_entityset type ref to data,
ls_paging type /iwbep/s_mgw_paging,
lv_skip type int4,
lv_top type int4.
field-symbols:
<fs_entityset> type any,
<fs_entityset_t> type standard table.

*create a second internal table like ct_entityset as a field symbol
create data lt_entityset like ct_entityset.
assign lt_entityset->* to <fs_entityset_t>.
move ct_entityset[] to <fs_entityset_t>.
* if skip > 0 retrieve the entries from skip + top - 1, e.g.
ls_paging-top = io_tech_request_context->get_top( ).
ls_paging-skip = io_tech_request_context->get_skip( ).
if io_tech_request_context->has_inlinecount( ) = abap_true. cs_response_context-inlinecount = lines( ct_entityset ). endif.
if ls_paging-skip is not initial. lv_skip = ls_paging-skip + 1. endif.
if ls_paging-top <> 0 and lv_skip is not initial.
lv_top = ls_paging-top + lv_skip - 1.
elseif ls_paging-top <> 0 and lv_skip is initial.
lv_top = ls_paging-top.
else.
lv_top = lines( ct_entityset ).
endif.
if io_tech_request_context->has_inlinecount( ) = abap_true.
describe table ct_entityset lines cs_response_context-inlinecount.
endif.
clear ct_entityset.
loop at <fs_entityset_t> assigning <fs_entityset> from lv_skip to lv_top.
append <fs_entityset> to ct_entityset.
endloop.
endmethod.





METHOD DEFINITION:
Class ZCL_SEGW_UTILITIES
Method SKIPTOPINLINECOUNT
Description Skip, Top and Inliine Count functions for any DPC ENTITYSET

IO_TECH_REQUEST_CONTEXT Importing Type Ref To /IWBEP/IF_MGW_REQ_ENTITYSET
CS_RESPONSE_CONTEXT Changing Type /IWBEP/IF_MGW_APPL_SRV_RUNTIME=>TY_S_MGW_RESPONSE_CONTEXT
CT_ENTITYSET Changing Type STANDARD TABLE
2 Comments
Labels in this area