Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Cannot use alias for dynamic column name in SELECT statement

Former Member
0 Likes
1,463

Hi,

I want to retrieve values from several tables by using dynamic column & table name as below:



DATA: tbl_name(30) TYPE c VALUE '/bic/tbi_srcsys',  " staticly initialized for this example
           col_name(30) TYPE c VALUE '/bic/bi_srcsys'.  " staticly initialized for this example

SELECT (col_name) INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).

The internal table "it_values" does not contain a field named "/bic/bi_srcsys", instead it has another generic field "value" so that the above code can be applied to other tables. I tried to use alias (AS) as below:


SELECT (col_name) AS value INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).

But this cannot work. I know that there are other ways to solve this problem, such as by using a single field in SELECT .. ENDSELECT and subsequently appending it to the work area and internal table as below:


SELECT (col_name)  INTO (lv_value) FROM (tbl_name).
  wa_value-value = lv_value.
  APPEND wa_value TO it_values.
ENDSELECT.

Just wonder if there is any other more elegant workaround, because I might have several other fields instead of only one?

Thanks.

Regards,

Joon Meng

3 REPLIES 3
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
742

Hello,

Just remove INTO CORRESPONDING FIELDS OF TABLE to INTO TABLE.

SELECT (col_name) INTO CORRESPONDING FIELDS OF TABLE it_values FROM (tbl_name).

SELECT (col_name) INTO TABLE it_values FROM (tbl_name).

BR,

Suhas

Read only

Former Member
0 Likes
742

Hi Suhas,

thanks for the quick reply.

Sorry that I have not well described the structure of the internal table "it_values". This internal table contains several other fields (key, type, value, etc.).

I guess that the following code


SELECT (col_name) INTO TABLE it_values FROM (tbl_name).

works if the internal table only has one field (value) or the field "value" is in the first position, right?

In this case, I need to fill the "value" field of internal table it_values (ignore the other fields like type, key) with values retrieved from (col_name) of the DDIC table.

Looking forward to your reply.

BR,

Joon Meng

Read only

Former Member
0 Likes
742

Hi Joon,

Were you able to find a solution for this? I am in a similar situation.

Thanks,

Puja