2023 Aug 17 12:09 AM
Hi,
What would be the equivalent ABAP 7.5 code for below old code, basically deleting a row with blank level_2_bom value, if there is a row with level_2_bom value for combination of key fields.
LOOP AT gt_data INTO ls_data WHERE level_2_bom IS NOT INITIAL.
READ TABLE gt_Data INTO DATA(ls_data1) WITH KEY matnr = ls_data-matnr
swerk = ls_data-swerk
stlnr = ls_data-stlnr
level_1_bom = ls_data-level_1_bom
level_2_bom = ''.
IF sy-subrc = 0.
DELETE table gt_Data from ls_data1 .
ENDIF.
ENDLOOP.
2023 Aug 17 7:59 AM
What did you try? If you know a little bit, you probably have the beginning code.
NB: the old code is missing lot of optimization, if you don't see that, I fear that going to a constructor expression won't improve. Code improvement is more important than using a constructor expression.
2023 Aug 18 6:32 AM
2023 Aug 18 8:33 AM
2023 Aug 18 4:33 PM
2023 Aug 18 6:13 PM
2023 Aug 18 8:01 PM
2023 Aug 19 1:23 PM
2023 Aug 19 1:45 PM
As you know, a Constructor Expression builds an internal table from scratch, Update or Delete are out of scope for constructor expressions.
Update and Delete are not good candidates for replacement by a constructor expression, due to performance and intermediate memory used.
If you still want to do it for some reason, you may filter the lines you copy via either the constructor operator FILTER or via the WHERE word.
But in your case, you use a kind of LINE_EXISTS (see ABAP doc if you don't know), so the constructor expression has to be complexified with a trick based on "LINES OF COND" to add either 0 or 1 line.
Also, using an internal table both as input and output is a classic problem, because a target variable is usually cleared at the start of the constructor expression so it requires to use another trick based on LET:
itab = VALUE #(
LET temp_itab = itab IN
FOR ... IN temp_itab
WHERE ( ... )
( LINES OF COND ty_lines(
WHEN line_exists( temp_itab[ ... ] ) THEN
VALUE ty_line( ... ) ) ) ).
As you see, it's both less legible and less performing, so I advise to keep your current code.