AlexanderK February 2016

Type conflict within deleting table from internal table

I've had a dump recently,

DATA: gt_data    TYPE SORTED TABLE OF ty_data WITH NON-UNIQUE KEY bukrs gaapnm,
     ...
     lt_tabdel  TYPE standard TABLE OF ty_data.

  LOOP AT gt_data ASSIGNING <gf_data>.
    IF <gf_data>-KANSW + <gf_data>-KAUFW = 0.
      APPEND <gf_data> TO lt_tabdel.
    ENDIF.
  ENDLOOP.

  IF lt_tabdel IS NOT INITIAL.
    DELETE gt_data FROM lt_tabdel.
  ENDIF.

And on the line with deleting table from internal table - i've had a dump: In statement Convert object to integer only numerical type data objects are supported at argument position "object". In the present case, operand "object" has the non-numerical data type "TABLE OF TY_DATA". I just can't understand - why? Both of it had the same type... So, it will be great if you could provide some advice and a bit of explanation of error origins.

Answers


vwegert February 2016

You have (inadvertently) used this variant of the DELETE statement that uses FROM and TO to specify indexes, i. e. numbers of table lines. In a sense, you are coding delete all lines in gt_data below the one identified by the line number in lt_tabdel, and the system goes belly-up when trying to convert the contents of lt_tabdel to an integer.

As far as I can see - i. E. if you've provided a complete code sample - this should be sufficient:

LOOP AT gt_data ASSIGNING <gf_data>.
  IF <gf_data>-KANSW + <gf_data>-KAUFW = 0.
    DELETE gt_data.
    CONTINUE. " safety measure
  ENDIF.
ENDLOOP.

For an explanation of the CONTINUE statement, check this answer.


AlexanderK February 2016

Ok, i found solution. Delete - was the wrong command. So i used this one instead:

LOOP AT gt_data ASSIGNING <gf_data>.
    IF <gf_data>-KANSW + <gf_data>-KAUFW <> 0.
      append <gf_data> to lt_data.
    ENDIF.
  ENDLOOP.

  gt_data[] = lt_data[].

Just filled another table and assigned it contents to the main table.

Post Status

Asked in February 2016
Viewed 1,069 times
Voted 13
Answered 2 times

Search




Leave an answer