Skip to Content

code logic to get number of rows of particular document in internal table

eg: if a internal table (it_example ) has documents numbers

AB001 (row 1)

AB001(row 2)

AB001(row 3)

AB002(row 4)

AB002(row 5)

AB003(row 6)

then the output should display number of rows

AB001 = 3

AB002 = 2

AB003 = 1

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Apr 16 at 02:55 PM

    Use the COLLECT statement to summarise into a HASHED table. See documentation for details.

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 17 at 02:54 AM

    one more option: LOOP AT GROUP of document with addition: SIZE to get the number of rows.

    Add comment
    10|10000 characters needed characters exceeded

    • I used to use COLLECT in my coding but since there is new LOOP AT...GROUP BY i really enjoy it. there are some advantages like i can control the key in group, also i can "colect" not just numeric field but other things too.anw, its depend on what we working on.

  • Apr 17 at 05:24 AM

    Hello Aishwarya NA,

    you can try with loop at group as Quynh said, it is new statement but I like it so much.

    Just try this code.

    TYPES: BEGIN OF ts_cols,
             col1 TYPE char5,
             col2 TYPE char5,
             col3 TYPE char5,
           END OF ts_cols.
    
    
    TYPES: BEGIN OF ts_group_cols,
             col1 TYPE char5,
             size TYPE i,
           END OF ts_group_cols.
    
    
    DATA wa TYPE ts_group_cols.
    DATA tab TYPE TABLE OF ts_group_cols.
    
    
    TYPES tt_cols TYPE STANDARD TABLE OF ts_cols WITH DEFAULT KEY.
    DATA(lt_tab) = VALUE tt_cols(
      ( col1 = 'AB001 ' col2 = 'Test2' col3 = 'Hap' )
      ( col1 = 'AB001 ' col2 = 'Test2' col3 = 'Morg' )
      ( col1 = 'AB001 ' col2 = 'Aishw' col3 = 'Tag' )
      ( col1 = 'AB002 ' col2 = 'Ibo' col3 = 'Sund' )
      ( col1 = 'AB002 ' col2 = 'Ibrah' col3 = 'Frei' )
      ( col1 = 'AB003 ' col2 = 'Sad' col3 = 'Nix' ) ).
    
    
    LOOP AT lt_tab INTO DATA(ls_col)
    GROUP BY ( id = ls_col-col1
               size = GROUP SIZE )
    ASCENDING REFERENCE INTO DATA(group_ref).
    
    
      wa-col1 = group_ref->*-id.
      wa-size = group_ref->*-size.
      APPEND wa TO tab.
    ENDLOOP.
    BREAK-POINT.
    


    Best regards

    Ebrahim


    loopatgroup.jpg (100.2 kB)
    Add comment
    10|10000 characters needed characters exceeded