Application Development and Automation 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: 
Read only

count in itab

Former Member
0 Likes
1,043

hi,

I have to find the count in the itab based on some conditions.

How to do it.

Pls help.

Priya

hi,

I have to find the count in the itab based on some conditions.

How to do it.

Pls help.

Priya

8 REPLIES 8
Read only

Former Member
0 Likes
924

HI,

use LOOP at ITAB where 'condition'.

increment a counter.

endloop.

delete ITAB entries for unwated condition

and use DESCRIBE TABLE LINES v_lines.

rgds,

latheesh

Read only

Former Member
0 Likes
924

Hi

You can only loop your table for those condition and count the number of hits.

LOOP AT ITAB WHERE

COUNT = COUNT + 1.

ENDLOOP.

Or you can count the records while appending them.

Max

Read only

suresh_datti
Active Contributor
0 Likes
924

hi,

try this..

data w_cnt type i.


loop at itab where <condition>
              transporting no fields.

w_cnt = w_cnt + 1.
endloop.
* W_cnt will have the count.

Regards,

Suresh Datti

Read only

Former Member
0 Likes
924

Hi,

If you have three condition and you want count accordingly then have three count variable and write logic for that.

loop at itab.

if condition 1.

count1 = count1+1.

elseif condition 2 .

count2 =count2 +1 .

elseif condition 3 .

count3 = count3 +1 .

endif.

<i>Hope This Info Helps YOU.</i>

Regards,

Raghav

Read only

Former Member
0 Likes
924

Hai Priya

Go through the following Code

************************************************************************

  • Table Declaration *

************************************************************************

TABLES: mara.

************************************************************************

  • Types Declaration *

************************************************************************

TYPES: BEGIN OF typ_mara,

matnr TYPE mara-matnr, "Material Number"

mbrsh TYPE mara-mbrsh, "Industrial Sector"

mtart TYPE mara-mtart, "Material Type"

meins TYPE mara-meins, "Base Unit of Measure"

END OF typ_mara.

************************************************************************

  • Intrnal tables Declaration *

************************************************************************

DATA: it_mara TYPE STANDARD TABLE OF typ_mara WITH HEADER LINE.

Data : V_Count type I.

Data : V_lines type I.

************************************************************************

  • Selection Screen *

************************************************************************

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS : p_mtart LIKE mara-mtart default 'ROH'.

SELECTION-SCREEN : END OF BLOCK b1.

************************************************************************

************************************************************************

  • At Selection-screen *

************************************************************************

AT SELECTION-SCREEN.

***

PERFORM validte_inputdata.

&----


*& Form Validte_Inputdta

&----


  • Validation of Select Option

----


FORM validte_inputdata .

SELECT SINGLE * FROM mara

WHERE mtart = p_mtart.

IF sy-subrc <> 0.

MESSAGE e001 WITH 'Material'(002) 'Type'(003) 'Does Not Exit'(400).

ENDIF.

ENDFORM. " Validte_Inputdta

START-OF-SELECTION.

***

SELECT matnr

mbrsh

mtart

meins

INTO TABLE it_mara

FROM mara

WHERE mtart = p_mtart.

if sy-subrc = 0.

sort it_mara by matnr.

else.

MESSAGE e001 WITH 'No data Found' ' For the Given'

'Selection Criteria'(400).

endif.

*First way

DESCRIBE TABLE it_mara LINES v_lines.

write 😕 v_lines.

*2nd way

loop at it_mara where mtart = p_mtart.

V_count = V_count + 1.

endloop.

write 😕 v_count.

Thanks & regards

Sreeni

Read only

Former Member
0 Likes
924

Hi Priya,

only one condition or many conditions

data: count type i.
Loop at itab where field = 'ABC'.
count = count + 1.

endif.

regards

vijay

Read only

former_member480923
Active Contributor
0 Likes
924

Hi

Itab1 - ur intial table.

itab2 - dummy table liek itab1.

try this code.......

itab2[] = itab1[].

delete itab2[] where = <condition>

describe itab2 lines <variable>.

hope this help

Anirban

Read only

Former Member
0 Likes
924

Hi,

You can use any of the following techinic.

1) loop at itab.

incr = incr + 1.

endloop.

write : incr.

2) By using "DESCRIBE" Statement

Thanks

Sunil.