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: 

Field Count

Former Member
0 Kudos

Hi,

I want to know the fields that are filled in the table.

For exanple I have an internal table which contains 10 fields with field name FIELD1,FIELD2,...ETC.

Suppose there are 100 records in the table.Now I want to know how many records have field1 value.Same for other records.

Do let me know.

Thanks in advance.

SP

6 REPLIES 6

Former Member
0 Kudos

data lv_count     type i value 0.

loop at itab into wa.
  if not wa-field1 is initial.
    lv_count = lv_count + 1.
  endif.
endloop.

write: 'Number of records with a value in Field1: ', lv_count.

krishnendu_laha
Active Contributor
0 Kudos

Hi Sandeep,

I think this is a crude requirement. you have to follow this path:

data: loc_count1 type p, loc_count2 type p, loc_count3 type p.

loop at int_data.

if field1 ne space.

loc_count1 = loc_count1 + 1.

endif.

if field2 ne space.

loc_count2 = loc_count2 + 1.

endif.

if field3 ne space.

loc_count3 = loc_count3 + 1.

endif.

endloop.

Hope this will solve ur problem.

Regards

Krish

former_member582701
Contributor
0 Kudos

LOOP AT itab.

IF NOT itab-field IS INITIAL.

v_counter = v_counter + 1.

ENDIF.

ENDLOOP.

You need one counter for any field you want to check.

I think there is not any sentence in SAP for do it authomatically.

regards

former_member189059
Active Contributor
0 Kudos
data: lv_count type i value 0.

loop at itab where field1 <> ''.
 lv_count = lv_count + 1.
endloop.

write:/ lv_count , 'non blank values'.

Former Member
0 Kudos

Hi Sandeep,

U can loop at the itab with condtion where field1 <> ' '.

Create a counter initialized with value 0, and within the loop incrase the count value by 1.

so therefore for every hit, it will increase the count value by 1..atlast u ll have the no.of records which have the value for field1.

Code follows,

data: count type i value 0.

loop at itab where field1 <> ' '.

count = count + 1.

endloop.

Write: Count.

hope this helps.

Former Member
0 Kudos

hin sandeep, seeing some of the other solution i´d still advice you to check against initial state and not against space or ' ', since e.G. the initial value of a type p field is 0,00, which again is not equal to space, but still it´s not a filled value.