2023 Oct 16 9:29 AM
Hi Experts,
I have two set of bank data in two internal tables. For ex: It_knbk1 (having 10 entries) and lt_knbk2 (having 4 entries).
I need to filter out and move the non-matching or different between the two to another new internal table. i.e., (the difference of 6 entries).
How to achieve this using inline declaration or ABAP 7.4 commands. I know how to achieve it using our old techniques but would like to use the new ABAP 7.4 commands.
Please help.
Thanks.
2023 Nov 02 7:39 AM
Resolved with the help of sandra.rossi 's answer. Thanks sandra.rossi.
TYPES: begin of ts_knbk,
kunnr ...
types tt_xknbk type sorted table of ts_knbk ...
types tt_yknbk type sorted table of ts_knbk ...
DATA(xknbk) = VALUE tt_xknbk( ... ).
DATA(yknbk) = VALUE tt_yknbk( ... ).
DATA(gt_del_knbk) = FILTER tt_yknbk( yknbk ... IN xkbnk ... ).
2023 Oct 16 1:42 PM
Hi,
you can check this example: demo_filter_table_condition
https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenfilter_table_condition_abexa.htm
The classic abap could be:
loop at It_knbk1 into wa_1.
read table lt_knbk2 transporting no fields with key table_line = wa_1.
check sy-subrc is not initial.
insert wa_1 into table lt_result.
endloop.
2023 Oct 16 5:57 PM
I guess the visitors would see more the classic part of your answer (which is NOT what the OP asked), than the good FILTER part of your answer (hyperlink).
2023 Oct 24 7:48 AM
Hi xtrnhfo,
What must be the data type for lt_knbk2?
the table_line doesn't work here as it always considering all the entries between lt_knbk2 and wa_1 are going to sy-subrc is not initial, even though I have a matching entry.
Please let me know.
Thanks.
2023 Oct 24 9:10 PM
HI,
you can also use single fields as key
for example:
read table lt_knbk2 transporting no fields with key kunnr = wa_1-kunnr country = wa_1-country.
You can define the internal table as reference to the db table
lt_knbk2 type standard table of yknbk.
2023 Oct 16 1:47 PM
Hi sankar1781 ,
try this (NEW ABAP):
DATA(lt_knbk_diff) = VALUE knbk_t(
FOR ls_knbk IN COND #( WHEN lines( lt_knbk1 ) >= lines( lt_knbk2 ) THEN lt_knbk1 ELSE lt_knbk2 )
( LINES OF COND #(
WHEN lines( lt_knbk1 ) >= lines( lt_knbk2 ) AND NOT line_exists( lt_knbk2[ table_line = ls_knbk ] ) THEN VALUE #( ( ls_knbk ) )
WHEN lines( lt_knbk2 ) > lines( lt_knbk1 ) AND NOT line_exists( lt_knbk1[ table_line = ls_knbk ] ) THEN VALUE #( ( ls_knbk ) )
) )
).
2023 Oct 16 4:52 PM
Not sure what NEW means, but saying it works with ABAP 7.40 will make your answer still valid in the future.
2023 Oct 16 5:19 PM
Hi sandra.rossi
the creator of the question requested a "new" or more recent method for calculating the difference.That's the reasson I wrote "NEW". 7.40 is not strictly new
Kind regards
Julian
2023 Oct 16 5:56 PM
Okay but your code works with ABAP 7.40 anyway. So why saying "NEW" although your code is "OLD"? 😉
2023 Oct 24 7:42 AM
Hi julian.danho,
Here the KNBK_T is the type declaration of LT_KNBK*?
Thanks.
2023 Oct 16 4:54 PM
Many ways to do it. What did you try?
e.g. via FILTER ... IN or FILTER ... NOT IN ...
2023 Oct 17 8:25 AM
Hi sandra.rossi ,
Thanks for your prompt response (always).
I tried as the below image but got 0/null result to gt_del_knbk.
@xtrnhfo, thanks for your response and your answer but I would like to achieve it using ABAP 7.4
@julian.danho, Didn't try it as I thought it can be achieved by using Filter. Let me check yours as well. Thanks a lot.
2023 Oct 17 1:51 PM
I can't answer why you get "0/null result" if you don't share any other information. All depends on input data and actual/expected results which I don't have.
2023 Oct 24 7:41 AM
Hi sandra.rossi,
Even I tried with EXCEPT IN using FILTER but no use.
So, other information of data input between two tables are shared here, as a snapshot. Validating based on the KUNNR, COUNTRY and BANK KEY, the difference entry of CITI1 must be fetched between XKNBK and YKNBK.
Hope I answered to your question.
Thanks.
2023 Oct 24 10:31 AM - edited 2025 Feb 05 2:50 PM
No, sorry, it's not clear. Please create a minimal reproducible program and I'll look at it.
e.g.
TYPES: begin of ts_knbk,
kunnr ...
types tt_xknbk type sorted table of ts_knbk ...
types tt_yknbk type sorted table of ts_knbk ...
DATA(xknbk) = VALUE tt_xknbk( ... ).
DATA(yknbk) = VALUE tt_yknbk( ... ).
DATA(gt_del_knbk) = FILTER tt_yknbk( yknbk ... IN xkbnk ... ).
2023 Nov 02 7:39 AM
Resolved with the help of sandra.rossi 's answer. Thanks sandra.rossi.
TYPES: begin of ts_knbk,
kunnr ...
types tt_xknbk type sorted table of ts_knbk ...
types tt_yknbk type sorted table of ts_knbk ...
DATA(xknbk) = VALUE tt_xknbk( ... ).
DATA(yknbk) = VALUE tt_yknbk( ... ).
DATA(gt_del_knbk) = FILTER tt_yknbk( yknbk ... IN xkbnk ... ).