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

Help on SELECT Query - count

Former Member
0 Likes
1,430

Hi Gurus,

I am new to Abap and have a specific requirement.

I have attached my coding below.

I need to count the number of exidv in my internal table. Now my coding displays 10 exidvs correctly, but not counting as 10.

Pls help.

Coding follows.

Types: begin of t_final,

tknum type vttk-tknum,

vbeln type vttp-vbeln,

wadat type likp-wadat, bolnr type likp-bolnr, btgew type likp-btgew, volum type likp-volum, gewei type likp-gewei,

vgbel type lips-vgbel,

name1 type adrc-name1," vbeln type vbpa-vbeln,

street type adrc-street, city1 type adrc-city1, post_code1 type adrc-post_code1,

exidv type vekp-exidv,

count type n length 3,

end of t_final.

Data: it_final type t_final occurs 0,

wg_final type t_final.

data: exidv_chk type vekp-exidv, count type n length 3.

select atknum bvbeln

cwadat cbolnr cbtgew cvolum c~gewei

d~vgbel

fstreet fname1 fcity1 fpost_code1

h~exidv

count( distinct h~exidv )

from vttk as a inner join vttp as b on atknum = btknum

inner join likp as c on cvbeln = bvbeln

inner join lips as d on cvbeln = dvbeln

inner join vbpa as e on dvgbel = evbeln

inner join adrc as f on eadrnr = faddrnumber

inner join vepo as g on cvbeln = gvbeln

inner join vekp as h on gvenum = hvenum

into corresponding fields of table it_final where atknum = g_tknum and eparvw = 'WE'

group by atknum bvbeln cwadat cbolnr cbtgew cvolum cgewei dvgbel fstreet fname1 fcity1 fpost_code1 h~exidv.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,383

Hi,

Do like this after your select statement with out the COUNT option.

SORT itab BY exidv. " itab the internal table having the selected records

DELETE itab WHERE exidv IS INITIAL. " Deletes lines where there is no exidv

DELETE ADJACENT DUPLICATES FROM itab COMPARING exidv.

count = lines( itab ). " Here the count will be stored by the number of unique exidv

Note: Instead of COUNT you can use DESCRIBE to get the lines of ITAB

Hope this may help you.

Regards,

Smart Varghese

7 REPLIES 7
Read only

vallamuthu_madheswaran2
Active Contributor
0 Likes
1,383

In select query remove the count.

after select query use the following.

DELETE itab WHERE exidv is initial.

data: num type i.

DESCRIBE TABLE ITAB LINES num.

num ==> count of the internal table.

Thanks & Regards,

Vallamuthu.M

Read only

0 Likes
1,383

Thanks Vallamuthu.

But this method ultimately counts the number of lines of the internal table and not exidv.

I mean if internal table contains 10 exidvs in which 2 are repeating, I need the count as 8. But this method counts as 10 which is size of internal table.

Any other suggestions pls...

Read only

Former Member
0 Likes
1,383

Hi,

In the above code you can add the following lines :-

DELETE itab WHERE exidv is initial.

sort itab with exidv.

delete adjascent duplicates from itab comparing exidv.

data: num type i.

DESCRIBE TABLE ITAB LINES num.

num ==> count of the internal table.

This will give you the exact count of exidv without repetitions.

Hope this helps.

Regards,

Samreen.

Read only

Former Member
0 Likes
1,383

Well then you could declare a separate internal table for the exidv values alone and make the count.

after the select statement,


data: begin of itab1 occurs 0,
         exidv  type exidv .
        end of itab1.

loop at itab.
itab-exidv  = itab1-exidv .
append itab1.
clear itab1.
endloop.

delete adjacent duplicates from itab1.

describe table itab1 lines l1.

Vikranth

Read only

Former Member
0 Likes
1,383

Hi,

Please refer reply down.

Regards,

Smart Varghese

Read only

Former Member
0 Likes
1,384

Hi,

Do like this after your select statement with out the COUNT option.

SORT itab BY exidv. " itab the internal table having the selected records

DELETE itab WHERE exidv IS INITIAL. " Deletes lines where there is no exidv

DELETE ADJACENT DUPLICATES FROM itab COMPARING exidv.

count = lines( itab ). " Here the count will be stored by the number of unique exidv

Note: Instead of COUNT you can use DESCRIBE to get the lines of ITAB

Hope this may help you.

Regards,

Smart Varghese

Read only

0 Likes
1,383

Thanks everyone,

Now the issue is solved.

But anyone know why the count in select query doesnot work? If it is wrong it should have given syntax error. But its not.

Can someone explain?

Again thanks for timely help.