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: 

How to count no of line present in internal table depending on condtion.

0 Kudos
1,777

Hi,

I want to count no of line present in one internal table.

For example: I have an internal table with output tax line item

lwa_gt_alv-ty_auste_ep consider this internal table having 100 lines

depending on the condition copany code(BUKRS), Year(GJAHR), and Document number(BELNR).

I want to count the number of line present for above mentioned condition in internal table lwa_gt_alv-ty_auste_ep.

Kindly help as soon as possible.

Thanks and best regards,

Niteesh Rai

1 ACCEPTED SOLUTION

Former Member
0 Kudos
228

Hello


data: counter type i.
loop at itab where BUKRS = " condition for bukrs here
               and GJAHR = " condition for gjahr here
               and BELNR = " condition for belnr here
  counter = counter + 1.
endloop.
write counter.

5 REPLIES 5

Former Member
0 Kudos
229

Hello


data: counter type i.
loop at itab where BUKRS = " condition for bukrs here
               and GJAHR = " condition for gjahr here
               and BELNR = " condition for belnr here
  counter = counter + 1.
endloop.
write counter.

0 Kudos
228

Hi ,

Problem in looping through this internal table is, I am allready looping on the internal table and inside the loop i need to count the no of line present for the mentioned condtion.

I dont want to loop it again because it may cause a performance issue in future. Is there any conditon like "read table itab" through which I can transer the no of line satisfied my condition and then I will describe the new internal table ?

Regards,

Niteesh

0 Kudos
228

Hello

So, count into exist loop/endloop:


data: counter type i.
loop at itab.
* do anything here ...
  if BUKRS = " condition for bukrs here
  and GJAHR = " condition for gjahr here
  and BELNR = " condition for belnr here
    counter = counter + 1.
  endif.
* do anything here ...
endloop.
write counter.

Also you may to try other way:


data: counter type i.
data: itab1 like itab occurs 0.
itab1[] = itab[].
delete itab1 where BUKRS NE " condition for bukrs here
               and GJAHR NE " condition for gjahr here
               and BELNR NE " condition for belnr here
describe table itab1 lines counter.
write counter.

0 Kudos
228

Hello Nitesh

An optimized version would be:


data: counter type i.
loop at itab TRANSPORTING NO FIELDS 
            where BUKRS = " condition for bukrs here
               and GJAHR = " condition for gjahr here
               and BELNR = " condition for belnr here
  counter = counter + 1.
endloop.
write counter.


" Or:
  lt_itab2 = itab[].
  DELETE lt_itab2 WHERE ( bukrs NE '1000'     OR
                                          gjahr  NE '2009'      OR
                                          belnr  NE '12345678' ).
  DESCRIBE TABLE lt_itab2 LINES counter.

Regards

Uwe

0 Kudos
228

Hi Uwe,

Thanks alot, this problem is resolved.

With best regards,