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

Runtime Error >> ABAP/4 processor: TABLE_ILLEGAL_STATEMENT

Former Member
0 Likes
2,798

Dear all,

I had modify a sorting form of the program, then when I run the background job it had been cancelled by the SAP system and come out with this TABLE_ILLEGAL_STATEMENT run time error.

The Error Analysis:

You attempted to change, delete or create a line in the internal table "ITAB_PRT", but no valid cursor exists for the table.

Possible reason:

1. The relevant ABAP/4 statement doest not include the addition "... INDEX...", although the statement is not inside a "LOOP...ENDLOOP" loop processing this table.

2. The relevant ABAP/4 statement was called from within a "LOOP...ENDLOOP" loop after a DELETE "ITAB_PRT".

I had no idea how to correct this runtime error, anyone can help?

Thanks alot!

Best Regards,

PC

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,155

when you are using DELETE ITAB statement.. you must specify INDEX (which number of row u want to delete.. 1st row..etc) or you have to specify where clause..

if you are using DELETE inside LOOP.. ENDLOOP then the system automatically identifies INDEX. So no need to specify.. but outside we must specify index or condition.

13 REPLIES 13
Read only

Former Member
0 Likes
2,156

when you are using DELETE ITAB statement.. you must specify INDEX (which number of row u want to delete.. 1st row..etc) or you have to specify where clause..

if you are using DELETE inside LOOP.. ENDLOOP then the system automatically identifies INDEX. So no need to specify.. but outside we must specify index or condition.

Read only

Former Member
0 Likes
2,155

You probably did something like this:

read table itab with key
  f1 = something.
f2 = 'YYY'.
modify itab.  

It should be:

read table itab with key
  f1 = something.
f2 = 'YYY'.
modify itab index sy-tabix.    "<======

Rob

Read only

0 Likes
2,155

Hi,

I did'nt use modify itab, but delete itab.

Can I put delete itab as delete itab index sy-tabix?

In the runtime error log it show the program terminate at line 2344

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

023290 ? FORM FILTER_ITAB.

023300 ? *

023310 ? SORT ITAB_PRT BY AREA.

023320 ?

023330 ? LOOP AT ITAB_PRT WHERE AREA = 'SCON'.

023340 ? MOVE-CORRESPONDING ITAB_PRT TO ITAB_PRT_SUB.

023350 ? APPEND ITAB_PRT_SUB.

023360 ? ENDLOOP.

023370 ? DELETE ITAB_PRT WHERE AREA = 'SCON'.

023380 ?

023390 ?

023400 ? IF MMTART = 'X' AND MSPART = 'X'.

023410 ? LOOP AT ITAB_PRT WHERE AREA+0(1) = 'M'.

023420 ? IF NOT ITAB_PRT-SPART IN MDIV.

023430 ? DELETE ITAB_PRT.

<b>> ? ENDIF. </b> "<======

023450 ? IF NOT ITAB_PRT-MTART IN MMT.

023460 ? DELETE ITAB_PRT.

023470 ? ENDIF.

023480 ? ENDLOOP.

023490 ? ENDIF.

023500 ?

023510 ? IF P1MTART = 'X' AND P1SPART = 'X'.

023520 ? LOOP AT ITAB_PRT WHERE AREA = 'PDDP' OR AREA = 'PHPP1' OR

023530 ? AREA = 'PHPP2' OR AREA = 'PLVT' OR

023540 ? AREA = 'PVJB' OR AREA = 'PSNB'.

023550 ?

023560 ? "or area = 'SUBCON'.

023570 ? IF NOT ITAB_PRT-SPART IN P1DIV.

023580 ? DELETE ITAB_PRT.

023590 ? ENDIF.

023600 ? IF NOT ITAB_PRT-MTART IN P1MT.

023610 ? DELETE ITAB_PRT.

023620 ? ENDIF.

023630 ? ENDLOOP.

<b>Active calls / events</b>

Nr.... Type........ Name..........................

Programm

Include Line

1 LOOP FILTER_ITAB

ZMM_STKMOV_BYAREA02

ZMM_STKMOV_BYAREA02 <b>2344</b>

2 FORM FILTER_ITAB

ZMM_STKMOV_BYAREA02

ZMM_STKMOV_BYAREA02 <b>2339</b>

3 EVENT END-OF-SELECTION

ZMM_STKMOV_BYAREA02

ZMM_STKMOV_BYAREA02 <b> 909</b>

<b>Internal notes</b>

The termination occurred in the function "LineNrLoop" of the SAP

Basis System, specifically in line 2778 of the module " ".

The internal operation just processed is "TDEL".

Read only

Sathish
Product and Topic Expert
Product and Topic Expert
0 Likes
2,155

In the program, keep the cursor on DELETE statement and press F1 for the help documentation.

This explains the different options of using INDEX, FROM, WITH TABLE KEY with example.

Read only

0 Likes
2,155

It's dangerous to delete a table that you are looping through. A better approach is to identify the records you want to delete during the loop pass and actually delete them after the loop.

Add a new field DEL_FLAG to internal table itab_prt and then:

LOOP AT itab_prt WHERE area+0(1) = 'M'.
  IF NOT itab_prt-spart IN mdiv.
    itab_prt-del_flag = 'X'.
  ENDIF.
  IF NOT itab_prt-mtart IN mmt.
    itab_prt-del_flag = 'X'.
  ENDIF.
ENDLOOP.

DELETE itab_prt WHERE del_flag = 'X'.

Rob

Read only

0 Likes
2,155

Hi rob, can i make it like tat ? i add 1 more line to make sure the itab_prt was not empty..

Thanks!

IF MMTART = 'X' AND MSPART = 'X'.

LOOP AT ITAB_PRT WHERE AREA+(1) = 'M'.

IF NOT ITAB_PRT[] IS INITIAL.

IF NOT ITAB_PRT-SPART IN MDIV.

itab_prt-del_flag = 'X'. "delete itab_prt index sy-tabix.

ENDIF.

IF NOT ITAB_PRT-MTART IN MMT.

itab_prt-del_flag = 'X'. "delete itab_prt index sy-tabix.

ENDIF.

ENDIF.

ENDLOOP.

DELETE itab_prt WHERE del_flag = 'X'.

ENDIF.

Read only

0 Likes
2,155

The line is redundant. If the table were empty, it won't enter the loop and execute the statement. You could put it before the loop, but it really won't affect the results. I'd leave it off.

Rob

Read only

0 Likes
2,155

Hi ,

i would put it like this:

IF MMTART = 'X' AND MSPART = 'X'.

LOOP AT ITAB_PRT WHERE AREA+(1) = 'M'.

<b>VARIABLE = sy-tabix.</b>

IF NOT ITAB_PRT-SPART IN MDIV.

<b>itab_prt-del_flag = 'X'. </b>

ENDIF.

IF NOT ITAB_PRT-MTART IN MMT.

<b>itab_prt-del_flag = 'X'. </b>

ENDIF.

<b>if itab_prt-del_flag = 'X'..

delete itab_prt index VARIABLE.

endif.</b>

ENDLOOP.

Regards,

Sooness.

Read only

0 Likes
2,155

Hi,

Is that possible to let me write like this ?

IF MMTART = 'X' AND MSPART = 'X'.

LOOP AT ITAB_PRT WHERE AREA+(1) = 'M'.

IF NOT ITAB_PRT-SPART IN MDIV.

ITAB_PRT-DEL_FLAG = 'X'. "delete itab_prt index sy-tabix.

ENDIF.

IF NOT ITAB_PRT-MTART IN MMT.

ITAB_PRT-DEL_FLAG = 'X'. "delete itab_prt index sy-tabix.

ENDIF.

ENDLOOP.

IF ITAB_PRT-DEL_FLAG = 'X'.

DELETE ITAB_PRT INDEX SY-TABIX.

ENDIF.

ENDIF.

IF P1MTART = 'X' AND P1SPART = 'X'.

LOOP AT ITAB_PRT WHERE AREA = 'PDDP' OR AREA = 'PHPP1' OR

AREA = 'PHPP2' OR AREA = 'PLVT' OR

AREA = 'PVJB' OR AREA = 'PSNB'.

"or area = 'SUBCON'.

IF NOT ITAB_PRT-SPART IN P1DIV.

<i> DELETE ITAB_PRT INDEX SY-TABIX.</i>

ENDIF.

IF NOT ITAB_PRT-MTART IN P1MT.

<i>DELETE ITAB_PRT INDEX SY-TABIX</i>.

ENDIF.

ENDLOOP.

the run time error only show that the error come from the MMTART = 'X' loop, should I change other's 'DELETE ITAB_PRT INDEX SY-TABIX' in the loop to the delete indicator?

Thanks & Regards!

Read only

Former Member
0 Likes
2,155

Dear rob,

I think that 1 u advice was not working probably, I had test run the report, it din filter out the data i not needed.

Thanks

PC

Read only

0 Likes
2,155

Yes, of course. I made the same mistake I always do. I forgot the MODIFY:

IF mmtart = 'X' AND mspart = 'X'.
  LOOP AT itab_prt WHERE area+(1) = 'M'.
    IF NOT itab_prt-spart IN mdiv.
      itab_prt-del_flag = 'X'. 
      MODIFY itab_prt.
    ENDIF.
    IF NOT itab_prt-mtart IN mmt.
      itab_prt-del_flag = 'X'.
      MODIFY itab_prt.
    ENDIF.
  ENDLOOP.
  DELETE itab_prt WHERE
    del_flag = 'X'.
ENDIF.

Rob

Read only

0 Likes
2,155

Dear Rob,

The same run time error occur again.

Any other advice?

Thanks alot!

Best Regards,

PC

Read only

0 Likes
2,155

Would you please post the portion of the code that contains the code where the program dumped?

Rob