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

collect it_

Former Member
0 Likes
779

Hi all,

I have internal table with bukrs numbers , how to create second table which will contain number of bukrs.

EG. I have bukrs 1020

1020

1008

1008

1008

tale must contain 1020 2 rec

1008 3 rec

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
757

Hi.

COLLECT statement SUMs the Numerical fields while comparing all the char fileds. so in your case you want to have count of Bukrs. To achevie this you need to have one more column for count initially this column holds the value in the internal table. When you loop this internal table and collect the data in other internal table then count field get's summed up for all common bukrs.

the other way..

SORT ITAB BY BUKRS.
LOOP AT itab.
CNT = CNT + 1.

AT END OF BUKRS.
  ITAB1-BUKRS = ITAB-BUKRS.
  ITAB1-CNT = CNT.
  APPEND ITAB1.
  CLEAR : ITAB1, CNT.
ENDAT.
ENDLOOP.

Hi.

COLLECT statement SUMs the Numerical fields while comparing all the char fileds. so in your case you want to have count of Bukrs. To achevie this you need to have one more column for count initially this column holds the value in the internal table. When you loop this internal table and collect the data in other internal table then count field get's summed up for all common bukrs.

the other way..

SORT ITAB BY BUKRS.
LOOP AT itab.
CNT = CNT + 1.

AT END OF BUKRS.
  ITAB1-BUKRS = ITAB-BUKRS.
  ITAB1-CNT = CNT.
  APPEND ITAB1.
  CLEAR : ITAB1, CNT.
ENDAT.
ENDLOOP.

4 REPLIES 4
Read only

Former Member
0 Likes
757

Hi Nick,

create another internal table with fields put first field as Bukrs.

next sort the internal table with Bukrs.

next delete abjacent duplicates comapring Bukrs.



data : begin of itab occurs 0,
1
2
3
4
bukrs.
         end of itab.

data : begin of itab1,
Bukrs
         end of itab.

Loop at itab.
move-corresponding itab to itab1.
append itab1.
endloop.

sort itab1.
delete adjacent duplicates from itab1.

Regards,

Prabhduas

Read only

Former Member
0 Likes
757

Use COLLECT statement.

For it create second field qty of type Integer. First put 1 to every record of it-qty.

Then collect them.

Type of t_serno1-qty is Integer .

LOOP AT t_tserno INTO w_tserno_ds.

w_tserno1_ds-fld1 = w_tserno_ds-fld1.

w_tserno1_ds-qty = 1.

COLLECT w_tserno1_ds INTO t_tserno1.

CLEAR : w_tserno1_ds.

ENDLOOP.

Thanks

Amurta

Read only

Former Member
0 Likes
757

build a table itab2 with two fields : BUKRS and NUM

pass value 1 to the NUM field

loop at itab.
itab1-bukrs = itab-bukrs.
itab1-num = 1.
append itab1.
endloop.

your ITAB2 looks like this

1020 1

1020 1

1008 1

1008 1

1008 1

Then have another itab like itab2 (Call it itab3)

do like this

loop at itab2.
collect itab2 into itab3.
endloop.

Regards,

Ravi

Read only

Former Member
0 Likes
758

Hi.

COLLECT statement SUMs the Numerical fields while comparing all the char fileds. so in your case you want to have count of Bukrs. To achevie this you need to have one more column for count initially this column holds the value in the internal table. When you loop this internal table and collect the data in other internal table then count field get's summed up for all common bukrs.

the other way..

SORT ITAB BY BUKRS.
LOOP AT itab.
CNT = CNT + 1.

AT END OF BUKRS.
  ITAB1-BUKRS = ITAB-BUKRS.
  ITAB1-CNT = CNT.
  APPEND ITAB1.
  CLEAR : ITAB1, CNT.
ENDAT.
ENDLOOP.