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 to insert on dbtable

Former Member
0 Likes
507

I have this code:

REPORT Z99BW047.

tables : Z99BW69,Z99BW92.

DATA: begin of ITAB1 occurs 0.

INCLUDE STRUCTURE Z99BW69.

DATA: end of ITAB1.

DATA: begin of ITAB2 occurs 0.

INCLUDE STRUCTURE Z99BW69.

DATA: end of ITAB2.

  • Seleccionamos los PC en una table interna

select *

from Z99BW69

INTO CORRESPONDING FIELDS OF TABLE ITAB1

where VGART ='PC'.

**aND BLDAT ='20060320'

*and MATNR = '000000000000000021'

*and BUKRS ='S00'

*and POPER = '003'.

*ordenamos la tabla interna para hacer el AT NEW.

sort itab1 by MANDT BUKRS MATNR POPER BLDAT BELNR.

*Cojemos solo aquellos valors que cambien con el AT NEW.

LOOP AT ITAB1.

AT NEW POPER.

read table itab1 index sy-tabix.

append itab1 to itab2.

ENDAT.

ENDLOOP.

break-point.

delete from Z99BW92.

LOOP AT ITAB2.

read table itab2 index sy-tabix.

INSERT Z99BW92 FROM TABLE ITAB2 ACCEPTING DUPLICATE KEYS.

ENDLOOP.

break-point.

ANd I define Z99BW92 with this keys:

MANDT CLNT

BUKRS CHAR

MATNR CHAR

POPER NUMC

BLDAT DATS

CK_BELNR CHAR

CK_KJAHR NUMC

CK_MLPOS NUMC

BDATJ NUMC

CURTP CHAR

CPUDT DATS

TCODE CHAR

But in the final LOOP, if I dont write ACCEPTING DUPLICATE KEYS, the program create a dump in the second register. And the registers are diferents!!!!!

And If I write ACCEPTING DUPLICATE KEYS, the program goes to slow !!

I dont understand anything....

thanks

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
485

Since you are using the FROM TABLE syntax, there is no reason to LOOP it. This is your problem. This should be all you need.

break-point.

delete from Z99BW92.

INSERT Z99BW92 FROM TABLE ITAB2.

break-point.

Regards,

Rich Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
486

Since you are using the FROM TABLE syntax, there is no reason to LOOP it. This is your problem. This should be all you need.

break-point.

delete from Z99BW92.

INSERT Z99BW92 FROM TABLE ITAB2.

break-point.

Regards,

Rich Heilman

Read only

0 Likes
485

Of course, you can keep the ACCEPTING DUP KEYS too.

break-point.
 
delete from Z99BW92.
 
INSERT Z99BW92 FROM TABLE ITAB2 ACCEPTING DUPLICATE KEYS.
 
break-point.

Regards,

Rich Heilman

Read only

0 Likes
485

Thanks a lot ! i didnt see it ! 😜