‎2020 Sep 01 2:48 AM
I want to loop through a itab for these rows which value is not equal.
So I wrote code like
LOOP AT gt_alv3 INTO gs_alv3 where product_id <> old_product_id .
......
ENDLOOP.
And it has error. And the following code has no error.
LOOP AT gt_alv3 INTO gs_alv3 where product_id <> gs_alv3-old_product_id .
......
ENDLOOP.
But I wonder is this correct? And by writng this will it only loop through those line under the condition?Thx.
‎2020 Sep 01 6:50 AM
Unfortunately, with LOOP you cannot compare two attributes of an internal table against each other.
The first operand (operand1) is a component of the internal table and the second operand (operand2) is any object other then one of the internal table. Please always check the SAP ABAP documentation when trying to understand ABAP statements.
(You can however do this logic with a SELECT statement, maybe that would be another possibility for you.)
So to solve your problem for a given internal table, you need to check for a difference in product_id and old_product_id from within the loop. Is old_product_id always filled, even if it is the same, otherwise you would also have to check for not initial.
LOOP AT gt_alv3 INTO gs_alv3.
CHECK gs_alv3-product_id <> gs_alv3-old_product_id.
CHECK gs_alv3-old_product_id IS NOT INITIAL.
...
ENDLOOP.
‎2020 Sep 01 2:56 AM
HI,
Create gt_alv_temp as a temporary table
gt_alv_temp[] = gt_alv3[].
delete gt_alv_temp where product_id ne old_product_id .
loop at gt_alv_temp.
Endloop.
‎2020 Sep 01 3:44 AM
‎2020 Sep 01 5:36 AM
‎2020 Sep 01 6:16 AM
It's a syntax check error in Eclipse and I can't activate it with this error.. The error code is
The field "OLD_PRODUCT_ID" is unknown, but there is a field with the similar name "LV_PRODUCT_ID". "LV_PRODUCT_ID".
what I want is in internal table gt_alv3, there are columns product_id and old_product_id, and I want to loop through rows which these two columns has different value. and I'm sure they exist in the table and has same data type.
‎2020 Sep 01 6:50 AM
Unfortunately, with LOOP you cannot compare two attributes of an internal table against each other.
The first operand (operand1) is a component of the internal table and the second operand (operand2) is any object other then one of the internal table. Please always check the SAP ABAP documentation when trying to understand ABAP statements.
(You can however do this logic with a SELECT statement, maybe that would be another possibility for you.)
So to solve your problem for a given internal table, you need to check for a difference in product_id and old_product_id from within the loop. Is old_product_id always filled, even if it is the same, otherwise you would also have to check for not initial.
LOOP AT gt_alv3 INTO gs_alv3.
CHECK gs_alv3-product_id <> gs_alv3-old_product_id.
CHECK gs_alv3-old_product_id IS NOT INITIAL.
...
ENDLOOP.
‎2020 Sep 01 8:35 AM
I post here the important part of the question added by the OP (this comment😞
"It's a syntax check error in Eclipse and I can't activate it with this error.. The error code is
The field"OLD_PRODUCT_ID" is unknown, but there is a field with the similar name "LV_PRODUCT_ID"."what I want is in internal table gt_alv3, there are columns product_id and old_product_id, and I want to loop through rows which these two columns has different value. and I'm sure they exist in the table and has same data type.
‎2020 Sep 01 10:52 PM
Per WHERE clause in LOOP documentation, the second operand(old_product_id) can NOT be a component of internal table; but it can be a component of a VARIABLE (gs_alv3).
<<<<<<<<<< portion of text from help.sap.com<<<<<<<<<<<<<<<<
The remaining operands of a relational expression are general expression positions at which any suitable individual operands or expressions can be specified, but no components of the internal table.
>>>>>>>>>end<<<<<<<<<<<<<