‎2009 May 11 7:42 PM
Hi all,
I am trying to insert data into databse table CRMD_PARTNER in CRM. and I wrote the following code.
But the records are not getting inserted. but if i hard code the values then i am able to insert.
.....
if not Jtab[] is initial.
INSERT CRMD_PARTNER FROM TABLE JTAB ACCEPTING DUPLICATE KEYS.
COMMIT WORK.
ENDIF.
can some one tell me what is wrong? i am unable to insert the records..
Kindly help,
Regards,
Jessica Sam
‎2009 May 11 7:48 PM
Hi Jessica,
If you try to insert the new values with duplicates by accepting , it will not insert because it is database table define with some Primary key Fields..
try to use the MOdify command instead of Insert.
so if any Duplicates comes it will overwrite the existing record if any new record comes it will insert..
if not Jtab[] is initial.
loop at JTAB.
Modify CRMD_PARTNER FROM JTAB .
if sy-subrc = 0.
COMMIT WORK.
else.
Roll Back.
endif.
endloop.
ENDIF.
Regards,
Prabhudas
‎2009 May 11 7:57 PM
Prabhu...
I used Modify as suggested by you..butstill no use. unable to inert records into databse table
any clues what i am missing.
‎2009 May 11 8:04 PM
H Jessica,
Check the Table JTAB Structure , it should be equal to the CRMD_PARTNER table structure..
and check r u passing the All key field ..
Regards,
Prabhudas
‎2009 May 11 8:06 PM
Possible reasons insert got failed
1. Same primary key values are already available in table CRMD_PARTNER
Try this code before making INSERT
loop at jtab.
v_tabix = sy-tabix.
select single * from crmd_partner where <primary key> = jtab-<primary key>
if sy-subrc 0.
delete jtab index v_tabix.
continue.
endif.
endloop.
a®
‎2009 May 11 8:50 PM
I tried everything. I am passing all key fields and my structute of jtab is same as that of the table, but still i dont see any records being inserted in my table.
data: begin of Jtab occurs 0.
INCLUDE STRUCTURE CRMD_PARTNER.
DATA: end of Jtab
if not Jtab[] is initial.
loop at JTAB.
Modify CRMD_PARTNER FROM JTAB .
if sy-subrc = 0.
COMMIT WORK.
else.
MSG5 = 'SOME RECORD MISSED'.
MOVE MSG5 TO IT_RESULT-MESSAGE.
APPEND IT_RESULT.
endif.
endloop.
some one please help..i am trying to insert data into the database and that doesnt get instered ..any clues about what i am missing wil be highly appreciated.
regards,
jessica sam
‎2009 May 11 10:17 PM
Jessica,
1) Is it possible to post the entire program? If the program is too long, please create a short sample program, make sure that doesn't work, and then post the code here.
2) Do you know for a fact that Jtab[] is not initial? Did you go into debug and verify?
3) Don't go in a loop and modify one record at a time. Modify everything in one shot. Place the cursor on MODIFY statement and hit F1 key for the syntax.
4) MODIFY, INSERT, and UPDATE statements work fine. You will have to figure out what you are doing wrong. Code snippets you are posting are not enough for us to guess the problem.
Debugger is a programmer's best friend. Learn to use it, and you will solve most of your programming problems and feel really good by the end of the day.
‎2009 May 11 8:02 PM
ACCEPTING DUPLICATE KEYS won't allow you to insert more than one record with duplicate keys. It just won't give a non-zero SY-SUBRC if it encounters the situation.
Try pressing F1.
Rob