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

Deleting internal table using index

venkatasap
Participant
0 Likes
48,632

Hi Sap All.

when i try to delete the data in the Internal table using index,iam getting the short dump as mentioned below :

Error in ABAP/4 statement when processing an internal table.

t happened?
Error in the ABAP Application Program

The current ABAP program "ZRECHECKDOCU_LICENSEUPD" had to be terminated because
  it has
come across a statement that unfortunately cannot be executed.

or analysis
When changing or deleting one or more lines of the internal table
"\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB" or when inserting in the table
  "\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB", 0 was used as
the line index. An index less than or equal to zero is not
allowed.

The error can occur when using the following options:
1. "INDEX idx" for specifying the line number in the table
  "\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB"
    where you want to change, insert or delete.
2. "FROM idx" for specifying the start index when deleting a line
    area from or inserting a line area into the table
  "\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB".
3. "TO idx" for specifying the end index when deleting a line
    area from or inserting a line area into the table
  "\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB".

At the time of the termination, the table contained 1140 lines.

delete itab index SY-TABIX.

The  soucre code of the program is as below :

loop at itab into wa_itab.
       if sy-tabix = '384'.
         break Varma.
         endif.
       if wa_itab-msgv1 = '400040'.
         Break varma.
         endif.
     if wa_itab-msgno = '159' AND wa_itab-MSGV1 EQ 'Checked / Available: Serv'.
     DELETE itab index sy-tabix .
*from wa_messtab2.
*where msgno = '159' AND MSGV1 EQ 'Checked / Available: Serv'.
     if sy-subrc = 0.
     sy-tabix = sy-tabix - 1.
*loop at it_messtab2 into wa_messtab2 from  sy-tabix.
       read table itab into wa_itab index sy-tabix.
     if sy-tabix > 0.
       TAB = sy-tabix + 1.
       read table itab into wa_itab2 index TAB.

       if wa_itab-msgno = '159' AND wa_itab-MSGV1 EQ 'Checked / Blocked: Servic'.
         elseif wa_itab-msgno = '159' AND wa_itab-MSGV1 EQ 'Checked / Blocked: Servic' AND  wa_itab2-msgno = '159' AND wa_itab2-MSGV1 EQ 'Checked / Blocked: Servic' .
       continue.
       endif.
              delete itab index sy-tabix.(the Shordump is directing to this line)**********************************************
      endif.
*      endloop.
      endif.
      endif.

will be waiting for best answer.

regards.

Varma

Moderator Message: Please use the code formatting options via: Insert --> Syntax highlighting. I don't see any option available for ABAP though

Message was edited by: Suhas Saha

1 ACCEPTED SOLUTION
Read only

vimalv
Active Participant
0 Likes
19,165

Varma,

Sy-tabix changes with Loop as well as your READ statement.

Like all others here mentioned, it would be better to capture the index you'd like to use into a variable, say l_tabix.

Also, keeping performance issues in mind, I would advice you to add a DEL_FLAG field of char1 to your structure/type,

set the flag for lines you want to delete and Delete them after the loop.

Sample code is something like this:

TYPES: BEGIN OF TY_TAB,

              ... "other variables

              DEL_FLAG type CHAR1,

             END OF TY_TAB.

DATA: ITAB type table of TY_TAB.
FIELD-SYMBOLS: <FS_TAB> type TY_TAB.

....

LOOP AT ITAB ASSIGNING <FS_TAB>.

IF YOUR_CONDITION = TRUE.

<FS_TAB>-DEL_FLAG = 'X'

ENDIF.

ENDLOOP.

DELETE ITAB where DEL_FLAG = 'X'.

Hi Sap All.

when i try to delete the data in the Internal table using index,iam getting the short dump as mentioned below :

Error in ABAP/4 statement when processing an internal table.

t happened?
Error in the ABAP Application Program

The current ABAP program "ZRECHECKDOCU_LICENSEUPD" had to be terminated because
  it has
come across a statement that unfortunately cannot be executed.

or analysis
When changing or deleting one or more lines of the internal table
"\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB" or when inserting in the table
  "\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB", 0 was used as
the line index. An index less than or equal to zero is not
allowed.

The error can occur when using the following options:
1. "INDEX idx" for specifying the line number in the table
  "\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB"
    where you want to change, insert or delete.
2. "FROM idx" for specifying the start index when deleting a line
    area from or inserting a line area into the table
  "\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB".
3. "TO idx" for specifying the end index when deleting a line
    area from or inserting a line area into the table
  "\PROGRAM=ZRECHECKDOCU_LICENSEUPD\DATA=ITAB".

At the time of the termination, the table contained 1140 lines.

delete itab index SY-TABIX.

The  soucre code of the program is as below :

