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: 

Runtime error in my program

Former Member
0 Kudos

*&---------------------------------------------------------------------*
*& Report  ZGSCREEN                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
 
REPORT  ZGSCREEN no standard page heading
.
tables :zgtable,sscrfields.
 
data:begin of itable occurs 0,
     mandt like zgtable-mandt,
     trackid like zgtable-trackid,
     artist like zgtable-artist,
     end of itable.
selection-screen begin of block block1 with frame title txt1.
parameters:trackid(15) type n, *I changed from trackid like zgtable-trackid
           artist(30) type c.
 
selection-screen skip 5.
 
selection-screen begin of line.
selection-screen pushbutton (20) but1 user-command but1.
selection-screen position 25.
selection-screen pushbutton (8) but2 user-command but2.
selection-screen position 38.
selection-screen pushbutton (10) but3 user-command but3.
selection-screen position 55.
selection-screen pushbutton (10) but4 user-command but4.
 
selection-screen end of line.
selection-screen end of block block1.
 
initialization.
but1 = 'Save to Dbase'.
but2 = 'Clear'.
but3 = 'Update'.
but4 = 'Exit'.
 
 
at selection-screen.
*move 800 to itable-mandt.
move trackid to itable-trackid.
move artist to itable-artist.
 
append itable.

if sscrfields-ucomm eq'BUT1'.
 
  insert zgtable from itable.
  commit work.
endif.
 
if sscrfields-ucomm eq 'BUT4'.
leave program.
endif.

The problem it that my program is working well now.I added a record Trackid:2 Artist:Gopi Kumaran and clicked 'save to database',it saved.Then again changed trackid 2 to 3 and Gopi kumaran to A R Rehman,clicked 'save to database' (without quiting the screen).I get a run time error 'The ABAP/4 Open SQL array insert results in duplicate database records'.I dont know why.That is first time the record is adding,if i repeat it without quitting the screen the error is coming.Anyhow I tried commenting 'move 800 to itable-mandt'.The error says duplicate record.I dont know why.

4 REPLIES 4

Former Member
0 Kudos

Hi Gopi.,

Try this.

Whenever you insert values to the table, you have enqueue and dequeue the table .

**- Lock the table for updation

CALL FUNCTION 'ENQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'E'

tabname = 'ZGTABLE'

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

  • IF sy-subrc <> 0.

  • ENDIF.

**- Updating the values in the afterbilled table.

MODIFY zgtable FROM TABLE itable.

COMMIT WORK.

**- Unlock the table after Updation.

CALL FUNCTION 'DEQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'E'

tabname = 'ZGTABLE'.

Reward If Useful.

Regards,

Chitra.

Former Member
0 Kudos

Hi,

When you use INSERT statement in this manner it transfer all the values in the internal table into the database.

In your case I think for the first value as the z-table is empty it is taking the first value.

After you enter the second value into the internal table, naw it has 2 values.

When you try to move the internal table values to the z-table, system try to insert these values in the z-table.

This results in duplicate values and probably duplication of primary key in Z-table.

Sol: take internal table values in work area and then insert into Z-table

0 Kudos

Thanks a lot gaurav.I did it.Its working.I changed as you said,moved data from internal tables to work area and work area to database.I updated the table with update push button too with statement 'update zgtable set artist = artist where trackid = trackid.I thought of putting 'fetch' push button next to track id field box.I tried with position statement but its coming to next line.How to make appear next to line.One more thing how its working if we move data from internal table to work area and to database.

Thanks

0 Kudos

Hi,

What is hapening with internal table?

You put first set of values in the internal table and append it. It moves from header to internal table body.Now when you move this internal table to database it goes successfully as it has only one value.

Second time when you enter some value through the selection screen into the internal table and append it, now in the internal table has got 2 values, the first value you placed in previous cycle and second value you appended now.

When you move intrnal table to database(ztable) it moves both the values to the database. BUT the first value is already present in the database table. so it results in conflict with duplication of primary key. thats why this error.

In workarea we take value one at a time as it can take only one value and only one value move to the database and so the problem is solved.

regards

gaurav

Deserve reward points.