Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to sum data based on a conidtion.

0 Kudos

Hi

I need to sum up amounts based on condition of a activity type ,

I need to sum up column CKIS-WERTN based on condition activity type in CKIS-LSTAR so if i have a activity type DYEH.I need to sum up amounts based on activity type DYEH and the report must create a new column called DYEH and input the sum value in line with cost estimate number.

I have 6 different activity types.

*& Report Z_COST_MATERIAL5

*&---------------------------------------------------------------------*

*& Report  Z_COST_MATERIAL5

REPORT  z_cost_material5 LINE-SIZE 160.

* 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.

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.
*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
  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
  INTO CORRESPONDING FIELDS OF TABLE it_keph
WHERE A~MATNR IN MATERIAL
    and a~bwkey EQ '3000'
    AND B~KKZST EQ 'X'.
*PROCESSING DATA IN IT_ZEPH
  LOOP AT it_keph INTO wa_keph.
    WRITE: / wa_keph-matnr,WA_KEPH-KST001,WA_KEPH-KST004,WA_KEPH-KST006,WA_KEPH-KST010,WA_KEPH-KALNR,WA_KEPH-LSTAR,WA_KEPH-WERTN,WA_KEPH-KSTAR.
  ENDLOOP.
2 REPLIES 2

thanga_prakash
Active Contributor
0 Kudos

@zubair sultan You can make use of ALV display to display it's sub total based on activity type in CKIS-LSTAR, in field catalog you might have to specify subtotal flag as 'X' for this field, then automatically when you display the output, results will be displayed with sum of amounts for every activity type. Refer to the below links for reference.

ALV Total & Subtotal

Display ALV Total & Subtotal

DoanManhQuynh
Active Contributor

so what is your question?