Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8533

Re: How to add amount of 2 records with same Key fields in an internal table?

$
0
0

Yes, after this we need to apply the same logic I had given above.

it_dat1 is of type table whose fields are in the order f1 f2 f3 f10 f4 ----f9 f11 f12

the field names in it_dat1 and it_tab1 should be same.

 

Loop at itab1 into wa_itab1.

move-corresponding wa_itab1 to wa_dat1.

append wa_dat1 to it_dat1.

clear : wa_dat1, wa_itab1.

endloop.

 

sort it_dat1 by f1 f2 f3 f10.

loopat it_dat1 into wa_dat1.
wa_tmp = wa_dat1.
lv_amount = wa_dat1-f12+ lv_amount.
atendof f10.
      wa_tmp-f12 = lv_amount.
      append wa_tmp to it_final.
      clear : lv_amount.
endat.
        clear : wa_tmp, wa_dat1.
endloop.

 

Option 2

Or you could use the following logic with the original internal table it_dat1. (No need to move as above)


  clear wa_tmp.
  loopat it_dat1 into wa_dat1.
   if wa_tmp-f1 = wa_dat1-f1 AND wa_tmp-f2 = wa_dat1-f2 AND wa_tmp-f3 = wa_dat1-f3 AND wa_tmp-f10 = wa_dat1-f10 .
      wa_final = wa_dat1.
      lv_amount = wa_tmp-f12 + lv_amount.
      clear wa_tmp.
  else.
    ifnot wa_tmp isINITIAL.
      wa_final = wa_tmp.
      wa_final-f12 = lv_amount.
      append wa_final to it_final.
      lv_amount = wa_dat1-f12.
      clear : wa_final.
    endif .
    lv_amount = wa_dat1-f12.
    endif.
wa_tmp = wa_dat1.
clear wa_dat1.
endloop.

 

Check my answer on a related thread.

 

Re: Delete the same entry.

Viewing all articles
Browse latest Browse all 8533

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>