我有一個需要動態運行此查詢的需求。有沒有人有過這種查詢?來自內部表的動態查詢
READ TABLE table_name TRANSPORTING feild_name INTO table_name
WITH KEY key_feild1 = value1,
key_feild2 = value2,
key_feild3 = value3.
我有一個需要動態運行此查詢的需求。有沒有人有過這種查詢?來自內部表的動態查詢
READ TABLE table_name TRANSPORTING feild_name INTO table_name
WITH KEY key_feild1 = value1,
key_feild2 = value2,
key_feild3 = value3.
根據this answer,下面是另一種可能的解決方案。雖然,它有點難看,但它確實有效。
DATA: table_tab TYPE TABLE OF rsdstabs,
selid TYPE rsdynsel-selid,
cond_tab TYPE rsds_twhere,
field_tab TYPE TABLE OF rsdsfields,
string TYPE string.
FIELD-SYMBOLS <cond> LIKE LINE OF cond_tab.
table_tab = VALUE #((prim_tab = 'USR02')).
CALL FUNCTION 'FREE_SELECTIONS_INIT'
EXPORTING
kind = 'T'
IMPORTING
selection_id = selid
TABLES
tables_tab = table_tab
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE 'Error in initialization' TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDIF.
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = selid
title = 'Free Selection'
as_window = ' '
IMPORTING
where_clauses = cond_tab
TABLES
fields_tab = field_tab
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE 'No free selection created' TYPE 'I'.
LEAVE PROGRAM.
ENDIF.
FIELD-SYMBOLS: <fld> TYPE any.
DATA: field1 TYPE c LENGTH 10, value1 TYPE string,
field2 TYPE c LENGTH 10, value2 TYPE string,
field3 TYPE c LENGTH 10, value3 TYPE string,
field4 TYPE c LENGTH 10, value4 TYPE string,
field5 TYPE c LENGTH 10, value5 TYPE string,
field6 TYPE c LENGTH 10, value6 TYPE string,
field7 TYPE c LENGTH 10, value7 TYPE string,
field8 TYPE c LENGTH 10, value8 TYPE string,
field9 TYPE c LENGTH 10, value9 TYPE string,
num1(1) TYPE n,
fldname TYPE fieldname,
valname TYPE fieldname.
ASSIGN cond_tab[ tablename = 'USR02' ] TO <cond>.
IF sy-subrc = 0.
LOOP AT <cond>-where_tab ASSIGNING FIELD-SYMBOL(<fs_cond>).
num1 = sy-tabix.
CONCATENATE 'field' num1 INTO fldname.
CONCATENATE 'value' num1 INTO valname.
ASSIGN (fldname) TO <fld>. "assigning field name
string = <fs_cond>.
REPLACE REGEX `(^.*\(\s)(.*)(EQ.*)` IN string WITH '$2'.
<fld> = string.
ASSIGN (valname) TO <fld>. "assigning value
string = <fs_cond>.
REPLACE REGEX `(.*EQ\s)'(.*)('\s*\))` IN string WITH '$2'.
<fld> = string.
ENDLOOP.
ENDIF.
SELECT *
FROM usr02
INTO TABLE @DATA(lt_usr).
READ TABLE lt_usr ASSIGNING FIELD-SYMBOL(<fs_usr>)
WITH KEY (field1) = value1
(field2) = value2
(field3) = value3
(field4) = value4
(field5) = value5
(field6) = value6
(field7) = value7
(field8) = value8
(field9) = value9.
樣本建立在USR02表上。
FREE_SELECTIONS_INIT
FM根據這些字段建立WHERE條件。 READ TABLE
語句模板中,空白字段僅被忽略,表格僅通過填充鍵讀取。
你需要動態的部分是什麼? – szako
他們的關鍵部分是我掙扎的地方 –
[可以使用任意數量的關鍵字段規範動態創建READ TABLE語句嗎?](https://stackoverflow.com/questions/18869119/can-a-read -table-statement-be-created-dynamic-with-an-any-of-ke) – vwegert