Application Development 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: 

How to Comparing 2 internal table and get the different records

former_member635273
Participant
285

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.
3 REPLIES 3

FredericGirod
Active Contributor
92

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.

Sandra_Rossi
Active Contributor
92

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?

former_member635273
Participant
0 Kudos
92

frdric.girod yes it does.

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