SAP Gateway OData service with LCHR long string

坚强是说给别人听的谎言 提交于 2019-12-04 20:23:02

The answer is CDS Table Function. The basic idea is to push the search down to HANA which is implemented by AMDP. I did some local testing to answer this by concrete code.

I created a table zza_test

@EndUserText.label : 'TEST'
@AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #LIMITED
define table zza_test {
    key mandt : mandt not null;
    key bukrs : bukrs not null;
    cnt       : abap.int4;
    des       : abap.lchr(2000);
}

Defined a CDS table function zza_test_tf with parameter search_str.

@EndUserText.label: 'TEST TF'
define table function zza_test_tf
with parameters
    @Environment.systemField: #CLIENT
       clnt   :abap.clnt,
       search_str : char255
returns
{
    mandt : mandt;
    bukrs : bukrs;
    cnt   : abap.int4;
    des   : abap.lchr(2000);

}
implemented by method zcl_zza_test_tf=>search_des;

Created a Class zcl_zza_test_tf with interface if_amdp_marker_hdb and implement the method search_des

class zcl_zza_test_tf definition
public
final
create public .

public section.
  interfaces if_amdp_marker_hdb.
  class-methods search_des

      for table function zza_test_tf.
 endclass.

class zcl_zza_test_tf implementation.

   method search_des by database function for hdb
      language sqlscript
      options read-only
      using zza_test.

      return select mandt,bukrs, cnt, des
                from zza_test where des like concat( concat( '%', 
                   :search_str), '%');

   endmethod.

endclass.

Now we have a CDS table funtion with parameters. Run the CDS view and input the search parameter to get the result. You can even define your HANA SQL in your AMDP implementation with fuzzy search.

To fulfill the requirement, you implement the Open SQL select on this CDS view at your GateWay layer.

data:
    lt_test type standard table of ZZA_TEST_TF.

select * from ZZA_TEST_TF( search_str = 'DUM' ) into table @lt_test.

Everything should work. Hope it helps. Thank you!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!