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 identify which count belong to which value?

Former Member
0 Kudos

hi all,

currently after i select all my distinct value and give it a total count how do i know which count belong to which value. for etc,

i have 2 values: male and female.

how do i code it in a way where it can count me the total number of male and total number of female and write it out in ABAP.

etc:

male 2 (count)

female 5 (count)

hope that someone know a way to this! thx!

Edited by: Daphne on Dec 27, 2007 10:35 AM

14 REPLIES 14

Former Member
0 Kudos

Hi,

Suppose itab1 is your table contains male and female

declare same internal table like itab1 i.e. itab2 and itab3

do itab2= itab1

delete itab2 where field <> male.

itab3 = itab1

delete itab3 where field <> female.

describe table itab2 lines lin.

descrile table itab3 lines lin2.

write 😕 lin, lin2.

these contains only male and female count .

regards,

siva chalasani.

reward points if found usefull.

Former Member
0 Kudos

data: begin of wa,

gender type ztable-gender,

tot type i,

end of wa.

data: itab like table of wa.

select gender count(*) from ztable into table itab group by gender.

Former Member
0 Kudos

hi,

what if i have more than 10 value??? wont i have to declare another 10 itab which make it messy and complicated? do u have a easier way out? or do u mind giving me a sample basic code for reference? thx~

Former Member
0 Kudos

hi Ramu,

that SQL statement u suggest with a group by in the end does it mean it can print out the count according to the individual values?

0 Kudos

Dear Daphne,

For example....if my table is having data like below....

empno gender

1 male

2 female

3 male

4 female

5 male

now my itab wil contain.....

gender tot

male 3

female 2

loop at itab into wa.

write:/ wa-gender, wa-tot.

endloop.

will print the above result.

Former Member
0 Kudos

Can u use GROUP BY <fileldname> addition in your query and try?

Reward if helpful.

Regards,

Sathishkumar.V

Former Member
0 Kudos

sorry the group by do not have any effect.

Former Member
0 Kudos

hi Ramu,

can i have a more complete code for this starting from the declaring to the print out of the result?

cos i am totally confused. really sorry and thx abt it

0 Kudos

Hi Daphne,

For example in my system i am having a table name = ztable which is having two fields like name,gender.

In my program, i want to count the no.of males, females in my ztable.

Declaration part:

*the workarea which will going to have the gender and its corresponding counts.

data: begin of wa,

gender type ztable-gender,

total type i,

end of wa.

*the internal table which will going to have the gender and its corresponding counts.

data: itab like table of wa.

*here i am grouping by gender, because i want to count of gender only....

select gender count(*) from ztable into table itab group by gender.

loop at itab into wa.

write:/ wa-gender, wa-total.

endloop.

*the above loop will print the corresponding gender and its counts

Please give your table structure for better understanding...and your piece of code too..

Former Member
0 Kudos

Hi,

Try like this .you may get solution.

report zsample.

TABLES:zmdemain.

DATA:itab LIKE zmdemain OCCURS 0 WITH HEADER LINE.

DATA:v_0 TYPE i ,v_1 TYPE i.

DATA:v_date LIKE sy-datum.

START-OF-SELECTION.

v_date = sy-datum - 30.

CLEAR: v_0,v_1.

SELECT * INTO zmdemain FROM zmdemain

WHERE ernam = 'HZ232M' AND erdat LT v_date.

IF zmdemain-male = 'X'.

v_1 = v_1 + 1.

ELSEIF zmdemain-female = 'X'.

v_0 = v_0 + 1.

ENDIF.

WRITE:/ v_0,v_1,zmdemain-serial_no,zmdemain-male,zmdemain-female.

ENDSELECT.

Here you replace withztable with your table and in where clause you put condition as your reqt and take 2 variables like v_male and v_female and keep on incrementing.

If any issues please rever back.

Regds

Sivaparvathi

Please reward points if helpful.

data:begin of itab occurs 0,

gender(6),

age type i,

end of itab.

itab-gender = 'F'.

itab-age = '20'.

append itab.clear itab.

suppose you got this type of data from select stmt.

clear:v_cnt_F,v_cnt_M.

loop at itab.

if itab-gender - 'F'.

v_cnt_F = v_cnt_F + 1.

elseif itab-gender = 'M'.

v_cnt_M = v_cnt_M + 1.

endif.

endloop.

write:/ ' Male count:::', v_cnt_M.

write:/ ' FeMale count:::', v_cnt_F.

this is the logic i think you reposted for some others query.

Regds

Sivaparvathi

Please reward points if helpful...

Edited by: Siva Parvathi on Dec 27, 2007 11:11 AM

Former Member
0 Kudos

hi siva,

thx for the code u gave me. but my situation is my value is not hardcode. it is dynamically choosen from user at screen 1 before it direct the user to screen 2 for the result of the individual count.

0 Kudos

Hi Daphne,

if your requirement is based on your input selection...then

data: total type i.

if chkmale1 = 'X'.

select count(*) from ztable into total where gender = 'MALE'.

write:/ 'No. of Males : ', total.

elseif chkfemale1 = 'X'.

select count(*) from ztable into total where gender = 'FEMALE'.

write:/ 'No. of Females : ', total.

endif.

Former Member
0 Kudos

hi ramu,

thx for ur guidance. but for my case, it is a dynamically value choosen by user. so it can be any table or column choosen by the user. i dun have specific table structure.

Former Member
0 Kudos

solve