2009 Jan 12 11:13 AM
Hi Experts,
Can any budy say that How can we insert multiple records from internal table to DB table in a single statment.
Exactly my requirment is I have to insert two DB tables when user push SAVE button, one is header table and second is item table . my problem is in the intrnal table only one record is updating.
Thanks & Regards,
DTK
2009 Jan 12 4:23 PM
Hi,
It is all about the primary key fields of the database table.
IE:
You have a db table with following fields
MANDT (primary key field)
BUKRS (primary key field)
BELNR (primary key field)
GJAHR
VBELN
and it with same fields.
MANDT BUKRS BELNR GJAHR VBELN
120 0010 160000 2008 450000
120 0010 160000 2007 450003
120 0020 160000 2008 450000
200 0010 160001 2008 450001
200 0010 160001 2007 450001
If you use INSERT statement, only 3 of these will be inserted into the database table, why?
Because: Each database table must include one or a very small group of key fields that uniquely identify each table line by its value. These fields are known as the primary keys of the table.
And as lines 1 and 2 / 4 and 5 have the same MANDT BUKRS and BELNR only one will be inserted into the table.
If the database table is your own one, you will need to modify it so that it would work.
Good luck!
Hi Experts,
Can any budy say that How can we insert multiple records from internal table to DB table in a single statment.
Exactly my requirment is I have to insert two DB tables when user push SAVE button, one is header table and second is item table . my problem is in the intrnal table only one record is updating.
Thanks & Regards,
DTK
2009 Jan 12 11:16 AM
2009 Jan 12 11:17 AM
hi,
use as follows:
modify ztable from internal table.
thanks,
anupama.
2009 Jan 12 11:18 AM
u have to take all the data in internal table which is goig to update in tabel and then use insert statement .
2009 Jan 12 11:18 AM
Use INSERT target FROM TABLE itab [ACCEPTING DUPLICATE KEYS] ...
2009 Jan 12 11:19 AM
Hi,
Check out the following link for inserting several lines into database.
http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/frameset.htm
Regards,
Deepthi
2009 Jan 12 11:20 AM
hi,
u can use "modify dbtab from table itab".
regards,
Sumanjeet.
2009 Jan 12 11:20 AM
hi Devalla,
use MODIFY dbtab from itab
APPEND
for syntax use tcode ABAPDOCU
thanks
Sachin
2009 Jan 12 11:21 AM
Hi,
Besides above, you can also use :
loop at itab into wa.
insert into ztable values wa.
endloop.
attention: the structure of itab should be the same as ztable.
2009 Jan 12 11:27 AM
Hi
You can use the statement
Loop statement
modify ztab from table itab
Append
endloop.
Hope it helps u out
Thanks & Regards
2009 Jan 12 11:51 AM
Hi,
Use
LOOP AT ITAB INTO WA.
modify ztab from table itab
Append
ENDLOOP.
Regards,
Jyothi CH.
2009 Jan 12 12:07 PM
2009 Jan 12 12:16 PM
Hi Devalla,
Use the statement, to insert records from internal table into ztable in one go:-
MODIFY <ztable_name> FROM <internal_table>.
This statement will INSERT records into the Ztable if no records found corresponding to the key fields.
But if rcords found for key fields, it will work as UPDATE statement into Ztable.
Hope this solves your problem.
Thanks & Regards,
Tarun Gambhir
2009 Jan 12 3:47 PM
Loop at your internal table and INSERT records one by one..
if it still inserts one record then it means things are wrong with the Key in ur DB or values in internal table..
Check and revert.
2009 Jan 12 4:23 PM
Hi,
It is all about the primary key fields of the database table.
IE:
You have a db table with following fields
MANDT (primary key field)
BUKRS (primary key field)
BELNR (primary key field)
GJAHR
VBELN
and it with same fields.
MANDT BUKRS BELNR GJAHR VBELN
120 0010 160000 2008 450000
120 0010 160000 2007 450003
120 0020 160000 2008 450000
200 0010 160001 2008 450001
200 0010 160001 2007 450001
If you use INSERT statement, only 3 of these will be inserted into the database table, why?
Because: Each database table must include one or a very small group of key fields that uniquely identify each table line by its value. These fields are known as the primary keys of the table.
And as lines 1 and 2 / 4 and 5 have the same MANDT BUKRS and BELNR only one will be inserted into the table.
If the database table is your own one, you will need to modify it so that it would work.
Good luck!
2009 Jan 13 4:31 AM
Hi Märten Tootmaa,
Thankyou very much.
My problem solved.
Thanks & Regards,
Devalla Tarun Kumar
2009 Mar 17 11:53 AM
Hi Devalla
Could you please tell me how you have solved this problem.
I am also getting same problem.
Regards.
2009 Mar 20 8:04 AM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |