2022 Dec 29 11:16 AM
Hi guys, there is someone can explain me what is the value of sy-tabix when it's into a LOOP AT stantment where I also have a READ table?
I declared a variable to maintain the index of my itab for deleting the row with condition, but why it doesn't work well if i just directly write : DELETE itab INDEX sy-tabix?
DATA: lv_tabix TYPE sy-tabix.
LOOP AT itab.
lv_tabix = sy-tabix.
READ TABLE itab2 WITH KEY werks = itab-werks BINARY SEARCH.
IF itab-daycont < itab2-switch.
DELETE itab INDEX lv_tabix. "istead of sy-tabix
ENDIF.
ENDLOOP.
2022 Dec 29 11:25 AM
READ TABLE will change sy-tabix, that's why you need to save it before.
2022 Dec 29 11:25 AM
READ TABLE will change sy-tabix, that's why you need to save it before.
2022 Dec 29 1:36 PM
To delete the current row in a LOOP block you can use DELETE statement without INDEX.
DELETE itab.
2022 Dec 29 3:11 PM
Another option by indicating explicitly that you delete the current line in a loop:
DELETE itab USING KEY loop_key.
(the advantage compared to "DELETE itab" is that the syntax checker tells you when it's outside a loop; when you use "DELETE itab" outside a loop, the syntax checker doesn't warn, but that will produce a runtime error).
2022 Dec 29 7:42 PM
Why not just modify your program a little bit and figure it out yourself? Oh, and LOOP AT itab? Do not use tables with header lines. Very bad practice.
Also, READ ... BINARY SEARCH? Just define itab2 as a sorted table.
Whereever you go this sample code from it is over twenty years out of date.
DATA lv_tabix TYPE sy-tabix.
LOOP AT itab INTO DATA(wa).
WRITE / sy-tabix, 'Just after loop'.
lv_tabix = sy-tabix.
READ TABLE itab2 WITH KEY werks = itab-werks BINARY SEARCH.
WRITE / sy-tabix, 'Just after read'.
IF itab-daycont < itab2-switch.
DELETE itab INDEX lv_tabix. "istead of sy-tabix
ENDIF.
ENDLOOP.
2022 Dec 30 8:02 AM
Matthew, I appreciate your comment, but for someone just starting out with programming in general, is not that immediate to come to the tips you have given, and because I didn't find a way or an answer that actually answered my doubt I just simply used this platform as everyone do.
And lastly, this over twenty years out of date code, is my code.
2022 Dec 30 10:18 AM
You are using techniques that as a newbie you shouldn't be using. Tables with header lines (OCCURS) are a definite no-no. It could get you into very bad habits. ISure it's your code, but it looks like you're using a template from old training material to get you started. I strongly suggest getting some up-to-date training materials. As you progress also look at relevant parts of how to write Clean ABAP. It will give you many tips on how to write well. Remember, your program must not just work, it must also be maintainable by someone else, and be easy to change without breaking.
As you're a newbie, I did provide you with a way of figuring it out for yourself. Hence the WRITE statements.
I strongly suggest also that you learn how to debug. This can resolve many doubts you might have. For instance debugging your original program would have shown you, step by step, how the variables changed for each statement.
2022 Dec 30 10:38 AM
2022 Dec 30 1:02 PM