‎2008 Jul 31 8:08 AM
Hi,
I am not able to insert the internal table content into the database, properly.
I have a DB table and an IT of same structure. This is my code:
LOOP AT ltb_factuur.
* INSERT INTO z4968_factuur VALUES ltb_factuur.
* INSERT z4968_factuur FROM ltb_factuur.
*z4968_factuur[] = ltb_factuur[].
MOVE-CORRESPONDING ltb_factuur TO z4968_factuur.
IF sy-subrc <> 0.
it_err_msgs-errors = 'Error inserting record in database'.
APPEND it_err_msgs.
EXIT.
ENDIF.
APPEND z4968_factuur.
* MODIFY z4968_factuur.
ENDLOOP.
There are about 100 records in the IT, but I can see only 2 records in the DB table! Can anybody let me know where am I going wrong here? I used INSERT too before using MOVE_CORRESPONDING, this too failed.
Thank you,
Warm regards,
Deepak
‎2008 Jul 31 8:12 AM
Have you checked that the data is unique to the keys that you have defined on the table. If not you will lose some records as they overwrite existing data.
If it's updating 2 records only then this would be the first thing that I would check out.
Cherrs
Jules
‎2008 Jul 31 8:12 AM
Hi,
Try to use Work Area in MOVE-CORRESPONDING statement.
Hope it is helps.
Regards,
T.Durai murugan.
‎2008 Jul 31 8:13 AM
Hi Deepak,
Try to use the Insert statement..this might solve your program
‎2008 Jul 31 8:14 AM
hiii
create an internal table with the same structure like the database table.get data into that internal table.
Now use Modify Query to modify the database table.
like below
Modify (database-table) from (internal-table)
regards
twinkal
‎2008 Jul 31 8:15 AM
Hi deepak,
use the below statement.
insert dbtab from table itab.
Reward if useful.
Cheers,
Balaji
‎2008 Jul 31 8:15 AM
Hi Deepak,
Use-
loop at ltb_factuur into wa_factuur.
MODIFY z4968_factuur from wa_factuur.
endloop.
Regards,
Aparna Gaikwad.
‎2008 Jul 31 8:17 AM
Hi,
Try this code.
data: wa_ltb_factuur like line of ltb_factuur,
wa_z4968_factuur like line of z4968_factuur.
loop at ltb_factuur into wa_ltb_factuur.
move wa_ltb_factuur to wa_z4968_factuur.
insert z4968_factuur from wa_z4968_factuur.
clear wa_z4968_factuur.
endloop.
‎2008 Jul 31 8:21 AM
Hi,
1. From your code it seems the
internal table = ltb_factuur (with header line)
database table = z4968_factuur
2. This simple logic will also work.
Loop at ltb_factuur.
MODIFY z4968_factuur from ltb_factuur.
Endloop.
MODIFY will automatically take care of appending or modifying
the records in the database, based upon the primary key combination from the work area and availability of that record
in the database table.
regards,
amit m.
‎2008 Jul 31 8:22 AM
pass the data from internal table to ztable workarea and use
insert ztable.
may be u have duplicate entries in the internal table.
check the key fields in the internal table.
if they are unique u can get that in ztable.
‎2008 Jul 31 8:23 AM
‎2008 Jul 31 8:24 AM
Hi
Try the following...
INSERT INTO z4968_factuur FROM ltb_factuur.
( * No need to loop the internal table. )
Hope it helps.
Murthy
Edited by: Kalyanam Seetha Rama Murthy on Jul 31, 2008 9:42 AM
‎2008 Jul 31 8:28 AM
Hi,
First of all create an internal table with the same structure like the database table you haveand also create a work area of same structure, then get data into that internal table.
Then use MODIFY statement . MODIFY statement takes care of inserting a now record or updating a record.
Try this piece of code:
data: wa_ltb_factuur like line of ltb_factuur,
wa_z4968_factuur like line of z4968_factuur.
Loop at ltb_factuur into wa_ltb_factuur.
move wa_ltb_factuur to wa_z4968_factuur.
MODIFY z4968_factuur from wa_z4968_factuur.
clear wa_z4968_factuur.
IF sy-subrc EQ 0.
COMMIT WORK.
ELSE.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Endloop.hope this helps.
thanx,
dhanashri.
Edited by: Dhanashri Pawar on Jul 31, 2008 9:29 AM
‎2008 Aug 01 6:05 AM
Thank you so much everyone for helping me out. I tried almost all possibilities, but its inserting only ONE record in DB! I have 121 records in the Internal Table.
Hi Sathya,
I tried the piece of code that you had suggested. Unlike other options that have been mentioned here, this code is inserting more than one record. But its stopping after inserting 47 records. Its not inserting all the 121 records.
I tried debugging, but unfortunately am not able to see the records being filled in the DB table in debug mode!
Where am I going wrong?
Thank you,
Warm regards,
Deepak
‎2008 Aug 01 6:15 AM
clear z4968_factuur
After Append statement.
or
first check structure of both.
Regards,
Swarup