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

Unable to insert record in database table with INSERT

Former Member
0 Likes
2,093

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

7 REPLIES 7
Read only

Former Member
0 Likes
1,050

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

Read only

0 Likes
1,050

Prabhu...

I used Modify as suggested by you..butstill no use. unable to inert records into databse table

any clues what i am missing.

Read only

0 Likes
1,050

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

Read only

0 Likes
1,050

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®

Read only

0 Likes
1,050

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

Read only

0 Likes
1,050

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.

Read only

Former Member
0 Likes
1,050

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