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: 

Not summing up -internal table entries

Former Member
0 Kudos
198

Hi,

Below is the code I am trying to get respective totals of cost elements.

but i am getting output as.

51000 120

51000 300

54000 700

54000 100

54000 400

I need following output

51000 420

54000 1200

REPORT  YY.

tables: prps.

data: t_prps like prps occurs 0 with header line.
data: t_final like zjob occurs 0 with header line.

types: t_coep type coep.


data: it_coep TYPE STANDARD TABLE OF t_coep.
DATA : wa_coep TYPE t_coep.
DATA : wa1_coep TYPE t_coep.

select-options:

s_pspid for prps-psphi.

select * from PRPS  into corresponding fields of table t_prps
where psphi in s_pspid.

***Actual Costs
select * from coep into corresponding fields of table it_coep
for all entries in t_prps
where objnr = t_prps-objnr.



sort it_coep by kstar.

loop at it_coep into wa1_coep.

  wa1_coep-wtgbtr = wa1_coep-wtgbtr   + wa_coep-wtgbtr .

  AT END OF kstar.
    ULINE.
    WRITE: / wa1_coep-wtgbtr , 30 wa1_coep-kstar  .
    move wa1_coep-wtgbtr to t_final-CJTDAT.
    move wa1_coep-kstar to t_final-kstar.

    append t_final.
    CLEAR wa1_coep.
    SKIP.
  ENDAT.

endloop.


loop at t_final.

  write:/10 t_final-kstar, 40 t_final-cjtdat.

endloop.

What am i doing wrong?

rgds

vara

1 ACCEPTED SOLUTION

Former Member
0 Kudos
148

Hi,

Since kstar is not the first field in the internal table it_coep...the AT END OF event will be triggered even if there is any change in the previous columns..Please check the help for details..

to solve this..

1) you can use COLLECT..in which the intenal table should have only cost element and amount columns.

OR

2) change the internal table IT_COEP to have only cost element and amount columns..

Thanks

Naren

6 REPLIES 6

Former Member
0 Kudos
149

Hi,

Since kstar is not the first field in the internal table it_coep...the AT END OF event will be triggered even if there is any change in the previous columns..Please check the help for details..

to solve this..

1) you can use COLLECT..in which the intenal table should have only cost element and amount columns.

OR

2) change the internal table IT_COEP to have only cost element and amount columns..

Thanks

Naren

Former Member
0 Kudos
148

Hi,

loop at it_coep into wa1_coep.
 
  wa_coep-wtgbtr = wa_coep-wtgbtr   + wa1_coep-wtgbtr .  " Change
 
  AT END OF kstar.
    ULINE.
    WRITE: / wa_coep-wtgbtr , 30 wa1_coep-kstar  .    " Change
    move wa_coep-wtgbtr to t_final-CJTDAT.                " Change 
    move wa1_coep-kstar to t_final-kstar.
 
    append t_final.
    CLEAR : wa1_coep, wa_coep.                  " Change
    SKIP.
  ENDAT.
 
endloop.

Former Member
0 Kudos
148
REPORT  YY.
 
tables: prps.
 
data: t_prps like prps occurs 0 with header line.
data: t_final like zjob occurs 0 with header line.
 
types: t_coep type coep.
 
 
data: it_coep TYPE STANDARD TABLE OF t_coep.
DATA : wa_coep TYPE t_coep.
DATA : wa1_coep TYPE t_coep.
 
select-options:
 
s_pspid for prps-psphi.
 
select * from PRPS  into corresponding fields of table t_prps
where psphi in s_pspid.
 
***Actual Costs
select * from coep into corresponding fields of table it_coep
for all entries in t_prps
where objnr = t_prps-objnr.
 
 
 
sort it_coep by kstar.
 
CLEAR : l_wtgbt.
loop at it_coep into wa1_coep.
 
* wa1_coep-wtgbtr = wa1_coep-wtgbtr   + wa_coep-wtgbtr . "Wrong use a temporary variable to do the summing

l_wtgbt = l_wtgbtr +  wa_coep-wtgbtr/
 
  AT END OF kstar.
    ULINE.
    WRITE: / wa1_coep-wtgbtr , 30 wa1_coep-kstar  .
    move l_wtgbtr to t_final-CJTDAT.                " line changed
    move wa1_coep-kstar to t_final-kstar.
 
    append t_final.
    CLEAR: wa1_coep, l_wtgbtr.   "line changed
    SKIP.
  ENDAT.
 
endloop.
 
 
loop at t_final.
 
  write:/10 t_final-kstar, 40 t_final-cjtdat.
 
endloop.

0 Kudos
148

Avinash & Vishnu,

I tried both of your codes.. I am still getting same old output.

Narendra,

I followed your second suggestion and chnaged code like below.

Even though I see entries in my internal table.It is displaying zeros..

REPORT  YY.

tables: prps.

data: t_prps like prps occurs 0 with header line.
data: t_final like zjob occurs 0 with header line.

*types: t_coep type coep.

types: begin of t_coep ,

kstar like coep-kstar,
wtgbtr like coep-wtgbtr,

end of t_coep.


data: it_coep TYPE STANDARD TABLE OF t_coep.
DATA : wa_coep TYPE t_coep.
DATA : wa1_coep TYPE t_coep.

select-options:

s_pspid for prps-psphi.

select * from PRPS  into corresponding fields of table t_prps
where psphi in s_pspid.

***Actual Costs
select kstar wtgbtr from coep into corresponding fields of table it_coep
for all entries in t_prps
where objnr = t_prps-objnr.


loop at it_coep into wa1_coep.

  wa1_coep-wtgbtr = wa1_coep-wtgbtr   + wa_coep-wtgbtr .

  AT END OF kstar.
    ULINE.
    WRITE: / wa1_coep-wtgbtr , 30 wa1_coep-kstar  .
    move wa1_coep-wtgbtr to t_final-CJTDAT.
    move wa1_coep-kstar to t_final-kstar.

    append t_final.
    CLEAR wa1_coep.
    SKIP.
  ENDAT.

endloop.


loop at t_final.

  write:/10 t_final-kstar, 40 t_final-cjtdat.

endloop.

Edited by: Vara K on Jan 28, 2009 8:58 PM

0 Kudos
148

I got it.

I had to change LOOP.

loop at it_coep into wa_coep.

wa1_coep-wtgbtr = wa1_coep-wtgbtr + wa_coep-wtgbtr .

AT END OF kstar.

ULINE.

WRITE: / wa1_coep-wtgbtr , 30 wa1_coep-kstar .

move wa1_coep-wtgbtr to t_final-CJTDAT.

move wa_coep-kstar to t_final-kstar.

append t_final.

CLEAR wa1_coep.

SKIP.

ENDAT.

endloop.

Thank you all..

Rgds

Vara

Former Member
0 Kudos
148

Use COLLECT statement, before that you should declare the fields which you want to add as Numeric.

Let me know if you want answer in detail.

mubeen