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

Update vs Insert

Former Member
0 Likes
1,014

Hi,

can we use update to fill data in Z table rather than using insert command.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
981

No,

MODIFY

adds data if not available or updates when available

regards

11 REPLIES 11
Read only

Former Member
0 Likes
981

no

Read only

Former Member
0 Likes
981

use modify not update

Read only

Former Member
0 Likes
982

No,

MODIFY

adds data if not available or updates when available

regards

Read only

0 Likes
981

Well Matthias Rieken ,

Actually my requirment is that if data inserted into table i want to set one field which is FLAG in table as "N" means it inserted firsted time but when it already exist then that FLAG should be set "U" means it updated.

please advise..

Read only

0 Likes
981

check if the entry already exists in the Z table ..

select single * from ztable .....

if sy-subrc = 0.

update ... with flag = 'U'

else.

Insert .... with flag = 'N'

endif.

Read only

0 Likes
981

hmm

my first idea where



SELECT * FROM TABLE WHERE KEY = KEY 

IF SY-SUBRC = 0
   UPDATE ..... WHERE KEY=KEY 
ELSE 
   INSERT .....
ENDIF 

Read only

peter_ruiz2
Active Contributor
0 Likes
981

hi,

the answer is no but you can use modify table if you want to insert entries in case they do not exist in the database or update the z table if the keys exist.

regards,

peter

Read only

Former Member
0 Likes
981

and still i tell you rather use insert or append than modify even tho modify works.

Read only

Former Member
0 Likes
981

You can use modify statement instead of update.

Modify statement updates the reocord when record already exits and it is inserted when the record does not exits.

Edited by: S@N on Apr 4, 2008 3:01 PM

Read only

Former Member
0 Likes
981

You can Use Modify rather than Update.

Thank you

Nikunj shah

Read only

Former Member
0 Likes
981

Thank you All................

Problem has been solved and confusion has been cleared now.

i did by this way...

INSERT zpayroll FROM it_final.

IF sy-subrc = 0.

COMMIT WORK.

ELSE.

it_final-updte = 'U'.

UPDATE zpayroll FROM it_final.

IF sy-subrc = 0.

COMMIT WORK.

ENDIF.

ENDIF.

And Done.