简体   繁体   English

选择带偏移量的语句?

[英]Select statement with offset?

I'm trying to use this SELECT statement in ABAP:我正在尝试在 ABAP 中使用此 SELECT 语句:

  SELECT DISTINCT * FROM  dbtab
     INTO CORRESPONDING FIELDS OF TABLE itab
     WHERE  field1+7(16)  IN s_field1
     AND    field2        IN s_field2.

but I can't use offset for a dbtab column.但我不能对 dbtab 列使用偏移量。 How can I solve this problem?我怎么解决这个问题?

I'm trying to avoid loop like我试图避免循环

  SELECT DISTINCT * FROM  dbtab
     WHERE  field2        IN s_field2.
       IF field1+7(16)  IN s_field1
           ...
       endif.
  endselect.

You can't use offset in OPEN SQL.您不能在 OPEN SQL 中使用偏移量。

I would recommend to make a SELECT into an internal table and loop over it like this.我建议将 SELECT 放入内部表并像这样循环遍历它。

SELECT DISTINCT * FROM dbtab
INTO CORRESPONDING FIELDS OF TABLE itab
WHERE field2 IN s_field2.

LOOP AT dbtab into wa_itab.
  IF wa_itab-field1+7(16) IN s_field1
    ...
  ENDIF.
ENDLOOP.

On the other hand I would also define the internal table as SORTED or HASHED or if you prefer try to SORT itab by the field you are making the comparison.另一方面,我还将内部表定义为 SORTED 或 HASHED,或者如果您更喜欢尝试按要进行比较的字段进行 SORT itab。 Field symbols could be an alternative also.字段符号也可以作为替代。

Hope it helps.希望能帮助到你。

If your policies allow you to you can use probably use an EXECUTE_SQL block instead, for example if you have an Oracle backend, which allows you to leverage native SQL constructs instead of just OPEN SQL.如果您的策略允许您可以使用 EXECUTE_SQL 块来代替,例如,如果您有 Oracle 后端,它允许您利用本机 SQL 构造而不仅仅是 OPEN SQL。 It's a judgement call whether this is justified or not depending on the performance gain.这是否合理取决于性能增益,这是一个判断电话。 I think it's probably not.我想可能不是。

You could also use a LIKE clause, which isn't as efficient as exactly knowing the offset, but would allow you to encapsulate each option with %: WHERE field 1 LIKE '%search_partial%' OR field1 LIKE...您还可以使用 LIKE 子句,它不如准确知道偏移量那么有效,但可以让您用 % 封装每个选项: WHERE field 1 LIKE '%search_partial%' OR field1 LIKE...

What is the use-case for this, it might be there's a more appropriate option if we have some context.这有什么用例,如果我们有一些上下文,可能会有更合适的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM