While programming at work, a friend presented me a very interesting case:
There is a table with wildcard values, such as "test". This register is able to find words containing 'test' in them, as it does not matter what comes before or after the word.
There is another table which holds registers with the desired text, such as 'this is a test' for example.
The regular access preference would be from the wildcard table to the text table, but this is not possible in my friend's scenario.
He actually came with a solution, but it doesn't feel it is as good as it could be.
His idea was to select every wildcard register and every text needed. Then, he would delete from the wild card table every register which did not have a matching target in the text table, as it is already correct and containing only pertinent values.
In ABAP this could be written as:
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.
Since this is done in ABAP, i thought there would be a select statement capable of doing this validation process directly into the database, for the wildcard table may be too big to select everything, iterate, and process.
EDIT: The general Idea is to use the text to find appropriate wildcards for it, without testing every single wildcard with every single text. I would like to know if this is possible to be implemented in any solution, be it database-oriented, i.e in a select statement or in pure code.