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: 

Count lines for internal table no condition known

0 Kudos

hello,

I need to count the sum of persons in a internal table which have the same costcenter, "where kostl = ABC" is not possible in this case, all kostl are selected

Data is like

pernr stat1 stat2 bukrs kostl (and many more fields)

I need the counts of persons with the same kostl for a second internal table

Any Ideas?

Thanks

2 REPLIES 2

sunil_mani
Active Participant

Hi Andre,

Use group by KOSTL and COUNT( 'PERSON') in your select statement. See the similar syntax below -

SELECT COUNT( 'PARTNER' ) AS count,
type
FROM but000
GROUP BY type
INTO TABLE @DATA(lt_partner).
Your Scenario:-
SELECT COUNT( 'PERSON' ) AS count,
kostl
FROM 'Your table name'
GROUP BY KOSTL
INTO TABLE @DATA(lt_person).

Sandra_Rossi
Active Contributor
0 Kudos

Not sure what exactly you're looking for, my 2 cents:

TYPES: BEGIN OF ty_first_itab_line,
         kostl TYPE kostl,
       END OF ty_first_itab_line,
       ty_first_itab TYPE STANDARD TABLE OF ty_first_itab_line WITH EMPTY KEY,
       BEGIN OF ty_second_itab_line,
         kostl TYPE kostl,
         count TYPE i,
       END OF ty_second_itab_line,
       ty_second_itab TYPE STANDARD TABLE OF ty_second_itab_line WITH EMPTY KEY.
DATA(first_itab) = VALUE ty_first_itab( ( kostl = 'A' ) ( kostl = 'A' ) ).
DATA(second_itab) = VALUE ty_second_itab(
              FOR GROUPS <group> OF <line> IN first_itab
              GROUP BY ( kostl = <line>-kostl count = GROUP SIZE )
              ( count = <group>-count
                kostl = <group>-kostl ) ).
ASSERT second_itab = VALUE ty_second_itab( ( count = 2 kostl = 'A' ) ).