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

please verify my logic for inserting records into database?

Former Member
0 Likes
765

hi gurus.

iam getting the data into my internal table (g_vcontrol_itab) before this logic

but my records what ever in internal table is not inserting into my

database please check this code .

WHEN 'INSERT'.

LOOP AT g_vcontrol_itab INTO g_vcontrol_wa.

INSERT into zcust_call_rec values g_vcontrol_wa.

IF sy-subrc = 0.

MESSAGE i010(zmessage).

ELSE.

MESSAGE i000(0) WITH 'NOT INSERTED'.

ENDIF.

ENDLOOP.

regards ,

satheesh.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
748

hi,

Verify the data present in the DB table.

Error may be due to the duplicate records present in the internal table.

Regards,

Sankar

hi gurus.

iam getting the data into my internal table (g_vcontrol_itab) before this logic

but my records what ever in internal table is not inserting into my

database please check this code .

WHEN 'INSERT'.

LOOP AT g_vcontrol_itab INTO g_vcontrol_wa.

INSERT into zcust_call_rec values g_vcontrol_wa.

IF sy-subrc = 0.

MESSAGE i010(zmessage).

ELSE.

MESSAGE i000(0) WITH 'NOT INSERTED'.

ENDIF.

ENDLOOP.

regards ,

satheesh.

5 REPLIES 5
Read only

Former Member
0 Likes
748

Hi,.

Try this.

LOOP AT g_vcontrol_itab .

INSERT into zcust_call_rec values g_vcontrol_itab.

IF sy-subrc = 0.

MESSAGE i010(zmessage).

ELSE.

MESSAGE i000(0) WITH 'NOT INSERTED'.

ENDIF.

ENDLOOP.

Remove work area

Regards,

Priyanka.

Read only

Former Member
0 Likes
749

hi,

Verify the data present in the DB table.

Error may be due to the duplicate records present in the internal table.

Regards,

Sankar

Read only

Former Member
0 Likes
748

hi,

Just chk this sample.

DATA : BEGIN OF int OCCURS 0,
       client LIKE ztable-client,
       emp_name LIKE ztable-emp_name,
       emp_id LIKE ztable-emp_id,
       END OF int.
 
 
int-client = '501'.
int-emp_name = 'Test Data'.
int-emp_id = '0001'.
 
APPEND int.
 
INSERT ztable FROM TABLE int.
COMMIT WORK.

Rgds

Reshma

Read only

Former Member
0 Likes
748

Hi

Did you check if there are any records in the table, with the same Primary key as that of the records in the internal table.

Except for that, i dont see any reason why its failing.

<b>INSERT INTO dbtab VALUES wa.</b>

Regards

Raj

Read only

0 Likes
748

If you restructure your code a little like this:

WHEN 'INSERT'.
  LOOP AT g_vcontrol_itab INTO g_vcontrol_wa.
    clear: zcust_call_rec.
    move-corresponding g_vcontrol_wa to zcust_call_rec.
*" put a break-point here to see what is in zcust_call_rec
    break-point.
    insert zcust_call_rec.
    IF sy-subrc = 0.
      MESSAGE i010(zmessage).
    ELSE.
      MESSAGE i000(0) WITH 'NOT INSERTED'.
    ENDIF.
ENDLOOP.

then at the break-point you will be able to see what is about to be attempted in the DB insert more clearly e.g. you may have some key fields in zcust_call_rec empty.