Skip to Content
0
Nov 18, 2019 at 02:15 PM

How to sum data based on a condition into a new field

271 Views

Hi

Guys please can you help . I need to create new fields based on data pulled from field CKIS-KOSTL. then i require the data to be sum up based on condition CKIS-KOSTL the values to be sum is in CKIS-WERTN.

How do I create a new field "1350" and "1380" and sum up data from CKIS-WERTN based on condition CKIS-KOSTL which has cost centres "1350" & "1380".

*& Report  Z_COST_MATERIAL5
REPORT  z_cost_material5 LINE-SIZE 250.
* TABLE DECLARATION
TYPES: BEGIN OF z_keph,
      matnr TYPE mbew-matnr,
      BWKEY TYPE mbew-bwkey,
      KST001 TYPE KEPH-KST001,
      kst004  TYPE keph-kst004,
      KST006 TYPE keph-kst006,
      KST010 TYPE keph-kst010,
      kalnr TYPE keph-kalnr,
      KKZST TYPE KEPH-KKZST,
      KSTAR TYPE CKIS-KSTAR,
      WERTN TYPE CKIS-WERTN,
      LSTAR TYPE CKIS-LSTAR,
      KADKY TYPE KEPH-KADKY,
      KOSTL TYPE CKIS-KOSTL.
TYPES:END OF z_keph.
 DATA: it_keph TYPE STANDARD TABLE OF z_keph INITIAL SIZE 0,
wa_keph TYPE z_keph,     "work area (header line)
wa_keph1 LIKE LINE OF it_keph.

SELECT-OPTIONS:
material FOR WA_KEPH-MATNR,
COSTINGD FOR WA_KEPH-KADKY.

*START OF SELECTION "TO INPUT DATA INTO INTERNAL TABLE IT_KEPH
START-OF-SELECTION.
  SELECT: A~MATNR A~BWKEY B~KST001 B~KST004 B~KST006 B~KST010 B~KALNR C~KSTAR C~WERTN C~LSTAR C~KOSTL
  FROM mbew AS a
  JOIN keph AS b
  ON a~kaln1 EQ b~kalnr INNER JOIN CKIS AS C
  ON B~KALNR EQ C~KALNR
  AND
   B~KADKY EQ C~KADKY
  INTO CORRESPONDING FIELDS OF TABLE it_keph
WHERE A~MATNR IN MATERIAL
    and a~bwkey EQ '3000'
    AND B~KKZST EQ 'X'
    AND B~KADKY IN COSTINGD.
*PROCESSING DATA IN IT_ZEPH
  LOOP AT it_keph INTO WA_KEPH.
    AT FIRST.
    WRITE:  'MATERIAL N0' COLOR 3,
           30 'DHU' COLOR 3,
            146 '1350' COLOR 3,
            156 '1380' COLOR 3.
     ULINE.
     ENDAT.
    WRITE: / WA_KEPH-MATNR,WA_KEPH-KST001,WA_KEPH-KST004,WA_KEPH-KST006,WA_KEPH-KST010,WA_KEPH-KSTAR,WA_KEPH-WERTN,WA_KEPH-LSTAR,WA_KEPH-KOSTL.
  ENDLOOP.

Attachments

aba10.jpg (147.6 kB)