Application Development 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: 

TABLE ILLEGAL STATEMENT error with MODIFY command

Former Member
0 Kudos

Hi gurus,

i want you to inform me about table illegal statement error. The error occurs when i use modify as below.

loop at itab.

select .......

where xxx eq itab-xxxx.

...........

...........

MODIFY itab.

endselect.

endloop.

i know that i have to give the sy-tabix as INDEX parameter to the modify command. but i want to know why i have to do this?

cause when i debug, i follow the sy-tabix field and it have not a change in select endselect.

may the reason of the error about cursor in select and cursor effects modify command?

or why?

Thx,

6 REPLIES 6

Former Member
0 Kudos

Hi Techmaster,

By writing MODIFY the ABAP processor should know what it has to modify, you should give something like index & what reocrds need to be modified.

Hope you understood.

Regards

Abhii...

SuhaSaha
Advisor
Advisor
0 Kudos

Hello,

I guess this is because your MODIFY statement is inside the SELECT ... ENDSELECT & not inside the LOOP ... ENDLOOP.

SAP documentation says:

Within a LOOP loop, the INDEX addition can be ommitted. In this case the current table line of the LOOP loop is changed.

You have to change the coding:


DATA: v_index TYPE i.

loop at itab.

v_index = sy-index.

select .......
where xxx eq itab-xxxx.
...........
...........
MODIFY itab INDEX v_index.
endselect.
endloop.

BR,

Suhas

PS: The coding practice followed is not very performance oriented as well. May be you should have a look around in some blogs, wikis in SCN & change the code accordingly.

Edited by: Suhas Saha on Nov 19, 2009 9:41 AM

kesavadas_thekkillath
Active Contributor
0 Kudos

The code you provided is not sufficient to propose a solution.

Former Member
0 Kudos

Thx All.

@ suhas saha.

As your message if i modify it with sy-tabix taken before select loop it works fine. But i want to know or understand why it does not work without SY-TABIX parameter as INDEX. When i debug, i saw that the SY-TABIX parameter does not change.

i know the solution of problem as you say but i only want to know the result of solution why..

Thx,

0 Kudos

Read the dump error analysis etc.

sample snap shot

You attempted to change, delete or create a line in the

internal table "\PROGRAM=YKRTEST2\DATA=IT[]", but no valid cursor exists

for the table.

Possible reasons:

1. The relevent ABAP/4 statement does not include the addition

"...INDEX...", although the statement is not

inside a "LOOP...ENDLOOP" loop processing this table.

2. The relevent ABAP/4 statement was called from within a

"LOOP...ENDLOOP" loop after a DELETE "\PROGRAM=YKRTEST2\DATA=IT[]".

Edited by: Keshu Thekkillam on Nov 19, 2009 2:48 PM

0 Kudos

Hello,

The sy-tabix values does not hold good when the modify statement is within Select..Endselect. Only when the modify statement is within LOOP...ENDLOOP you can omitt the index as it will be automatically assigned. This is the reason why the Modify statement is not able to fetch the automatic index value when within Select..Endselect unless specifically assigned.

Vikranth