09-27-2007 6:25 PM
Hi I have an internal table like this.
Invoice gross Group
161 1000 C
162 1200 C
162 1200 C
163 111 ABC
163 613 XYZ
163 613 PQR
Now I want to know the totel no. of group values for an invoice no.
Like, 161 -
1
162------1
163------3 etc.
How to do that.
Points are awaited for your answers.</b>
09-27-2007 6:30 PM
Hi,
Use AT NEW and AT END OF
Try something like this:
may need some tweaking..
LOOP at the table.
AT NEW invoice
initialize the count.
END AT.
count+1.
AT END OF invoice
write invoice, count.
ENDAT.
ENDLOOP.
Message was edited by:
Sri Tayi
09-27-2007 6:32 PM
sort the itab & use control breaks ie
data w_cnt type i.
sort itab.
loop at itab.
w_cnt = w_cnt + 1.
at end of invoice.
write: / itab-invoice, w_cnt.
clear w_cnt.
endat.
endloop.
~Suresh
09-27-2007 6:35 PM
Hi
Check this
sort itab by invno group.
* For Unique count you need to delete duplicates
delete adjacent duplicates comparing invno group.
sort itab by invno.
loop at itab.
at end of invno.
move 'Y' to v_flg.
endat.
v_no = v_no + 1.
if v_flg eq 'Y'.
move itab-invno to itab1-invno.
move v_no to itab1-count.
append itab1.
clear : v_flg, v_no.
endif.
endloop.
After this loop your itab1 contains the invno wise total count of group.
a®
09-27-2007 8:07 PM
Hi,
I can't sort main ITAB1 , because of variation in gross amount field. I am getting the count. But for invoice 162, I am getting count 2. But I suppose to get 1.
09-27-2007 8:15 PM
Hi,
If not sort the table and delete adjacent duplicates your result will not come correct.
For this you can make a copy of your main ITAB into ITAB_T
Like this way , and do your find for count on group by using ITAB_T
itab_t[] = itab[].
sort itab_t by invno group.
* For Unique count you need to delete duplicates
delete adjacent duplicates from itab_t comparing invno group.
sort itab_t by invno.
loop at itab_t.
at end of invno.
move 'Y' to v_flg.
endat.
v_no = v_no + 1.
if v_flg eq 'Y'.
move itab_t-invno to itab1-invno.
move v_no to itab1-count.
append itab1.
clear : v_flg, v_no.
endif.
endloop.
a®
09-27-2007 8:23 PM
09-27-2007 6:35 PM
Hi Priya,
In order to know the total number of group values for an invoice number,it is better to first store the invoce numbers(161,162,163 etc.) in a new internal table.
Then loop at the internal table(tab) into wa.
Inside it loop at the new internal table(itab1) nto wa1 which consists of the invoice numbers.
if wa-invoice = wa1-invoice.
counter = counter + 1.
else.
continue.
endif.
endloop.
write : counter.
endloop.
In case you have any further clarifications,do let me know.
Regards,
Puneet Jhari.
09-27-2007 6:40 PM
Hi
check the following code.
data : v_cnt type i,
v_cnt1 type i.
data : begin of itab occurs 0,
num type i,
end of itab.
itab-num = '1'.
append itab.
clear itab.
itab-num = '161'.
append itab.
clear itab.
itab-num = '162'.
append itab.
clear itab.
itab-num = '162'.
append itab.
clear itab.
itab-num = '163'.
append itab.
clear itab.
itab-num = '163'.
append itab.
clear itab.
itab-num = '163'.
append itab.
clear itab.
sort itab by num.
loop at itab.
at new num.
v_cnt1 = sy-tabix.
endat.
at end of num.
v_cnt = sy-tabix - v_cnt1 + 1.
write 😕 itab-num , v_cnt.
clear : v_cnt,v_cnt1.
endat.
endloop.
Regards,
Padmam.