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

MODIFY TABLE

Former Member
0 Likes
1,142

Hi,

i am modifying a ztable, if it is sucess it is returning 0 as sy-subrc, but if fails it should return sy-subrc as other than 0, but in my case even if i give the data already available in ztable with same primary key and secondary key value it returns 0, can any one please helps in this case

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,022

I think the way you are using modify is that ..if you do have primary and secondary key in your ztable then also if the data corresponding to that key is different then it will modify the table ... so please if you have got new primary key or secondary key please append the record i the table or else in other case use modify statement.

ragards

Jayant

8 REPLIES 8
Read only

Former Member
0 Likes
1,022

hi venkat ..

modify statement also modify the existing record related to P Key..so returns 0..so it ll return 0 in both cases..unless until fields in modify staement do not match ztzble...

if record not found it append

else

it modify,,

hope this is clear

Message was edited by:

Madan Gopal Sharma

Read only

Former Member
0 Likes
1,022

Hi Venkat

To insert or change a single line in a database table, use the following:

MODIFY <target> FROM <wa> .

The contents of the work area <wa> are written to the database table <dbtab>. The work area <wa> must be a data object with at least the same length and alignment as the line structure of the database table. The data is placed in the database table according to the line structure of the table, and regardless of the structure of the work area. It is a good idea to define the work area with reference to the structure of the database table.

If the database table does not already contain a line with the same primary key as specified in the work area, a new line is inserted. If the database table does already contain a line with the same primary key as specified in the work area, the existing line is overwritten. SY-SUBRC is always set to 0.

A shortened form of the above statement is:

MODIFY <dbtab>.

In this case, the contents of the table work area <dbtab> are inserted into the database table with the same name. You must declare this table work area using the TABLES statement. In this case, it is not possible to specify the name of the database table dynamically. Table work areas with the same name as the database table (necessary before Release 4.0) should no longer be used for the sake of clarity.

<b>Modify will insert a new record if there is no record with that primary key , if it has a record then Modify will update the record if you need to only insert then use INSERT statement,or if you want to only update then use UPDATE statement </b>

Regards Rk

Read only

Former Member
0 Likes
1,022

use UPDATE command ..to get the expected sy-subrc instead MODIFY

Read only

former_member673464
Active Contributor
0 Likes
1,022

hii..

To insert lines into a database table regardless of whether there is already a line in the table with the same primary key, use the following:

MODIFY <target> <lines>.

If the database table contains no line with the same primary key as the line to be inserted, MODIFY works like INSERT, that is, the line is added.

If the database already contains a line with the same primary key as the line to be inserted, MODIFY works like UPDATE, that is, the line is changed.

For performance reasons, you should use MODIFY only if you cannot distinguish between these two options in your ABAP program.

You can add or change one or more lines <lines> in a database table <target>. You can only insert or change lines in an ABAP Dictionary view if it only contains fields from one table, and its maintenance status is defined as Read and change. You may specify the database table <target> either statically or dynamically.

regards,

veeresh

Read only

Former Member
0 Likes
1,022

HI,

Modify does modifications to the tables when it finds the key data..

It does not mind whether the data is already present ..

Better option is check whether the data is already available before modifying it..

If not available then modify// Else you can use UPDATE command

reward if useful

regards,

nazeer

Message was edited by:

nazeer shaik

Read only

Former Member
0 Likes
1,023

I think the way you are using modify is that ..if you do have primary and secondary key in your ztable then also if the data corresponding to that key is different then it will modify the table ... so please if you have got new primary key or secondary key please append the record i the table or else in other case use modify statement.

ragards

Jayant

Read only

Former Member
0 Likes
1,022

hi

good

check out with your select stament and the sy-dbcnt value in the debugging mode and if necessary change the code accordingly.

thanks

mrutyun^

Read only

Former Member
0 Likes
1,022

hi,

Try to update the data then if its not present it can append it into the body...just check ur select statement also...even it might be giveb wrong.

if useful reward with points,

with regards,

madhuri.