loop at itab into wa_itab.
       if sy-tabix = '384'.
         break Varma.
         endif.
       if wa_itab-msgv1 = '400040'.
         Break varma.
         endif.
     if wa_itab-msgno = '159' AND wa_itab-MSGV1 EQ 'Checked / Available: Serv'.
     DELETE itab index sy-tabix .
*from wa_messtab2.
*where msgno = '159' AND MSGV1 EQ 'Checked / Available: Serv'.
     if sy-subrc = 0.
     sy-tabix = sy-tabix - 1.
*loop at it_messtab2 into wa_messtab2 from  sy-tabix.
       read table itab into wa_itab index sy-tabix.
     if sy-tabix > 0.
       TAB = sy-tabix + 1.
       read table itab into wa_itab2 index TAB.

       if wa_itab-msgno = '159' AND wa_itab-MSGV1 EQ 'Checked / Blocked: Servic'.
         elseif wa_itab-msgno = '159' AND wa_itab-MSGV1 EQ 'Checked / Blocked: Servic' AND  wa_itab2-msgno = '159' AND wa_itab2-MSGV1 EQ 'Checked / Blocked: Servic' .
       continue.
       endif.
              delete itab index sy-tabix.(the Shordump is directing to this line)**********************************************
      endif.
*      endloop.
      endif.
      endif.

will be waiting for best answer.

regards.

Varma

Moderator Message: Please use the code formatting options via: Insert --> Syntax highlighting. I don't see any option available for ABAP though

Message was edited by: Suhas Saha

7 REPLIES 7
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
19,165

The dump itself say the index which you are trying to use is 0 or less than 0. Secondly please dont modify sy-tabix. Make a local variable and check. It is also good practice to put a check if lv_tabix gt 0 before deleting using index option.

Also note that sy-tabix value will not remain same for each read you are doing on table or modify etc it will update this tabix.

Nabheet

Read only

Former Member
0 Likes
19,165

Hi Gagdish,

DELETE <itab> [INDEX <idx>].

Here the line with the specified index will be deleted. We can use the same statement without INDEX addition within a loop. That time it will delete the current line.

Use Counter variable inside the loop.

Hope this will help.

BR, Mantu

Read only

Former Member
0 Likes
19,165

Hi,

Please do not modify the system variable sy-tabix.

Since you are using READ statement inside a LOOP the sy-tabix will get changed.

Better option is to create a local variable (TYPE SY-TABIX) and use the same ,clear it after completing each loop.

Regards,

Arun

Read only

Former Member
0 Likes
19,165

Hi,

can you check  this code .

Loop at itab into wa-itab..

lv_tabix = sy-tabix.

*Check the conditions

if lv_tabix = '399'.

<Code>.

*deleting.

delete itab form wa_itab index lv_tabix.

endif.

Endloop.

*while modifying table also use like this.

modify itab index lv_index.

Regards,

Gurunath Kumar D

Read only

Former Member
0 Likes
19,165

Jagdish,

One thumb rule: Don't change the System variable as this keep changing.

Store the value in variable and play with

Please check for SY-SUBRC = 0 .

Thanks

Sridhar

Read only

Former Member
0 Likes
19,165

Hi Jagdish,

The same issue I had in the past, and my best solutions to you is.....

1) As Sridhar said, You must not modify the system variables, even if you change it don't have any impact on system variable (System will automatically modify them, in debug mode you can check this).

2) The error clearly says that, your are trying to delete a row which is not exist in itab.

2) So, before you use  DELETE itab index sy-tabix .  I would request you to please check whether your internal tab has data or not by using Syntax

If itab[] is not initial.

DELETE itab index sy-tabix . 

endif.

I believe this will definitely solve your problem

Regards,

Rajesh Sadula

Read only

vimalv
Active Participant
0 Likes
19,166

Varma,

Sy-tabix changes with Loop as well as your READ statement.

Like all others here mentioned, it would be better to capture the index you'd like to use into a variable, say l_tabix.

Also, keeping performance issues in mind, I would advice you to add a DEL_FLAG field of char1 to your structure/type,

set the flag for lines you want to delete and Delete them after the loop.

Sample code is something like this:

TYPES: BEGIN OF TY_TAB,

              ... "other variables

              DEL_FLAG type CHAR1,

             END OF TY_TAB.

DATA: ITAB type table of TY_TAB.
FIELD-SYMBOLS: <FS_TAB> type TY_TAB.

....

LOOP AT ITAB ASSIGNING <FS_TAB>.

IF YOUR_CONDITION = TRUE.

<FS_TAB>-DEL_FLAG = 'X'

ENDIF.

ENDLOOP.

DELETE ITAB where DEL_FLAG = 'X'.