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

Please help me correct this code

Former Member
0 Likes
608

I have a custom table for some application.

I want to write a program which can reverse the entries in that table for the given selection.

Can you guys please help me with this, I've been able to achieve following:

Note: SYSTEMTIME is one of the primary keys of the table

Code below throws following error:

SAPSQL_ARRAY_INSERT_DUPREC

The ABAP/4 Open SQL array insert results in duplicate database records.

REPORT ZDIFF_REVERSE .

tables: ztable1.

data: itab like ztable1 occurs 0 with header line.

SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.

select-options: LOCATION for ztable1-LOCATION obligatory,

DATE for ztable1-DATE obligatory,

user for ztable1-user obligatory.

parameter: test as checkbox default 'X'.

SELECTION-SCREEN END OF BLOCK blk1.

*select * from ztable1 into table itab*

where LOCATION in LOCATION

and DATE in DATE

and user in user.

Loop at itab.

write:/ itab-LOCATION, itab-DATE, itab-user, itab-ORIGINALAMOUNT,

itab-CORRECTEDAMT, itab-DIFFAMT.

endloop.

if test = ' '.

loop at itab.

*itab-ORIGINALAMOUNT = -1 * itab-ORIGINALAMOUNT.*

*itab-CORRECTEDAMT = -1 * itab-CORRECTEDAMT.*

*itab-DIFFAMT = -1 * itab-DIFFAMT.*

itab-SYSTEMDATE = sy-datum.

itab-SYSTEMTIME = SY-UZEIT.

insert ztable1 from table itab.

endloop.

* *

endif.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
577

Hi,

You didn't modify the internal table...and you are trying to insert the same records that you got.

Try this..

loop at itab.

itab-SYSTEMDATE = sy-datum.

itab-SYSTEMTIME = SY-UZEIT.

MODIFY itab.

endloop.

insert ztable1 from table itab.

Thanks

Naren

4 REPLIES 4
Read only

Former Member
0 Likes
577

IF you want to reverse the records then why are you using insert instead of delete?

You are getting the dump because you are trying to insert records that are already there

Read only

Former Member
0 Likes
577

Don't you think you first edit one element:


itab-SYSTEMDATE = sy-datum.
itab-SYSTEMTIME = SY-UZEIT.

and then you insert whole itab?


insert ztable1 from table itab.

It would be better to use table without header line...

reg.

wojciech.

Read only

Former Member
0 Likes
578

Hi,

You didn't modify the internal table...and you are trying to insert the same records that you got.

Try this..

loop at itab.

itab-SYSTEMDATE = sy-datum.

itab-SYSTEMTIME = SY-UZEIT.

MODIFY itab.

endloop.

insert ztable1 from table itab.

Thanks

Naren

Read only

0 Likes
577

Narendra, you nailed it. Adding modifty solved..

In reference to earlier post, I dont want to delete it coz this table feeds BI for reporting. Inorder to have a consistent reporting I am reversing it.