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

delete rows from internal table giving dump

Former Member
0 Likes
6,112

Hi All,

im trying to delete rows from my internal table using the below logic but its giving a dump.

Pls help.

  LOOP at itabINTO wa.

    lv_int = strlen( wa ).

    lv_int = lv_int - 3.

    IF wa+lv_int(3) = 'XYZ'.

      DELETE itab FROM wa.

    ENDIF.

  ENDLOOP.

Thanks & regards,

Faiz

Hi All,

im trying to delete rows from my internal table using the below logic but its giving a dump.

Pls help.

  LOOP at itabINTO wa.

    lv_int = strlen( wa ).

    lv_int = lv_int - 3.

    IF wa+lv_int(3) = 'XYZ'.

      DELETE itab FROM wa.

    ENDIF.

  ENDLOOP.

Thanks & regards,

Faiz

12 REPLIES 12
Read only

Abhijit74
Active Contributor
0 Likes
2,516

Hello,

Do not delete within a loop. Take a flag field into your internal table.  set flag for the record which you want to delete. Delete  outside the loop, Delete the records where flag = 'X'.

Thanks,

Abhijit

Read only

Former Member
0 Likes
2,516

Hi Faizur,

Dont use DELETE statement with in LOOP.

u can use below code.

take one field into ur Internal Table.

Like field DEL

data : lv_tabix type sytabix.

LOOP at itabINTO wa.
lv_tabix = sy-tabix.
    lv_int = strlen( wa ).

    lv_int = lv_int - 3.

    IF wa+lv_int(3) = 'XYZ'.

      now wa-del = 'X'.


modify itab from wa index l v_tabix.

  ENDIF.

  ENDLOOP.

DELETE ITAB WHERE DEL = 'X'.

It will work properly.

Thanks

tarak

Read only

Former Member
0 Likes
2,516

hi,

          the reason for the dump is because of this statement only..

  LOOP at itabINTO wa.

    lv_int = strlen( wa ).

    lv_int = lv_int - 3.

    IF wa+lv_int(3) = 'XYZ'.

      DELETE itab FROM wa.

    ENDIF.

  ENDLOOP.

    lv_int = strlen( wa ).     lv_int = lv_int - 3. this statement wont work definitely  ..

wa must be a character type data object , i mean data type( C, N, D, T or STRING)

otherwise strlen wont work..

thanks,

Mathan R.


Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,516

Remove the "from WA". It is interpreted as a FROM idx1 [TO idx2] option and should have raised a CONVT_NO_NUMBER

Regards,

Raymond

Read only

reachdebopriya
Active Participant
0 Likes
2,516

Hi Faizur,

Check this code below.

Put a field flag type char1 in the structure of wa/itab.

Field-Symbol: <lfs_wa> type (structure name).

  LOOP at itab assigning <lfs_wa>.

    lv_int = strlen( <lfs_wa> ).

    lv_int = lv_int - 3.

    IF <lfs_wa>+lv_int(3) = 'XYZ'.

     <lfs_wa>-flag = 'X'.
    ENDIF.

  ENDLOOP.

DELETE itab where flag EQ 'X'.

Regards,

Debopriya Ghosh

Read only

Former Member
0 Likes
2,516

Hi Faizur,

You can try like dis.

  

DELETE table itab FROM wa.

Regards,

Santanu Mohapatra.

Read only

Former Member
0 Likes
2,516

The best is to use index. It is accurate way of deleting the correct line of the itab.

LOOP at itab INTO wa.

lf_index = sy-tabix.

** all your checks.
    lv_int = strlen( wa ).
    lv_int = lv_int - 3.

    IF wa+lv_int(3) = 'XYZ'.

      "  DELETE itab FROM wa.

delete itab index lf_index.

    ENDIF.

clear : lf_index.

  ENDLOOP.

Read only

Former Member
0 Likes
2,516

Please avoid to use DELETE within LOOP.

Thanks

tarak

Read only

gurunathkumar_dadamu
Active Contributor
0 Likes
2,516

Hi Faizur,

dont use the delete statement inside the loop.like this scenario use any flag and moidify the itab transporting the flag. after that try to delete where FLAG = 'X'.

Regards,

Gurunath Kumar D

Read only

vigneshyeram
Active Participant
0 Likes
2,516

Dear Faizur,

Its better to use index while deleting.

please check the below code.

data: lv_index type sy-index.

LOOP at itabINTO wa.

     lv_index = sy-tabix.

    lv_int = strlen( wa ).

    lv_int = lv_int - 3.

    IF wa+lv_int(3) = 'XYZ'.

      DELETE itab index lv_index.

    ENDIF.

  clear: lv_index.

  ENDLOOP.

Hope this helps you.

Kindly let me know your feedback.

Thanks & Regards,

Vignesh Yeram

Read only

Former Member
0 Likes
2,516

Dear Rehman,

I think You are getting Null Value into the work area.

Use Sy-subrc After reading an internal table into Work Area .

And Put Ur Logic in the if Condition.

Read table into wa.

if sy-subrc = 0.

*****************

ur logic

*****************

End if.

This may help u.

Thanks & Regards

Kranthi Kumar Reddy G

Message was edited by: Kranthi Kumar Reddy

Read only

Former Member
0 Likes
2,516

hi,

Declare all fields in wa of type C, N, D or T...

Try this..

LOOP at itab INTO wa.


          lv_index = sy-tabix.


          lv_int = strlen( wa ).


          lv_int = lv_int - 3.


    IF wa+lv_int(3) = 'XYZ'.


          wa-delete = 'X'.

          MODIFY itab from wa index sy-tabix.

     endif.

endloop.

      DELETE itab where delete = 'X'.