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 statement

Former Member
0 Likes
1,472

Hi all,

I have a problem with the modify statement. I have declared an internal table xkomv:

data:begin of xkomv occurs 0.

include structure komv.

data : end of xkomv.

data : calc_price like komv-kwert.

read table xkomv with key kschl = 'EDI1'.

xkomv-kwert = calc_price.

modify xkomv.

after this modify statement... I am getting a dump. Please tell me if there is anything wrong in the statement.

Thanks,

archana

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,263

You CAN use the MODIFY statement after a READ as well as within a LOOP. You don't need to use TRANSPORTING either.

Your code should look like this:


READ TABLE xkomv WITH KEY kschl = 'EDI1'.
IF sy-subrc EQ 0.
  xkomv-kwert = calc_price.
  MODIFY xkomv INDEX sy-tabix.
ENDIF.

This will only change the first entry it finds, if you need to change more than one entry:


LOOP AT xkomv WHERE kschl EQ 'EDI1'.
  xkomv-kwert = calc_price.
  MODIFY xkomv.
ENDLOOP.

Notice, you don't need INDEX inside a LOOP.

Edited by: Gill Ackroyd on Dec 18, 2008 11:21 AM

10 REPLIES 10
Read only

GauthamV
Active Contributor
0 Likes
1,263

hi,

try this.



read table xkomv with key kschl = 'EDI1'.
if sy-subrc = 0.
xkomv-kwert = calc_price.
endif.
modify xkomv transporting kwert.

Read only

Former Member
0 Likes
1,263

Hi Archana,

You need to use Index for modify.

Change the code as below.


read table xkomv with key kschl = 'EDI1'.
If sy-subrc eq 0.
xkomv-kwert = calc_price.
modify xkomv index sy-tabix 
                     transporting kwert.
endif.

This should work.

Best Regards,

Ram.

Edited by: ram Kumar on Dec 18, 2008 12:10 PM

Read only

Former Member
0 Likes
1,263

Hi you have to use MODIFY in loop only.

loop at itab into wa.

wa-num = '10'.

modify itab from wa.

endloop.

Regards,

Ajay

Read only

Former Member
0 Likes
1,263

have u defined calc_price as data type CURR ? Please check that .

Regards,

Ajay

Read only

Former Member
0 Likes
1,263

Hi,

Here u have to use the index and transporting statement

e.g modify xkomv index (row no) transporting kwert.

Here u can also use sytabix....

data : mytabix type sy-tabix.

read table xkomv with key kschl = 'EDI1'.

mytabix = sy-tabix.

xkomv-kwert = calc_price.

modify xkomv index mytabix.

Read only

Former Member
0 Likes
1,263

Hi Archana,

while using MODIFY statement you need to specify the index else system treats index as 0,

which results in short dump.

you need to modify the itab in the loop only

loop at itab.

modify itab index sy-tabix.

endloop

if you are using a READ key word

data tabix type sy-tabix.

loop at itab.

tabix = sy-tabix.

read table itab -


modify itab index tabix." since sy-tabix changes from loop and then in the read statement

endloop

Regards

Ramchander Rao.K

Read only

Former Member
0 Likes
1,263

read table xkomv with key kschl = 'EDI1'.

if sy-subrc = 0.

xkomv-kwert = calc_price.

modify xkomv index sy-tabix..

endif.

or its better to use field-symbols.

read table xkomv with key kschl = 'EDI1' assigning <fs_komv>

if sy-subrc = 0.

<fs_komv>-kwert = calc_price.

endif.

Read only

Former Member
0 Likes
1,263

Use Modify with INDEX .

or use

loop at xkomv where kschl = 'EDI1'.
 xkomv-kwert = calc_price.
 modify xkomv.
endloop.

Read only

Former Member
0 Likes
1,264

You CAN use the MODIFY statement after a READ as well as within a LOOP. You don't need to use TRANSPORTING either.

Your code should look like this:


READ TABLE xkomv WITH KEY kschl = 'EDI1'.
IF sy-subrc EQ 0.
  xkomv-kwert = calc_price.
  MODIFY xkomv INDEX sy-tabix.
ENDIF.

This will only change the first entry it finds, if you need to change more than one entry:


LOOP AT xkomv WHERE kschl EQ 'EDI1'.
  xkomv-kwert = calc_price.
  MODIFY xkomv.
ENDLOOP.

Notice, you don't need INDEX inside a LOOP.

Edited by: Gill Ackroyd on Dec 18, 2008 11:21 AM

Read only

Former Member
0 Likes
1,263

You dont need to use any extensions of MODIFY statement.

Just put a sy-subrc check after your read statement.

You got a dump because no value must have been read and you used Modify.