‎2009 Aug 11 10:38 AM
Hi,
I want to insert internal table into database table.
i have use following code
loop at it_header.
INSERT ZTAB from table it_header accepting duplicate keys.
endloop.
but above code insert only first line not multipal.
Thanks in Advance.
Sam
‎2009 Aug 11 10:46 AM
Hi,
"Dont write this statment in LOOP....ENDLOOP
INSERT ZTAB from TABLE it_header[] ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
MESSAGE 'Data Successfully saved into Database table' TYPE 'S'.
ENDIF.
Thanks
‎2009 Aug 11 10:41 AM
HI,
Try this
MODIFY ZTAB from table it_header.
If sy-subrc eq 0.
Commit work.
endif.
Regards,
Nagaraj
‎2009 Aug 11 10:45 AM
first of all you dont need to use insert statement inside loop endloop.
secondly,
If the addition ACCEPTING DUPLICATE KEYS is specified, all rows are inserted for which this is possible. The remaining rows are rejected and sy-subrc is set to 4. The system field sy-dbcnt is set to the number of lines that are inserted. you must be passing values from internal table with same key as records of your ztable.that is shy system is inserting only one row.
‎2009 Aug 11 10:46 AM
Hi,
"Dont write this statment in LOOP....ENDLOOP
INSERT ZTAB from TABLE it_header[] ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
MESSAGE 'Data Successfully saved into Database table' TYPE 'S'.
ENDIF.
Thanks
‎2009 Aug 11 11:05 AM
Hi,
I have use your code.
INSERT ZTAB from TABLE it_header[] ACCEPTING DUPLICATE KEYS.
IF sy-subrc = 0.
MESSAGE 'Data Successfully saved into Database table' TYPE 'S'.
ENDIF.
but it insert one record not multiple.
Thanks & Regards.
Sam.
‎2009 Aug 11 11:11 AM
Hi,
make sure that the records in the internal table it_header from where you are trying to insert do not contain data which has the key field values in the database table repeated. In that case 1 record will be added as the database has to main the database integrity of single record per key fields. Accepting duplicate keys prevents a runtime error, if removed you receive a dump that means you are trying to insert multiple records with the same key.
Hope this helps.
regards,
Sachin
‎2009 Aug 11 10:47 AM
Hi,
You dont have to loop at it_header. You can directly use this
INSERT ZTAB FROM TABLE IT_HEADER ACCEPTING DUPLICATE KEYS.
Regards,
Vik
‎2009 Aug 11 10:49 AM
accepting duplicate keys will prevent the program from dumping out. It will however not insert duplicating records as this violates DB restriction (only unique records can be stored in relational DB). But only one record (from two or three duplicating one) will be inserted in fact.
MODIFY (as suggested above) will handle the entires with same key in DB ( this is just insert+update statements in one ) but will also not solve it entirely, due to same reason.
Regards
Marcin
‎2009 Aug 11 10:59 AM
Hi,
Try to use Work Area in MOVE-CORRESPONDING statement.
Hope it is helps.
Saurabh Goel
‎2009 Aug 11 11:06 AM
Hi SAM,
Creating a SingleRecord -
>>>>
INSERT INSERT INTO <dbtab> VALUES <wa>.
Eg. DATAwa_spfliTYPEspfli.
...
wa_spfli-carrid = 'LH'.
wa_spfli-connid = '0007'.
wa_spfli-cityto = 'SINGAPORE'.
...
INSERT INTO spfli VALUES wa_spfli.
Fsy-subrc NE 0.
-
Creating Several Records---->>>>
INSERT <dbtab> FROM TABLE <itab>.
Eg.
DATA:it_spfli TYPE STANDARD TABLE OF spfli,
wa_itab LIKE LINE OF it_spfli.
...
wa_itab-carrid= 'LH'.
wa_itab-connid= '0009'.
wa_itab-cityto= 'HONGKONG'.
...
APPEND wa_itab TO it_spfli.
....
....
....
APPEND wa_itab TO it_spfli.
INSERT spfli FROM TABLE it_spfli.
IFsy-subrc NE 0.
....