How to count the per group-entries and put them in the new table

Hello Guru,
I want to sort the table cdhdr.
for example :
  SELECT objectclas objectid changenr   *******
  INTO TABLE cdhdr_data
  FROM cdhdr
  WHERE ( ********) AND
        objectclas = i_objectclas
The problem that I need to order the table by objectclas and objectid.
Let say objectclas is always MATERIAL.
Let's assume our key is changenr. May be our key will change to "objectclas objectid".
So, my problem that I need to get the number of the same "objectid" with different "changenr".
And also I need to put the count number of each object id with different changenr in the table cdhdr_data.
For example
objectclas        objectid       changenr      count
MATERIAL      00***001      1                   3
MATERIAL      00***001      4                   3
MATERIAL      00***001      7                   3
MATERIAL      00***005      2                   2
MATERIAL      00***005      6                   2
MATERIAL      00***003      5                   2
MATERIAL      00***003      3                   2
So later I'm going to use it.
LOOP AT cdhdr_data FROM sy-tabix TO ( sy-tabix + cdhdr_dat ( sy-tabix ) + count - 1 )
some optimized cdpos processing
IF entry found.
*don't loose time
*change the boundery
sy-tabix = count
ENDIF.
ENDLOOP.
Best Regards,
Kais

Hi Marcin,
Thanks for replying.
I'm having a trouble.
Let say I got an error on insert into ****.
It says me that the object (i_)cdhdr_data is not known.
Why, should I avoid to put objectclas = i_objectclas there.
I need to have MATERIAL OR DOKUMENT.
I can't just put 10000entries like that.
I'm also sceptic about how much this operation will cost.
Because I need to proceed the data with cdpos.
And This's why I'm doing that.
Later with this implementation I'm gone use LOOP AT *** FROM sy-tabix TO ****.
If I use my method, it will cost lower than inserting, changing, ...
I rather ignore the objectid and don't make any processing.
But with your solution I can say its rapidly.
Let assume there's n entries in cdhdr and m entries per n in cdpos.
So my algorithm will select n entries and will follow n*m entries but some of them will be proceeded an other not.
in cdhdr :
for n entries : n * 1 selecting
in cdpos :
always : n*m comparing,
processing between : n1 - nm
With you algorithm we will do :
in cdhdr :
for n entries : n* (1 selection + 1 modifing + 1 appending) <=> each operation cost O(1)
in cdpos :
for comparing between : n1 - nm
processing between : n1 - nm
Let see the middle value :
your case :
in cdhdr  we have : n * O(3) ~ n * O(1) ~ O(n)
in cdpos :
O(c(nm)/2) + O(p(nm))2) ~ O((cp)((nm)/2)) ~ O(d(nm))  d= (cp)/2 ~ p/2
we know that O(c*n) ~ O (n) ; c ist a constant
c : comparing cost
p : processing cost
p >> c
my case :
in cdhdr  we have : n * O(1) ~ O(n)
in cdpos :
O(c(nm)) + O(p((nm)/2)) ~ ? maybe O(d(nm)) d = c + (p/2) ~ p/2
c : comparing cost
p : processing cost
p >> c
Ok, this in theorie, but in reality I've no idea.
Is there a mathematician there ?
Regards,
Kais
FORM get_cdhdr_data_modified_1
  USING
    i_from_date TYPE dats
    i_from_time TYPE terf
    i_to_date TYPE dats
    i_to_time TYPE terf
    i_objectclas TYPE j_objnr
  CHANGING
    cdhdr_data TYPE SORTED TABLE.
types: begin of t_cdhdr_data,
            objectclas type cdhdr-objectclas,
            objectid type cdhdr-objectid,
            changenr type cdhdr-changenr,
            count type i,
      end of t_cdhdr_data.
  DATA : i_cdhdr_data type table of t_cdhdr_data with key objectclas objectid changenr with header line.
  DATA: st_index LIKE sy-tabix, count TYPE i.
  SELECT objectclas objectid changenr
  INTO TABLE i_cdhdr_data
  FROM cdhdr
  WHERE ( ( udate GT i_from_date AND udate LT i_to_date ) OR
          ( udate EQ i_from_date AND udate NE i_to_date AND utime GE i_from_time ) OR
          ( udate EQ i_to_date AND ( udate NE i_from_date OR utime GE i_from_time ) AND utime LE i_to_time )
        ) AND
        objectclas = i_objectclas.
  INSERT INTO i_cdhdr_data FROM i_cdhdr_data.
ENDSELECT.
LOOP AT i_cdhdr_data.
  AT NEW objectid.
    "remember start position
    st_index = sy-tabix.
  endat
  at end of objectid.
  count = sy-tabix - st_index + 1. "count accual position
  cdhrd_data-count = count. "now you have how many entries are in each objectid
  MODIFY TABLE i_cdhdr_data FROM i_cdhdr_data.
ENDAT.
ENDLOOP.

Similar Messages

Maybe you are looking for

  • Deskew a pdf in photoshop?

    I'm trying to digitize a book for someone, however, after trying to deskew the pages by using both, Acrobat-> optimize pdf, and also using the crop and straighten tools on photoshop, I am left with the top of the pdf being straight and the bottom sli

  • Minimum Number of registered custom id:s/numbers to be registered for purchasing all F-secure products from network

    How many custom-id:s / custom-numbers etc. customer has to register(minimum)in order to purchase All f-secure products on ALL possible platforms?

  • Need a help to create user and assign BP to it

    Hi, I have requirement to create Users (like SU01) in CRM and for that users need to create BP with role EMPLOYEE and assign BP to that USER. Can anybody please help on which Function Module I need to use to create user and assign BP to it. Thanks in

  • Workspace Manager and APEX

    I was experimenting with using workspace manager (via DBMS_WM) to version a set of tables. Does everything I want, easily and quickly. However, when I update versioned objects in APEX, and then look at the HIST table, the user name is APEXPUBLIC_USER

  • Why can't I see my audio files in iWeb?

    When I open iWeb/iPhoto/Keynote etc I can't see Audio files to add them in. I can access photos and movies but not audio files. I can't even access Garageband files! Does anyone have any ideas as to why this is and how I can fix it???