Skip to end of metadata
Go to start of metadata
DATA: BEGIN OF itab OCCURS 0,
      f1 TYPE i,
      f2(6) TYPE c,
      f3(10) TYPE n,
      f4(16) TYPE p DECIMALS  2,
      END OF itab.
DATA: sub_tot(10) TYPE p DECIMALS 3.
**--1
itab-f1 = 1.
itab-f2 = 'ONE'.
itab-f3 = 10.
itab-f4 = '1000.00'.
APPEND itab.
CLEAR itab.
itab-f1 = 1.
itab-f2 = 'ONE'.
itab-f3 = 20.
itab-f4 = '2000.00'.
APPEND itab.
CLEAR itab.
itab-f1 = 1.
itab-f2 = 'ONE'.
itab-f3 = 30.
itab-f4 = '3000.00'.
APPEND itab.
CLEAR itab.
*--2
itab-f1 = 2.
itab-f2 = 'TWO'.
itab-f3 = 10.
itab-f4 = '1000.00'.
APPEND itab.
CLEAR itab.
itab-f1 = 2.
itab-f2 = 'TWO'.
itab-f3 = 20.
itab-f4 = '2000.00'.
APPEND itab.
CLEAR itab.
*-- 3
itab-f1 = 3.
itab-f2 = 'THREE'.
itab-f3 = 10.
itab-f4 = '1000.00'.
APPEND itab.
CLEAR itab.
itab-f1 = 3.
itab-f2 = 'THREE'.
itab-f3 = 20.
itab-f4 = '2000.00'.
APPEND itab.
CLEAR itab.
SORT itab BY f1.
LOOP AT itab.
  AT FIRST.
    WRITE: /35 ' MATERIAL DETAILS:'.
    ULINE.
  ENDAT.
  AT NEW f1.
    WRITE: / 'DETAILS OF MATERIAL:' COLOR 7  , itab-f1.
    ULINE.
  ENDAT.
  WRITE: / itab-f1, itab-f2, itab-f3, itab-f4.
  sub_tot = sub_tot + itab-f4.
  AT END OF f1.
    ULINE.
    WRITE: / 'SUB TOTAL :'  COLOR 3 INVERSE ON, sub_tot COLOR 3 INVERSE ON.
    CLEAR sub_tot.
  ENDAT.
  AT LAST.
    SUM.
    ULINE.
    WRITE: 'SUM:', itab-f4.
    ULINE.
  ENDAT.
ENDLOOP.
 

1 Comment

  1. Beware of the combination LOOP AT <> WHERE and the AT/FIRST at new! In this code replace

      SPAN

    Unknown macro: { font-family}

    .L0S52

    Unknown macro: { color}

    LOOP AT itab.

    with

      SPAN

    Unknown macro: { font-family}

    .L0S32

    Unknown macro: { color}

    .L0S52

    Unknown macro: { color}

    LOOP AT itab WHERE f4 GT 1500.

    and compare the result.