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: 

How to Group itab values....

Former Member
0 Kudos

Hi Experts,

I have created a report and inserted into itab. The values are

Matkl Pend.Qty. Pend Value.

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

SPG 5 100.00

SPG 3 300.00

SRG 2 300.00

SRG 7 800.00

Now i want to group matkl and total of Pendqty & value into another table.

How to do that.

Pl. give some idea.

Yusuf

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

chk out the code below:

sort itab1 by matkl.

loop at itab1.

at new matkl.

read table itab1 index sy-tabix.

itab2-matkl = itab1-matkl.

endat.

at end of matkl.

sum.

itab2-pendqty = itab1-pendqty.

itab2-pendvalue = itab1-pendvalue.

append itab2.

clear itab2.

endat.

endloop.

regards,

Navneeth K.

4 REPLIES 4

0 Kudos

HI,

DATA: itab type table of <your table> with key MATKL.

Now use.

COLLECT wa into ITAB.

COLLECT sums up all the numeric fields of the table if the KEY's of the records are same.

SO when push a WOrkarea into a table using PUSH if there exists a record with the key it just adds the value that is there in the workarea to the record.

Example:

DATA: BEGIN OF seats,

carrid TYPE sflight-carrid,

connid TYPE sflight-connid,

seatsocc TYPE sflight-seatsocc,

END OF seats.

DATA seats_tab LIKE HASHED TABLE OF seats

WITH UNIQUE KEY carrid connid.

SELECT carrid connid seatsocc

FROM sflight

INTO seats.

COLLECT seats INTO seats_tab.

ENDSELECT.

Regards,

Sesh

.

.

Former Member
0 Kudos

hi,

chk out the code below:

sort itab1 by matkl.

loop at itab1.

at new matkl.

read table itab1 index sy-tabix.

itab2-matkl = itab1-matkl.

endat.

at end of matkl.

sum.

itab2-pendqty = itab1-pendqty.

itab2-pendvalue = itab1-pendvalue.

append itab2.

clear itab2.

endat.

endloop.

regards,

Navneeth K.

0 Kudos

Hi Navneeth,

Yes I tried your logic and works fine.

Thanks,

Yusuf

Former Member
0 Kudos

HI.

We can use collect statement for this isuse.

DATA: BEGIN WA,

Matkl type <table-filed>

Pend.Qty type <table-filed>.

Pend Value type <table-filed>.

END OF WA.

DATA ttab LIKE WA

WITH UNIQUE KEY Matkl Pend.Qty.

SELECT matfl pend_qty pend_val

FROM dbt

INTO itab.

COLLECT dbt INTO itab.

ENDSELECT.

Reward all helpfull answers.

Regards.

Jay