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

Insert

Former Member
0 Likes
683

Hi all,

I have a piece of code ,

zest_obj-zproject_id = s_pid.

zest_obj-zricef_id = s_rid.

zest_obj-zobject_type = s_obtyp.

zest_obj-zcomplex_id = v_id.

zest_obj-zcomplex_seqno = v_seqno.

CASE v_ucomm.

WHEN 'SAVED'.

v_mess = 'Saved as Draft Version'.

zest_obj-zversion = 'D'.

WHEN 'SAVEF'.

v_mess = 'Saved as Final Version'.

zest_obj-zversion = 'F'.

ENDCASE.

zest_obj-zmanhours = v_tot.

IF fg_change NE 'X'.

INSERT zest_obj from zest_obj.

ELSE.

MODIFY zest_obj FROM zest_obj.

ENDIF.

IF sy-subrc = 0.

COMMIT WORK AND WAIT.

MESSAGE v_mess TYPE 'S'.

ELSE.

MESSAGE 'Record Not saved' TYPE 'E'.

ENDIF.

while executing my Transaction i got an error "

An SQL error occurred when accessing a table"

<b></b>

6 REPLIES 6
Read only

Former Member
0 Likes
651

Are you extracting all the keys for custom table correctly?

MODIFY statement works in both way - if record is not present in table, it creates one. If record is present in table, it updates. Can you just try with single MODIFY command, comment INSERT command.

Read only

0 Likes
651

I tried that too... still i'm getting the same error.... eventhough it is a new record...

Read only

0 Likes
651

Can you change the work area name to Z_***. I feel the name of table and work area is same, that might be causing the problem.

Read only

0 Likes
651

no i didnt create a separate work area...

i am using the DB Table as a work area to Insert.

Read only

0 Likes
651

Create a work area and try again.

Read only

Former Member
0 Likes
651

Hi,

I think you are trying to insert records in customized database table.

In the following code i created a database table zpspnrdate with key field index.

here look into the code and you find that i am using the modify statement and directly updating the database table from internal table.

READ TABLE itab INDEX indx.
  SELECT   MAX( zindex ) INTO zindex FROM zpspnrdate.
  zpspnrdate-zindex = zindex + 1.

  zpspnrdate-pspnr = itab-pspnr.
  zpspnrdate-zimi = itab-imi_date.
  zpspnrdate-zdatetype ='IMI DATE'.
  zpspnrdate-modfdate = sy-datum.
  zpspnrdate-zuser = sy-uname.
  zpspnrdate-zutime = sy-uzeit.

  MODIFY zpspnrdate.
  IF sy-subrc EQ '0'.
    MESSAGE ' Record Updated Successfully!' TYPE 'S'.
  ENDIF.

try in this way.

<i><b>regards

Debjani

Rewards point for all helpful answer</b></i>