Application Development and Automation 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: 
Read only

How to do Count

Former Member
0 Likes
480

Hi

I have got HKONT BLART BSCHL in a itab now I want to use an another field count where count of all the selected records is made per hkont at level 1, blart at level 2 and bschl at level 3

eg

hkont blart bschl count

766000 blank blank 55

766000 SA blank 40

766000 SA 40 15

766000 SA 50 25

766000 AB blank 15

766000 AB 40 5

766000 AB 50 10

in this for blart = AB 10 records of 50 bschl and 5 records of 40 bschl so total 15 , in that bschl shows blank, same for Blart = SA.

and the total of hkont shows 55 that is 15+40

ur help will be highly appreciate

3 REPLIES 3
Read only

Former Member
0 Likes
453

SORT itab.

LOOP AT itab.
  AT END OF bschl.
    SUM.
    tot_bschl = itab-bschl.
  ENDAT.

  AT END OF blart.
    SUM.
    tot_blart = itab-blart.
  ENDAT.

  AT END OF hkont.
    SUM.
    tot_hkont = itab-hkont.
  ENDAT.
ENDLOOP.

The fields starting with 'tot_' would contain subtotals for a given value in the field. You can capture these along with the corresponding bschl, blart and hkont and store in another table, write to the screen, etc.

Read only

Former Member
0 Likes
453

sort itab.

loop at itab.

at end of bschl.

sum.

move-corresponding itab to iout.

append out.

endat.

at end of blart.

sum.

move-corresponding itab to iout.

translate iout using '* '.

append out.

endat.

at end of hkont.

sum.

move-corresponding itab to iout.

translate iout using '* '.

append out.

endat.

endloop.

sort iout.

iout has the relevant data.

Read only

mike_mcinerney
Participant
0 Likes
453

In my opinion, the easies way is to COLLECT the data. Here's a working example... ...Mike


Report ZCreateStats .

Data : Begin of iTab Occurs 0 ,
       HKont Type HKont ,
       Blart Type Blart ,
       BSChl Type BSCHl ,
       End Of iTab .

Data : Begin of Stats Occurs 0 ,
       HKont Type HKont ,
       Blart Type Blart ,
       BSChl Type BSCHl ,
       n     Type I     ,
       End Of Stats     .

*---------------------------------------------------*

Perform Create_Your_Data .

*********************************************
* Just Collect The Data At Different Levels *
*********************************************

Loop at iTab Into Stats .
  Stats-N = 1 .          Collect Stats .
  Clear Stats-BsChl .    Collect Stats .
  Clear Stats-Blart .    Collect Stats .
EndLoop .


Perform Write_Stats .

*&--------------------------------------------------*
*&      Form  Create_Your_Data
*&--------------------------------------------------*
FORM Create_Your_Data .
  iTab-hKont = '0000766000' . 
  iTab-Blart = 'SA' .
  Do 15 Times .
   iTab-BsChl = '40' . Append iTab .
  EndDo .
       
  Do 25 Times .
   iTab-BsChl = '50' . Append iTab .
  EndDo .

  iTab-Blart = 'AB' .

  Do 5 Times .
   iTab-BsChl = '40' . Append iTab .
  EndDo .
       
  Do 10 Times .
   iTab-BsChl = '50' . Append iTab .
  EndDo .

ENDFORM.

*&------------------------------------------*
*&      Form  Write_Stats          
*&------------------------------------------*
FORM Write_Stats .              
  Sort Stats .
  Loop at Stats .
    Write : /1 Stats-HKont , Stats-Blart , 
               Stats-BSChl , Stats-n .
  EndLoop .    

ENDFORM.