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: 

internal table

Former Member
0 Kudos

like DELETE ADJACENT DUPLICATES i want add some same rows based on two same fields how it can be done

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can use Collect Statement.

COLLECT is used to Summarize the Data in internal table while adding the rows.

Collect <wa> into <itab>.

This statement compares the Non-numeric(Type C,N,D,T,X,String) fields of the work area with the Existing rows in the internal table. that means all the Non-numeric fields will act as key (For Eg Matno, Plant)

If a row is found with the same key:

It will add the Numeric fields instead of creating a new row.

If a row is not found with the same key:

It will create a new row like Append.

DATA : BEGIN OF ITAB1 OCCURS 0,

MATNR TYPE MARD-MATNR,

WERKS TYPE MARD-WERKS,

LABST TYPE MARD-LABST,

END OF ITAB.

DATA :WA LIKE ITAB1.

DATA: ITAB2 LIKE ITAB1 OCCURS 0.

SELECT MATNR WERKS LABST FROM MARD INTO TABLE ITAB1.

LOOP AT ITAB1 INTO WA.

COLLECT WA INTO ITAB2.

ENDLOOP.

Check the contents of both ITAB1 AND ITAB2.

Thanks.

4 REPLIES 4

paruchuri_nagesh
Active Contributor
0 Kudos

hi

use APPEND statement it will add another record

regards

Nagesh.Paruchuri

Former Member
0 Kudos

Hi,

LOOP AT itab.

if itab-field1 = itab-field2.

APPEND itab TO itab2.

endif.

ENDLOOP.

Now move all entry of itab2 to itab.

Regards,

Atish

Former Member
0 Kudos

Hi,

You can use Collect Statement.

COLLECT is used to Summarize the Data in internal table while adding the rows.

Collect <wa> into <itab>.

This statement compares the Non-numeric(Type C,N,D,T,X,String) fields of the work area with the Existing rows in the internal table. that means all the Non-numeric fields will act as key (For Eg Matno, Plant)

If a row is found with the same key:

It will add the Numeric fields instead of creating a new row.

If a row is not found with the same key:

It will create a new row like Append.

DATA : BEGIN OF ITAB1 OCCURS 0,

MATNR TYPE MARD-MATNR,

WERKS TYPE MARD-WERKS,

LABST TYPE MARD-LABST,

END OF ITAB.

DATA :WA LIKE ITAB1.

DATA: ITAB2 LIKE ITAB1 OCCURS 0.

SELECT MATNR WERKS LABST FROM MARD INTO TABLE ITAB1.

LOOP AT ITAB1 INTO WA.

COLLECT WA INTO ITAB2.

ENDLOOP.

Check the contents of both ITAB1 AND ITAB2.

Thanks.

Former Member
0 Kudos

Hi,

If it is not char field then key word COLLECT,

If it is char field then use the key word AT END OF <field>. and do your process..

If the hint is useful… Say thanks by reward….

Regards,

Prabhu Rajesh