‎2020 Oct 13 6:25 PM
Hi experts,
my requirement seems a little weird, but maybe you can help me.
We have a custom db-table, which comes with two colomns: table and field.
In this table (ZB01), the customer has values like KNA1 & NAME1, or KNVV & AUFSD.
The customer number is always known.
I would like to know, if it is possible to create a dynamic select with dynamic output like:
DATA: LT_ZB01 type STANDARD TABLE OF zb01.
Select * from zb01 into TABLE lt_zb01.
loop at lt_zb01 ASSIGNING FIELD-SYMBOL(<zb01>).
Select single (<zb01>-FIELD) from (<zb01>-TABLE)
into @data(lv_var)
where
kunnr = '0000030047'.
ENDLOOP.
In this custom table, there could be any table and table-field coming to have being selected.
I have tried with creation of "type ref to data" and @data(var) as output, but nothing works.
Is this possible? (We are in a S/4HANA environment)
Thanks in advance
‎2020 Oct 13 8:42 PM
You have to create the data object dynamically:
DATA dref_field TYPE REF TO data.
FIELD-SYMBOLS <field> TYPE ANY.
CREATE DATA dref_field TYPE (<zb01>-field).
ASSIGN dref_field->* TO <field>.
Select single (<zb01>-FIELD)
from (<zb01>-TABLE)
into @<field>
where kunnr = '0000030047'.
Of course, handle all exception situations like field is not valid...
‎2020 Oct 13 8:42 PM
‎2020 Oct 13 8:42 PM
You have to create the data object dynamically:
DATA dref_field TYPE REF TO data.
FIELD-SYMBOLS <field> TYPE ANY.
CREATE DATA dref_field TYPE (<zb01>-field).
ASSIGN dref_field->* TO <field>.
Select single (<zb01>-FIELD)
from (<zb01>-TABLE)
into @<field>
where kunnr = '0000030047'.
Of course, handle all exception situations like field is not valid...
‎2020 Oct 13 8:49 PM
‎2020 Oct 15 11:16 AM