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: 

ABAP new Syntax - DELETE inside FOR-Loop

0 Kudos
5,919

Hello together,

is there a new syntax statement to do the following?

LOOP AT lt_tab ASSIGNING <ls_ine> WHERE vbeln = <ls_dlv>-dlv_id.           

DELETE lt_tab_1 WHERE vbeln = <ls_dlv_split_request>-vbeln_new.           

DELETE lt_tab.         

ENDLOOP.

3 REPLIES 3

Sandra_Rossi
Active Contributor
2,862

Excuse me, but there is no relationship between lt_tab and lt_tab_1, is it normal? Or is your question only about DELETE lt_tab?

If your question is about DELETE:

  • Generally speaking, the "new syntax" (what does it mean?), probably you mean the "constructor expressions" introduced in ABAP 7.40, are used to construct (= initialize/append), not to "deconstruct" (= delete)
  • So, a workaround may be to reconstruct the internal table with all the lines except the ones to "delete", for instance using the constructor operator FILTER.

michael_piesche
Active Contributor
2,862
  • The "new syntax" doesnt make the "old syntax" obsolete, even though there might be some instances of 'old syntax' that shouldnt be used any more (e.g. explicit option BINARY SEARCH).
  • The new available expressions do have the capability, of making certain codings shorter, especially when help variables (fields, structures, tables) are necessary to perform a task.
  • I do not see a value however, in trying to force a few lines of coding into coding that represents the so called "new syntax".
  • The delete statement does not have a real corresponding expression for the "new syntax"
  • The lines of code you give obviously have a necessary 'looping' functionality around it, that should give more sense to your coding then the way it is presented right now, therefore, any attempt to apply the new more sophisticated expressions, should also include the surrounding logic as well, and not just concentrate on those few seemingly unrelated lines of code

Here are some examples with the new expressions that could help you with rewriting the code:

" VALUE expression
" New lt_tab_2 has only values from Old lt_tab_1 that are not in lt_tab based on vbeln
TYPES: rty_vbeln TYPE RANGE OF vbeln. DATA(lt_tab_2) = VALUE tty_tab_1( FOR wa1 IN lt_tab_1 WHERE ( KEY NOT IN VALUE rty_vbeln( FOR wa2 IN lt_tab ( SIGN = 'I' OPTION = 'EQ' LOW = wa2-vbeln ) ) ) ( vbeln = wa1-vbeln ) ). " FILTER expression " Table lt_tab is filtered by not having a specific value lt_tab = filter #( lt_tab WHERE vbeln <> <ls_dlv>-dlv_id ). " Table lt_tab_1 is filtered by values that are not in table lt_tab based on vbeln lt_tab_1 = filter #( lt_tab_1 EXCEPT in lt_tab where vbeln = vbeln ).

michael_piesche
Active Contributor
0 Kudos
2,862

coding1407, please follow up on your open question.

  • comment answers or your question if there are still open issues.
  • otherwise mark an answer as accepted if it helped you solve your problem
  • or post an answer of yourself and accept it if you found another useful solution yourself
  • or redirect your question to another question that is related and was useful to solve your problem
  • in the end, close your question