Application Development 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: 

select statement

former_member196517
Contributor
0 Kudos

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

former_member156446
Active Contributor
0 Kudos

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

ThomasZloch
Active Contributor
0 Kudos

try

select count (*) from (wa-tablename)

Greetings

Thomas

former_member156446
Active Contributor
0 Kudos

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.

0 Kudos

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

0 Kudos

see my post above, that should work for you.

0 Kudos

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

0 Kudos

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.

0 Kudos

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