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

select statement

former_member196517
Contributor
0 Likes
835

Hi All,

I have one internal table where i have stored transparent table names.. now i want to loop thru this internal table and want to count number of rows in all transparent tables so i will use select count (*) from transparent table name.. but as this is a string or name which is generated dynamically.. code gives a syntax error.. how to overcome this problem

my code is something like this

loop at itab into wa

select count (*) from wa-tablename

endloop

Regards

Anuj

1 ACCEPTED SOLUTION
Read only

former_member156446
Active Contributor
0 Likes
818

Hi Anuj

else check this way


data: lv_tb type DD02D-DBTABNAME.

loop at itab into wa

lv_tb = wa-tablename.

select count (*) from lv_tb.

endloop.

7 REPLIES 7
Read only

ThomasZloch
Active Contributor
0 Likes
818

try

select count (*) from (wa-tablename)

Greetings

Thomas

Read only

former_member156446
Active Contributor
0 Likes
819

Hi Anuj

else check this way


data: lv_tb type DD02D-DBTABNAME.

loop at itab into wa

lv_tb = wa-tablename.

select count (*) from lv_tb.

endloop.

Read only

0 Likes
818

doesnt work.. says syntax error lv_tb doesnt exist in ddic.

Read only

0 Likes
818

see my post above, that should work for you.

Read only

0 Likes
818

Hi,

Try this

Data: l_cnt type i.

parameters: p_tname type char30 default 'MARA'.

select Count(*) from (p_tname) into l_cnt.

Regards,

Satish

Read only

0 Likes
818

Hi this works, I tested it... just fill the itab during debugging..


TABLES: vbak , vbap.

DATA: BEGIN OF itab OCCURS 0,
       lv_tb TYPE dd02d-dbtabname,
      END OF itab,
    l_count TYPE i.
DATA: lv_tb TYPE dd02d-dbtabname.

LOOP AT itab.
  lv_tb = itab-lv_tb.

  SELECT COUNT(*) AS l_count
    INTO l_count
    FROM (lv_tb).

  WRITE l_count.

ENDLOOP.

Read only

0 Likes
818

loop at itab into wa
select count (*) from (wa-tablename).
write: \ wa-tablename, sy-dbcnt.
endloop.

In most cases, ABAP requires the field in (brackets) if you want it's value to be interpreted.

Regards,

Clemens