01-18-2008 12:29 AM
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 knb1-bukrs,
zuonr LIKE bsid-zuonr, "sort key "CR01
belnr LIKE bsid-belnr,
kunnr LIKE kna1-kunnr,
bldat LIKE bsid-bldat,
budat LIKE bsid-budat,
netdt LIKE bsega-netdt,
waers LIKE bsid-waers,
wrbtr LIKE bsid-wrbtr,
shkzg LIKE bsid-shkzg,
xblnr LIKE bsid-xblnr, "WD041005a
sgtxt LIKE bsid-sgtxt,
dmbtr LIKE bsid-dmbtr,
END OF t.
DATA : t1 LIKE STANDARD TABLE OF t WITH HEADER LINE.
DATA : BEGIN OF t3 OCCURS 0,
kunnr TYPE kna1-kunnr,
END OF t3.
...........................................
End-of-selection.
Sort t.
LOOP AT t WHERE xblnr EQ space. "
t3-kunnr = t-kunnr.
APPEND t3.
ENDLOOP.
SORT t3.
DELETE ADJACENT DUPLICATES FROM t3.
LOOP AT t.
READ TABLE t3 WITH KEY kunnr = t-kunnr BINARY SEARCH.
IF sy-subrc EQ 0.
MOVE-CORRESPONDING t TO t1.
APPEND t1.
DELETE T.
ENDIF.
ENDLOOP.
01-18-2008 12:42 AM
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.
01-18-2008 12:42 AM
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.
01-18-2008 12:57 AM
hI,
Thank you for you advice.
My concern is that
the code :
sort t by xblnr.
delete t WHERE xblnr EQ space.
or
delete t WHERE xblnr is initial.
will just delet t where xblnr = space, while the other data
which belong to the same kunnr will still remain in table T.
Example:
Kunnr xblnr
1111 space
1111 0909
1111 0601
1222 0903
1333 0958
When the 1111 has space in xblnr, the other 0909
0601 which belong to the 1111 shoule be deleted too.
How can I do that?
Please help
Thank you in advance!
01-18-2008 1:00 AM
ok got you..
read table t into wa_t with key xblnr = space.
if sy-subrc eq 0.
lv_kunnr = wa_t-kunnr.
delete t where xblnr is initial.
delete t where kunnr = wa_t-kunnr.
endif.
award points if helpful.
Edited by: Jackandjay on Jan 17, 2008 8:02 PM
01-18-2008 1:16 AM
Hi,
Thank you for your e-mail.
I am confusing about what do you mean
lv_kunnr = wa_t-kunnr ?
lv_kunnr??
Thank you.
01-18-2008 1:25 AM
data: lv_kunnr type kunnr.
lv_kunnr is just a variable which holds the kunnr which has a space of xblnr. which we will be using to compare and delete all that records, which has a XBLNR field space and all its KUNNR
if table t is with a header line you can say
read table t with key xblnr = space.
if sy-subrc eq 0.
lv_kunnr = t-kunnr.
delete t where kunnr = wa_t-kunnr.
endif.
if table t does not have a header line , you need to declare a work area like data:wa_t like line of t. or t1. what so even ur table is and use the below code.
read table t into wa_t with key xblnr = space.
if sy-subrc eq 0.
lv_kunnr = wa_t-kunnr.
delete t where kunnr = wa_t-kunnr.
endif.
Edited by: Jackandjay on Jan 17, 2008 8:25 PM
01-18-2008 3:10 AM
01-18-2008 4:07 AM
DATA: BEGIN OF t OCCURS 0,
bukrs LIKE knb1-bukrs,
zuonr LIKE bsid-zuonr, "sort key "CR01
belnr LIKE bsid-belnr,
kunnr LIKE kna1-kunnr,
bldat LIKE bsid-bldat,
budat LIKE bsid-budat,
netdt LIKE bsega-netdt,
waers LIKE bsid-waers,
wrbtr LIKE bsid-wrbtr,
shkzg LIKE bsid-shkzg,
xblnr LIKE bsid-xblnr, "WD041005a
sgtxt LIKE bsid-sgtxt,
dmbtr LIKE bsid-dmbtr,
END OF t.
DATA : t1 LIKE STANDARD TABLE OF t WITH HEADER LINE.
DATA : BEGIN OF t3 OCCURS 0,
kunnr TYPE kna1-kunnr,
END OF t3.
...........................................
End-of-selection.
Sort t by XBLNR.
read table t where xblnr is initial.
if sy-subrc eq 0.
delete t where kunnr = t-kunnr.
endif.
LOOP AT t WHERE xblnr EQ space. "
t3-kunnr = t-kunnr.
APPEND t3.
ENDLOOP.
SORT t3.
DELETE ADJACENT DUPLICATES FROM t3.
LOOP AT t.
READ TABLE t3 WITH KEY kunnr = t-kunnr BINARY SEARCH.
IF sy-subrc EQ 0.
MOVE-CORRESPONDING t TO t1.
APPEND t1.
DELETE T.
ENDIF.
ENDLOOP.