Another Internal Table Example with SAP - ABAP

..
This is the View I have:


And the code I have:
REPORT ZTMP_TEST_INNBOUND2 LINE-COUNT 80.
 
* View name: Z_KNA1_VBRK
 
* Customer Code Wise List of Billing Documents of a Specified Company Code
* with Totals for Every Customer and a Grand Total. 
 
* Also output totals of fields NETWR and MWSBK for each customer, and finally
* grand totals for these fields.
 
DATA COMPANYCODE TYPE T001. " T001 is the Table: Company Codes
                            " BUKRS is the Company Code
                            " BUTXT is the Company Code text
 
DATA: BILL_DOCS_TAB   TYPE Z_KNA1_VBRK OCCURS 5, " reference to view
      BILL_DOCS_STRU  TYPE Z_KNA1_VBRK,
      COUNTER         TYPE I,          " COUNTER for billing documents of a customer
      PREV_KUNNR      TYPE KNA1-KUNNR, " previous KUNNR
      CTOTAL          TYPE VBRK-NETWR, " customer net value total
      CTAX_TOTAL      TYPE VBRK-MWSBK, " customer tax total
      GTOTAL          TYPE VBRK-NETWR, " grand net value total
      GTAX_TOTAL      TYPE VBRK-MWSBK. " grand tax total
 
* Get input from the user:
PARAMETERS CCODE TYPE VBRK-BUKRS DEFAULT 1000 VALUE CHECK.
 
START-OF-SELECTION.
 
    SELECT SINGLE * FROM T001 INTO COMPANYCODE WHERE BUKRS = CCODE.
    WRITE: 'Company Code: ', COMPANYCODE-BUTXT.
 
    SELECT * FROM Z_KNA1_VBRK UP TO 10 ROWS INTO TABLE BILL_DOCS_TAB 
    WHERE BUKRS = CCODE.
 
    SORT BILL_DOCS_TAB BY KUNNR ASCENDING.
 
    LOOP AT BILL_DOCS_TAB INTO BILL_DOCS_STRU.
 
        IF BILL_DOCS_STRU-KUNNR <> PREV_KUNNR.
            IF COUNTER <> 0.
                FORMAT INVERSE COLOR COL_GROUP. "customer total-different color
                WRITE: /1(17) '          CTOTAL', 18(15) '    CTAX TOTAL'.
                WRITE: /1(17) CTOTAL, 18(15) CTAX_TOTAL.
                FORMAT RESET. "restore default colors.
            ENDIF.
            IF SY-TABIX > 1.
                SKIP.
                CTOTAL = 0.
                CTAX_TOTAL = 0.
                COUNTER = 0.
            ENDIF.
 
            FORMAT INVERSE COLOR COL_POSITIVE. "customer info-different color
            WRITE: /5 ' Customer Number: ', 
            BILL_DOCS_STRU-KUNNR USING NO EDIT MASK.
            WRITE: /5 ' Customer Name: ', BILL_DOCS_STRU-NAME1, /.
            WRITE: /6(8) 'Doc no.', 15(10) 'Doc Date',
            26(18) 'Net Val in Doc Cur', 45(9) 'Exch Rate',
            55(18) 'Tax Amn in Doc Cur',
            73(6)  'Client'. 
            FORMAT RESET. "restore default colors.
        ENDIF.
 
        " Net Val in Doc Curr = Net Val in Doc Curr * Exchange Rate
        BILL_DOCS_STRU-NETWR = BILL_DOCS_STRU-NETWR * BILL_DOCS_STRU-KURRF.
 
        " Tax Amount in Doc Curr = Tax Amount in Doc Curr * Exchange Rate
        BILL_DOCS_STRU-MWSBK = BILL_DOCS_STRU-MWSBK * BILL_DOCS_STRU-KURRF.
 
        COUNTER = COUNTER + 1.
        WRITE: /1(3) COUNTER, 6(8) BILL_DOCS_STRU-VBELN, 
        15(10) BILL_DOCS_STRU-FKDAT, 26(18) BILL_DOCS_STRU-NETWR,
        45(9) BILL_DOCS_STRU-KURRF, 55(18) BILL_DOCS_STRU-MWSBK,
        73(6) BILL_DOCS_STRU-MANDT.
 
        GTOTAL = GTOTAL + BILL_DOCS_STRU-MWSBK.
        CTOTAL = CTOTAL + BILL_DOCS_STRU-NETWR.
 
        GTAX_TOTAL = CTAX_TOTAL + BILL_DOCS_STRU-MWSBK.
        CTAX_TOTAL = CTAX_TOTAL + BILL_DOCS_STRU-MWSBK.
 
        PREV_KUNNR = BILL_DOCS_STRU-KUNNR.
    ENDLOOP.
 
END-OF-SELECTION.
 
 
IF COUNTER > 1.
    FORMAT INVERSE COLOR COL_GROUP. "customer total-different color
    WRITE: /1(17) '          CTOTAL', 18(15) '    CTAX TOTAL'.
    WRITE: /1(17) CTOTAL, 18(15) CTAX_TOTAL.
    FORMAT RESET. "restore default colors.
ENDIF.
 
SKIP 1.
 
FORMAT INVERSE COLOR COL_TOTAL. "grand total-different color
 
WRITE: /(21) 'Grand Net Value Total',
        (15) 'Grand Tax Total'.
 
WRITE: /(21) GTOTAL UNDER BILL_DOCS_STRU-NETWR,
        (15) GTAX_TOTAL UNDER BILL_DOCS_STRU-MWSBK.

And finally the output: