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

problem with deleteing a record froma database table.

Former Member
0 Likes
1,730

HI,

iam facing a proble with the delete statement.

iam getting sy-subrc value = 4.

code

LOOP AT t_tab INTO w_tab.

IF w_tab-check = 'X' AND

w_tab-flag = 'X'.

DELETE t_tab . " deleting the value in the internal table

move-corresponding w_tab to ztest_tab.

delete ztest_tab.

ENDIF.

ENDLOOP.

ztest_tab is the database table name.

can any one help me.

regards

priyanka

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,706

Hi Priyanka,

Do like this


LOOP AT t_tab INTO w_tab.
IF w_tab-check = 'X' AND
w_tab-flag = 'X'.
"DELETE t_tab .  deleting the value in the internal table  Dont use this
move-corresponding w_tab to ztest_tab. " no need for this
delete ztest_tab FORM w_tab.
ENDIF.
ENDLOOP.
DELETE t_tab WHERE check = 'X' and flag = 'X'. "if u need to delete such records

13 REPLIES 13
Read only

Former Member
0 Likes
1,706

HI,

If u want to delete the same row from database table use

DELETE <dbtable> from <workarea>

Read only

Former Member
0 Likes
1,706

iam getting sy-subrc value = 4.

Where ur checking sy-subrc value .

In which statement ur geting that value...

Read only

Former Member
0 Likes
1,706

Have you declared "ztest_tab" using the tables declaration? If not try doing that.

TABLES:

ZTEST_TAB.

Read only

BH2408
Active Contributor
0 Likes
1,706

Hi ,

try use the

delete from <table > where condition.

Regards,

Bharani

Read only

viquar_iqbal
Active Contributor
0 Likes
1,706

Hi

You need to use delete t_tab from w_tab ( or use refresh or FREE statement to delete internal table )

Thanks

Viquar Iqbal

Read only

Former Member
0 Likes
1,706

hi,

Can you be more specific about the deletion you are trying to do ?

Moreover

move-corresponding w_tab to ztest_tab.

This statement has no effect on the database.

Thanks

Sharath

Read only

0 Likes
1,706

i have declared the tables satatement

ie :

tables :

ztest_tab.

after the delete statement is executed the operation is being failed.

ie : iam getting the sy-subrc value = 0.

Regards

Priyanka.

Read only

0 Likes
1,706

Hi

Use Commit statment after delete command.

Read only

0 Likes
1,706

hi,

Declare another internal table of structure similar to the earlier one.

Append the records to this 2nd table which satisfy the IF condition you have mentioned inside the loop.

loop at itab1 into w_itab1.

if------

ie. append ztest_tab to itab2.

endif.-----

endloop.

Use Delete DBTAB from table itab2.

This way you can achieve your required functionality, its working as per requirement

Regards

Sharath

Read only

0 Likes
1,706

hi,

PS. Never perform any database operations such as select, delete..etc inside loops (DO, loop...etc).

This kind of coding creates a severe performance overhead on your system.

Better assemble records of your choice for deletion into a internal table and delete using the table as a reference

Regards

Sharath

Read only

Former Member
0 Likes
1,706

Hi

For Deleteing record from Database specify the where condtion.

DELETE FROM ztest_tab

WHERE field1 = w_tab-field1 AND

field2 = w_tab-field2 .

OR

To delete multiple records.

DELETE ztest_tab FROM TABLE t_tab.

OR

To delete single record.

DELETE ztest_tab FROM w_tab.

Regards,

Raghu

Read only

Former Member
0 Likes
1,707

Hi Priyanka,

Do like this


LOOP AT t_tab INTO w_tab.
IF w_tab-check = 'X' AND
w_tab-flag = 'X'.
"DELETE t_tab .  deleting the value in the internal table  Dont use this
move-corresponding w_tab to ztest_tab. " no need for this
delete ztest_tab FORM w_tab.
ENDIF.
ENDLOOP.
DELETE t_tab WHERE check = 'X' and flag = 'X'. "if u need to delete such records

Read only

awin_prabhu
Active Contributor
0 Likes
1,706

Hi friend,

Check the data type and length of fields declared in program and

fields in database table(ztest_tab) are same.

Thanks.....