05-18-2020 10:48 AM
I want to query data from faglflext table by given accounting period. In this table each month is a column. like HSL01,HSL02,HSL03....I wonder is it possible to dynamcie create a SQL like select HSL01,HESL02,...from select-options. Such as if I enter accounting period as 3 to 5, then the SQL is select HSL03,HSL04,HSL05...like. I wonder can EXEC be used for that? Thx.
05-18-2020 11:21 AM
Hi loki_luo15
Something like this?
PARAMETERS: p_prstr TYPE i.
PARAMETERS: p_prend TYPE i.
DATA:
lv_period TYPE n LENGTH 2,
lt_fields TYPE TABLE OF string.
lv_period = p_prstr.
WHILE lv_period <= p_prend.
APPEND |HSL{ lv_period }| TO lt_fields.
lv_period = lv_period + 1.
ENDWHILE.
SELECT (lt_fields)
FROM faglflext
INTO TABLE lt_results
You could also retrieve all HSL fields, for all months and then read the data only from fields for which the period was specified on the selection screen.
Regards,
Mateusz