# How to Comparing 2 internal table and get the different records

I have 2 internal tables with the same structure. GT_AFPO and GT_AFPO. I wanna looping GT_AFPO that not in GT_AFPO2.

```
SELECT a~matnr a~aufnr a~psmng a~wemng a~amein a~ltrmi b~objnr c~stat
FROM afpo AS a
JOIN aufk AS b ON a~aufnr = b~aufnr
JOIN jest AS c ON b~objnr = c~objnr
INTO CORRESPONDING FIELDS OF TABLE gt_afpo
FOR ALL ENTRIES IN gt_mard
WHERE a~matnr = gt_mard-matnr AND a~pwerk = p_werks
AND c~stat = 'I0002'
AND c~inact = ''
.
SELECT a~aufnr FROM afpo AS a
JOIN aufk AS b ON a~aufnr = b~aufnr
JOIN jest AS c ON b~objnr = c~objnr
INTO CORRESPONDING FIELDS OF TABLE gt_afpo2
WHERE a~matnr = gw_mara-matnr AND a~pwerk = p_werks
AND c~stat = 'I0076' AND c~inact = ''.

LOOP AT gt_afpo INTO gw_afpo WHERE matnr = gw_mara-matnr.
lv_qty_pro = lv_qty_pro + gw_afpo-psmng.
ENDLOOP.```
10|10000 characters needed characters exceeded
• Frederic Girod yes it does.

Sandra Rossi Thnks sir. I'm using your code and it's solve. that's what i want.

• REDUCE + FILTER could perfectly fit to your question.

Otherwise the old way:

```LOOP AT gt_afpo INTO gw_afpo WHERE matnr = gw_mara-matnr.
IF NOT line_exists( gt_afpo2[ aufnr = gw_afpo-aufnr ] ).
lv_qty_pro = lv_qty_pro + gw_afpo-psmng.
ENDIF.
ENDLOOP.```

gt_afpo2 be declared as a table with a non-unique sorted key by AUFNR.

But shouldn't you have component MATNR in GT_AFPO2? And can't you do that in one SQL statement and one internal table?

• Sorry but, does your source code related to your question ? because you did not set the same kind of date in the two differentes tables.