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: 

Count matnr

Former Member
0 Kudos

Moderator message: please use a more informative subject in future

Dear Experts;

I am fetch values And stored in IT_EKPO. this itab available record in below format.

ebeln matnr count

10 lo45 0

10 l045 0

10 o77 0

13 li12. 0

my case is count matnr comparing ebeln.that is my output is stored it_ekpo1.for this way.

ebeln matnr count

10 lo45 2

10 lo77 1

13 li12 1

I am trying this code.is not working .

 it_ekpo1[] = it_ekpo[].
sort it_ekpo1 by matnr comparing ebeln.
sort it_ekpo by matnr comparing  ebeln.

loop at it_ekpo.
  clear count1.
 loop at it_ekpo1 where matnr = it_ekpo-matnr.
    read table it_ekpo1 with key ebeln = it_ekko-ebeln.
      loop at it_ekpo1 where matnr = it_ekpo-matnr.

    count1 = count1 + 1.
  endloop.
  it_count-matnr = it_ekpo-matnr.
  it_count-count1 = count1.
  append it_count.
  clear it_count.
endloop.

<<text removed>>

regards,

raj

Edited by: Matt on Dec 11, 2008 2:40 PM - Please use tags around your ABAP. Do not say "ASAP".

6 REPLIES 6

former_member1245113
Active Contributor
0 Kudos

Hi Sai,

Just use COLLECT key word within the loop

loop at itab.

collect itab.

and check the value of count in the debug mode

endloop

Regardss

Ramchander Rao.K

Former Member
0 Kudos

sort it_ekpo by ebeln matnr .

loop at it_ekpo.

count1 = count1 + 1.

it_ekpo1 = it_ekpo.

at end of matnr.

it_ekpo1 = count1.

append it_ekpo1.

clear count1.

endat.

Endloop.

or other way..

it_ekpo-count = 1.

modify it_ekpo where count eq 0 transporting count.

loop at it_ekpo.

collect it_ekpo1 from it_ekpo..

Endloop.

Edited by: avinash kodarapu on Dec 11, 2008 5:32 PM

Former Member
0 Kudos

Hi,

Use the following code.

Take counter as numeric value

Sort the internal table by matnr, ebeln.

Loop at it_ekko wa_ekko.

at end of ebeln.

sum.

move wa_ekko fields to wa_ekko1

then append wa_ekko1 to it_ekko1

endat.

endloop.

regards

Pavan

kesavadas_thekkillath
Active Contributor
0 Kudos

sort it_ekpo by ebeln matnr ascending.

loop at it_ekpo.

cnt = cn + 1.

at end of matnr.

read table it_ekpo index sy-tabix.

it_ekpo1-ebeln = it_ekpo-ebeln.

it_ekpo1-matnr = it_ekpo-matnr.

it_ekpo1-count = cnt.

append it_ekpo1.

cnt = 0.

endat.

endloop.

Former Member
0 Kudos

Hi Soosai,

The following code will work for you.

int_tab - Source table:

ebeln    matnr                                            count
10         lo45                                              0
10         lo45                                              0
10         o77                                               0
13         li12                                               0

int_tab1 - Target table:

ebeln    matnr                                            count
10         lo45                                              2
10         o77                                               1
13         li12                                               1

SORT int_tab BY ebeln matnr.

LOOP AT int_tab INTO wa_tab.
  w_count = w_count + 1.
  wa_tab1 = wa_tab.
  AT END OF matnr.

    wa_tab1-count = w_count.
    CLEAR w_count.
    APPEND wa_tab1 TO int_tab1.

  ENDAT.
ENDLOOP.

Hope this will help you.

Regards,

Manoj Kumar P

matt
Active Contributor
0 Kudos

Please use a more informative subject in future

Also - don't use ASAP. And do use tags around your ABAP