具有LCHR长字符串的SAP Gateway OData服务 [英] SAP Gateway OData service with LCHR long string
问题描述
我正在使用SAP Gateway开发使用oData服务的SAPUI5应用程序,我在其中实现了一个搜索功能,该功能生成SQL where条件.条件的一部分如下所示:... OR DESCRIPTION LIKE '%searchString%'...
.在我的数据库表中,我有一个字段DESCRIPTION
,其类型为LCHR
长度32000
.唯一的问题是字段DESCRIPTION
不能在WHERE
子句中.
I am developing a SAPUI5 application consuming oData services with SAP Gateway, where I have implemented a search functionality which is producing a SQL where condition. One part of the condition looks like follows: ... OR DESCRIPTION LIKE '%searchString%'...
. In my database table I have a field DESCRIPTION
which is of type LCHR
length 32000
. The only problem is that the field DESCRIPTION
cannot be in WHERE
clause.
通过oData服务在数据库表中搜索长字符串的正确方法是什么?我需要对搜索功能进行硬编码还是有一些更简洁的方法?
What would be a correct approach of searching long strings in database table via oData services? Do I need to hardcode the search functionality or is there some cleaner way?
推荐答案
答案是 CDS表功能.基本思想是将搜索下推到由 AMDP .我做了一些本地测试以通过具体代码来回答这个问题.
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.
我创建了一个表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);
}
使用参数search_str
定义CDS表函数zza_test_tf
.
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;
创建具有接口if_amdp_marker_hdb
的类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.
现在,我们有了带有参数的CDS表功能.运行CDS视图并输入搜索参数以获取结果.您甚至可以使用模糊搜索.
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.
要满足此要求,请在GateWay层的此CDS视图上实现Open SQL选择.
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!
这篇关于具有LCHR长字符串的SAP Gateway OData服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!