Skip to Content
author's profile photo Former Member
Former Member

Delete data from internal table?

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Jan 18, 2008 at 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.

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2008 at 03:10 AM

    NO ANSWERD.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 18, 2008 at 04: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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.