*----------------------------------------------------------------------*
*  Report  ZZXMP001                                                    *
*                                                                      *
*  Example on how to summarize columns and rows in internal tables.    *
*  i.e summarize peiod totals from the G/L account master record with  *
*  monthly debits/credits amount.                                      *
*----------------------------------------------------------------------*
REPORT ZZXMP001 LINE-SIZE 132.

*----------------------------------------------------------------------*
* Tables
*----------------------------------------------------------------------*
TABLES: GLT0.                 "G/L Account Master Record  Monthly Debits

*----------------------------------------------------------------------*
* Internal table with result specified automatic using Pattrn..
*----------------------------------------------------------------------*
DATA: BEGIN OF RESULT OCCURS   0,
        RLDNR LIKE GLT0-RLDNR,
        RRCTY LIKE GLT0-RRCTY,
        RVERS LIKE GLT0-RVERS,
        BUKRS LIKE GLT0-BUKRS,
        RYEAR LIKE GLT0-RYEAR,
        RACCT LIKE GLT0-RACCT,
        RBUSA LIKE GLT0-RBUSA,
        RTCUR LIKE GLT0-RTCUR,
        DRCRK LIKE GLT0-DRCRK,
        RPMAX LIKE GLT0-RPMAX,
        TSLVT LIKE GLT0-TSLVT,
        TSL01 LIKE GLT0-TSL01,
        TSL02 LIKE GLT0-TSL02,
        TSL03 LIKE GLT0-TSL03,
        TSL04 LIKE GLT0-TSL04,
        TSL05 LIKE GLT0-TSL05,
        TSL06 LIKE GLT0-TSL06,
        TSL07 LIKE GLT0-TSL07,
        TSL08 LIKE GLT0-TSL08,
        TSL09 LIKE GLT0-TSL09,
        TSL10 LIKE GLT0-TSL10,
        TSL11 LIKE GLT0-TSL11,
        TSL12 LIKE GLT0-TSL12,
        TSL13 LIKE GLT0-TSL13,
        TSL14 LIKE GLT0-TSL14,
        TSL15 LIKE GLT0-TSL15,
        TSL16 LIKE GLT0-TSL16,
        SUM1  LIKE GLT0-TSL16,
        SUM2  LIKE GLT0-TSL16,
      END OF RESULT.

*----------------------------------------------------------------------*
* Event: Top-of page
*----------------------------------------------------------------------*
TOP-OF-PAGE.
  WRITE:/01(15) 'tsl01'   RIGHT-JUSTIFIED
          ,(15) 'tsl02'   RIGHT-JUSTIFIED
          ,(15) 'tsl03'   RIGHT-JUSTIFIED
          ,(15) 'tsl04'   RIGHT-JUSTIFIED
          ,(15) 'tsl05'   RIGHT-JUSTIFIED
          ,(15) 'tsl06'   RIGHT-JUSTIFIED
          ,(15) 'sum'     RIGHT-JUSTIFIED
          .
  WRITE:/01 SY-ULINE.

*----------------------------------------------------------------------*
* Event: Initialization
*----------------------------------------------------------------------*
INITIALIZATION.
  CLEAR:   RESULT.
  REFRESH: RESULT.

*----------------------------------------------------------------------*
* Event: Start-of-selection
*----------------------------------------------------------------------*
START-OF-SELECTION.
   SELECT * FROM GLT0 INTO CORRESPONDING FIELDS OF RESULT
     WHERE BUKRS = '1000'
       AND RYEAR = '1994'.

*    Summarize the columns using add..until
     ADD RESULT-TSL01 THEN RESULT-TSL02 UNTIL RESULT-TSL06
         GIVING RESULT-SUM1.

     APPEND RESULT.
   ENDSELECT.

   LOOP AT RESULT.
     WRITE:/01(15) RESULT-TSL01
             ,(15) RESULT-TSL02
             ,(15) RESULT-TSL03
             ,(15) RESULT-TSL04
             ,(15) RESULT-TSL05
             ,(15) RESULT-TSL06
             ,(15) RESULT-SUM1.
*    Summarize rows
     AT END OF RBUSA .
       SUM.
       WRITE:/01 SY-ULINE.
       WRITE:/01(15) RESULT-TSL01 COLOR COL_TOTAL
               ,(15) RESULT-TSL02 COLOR COL_TOTAL
               ,(15) RESULT-TSL03 COLOR COL_TOTAL
               ,(15) RESULT-TSL04 COLOR COL_TOTAL
               ,(15) RESULT-TSL05 COLOR COL_TOTAL
               ,(15) RESULT-TSL06 COLOR COL_TOTAL
               ,(15) RESULT-SUM1  COLOR COL_TOTAL.
        SKIP 2.
      ENDAT.
   ENDLOOP.