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

Count entries of an internal table

Hello,

i want to count the amount of entries in connection with a condition. in open-sql its fairly easy.

select count( <field_1> ) into cnt from table where <field_1> = xyz.

how can i rebuild it for an internal table?

thx 4 help

markus

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2006 at 02:27 PM

    hi,

    Use <b>describe table</b> statement ... check help for syntax..

    REgards,

    Santosh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2006 at 02:29 PM

    Hi Matkus,

    <b>Example</b>

    DATA: N1 TYPE I,

    N2 TYPE I,

    ITAB1 TYPE TABLE OF I INITIAL SIZE 10,

    ITAB2 TYPE I OCCURS 5.

    <b>DESCRIBE TABLE ITAB1 OCCURS N1.

    DESCRIBE TABLE ITAB2 OCCURS N2.</b>

    Result: OCC contains the value 10 and N2 the value 5.

    Reward points if this helps.

    Manish

    Message was edited by: Manish Kumar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2006 at 02:30 PM

    Hi Markus,

    Use the describe command to get the number of lines.

    data: ITAB2 like ITAB1.

    data: WS_LINES TYPE I.

    LOOP AT ITAB1.

    IF ITAB1-FIELD = 'XYZ'.

    ITAB2-FIELD = ITAB1-FIELD.

    APPEND ITAB2.

    ENDLOOP.

    Describe table itab2 lines ws_lines.

    Regards.

    Message was edited by: Biju Varughese

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2006 at 02:34 PM

    Hi,

    Do u mean to say total no of records in the internal table ?? If so then use the following:

    data: l_count type i.

    Describe table i_kna1 lines l_count. (make sure before using this command the internal table already populated other wise count will be zeor only.

    Now l_count will be the total no of records in the internal table i_kna1.

    Cheers.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      There is not a single statement which can give you the result but there are many others way to do it.

      One of the them is as below.

      DESCRIBE TABLE itab1 LINES lcnt1.

      itab1[] = itab[].

      DELETE itab1 where {condition or NOT}

      DESCRIBE TABLE itab1 LINES lcnt.

      lcnt is the number if you use a NOT condition otherwise you can do is lcnt1 - lcnt is the total count.

  • author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2006 at 02:38 PM

    Hi

    Please use the loop conditions

    <b>loop at itab where field = 'xyz'.

    cnt = cnt + 1.

    endloop.

    Write: cnt.</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2006 at 02:50 PM

    Hi

    Yes you are correct there is not one single statement which will give you the required output.

    BUt you could check the logic i gave earlier.

    i.e

    loop at (internal table) where (field) = 10.

    cnt = cnt + 1.

    endloop.

    here cnt will contain the number of entries in the internal table with the field eq 10.

    Hope this helps.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2006 at 04:29 PM

    Hi,

    loop at itab.

    case itab-fld1.

    when 'A'.

    cnt = cnt + 1.

    endcase.

    endloop.

    write cnt.

    Regards

    amole

    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.