Hi,
I have a problem in deleting data from internal table.
When xblnr = space, all the belnr data belong to the same kunnr should be deleted from internal t.
My problem is that the belnr data still remain in the inter table T when xblnr = space.
Could you please correct my coding? Thank you.

DATA: BEGIN OF t OCCURS 0,
bukrs LIKE knb1bukrs,
zuonr LIKE bsidzuonr, "sort key "CR01
belnr LIKE bsidbelnr,
kunnr LIKE kna1kunnr,
bldat LIKE bsidbldat,
budat LIKE bsidbudat,
netdt LIKE bseganetdt,
waers LIKE bsidwaers,
wrbtr LIKE bsidwrbtr,
shkzg LIKE bsidshkzg,
xblnr LIKE bsidxblnr, "WD041005a
sgtxt LIKE bsidsgtxt,
dmbtr LIKE bsiddmbtr,
END OF t.
DATA : t1 LIKE STANDARD TABLE OF t WITH HEADER LINE.
DATA : BEGIN OF t3 OCCURS 0,
kunnr TYPE kna1kunnr,
END OF t3.
...........................................
Endofselection.
Sort t.
LOOP AT t WHERE xblnr EQ space. "
t3kunnr = tkunnr.
APPEND t3.
ENDLOOP.
SORT t3.
DELETE ADJACENT DUPLICATES FROM t3.
LOOP AT t.
READ TABLE t3 WITH KEY kunnr = tkunnr BINARY SEARCH.
IF sysubrc EQ 0.
MOVECORRESPONDING t TO t1.
APPEND t1.
DELETE T.
ENDIF.
ENDLOOP.
no need of loop and stuff, just say
sort t by xblnr.
delete t WHERE xblnr EQ space.
or
delete t WHERE xblnr is initial.
DATA: BEGIN OF t OCCURS 0,
bukrs LIKE knb1bukrs,
zuonr LIKE bsidzuonr, "sort key "CR01
belnr LIKE bsidbelnr,
kunnr LIKE kna1kunnr,
bldat LIKE bsidbldat,
budat LIKE bsidbudat,
netdt LIKE bseganetdt,
waers LIKE bsidwaers,
wrbtr LIKE bsidwrbtr,
shkzg LIKE bsidshkzg,
xblnr LIKE bsidxblnr, "WD041005a
sgtxt LIKE bsidsgtxt,
dmbtr LIKE bsiddmbtr,
END OF t.
DATA : t1 LIKE STANDARD TABLE OF t WITH HEADER LINE.
DATA : BEGIN OF t3 OCCURS 0,
kunnr TYPE kna1kunnr,
END OF t3.
...........................................
Endofselection.
Sort t by XBLNR.
read table t where xblnr is initial.
if sysubrc eq 0.
delete t where kunnr = tkunnr.
endif.
LOOP AT t WHERE xblnr EQ space. "
t3kunnr = tkunnr.
APPEND t3.
ENDLOOP.
SORT t3.
DELETE ADJACENT DUPLICATES FROM t3.
LOOP AT t.
READ TABLE t3 WITH KEY kunnr = tkunnr BINARY SEARCH.
IF sysubrc EQ 0.
MOVECORRESPONDING t TO t1.
APPEND t1.
DELETE T.
ENDIF.
ENDLOOP.
Add a comment