Skip to Content
0
Former Member
Aug 01, 2016 at 07:04 AM

Alternative for Loop at - Collect

1945 Views

Hi All,

I have an internal table which consist of [27166x24(336)]Standard Table, and need to loop - collect to got the sum of the dmbtr field.

Is there any alternative to get the sum since looping took so long (and it just the test data).

I tried put sum on the query but unable due to FAE.

Have put the table query and loop below, thanks in advance ! 😊

* Query

SELECT tbs~kunnr tbs~augdt tbs~augbl tbs~gjahr tbs~belnr tbs~budat
          tbs~bldat tbs~waers tbs~xblnr tbs~blart tbs~monat tbs~shkzg
          tbs~gsber tbs~dmbtr tbs~wrbtr tbs~zfbdt tbs~zterm tbs~rebzg tbs~vbeln
          tbs~xragl tbk~bktxt tbk~stblg tbk~stjah tbk~xreversal
   APPENDING TABLE t_paym FROM bsid AS tbs
      INNER JOIN bkpf AS tbk
              ON tbk~bukrs = tbs~bukrs
             AND tbk~belnr = tbs~belnr
             AND tbk~gjahr = tbs~gjahr
     FOR ALL ENTRIES IN t_itmrv
           WHERE tbk~bukrs = p_bukrs
             AND tbs~rebzg EQ t_itmrv-belnr
             AND tbs~rebzj EQ t_itmrv-gjahr 
AND tbs~kunnr EQ t_itmrv-kunnr.

*Loop

LOOP AT t_paym.
     lt_paym-kunnr = t_paym-kunnr.
     lt_paym-vbeln = t_paym-rebzg.
     lt_paym-amt   = t_paym-dmbtr.
     COLLECT lt_paym.
ENDLOOP.