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 count

Former Member
0 Likes
1,261

Dear all ,

I hav one requirment. Please no needful help.. => How can I not oblige?

i have one internal table

aaa bbb ccc

1 abc 20

1 abc 21

1 abc 23

1 abc 24

1 abc 25

1 abc 26

2 bca 30

2 bca 31

2 bca 32

2 bca 33

3 cab 40

3 cab 41

3 cab 42

3 cab 43

now i have want to count the same lines and have to display in another field in ALV

required output

aaa bbb ccc ddd

1 abc 20 6

1 abc 21

1 abc 23

1 abc 24

1 abc 25

1 abc 26

2 bca 30 4

2 bca 31

2 bca 32

2 bca 33

3 cab 40 4

3 cab 41

3 cab 42

3 cab 43

total 1's are 6

2's are 4

3's are 4.

how to display in ALV?

Moderator Message: Spec-dumping is not allowed. Please put some effort of your own first

Edited by: kishan P on Mar 14, 2011 4:53 PM

10 REPLIES 10
Read only

Former Member
0 Likes
1,222

Hi there,

You can use the offset concept, so that you can compare the each record from the internal.

With regards,

Aahbha

Read only

0 Likes
1,222

Hii...

can u send a sample code plss...

Read only

Read only

0 Likes
1,222

please see i have did like this.

select ebeln ebelp statu aedat matnr menge meins netpr peinh

up to 10 rows

from ekpo

into table it_ekko.

sort it_ekko by ebeln.

IT_EKKO1[] = IT_EKKO[].

LOOP AT IT_EKKO INTO WA_EKKO.

WA_EKKO2-EBELN = WA_EKKO-EBELN.

WA_EKKO2-cnt1 = WA_EKKO2-cnt1 + 1.

COLLECT WA_EKKO2 INTO IT_EKKO2.

clear wa_ekko2-cnt1.

clear wa_ekko2.

ENDLOOP.

Read only

0 Likes
1,222

now i have to display the count in it_ekko

loop at it_ekko into wa_ekko where ebeln = wa_ekko2-ebeln.

wa_ekko-cnt = wa_ekko2-cnt1.

modify it_ekko from wa_ekko.

endloop.

i'm not getting the output

Read only

0 Likes
1,222

Hi,

Sort your internal table by first field.

And then loop itab. Within that loop, use control break statement 'AT END OF' first field. within that AT END..ENDAT. increase the record count. Update your other internal table.

loop at itab into wa.
 wa2-fleid1 = wa1-field1.
 wa2-fleid2 = wa1-field2.
 wa2-fleid3 = wa1-field3.
 count = count + 1.
 at end  of wa-filed1.
  wa2-fleid4 = count.
  clear count.
 endat.
append wa2 to itab2.
endloop.

Thanks,

Naveen Inuganti.

Read only

0 Likes
1,222

hi,

i have to display in ALV

Read only

0 Likes
1,222

HI,

Use the function module 'REUSE_ALV_GRID_DISPLAY' for ALV grid display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid

i_grid_title = g_c_grid_title

is_layout = g_s_layout

it_fieldcat = g_t_fieldcat

i_save = 'A'

is_variant = g_variant

TABLES

t_outtab = g_t_outtab -


> give your final internal table here

EXCEPTIONS

program_error = 1

OTHERS = 2.

Regards,

Soumya.

Read only

nirajgadre
Active Contributor
0 Likes
1,222

Hi Anand,

try to implement below logic...

pass the internla table data into temp internal table.

sort temp internal table by aaa bbb.

clear count.

loop at temp internal table into workarea.

IF sy-tabix EQ 1.

lv_aaa = workarea-aaa.

lv_bbb = workarea-bbb.

ENDIF.

if lv_aaa EQ workarea-aaa and lv_bbb EQ workarea-bbb.

count = count + 1.

else.

update the final table column with the variable COUNT.

clear count.

ENDIF.

claer workarea.

ENDLoop.

Read only

Former Member
0 Likes
1,222

Hi

Use the logic below and before calling the function module to display ALV, pass the internal table with all 4 fields.

SORT it_test BY aaa ASCENDING.

LOOP AT it_test INTO wa_test.

lv_index = sy-tabix.

AT NEW aaa.

LOOP AT it_test INTO wa_test_temp WHERE aaa = wa_test-aaa.

lv_count = lv_count + 1.

ENDLOOP.

MOVE lv_count TO wa_test-ddd.

MODIFY it_test FROM wa_test INDEX lv_index TRANSPORTING ddd.

CLEAR lv_count.

ENDAT.

ENDLOOP.