cancel
Showing results for 
Search instead for 
Did you mean: 

Grouping fields of the internal table

Former Member
0 Kudos
119

hi all,

i ' m using an internal table, and y need to group fields like the following example:

what i have:

werks arbpl aufnr

ca01 ka mecha 1

ca01 ka mecha 1

ca01 ka li 1

ca01 ka li 1

what i need:

werks arbpl aufnr

ca01 ka mecha 2

ca01 ka li 2

can anyone help me?

Regards,

Roxana.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can use COLLECT..But the AUFNR field should be numeric

Thanks,

Naren

Former Member
0 Kudos

Hi Narendran,

what i have was wrong:

werks arbpl aufnr

ca01 ka mecha 10123

ca01 ka mecha 10124

ca01 ka li 1 10125

ca01 ka li 1 10126

what i need was ok:

werks arbpl aufnr

ca01 ka mecha 2

ca01 ka li 2

Aufnr is numeric, but i need to count how many order are in that plant and work center.

Regards,

Answers (3)

Answers (3)

Former Member
0 Kudos

I use the following logic to group data of an internal table.

werk arbpl count

ca01 kam 1

ca01 kam 2

loop at i_table into w_table.

add 1 to v_count.

at end of arbpl.

v_count = w_table-count.

clear v_count.

endat.

endloop.

and the result was

ca01 kam 3

Former Member
0 Kudos

See the below example code for Grouping all fields:

REPORT ZTEST_IEVENTS no standard page heading

line-count 40(2).

tables : vbap.

data : begin of i_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_vbap.

data wa_vbap like line of i_vbap.

data v_flag type c.

select-options s_vbeln for vbap-vbeln obligatory.

start-of-selection.

select vbeln

posnr

matnr

kwmeng

netpr from vbap

into table i_vbap

where vbeln in s_vbeln.

sort i_vbap by vbeln posnr.

end-of-selection.

loop at i_vbap.

move i_vbap to wa_vbap.

at first.

write:/2 'Order #',15 'Item #',28 'Material #',50 'Qty', 70 'Net value'.

skip 1.

endat.

at new vbeln.

write:/2 wa_vbap-vbeln,15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

v_flag = 'X'.

endat.

if v_flag ne 'X'.

write:/15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

endif.

at end of vbeln.

sum.

skip 1.

write:/5 'Sub totals', 47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

endat.

at last .

skip 1.

sum.

write:/5 'Grand Totals',47 i_vbap-kwmeng,65 i_vbap-netpr.

endat.

clear v_flag.

endloop.

amit_khare
Active Contributor
0 Kudos

As an alternative you can try this, I am not sure how much will it help -

sort itab by werks arbpl aufnr.

loop at itab.

at new aufnr

write:/ <fields>,count.

count =0.

endat.

count = count +1.

endloop.

Regards,

Amit