在工作中進行編程時,朋友向我呈現了一個非常有趣的情況: 有一個帶有通配符值的表格,例如「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