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

iNTERNAL tABLE qUERY

Former Member
0 Likes
586

I have an internal table :

ITAB containing :

================

Material1 decription

Material1 decription

Material1 decription

Material1 decription

Material2 decription

Material2 decription

Material2 decription

Material2 decription

Material3 decription

Material3 decription

Material3 decription

=============

I want the outout in another table as

Material1 4

Material2 4

Material3 3

===========

Here 4 and 3 are the number of records of each material in the internal table.

Any logic?

thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
561

loop at itab into wa.

at new materia..

flag =X.

clear count.

endat.

if flag = x.

count = count + 1.

endif.

endloop.

6 REPLIES 6
Read only

Former Member
0 Likes
562

loop at itab into wa.

at new materia..

flag =X.

clear count.

endat.

if flag = x.

count = count + 1.

endif.

endloop.

Read only

Former Member
0 Likes
561

Hi Pranu,

loop at itab into wa.

at end of matnr.

append wa to itab2.

endat.

endloop.

Regards,

Kaveri

Read only

JozsefSzikszai
Active Contributor
0 Likes
561

hi Pranu,

DATA : BEGIN OF itab2 OCCURS 0,

material TYPE matnr,

number TYPE i,

END OF itab2.

LOOP at itab. " Your original itab

itab2-material = itab-material.

itab2-number = 1.

COLLECT itab2.

ENDLOOP.

hope this helps

ec

Read only

Former Member
0 Likes
561

take another int table as itab1 with matnr and count field.

data : counter type i,

wtab like itab.

sort itab by matnr.

loop at itab.

counter = counter + 1.

mov-corresponding itab to wtab.

at end of itab-matnr.

itab1-matnr = wtab-matnr.

itab1-count = counter.

append itab1.

clear counter.

endat.

endloop.

regards

shiba dutta

Read only

Former Member
0 Likes
561

data: cnt type i.

data: itab type table of spfli .

data: begin of itab1 occurs 0,

carrid type spfli-carrid,

count type i,

end of itab1.

data: wa type spfli.

cnt = 0.

select * from spfli into table itab.

loop at itab into wa.

cnt = cnt + 1.

at end of carrid.

itab1-carrid = wa-carrid.

itab1-count = cnt.

append itab1.

cnt = 0.

endat.

endloop.

loop at itab1.

write:/ itab1-carrid, itab1-count.

endloop.

Read only

pavel_parshenkov2
Participant
0 Likes
561

HI Try like this.


DATA lt_newtab LIKE oldtab OCCURS 0 WITH HEADER LINE.
DATA lwa_item  LIKE lt_newtab.

SORT oldtab BY material decribtion.

LOOP AT oldtab.
  CLEAR lwa_item.
  MOVE oldtab TO lwa_item.
  AT END OF material.
    APPEND lwa_item TO t_newtab.
  ENDAT.
ENDLOOP.