在工作中进行编程时,朋友向我呈现了一个非常有趣的情况: 有一个带有通配符值的表格,例如“test”。这个寄存器能够在其中找到包含'test'
的单词,因为这个单词之前或之后的内容无关紧要。多对一选择
还有另一个表格,用于保存具有所需文本的寄存器,例如'this is a test'
。
常规访问首选项将从通配表到文本表,但这在我的朋友的情况下是不可能的。
他实际上有一个解决方案,但它并不觉得它可以做得很好。
他的想法是选择每个通配符寄存器和每个需要的文本。然后,他将从通配符表中删除每个在文本表中没有匹配目标的寄存器,因为它已经是正确的并且只包含相关的值。
在ABAP这可以写成:由于这是在ABAP完成
data:
wa_wildcard type string,
t_wildcards type table of string,
t_texts type table of string,
wa_text type string,
lv_index type sy-tabix,
lv_found type c.
select * from zt_texts into table t_texts. "Retrieves desired texts.
check sy-subrc is initial.
select * from zt_wildcards into table t_wildcards. "Retrieves all widlcards.
check sy-subrc is initial.
loop at t_wildcards into wa_wildcard. "Checks every Wildcard
move lv_index to sy-tabix. "Stores the iteration index for Wildcard table.
loop at t_texts into wa_text. "Checks if the actual wildcard matches any text retrieved.
if wa_text cp wa_wildcard-value. "If text contain parts of the wildcard string, it matches
move 'X' to lv_found. "Found a match, may exit the loop!
exit.
endif.
endloop.
if lv_found ne 'X'.
delete t_wildcards index lv_index. "removes the wildcard if no match was found.
endif.
endloop.
,我以为会有能够直接做这个验证过程到数据库中的select语句,为通配符表可太大而无法选择所有内容,迭代和处理。
编辑:一般的想法是使用文本为它找到适当的通配符,没有测试每一个单一的文本通配符。我想知道这是否可以在任何解决方案中实现,无论是面向数据库的,即选择语句还是纯代码。
有多大太大?顺便说一下,ABAP编码应该被取出并拍摄。请不要将此作为如何编写ABAP程序的示例。 – vwegert
这不是一个正确的代码,它是我写的东西,只是为了解释场景的工作原理以及没有ABAP知识的人更好地理解它。 “大”因素不仅是条目数量,而且是不必要的处理。想象一下,通配符表有200,000个条目,文本表有60万条并且没有找到匹配(假设情景)。 – Zeh
没有什么魔法可以让你免于检查每个表项的每个通配符。唯一的问题是您是否要将该处理卸载到最昂贵的资源(数据库服务器)或将其保存在ABAP处理中...... – vwegert