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

Deleting dbtab with dynamic SQL

Former Member
0 Likes
2,909

Hi,

I've a screen that receives a dbtab name and some conditions for deleting records, I've filled an itab with the conditions in order to use dynamic SQL. It runs perfectly if I do

SELECT * INTO <tab> FROM (dbtab) WHERE (conditions).

but it won't accept with the Delete statement.

DELETE FROM (dbtab) WHERE (conditions).

.

Is there any solution for this problem or do I really have to create a report dynamically?

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
1,880

Hi Andr,

you can use

SELECT * INTO <tab> FROM (dbtab) WHERE (conditions).

DELETE (dbtab) FROM TABLE <tab>.

Regards,

Clemens

10 REPLIES 10
Read only

Former Member
0 Likes
1,880

Hi,

Try deleting with in a loop..

LOOP AT <tab> ASSIGNING <FS>.

DELETE (dbtab) FROM <fs>.

ENDLOOP.

Thanks,

Naren

Read only

0 Likes
1,880

Hi...

Where do you want me to put the WHERE clause?

And the main problem is that I can't create an internal table from a reference of a dbtab (a variable with the name of the dbtab).

If I could create an itab with the structure of the dbtab my problem should be solved with:

SELECT * INTO CORRESPONDING FIELDS OF TABLE <itab> FROM (dbtab_name) WHERE (conditions).

and

DELETE FROM (dbtab_name) VALUES <itab>.

Read only

Former Member
0 Likes
1,880

Can you check your delete statement,it might be problem with your delete statement

delete db table from table int_table where condition..

Read only

0 Likes
1,880

I can't create an itab with the structure of the dbtab...

Read only

Former Member
0 Likes
1,880

Try this....


        DELETE (QUERY_TABLE) FROM TABLE <DYN_TABLE>.

Greetings,

Blag.

Read only

0 Likes
1,880

Hi,

I don't have the dbtab name into a field-symbol but in a variable... Like

dbtab_name = 'ZHR_AL'.

And when using your code I've to change to

DELETE (conditions) FROM TABLE (dbtab_name).

And the result is an error: Unable to interpret the expression "(DBTAB_NAME)".

#-/

Read only

0 Likes
1,880

DELETE (conditions) FROM TABLE (dbtab_name).

when you use above condition then it will delete the data from your internal table...

if you want to delete from database table then use :

DELETE (conditions) FROM TABLE (dbtab_name).

if you want to delete from internal table :

DELETE TABLE (dbtab_name). where conditions..

Thanks

Seshu

Read only

0 Likes
1,880

???

DELETE (conditions) FROM TABLE (dbtab_name).

when you use above condition then it will delete the

data from your internal table...

if you want to delete from database table then use :

DELETE (conditions) FROM TABLE (dbtab_name).

I've already solved my problem but I'd love to do it your way because it seems it would have a better performance...

But like I said before, with your solution it will give me a syntax error:

Unable to interpret the expression "(dbtab_name)". -

Regards,

André Costa

Read only

Clemenss
Active Contributor
0 Likes
1,881

Hi Andr,

you can use

SELECT * INTO <tab> FROM (dbtab) WHERE (conditions).

DELETE (dbtab) FROM TABLE <tab>.

Regards,

Clemens

Read only

Former Member
0 Likes
1,880

Hi Clemens Li,

thank you very much!! The solution is almost like you said:

SELECT * INTO <tab> FROM (dbtab) WHERE (conditions).
DELETE (dbtab) FROM <tab>.
ENDSELECT.

Now it works perfect! Thanks again.

Regards,

André Costa