Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

internal table

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

Tags:
Former Member
Former Member replied

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question