Skip to Content
author's profile photo Former Member
Former Member

select with count

Hallow I have to do a select from table pa0001 (table of employee )and I wont just to count the number of employee in this table . how can I do that .

This is my select how can I improve it (like persg).

( i heard about select count but i dont now how to use it)

Thanks for your time.

SELECT

FROM pa0001

INTO wa_teken_itab-ex_immobile

WHERE persg = '6'

AND persg = '7'

AND persg = '8'

AND orgeh = 'Z'

AND orgeh NE '00009999'

AND stell = 'A'.

regards

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 02:29 PM

    Hello Antonio,

    U can use like this

    SELECT <b>COUNT(*)</b>

    FROM pa0001

    INTO wa_teken_itab-ex_immobile

    WHERE persg = '6'

    AND persg = '7'

    AND persg = '8'

    AND orgeh = 'Z'

    AND orgeh NE '00009999'

    AND stell = 'A'.

    If this one is not working then,

    Select all the records into Itab and use.

    data: lv_no type i.

    DESCRIBE TABLE ITAB LINES LV_NO.

    LV_NO will have he number of records.

    You can also use the SY-DBCNT.,

    If useful reward.

    Vasanth

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 02:26 PM
    SELECT COUNT( * ) FROM pa0001
    INTO wa_teken_itab-ex_immobile
    WHERE persg = '6'
    AND persg = '7'
    AND persg = '8'
    AND orgeh = 'Z'
    AND orgeh NE '00009999'
    AND stell = 'A'.
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 02:28 PM

    HI,

    SELECT COUNT( DISTINCT EMPID )

    FROM pa0001

    INTO IT_EMPID_COUNT

    WHERE persg = '6'

    AND persg = '7'

    AND persg = '8'

    AND orgeh = 'Z'

    AND orgeh NE '00009999'

    AND stell = 'A'.

    now the field IT_EMPID_COUNT will have the No of records

    Regards

    Sudheer

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 02:30 PM

    try this code

    data : count type i.

    select count( * ) into count FROM pa0001

    INTO wa_teken_itab-ex_immobile

    WHERE persg = '6'

    AND persg = '7'

    AND persg = '8'

    AND orgeh = 'Z'

    AND orgeh NE '00009999'

    AND stell = 'A'.

    Dont forget to reward points.

    Regards,

    barath.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 09, 2007 at 02:30 PM

    You can't use COUNT, because there will be more than one record per employee. These records are date sensitive, so everytime there is a change, a new record is created with begin/end dates. So you will need to get all of these records within your condition, then sort by PERNR and delete the adjacent records.

    
    report zrich_0001.
    
    data: no_employees type i.
    data: ipa0001 type table of pa0001.
    
    select * from pa0001
                 into table ipa0001
                     where persg = '6'
                     and persg = '7'
                     and persg = '8'
                     and orgeh = 'Z'
                     and orgeh ne '00009999'
                     and stell = 'A'.
    
    sort ipa0001 by pernr ascending.
    delete adjacent duplicates from ipa0001 comparing pernr.
    
    
    describe table ipa0001 lines no_employees.
    
    write:/ no_employees.
    
    

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 02:37 PM

    Maybe I'm crazy, but is there ever going to be a record where persg = '6' AND '7' AND '8'?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 03:44 PM

    select * from pa0001

    into table itab

    where persg = '6'

    and persg = '7'

    and persg = '8'

    and orgeh = 'Z'

    and orgeh ne '00009999'

    and stell = 'A'.

    sort itab by pernr ascending.

    delete adjacent duplicates from itab comparing pernr.

    describe table itab lines count.

    write:/ count.

    AWARD POINTS

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.