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 of records

Former Member
0 Kudos

Hello,

i have an internal table itab table with records like :

number Status

1 NEW

2 NEW

3 NEW

4 NEW

5 CHANGE

6 CHANGE

8 DELETE

i want to have the count , who many records have new status ( 3 ) , change status ( 2 ) and delete status (1).

Thanks in advance.

Prem

1 ACCEPTED SOLUTION

former_member1245113
Active Contributor
0 Kudos

Hi Prem

change your Itab just like this and add one more field to give you the no of records

data : begin of itab occurs 0

status

number

no_rows

end of itab

here you pass 1 to each row showing that there is one row and modify your table

sort itab by status

loop at itab

collect (this KEY word COLLET sums all the numeric fields of the itab and give you back)

endloop

Best Regards

Ramchander Rao.K

Edited by: ramchander krishnamraju on Dec 10, 2008 5:44 AM

9 REPLIES 9

GauthamV
Active Contributor
0 Kudos

hi,

use control break statements and define a variable and count the records.

at new status.

..........

..........

endat.

former_member181995
Active Contributor
0 Kudos

press F1 on At end of.

Former Member
0 Kudos

Hi,

Use Control break stmt for this...

AT FIRST

AT NEW field

AT END Of field

AT LAST.

LOOP ur internal table,before that sort ur internal table.

with in LOOP ENDLOOP use control break stmt..

Try this....

Former Member
0 Kudos

Hi try this,

data : count_n type i,

count_c type i,

count_d type i.

loop at itab into wa.

if wa-status = 'NEW'.

count_n = count_n + 1.

elseif wa-status = 'CHANGE'.

count_c = count_c + 1.

else.

count_d = count_d + 1.

endif.

endloop.

write : count_n , count_c ,count_d .

regards,

Mr A

former_member1245113
Active Contributor
0 Kudos

Hi Prem

change your Itab just like this and add one more field to give you the no of records

data : begin of itab occurs 0

status

number

no_rows

end of itab

here you pass 1 to each row showing that there is one row and modify your table

sort itab by status

loop at itab

collect (this KEY word COLLET sums all the numeric fields of the itab and give you back)

endloop

Best Regards

Ramchander Rao.K

Edited by: ramchander krishnamraju on Dec 10, 2008 5:44 AM

Former Member
0 Kudos

Hi Prem,

Try this code

data: begin of itab1 occurs 0,

new(10),

cnt like sy-tabix.

end of itab1.

Loop at itab.

itab1-new = itab-v1.

itab1-cnt = 1.

collect itab1.

endloop.

Regards

Sathis

Former Member
0 Kudos

Hi,

Try this code

data: vnew type i,

vchange type i,

vdelete type i.

Loop at itab.

case status.

when 'NEW'.

vnew = vnew + 1.

when 'CHANGE'.

vchange = vchange + 1.

when 'DELETE'.

vdelete = vdelete + 1.

endcase.

Endloop.

write:/ 'New Status = ' , vnew, 'Change status = ', vchange, 'Delete status = ' , vdelete.

Regards

Thabitha.

0 Kudos

Hi

Hope you find this useful.

If your internal table has fields number and status , make sure you place the field status as the first one as shown below .

Data : begin of itab occurs 0,
       status type string,
        num type i,
     endof itab.

Then sort your internal table.

SORT ITAB BY STATUS .

Then declare a variable "count" to keep the count of records.

use the code as shown below.

loop at itab .
  at new status.
    count  = 1.
    endat.
  at end of status .
      write : / itab-status , count .
      endat.
      count  = count + 1.
 endloop.

Former Member
0 Kudos

Hi

Hope you find this useful.

If your internal table has fields number and status , make sure you place the field status as the first one as shown below .

Data : begin of itab occurs 0,
       status type string,
        num type i,
     endof itab.

Then sort your internal table.

SORT ITAB BY STATUS .

Then declare a variable "count" to keep the count of records.

use the code as shown below.

loop at itab .
  at new status.
    count  = 1.
    endat.
  at end of status .
      write : / itab-status , count .
      endat.
      count  = count + 1.
 endloop.