2008 Jan 10 4:07 PM
hi,
i have to check my itab if there are 20 or more blnr for one vtref.
at the checking i have to use the first 12 positions of the blnr.
i tried it with this loop but it doesn't work.
hope u can help me.
LOOP AT itab.
AT NEW vtref.
lf_merkblnr = itab-blnr.
CLEAR counter.
REFRESH wa_itab.
ENDAT.
IF itab-blnr(12) EQ lf_merkblnr(12).
+counter = counter + 1.+
APPEND itab TO wa_itab.
ENDIF.
AT LAST." vtref.
IF counter LE 20.
DELETE itab WHERE vtref = wa_itab-vtref.
ENDIF.
ENDAT.
ENDLOOP.
regards,
tobias
2008 Jan 10 4:25 PM
clear : counter.
LOOP AT itab where blnr eq lf_merkblnr.
IF itab-blnr(12) EQ lf_merkblnr(12).
counter = counter + 1.
APPEND itab TO wa_itab.
ENDIF.
AT end of vtref.
IF counter LE 20.
DELETE itab WHERE vtref = wa_itab-vtref.
ENDIF.
ENDAT.
ENDLOOP.
keep it mind that the first field in itab will be vtref and also sorted with vtref.
a®s
Edited by: a®s on Jan 10, 2008 11:25 AM
2008 Jan 10 6:51 PM
Hi aRs,
clear : counter.
LOOP AT itab where blnr eq lf_merkblnr. "all rows will not be looped, where is lf_merkblnr being set???
IF itab-blnr(12) EQ lf_merkblnr(12).
counter = counter + 1.
APPEND itab TO wa_itab.
ENDIF.
AT end of vtref.
IF counter LE 20.
DELETE itab WHERE vtref = wa_itab-vtref.
ENDIF.
ENDAT.
ENDLOOP.
I think the correct one will be:
LOOP AT itab.
AT NEW vtref.
lf_merkblnr = itab-blnr.
CLEAR counter.
REFRESH wa_itab.
ENDAT.
IF itab-blnr(12) EQ lf_merkblnr(12).
counter = counter + 1.
APPEND itab TO wa_itab.
ENDIF.
AT end of vtref.
IF counter LT 20. "LT and not LE for 20 or more
DELETE itab WHERE vtref = itab-vtref. "and not wa_itab
ENDIF.
ENDAT.
ENDLOOP.
Hope this helps.
Thanks
Sanjeev
2008 Jan 11 10:32 AM
there's still a failure in the code
when i debugg the program my lf_merkblnr stays empty but i dont know why.
hope someone has n idea why.
regards,
tobias
2008 Jan 11 11:35 AM
Hi Tobias,
the field sequence in the record of itab must be VTREF BLNR ....
And it must be sorted.
Regards,
Clemens
2008 Jan 11 11:53 AM
Hi Clemens,
i know and done this already.
DATA: BEGIN OF itab OCCURS 1000,
vtref TYPE dfkkop-vtref,
blnr TYPE dfkkop-xblnr,
bukrs TYPE dfkkop-bukrs,
gpart TYPE dfkkop-gpart,
n1 TYPE adrc-name1,
n2 TYPE adrc-name2,
n3 TYPE adrc-name3,
augst TYPE dfkkop-augst,
END OF itab.
SORT itab BY vtref blnr.
LOOP AT itab.
AT NEW vtref.
lf_merkblnr = itab-blnr.
CLEAR counter.
REFRESH wa_itab.
ENDAT.
IF itab-blnr(12) EQ lf_merkblnr(12).
counter = counter + 1.
APPEND itab TO wa_itab.
ENDIF.
AT END OF vtref.
IF counter LT 20.
DELETE itab WHERE vtref = itab-vtref.
ENDIF.
ENDAT.
ENDLOOP.
that's the reason why i don't unterstand it, that lf_merkblnr is empty.
the values of itab-blnr are changing in the loop but lf_merkblnr stays empty.
regards,
tobias
2008 Jan 10 5:00 PM
CHECK this code.
but actually i did not understand ur req.ment. if it has count le 20. then deleting the entries from itab. if it had more than 20 entries for the same vtref, wht will be the process.
TYPES: BEGIN OF ty_itab,
vtref(10) TYPE c,
belnr(20) TYPE c,
END OF ty_itab.
DATA: itab TYPE ty_itab OCCURS 0 WITH HEADER LINE,
wa_itab TYPE ty_itab OCCURS 0 WITH HEADER LINE,
temp_itab TYPE ty_itab OCCURS 0 WITH HEADER LINE.
DATA: temp(12) TYPE c.
DATA: counter(02) TYPE c,
flag TYPE c,
set TYPE c.
itab-vtref = '0000000001'.
itab-belnr = '000000000010001'.
APPEND itab.
itab-vtref = '0000000001'.
itab-belnr = '000000000010002'.
APPEND itab.
itab-vtref = '0000000004'.
itab-belnr = '000000000010003'.
APPEND itab.
itab-vtref = '0000000005'.
itab-belnr = '000000000010004'.
APPEND itab.
itab-vtref = '0000000001'.
itab-belnr = '000000000010005'.
APPEND itab.
itab-vtref = '0000000002'.
itab-belnr = '000000000010001'.
APPEND itab.
itab-vtref = '0000000002'.
itab-belnr = '000000000010002'.
APPEND itab.
itab-vtref = '0000000007'.
itab-belnr = '000000000010003'.
APPEND itab.
itab-vtref = '0000000008'.
itab-belnr = '000000000010004'.
APPEND itab.
itab-vtref = '0000000002'.
itab-belnr = '000000000010005'.
APPEND itab.
SORT itab BY vtref belnr.
LOOP AT itab.
AT NEW vtref.
CLEAR counter.
REFRESH wa_itab.
flag = 'X'.
ENDAT.
IF flag = 'X'.
temp = itab-belnr+0(12).
CLEAR: flag.
ENDIF.
IF itab-belnr(12) EQ temp.
counter = counter + 1.
APPEND itab TO wa_itab.
ENDIF.
AT END OF vtref.
IF counter LE 2.
set = 'X'.
ENDIF.
ENDAT.
IF set = 'X'.
APPEND LINES OF wa_itab TO temp_itab.
CLEAR: set.
ENDIF.
ENDLOOP.
LOOP AT temp_itab.
DELETE TABLE itab FROM temp_itab.
ENDLOOP.