cancel
Showing results for 
Search instead for 
Did you mean: 

itab filtering

former_member457420
Participant
0 Kudos

Hi Guys,

Have a situation as follows:

Have an internal table as below.Have filled the itab with a select statement.

DATA: BEGIN OF t2 OCCURS 0,	
	mdocnr TYPE rkwa-mblnr,
        mjahr TYPE rkwa-mjahr,
        zeile TYPE rkwa-zeile,
        budat TYPE rkwa-budat,
        matnr TYPE rkwa-matnr,
        belnr TYPE rkwa-belnr,
        bwart TYPE mseg-bwart,
        sobkz TYPE mseg-sobkz,
        lifnr TYPE mseg-lifnr,
        kdauf TYPE mseg-kdauf,	
	posnn TYPE vbfa-posnn,
        posnr TYPE ser01-posnr,
        obknr TYPE ser01-obknr,
        sernr TYPE equi-sernr,
        matn2 TYPE objk-matnr,
        mtart TYPE mara-mtart,

	END OF t2.

When looping through the itab:

When the itab contains for example, 3 rows(It could be more than 3 as well) with the same meaterial document number(mdocnr) and when t2-posnr > t2-posnn for all the 3 rows,I want to delete all the rows(In our example - 2 rows) except 1 and modify this row so that I want to make the posnr and posnn value TO empty strings and update or write it back to the itab.

When the hit is only one.Ie: where only 1 row is found where t2-posnr > t2-posnn ,I want to make the posnr and posnn value of this single row TO empty strings and update or write it back to the itab.

How could it be done....

Would appreciate if someone could post a sample code.

Thanks

P

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello pazzuzu

you can filter by

sort itab by mblnr (and all other fields).

DELETE ADJACENT DUPLICATES FROM itab comparing mblnr ( all other fields).

former_member457420
Participant
0 Kudos

How will I find the number of rows for example if the hit was 3(as in my example) or 1 ?

How will I edit or modify the one row in itab and write it back?

Former Member
0 Kudos

Hi,

You can get the total no.of records in t2.

Describe t2 length v_len.

If v_len > 1.

<your logic to delete the records based on t2-posnr>t2-posnn.>

elseif t2 = 1 .

if t2-posnr > t2-posnn.

<Empty the values for t2-posnr,t2-posnn.>

endif.

endif.

Thanks.

Ramya.

Answers (1)

Answers (1)

Former Member
0 Kudos

hi,

first sort your internal based on the key field and delete adjacent duplicates.

*********

sort t2 by <key>.

delete adjacent duplicates from t2.

*********

as you said that your' mblnr' is same for all rows,

then check for the condition whether that posnn > posnr inside the loop.

**********

if posnn > posnr.

*... then delete that row based upon the index.

before loop starts take a counter and assign default value '1' to it.

then after each loop pass increment the counter by '1'.

in this way you can achieve this.

regards,

sasi kanth.

former_member457420
Participant
0 Kudos

Thank You Guys.....