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

Better Delete Logic??

former_member194669
Active Contributor
0 Likes
705

Hi All,

I have requirement to write a function module to delete records from 125 Y(custom) tables

This is my scenario.


delete from y100 where docno eq v_docno.
if sy-subrc eq 0.
  delete from y101 where docno eq v_docno.
  if sy-subrc eq 0.
     ......... " Keep this loop all remaining 125 tables
  else.
    rollback.
else.
  rollback.
endif.

I know i can do this using lot of IF statements, I want know any other better way to do this?

Please don't suggest to use lot of IF statements.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
680

Hi ARS,

May we can do this way.

v_table = 'Y100'.

do 25 times.

delete from v_table where docno eq v_docno.

if sy-subrc ne 0.

flag = 'X'.

exit.

endif.

v_table = v_table + 1.

enddo.

if flag = 'X'.

rollback.

endif.

Ali.

Hi All,

I have requirement to write a function module to delete records from 125 Y(custom) tables

This is my scenario.


delete from y100 where docno eq v_docno.
if sy-subrc eq 0.
  delete from y101 where docno eq v_docno.
  if sy-subrc eq 0.
     ......... " Keep this loop all remaining 125 tables
  else.
    rollback.
else.
  rollback.
endif.

I know i can do this using lot of IF statements, I want know any other better way to do this?

Please don't suggest to use lot of IF statements.

4 REPLIES 4
Read only

Former Member
0 Likes
681

Hi ARS,

May we can do this way.

v_table = 'Y100'.

do 25 times.

delete from v_table where docno eq v_docno.

if sy-subrc ne 0.

flag = 'X'.

exit.

endif.

v_table = v_table + 1.

enddo.

if flag = 'X'.

rollback.

endif.

Ali.

Read only

0 Likes
680

Quadri

Thanks for your reply.

Here table names are not unique. Some times delete for table name go like

Y100, Y101, Y106, Y123 ....... like that

I am getting the table name to delete in a import parameter table.

Read only

0 Likes
680

ARS,

You can append all the table in one internal table and loop it.

This is one of the way.

Again it depends on your requirement.

Ali

Read only

0 Likes
680

Hi,

From your reply i understood, that i need to write dynamic delete, dynamically assign the table name something like this way

delete from = v_docno.

I think i need to field-symbol for this.

Anyway thanks for your help.