Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Delete data from internal table?

Former Member
0 Likes
1,312

Hi,

I have an internal table T as following:

-


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.

  • REFRESH t3.*

LOOP AT t WHERE xblnr EQ space. "change from belnr to xblnr by LI_Y 2008/01/16

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.

-


The outcome like this:

KUNNR XBLNR

11111 SPACE

11111 A1B2C3

11111 DEF34

22222 SPACE

22222 0980

33333 98987

33333 78648

44444 9804

My problem is that

*The first KUNNR (11111) which has space value was deleted,

But the second KUNNR (22222) which has space value can not be deleted.*

My Question

Is there any problem in my refresh t3?

How to correc the coding inorder to deleted all the recording of KUNNR which XBLNR has space value there????

Please help?

Thank you!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,281

hi.,

use delete t3 where XBLNR = Space.

Reward points if useful

Chandra

14 REPLIES 14
Read only

Former Member
0 Likes
1,282

hi.,

use delete t3 where XBLNR = Space.

Reward points if useful

Chandra

Read only

0 Likes
1,281

Hi,

Where should I put the

delete t3 where XBLNR = Space.

in my coding?

Thank you!

studyabap

Read only

Former Member
0 Likes
1,281

Hi,

Use this statement.

delete itab where xblnr is initial.

regards,

Santosh Thorat

Read only

former_member156446
Active Contributor
0 Likes
1,281

Hi Study

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.

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.

Read only

0 Likes
1,281

HI Jackandjay,

I write the coding as you advice like:

-


END-OF-SELECTION.

SORT t BY xblnr.

READ TABLE t with key xblnr = space.

IF sy-subrc EQ 0.

DELETE t WHERE kunnr = t-kunnr.

ENDIF.

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.

-


The result was not change. That means:

kunnr xblnr

11111 space

11111 aaaaaaaaa

22222 bbbbbbbbb

22222 space

33333 ccccccccc

*The records for 111111 has been deleted, but the records for 22222 can not been deleted.

  • If I select 11111 or 22222 seperatly to execute It works, but when I select 11111 TO 33333, It was not work.

how can I correct it.

Please help, thank you

Read only

0 Likes
1,281

But as per your question , you need to delete all KUNNR which have atleast one space in XBLNR.. so the code works accordingly...

How to differentiate not to delete 2222 with space? and delete 11111 with space?

Read only

0 Likes
1,281

Hi,

Yes, I need to delete all KUNNR which have at least one space in XBLNR.

But the outcome is that The 11111 which have at least one space in XBLNR was deleted from t and was shown in alv. While 22222 which supposed to be deleted either (because it has at least one space in XBLNR) was still shown in alv.

How can I correct it?

Thankyou.

studyabap.

Read only

0 Likes
1,281

Hi try this .....

END-OF-SELECTION.

SORT t BY xblnr.

loop at t where xblnr = space.

DELETE t WHERE kunnr = t-kunnr.

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.

award points if helpful...

Read only

0 Likes
1,281

Hi,

I tried that , but the outcome did not change.

When I the Kunnr which is supposed to be seleted into t3 could not be selected.

Is there any other methods??

Thank you in advance.

studyabc

Read only

Former Member
0 Likes
1,281

Hi,

Use the following statement.

Delete itab where XBLNR eq 'SPACE'.

Should work.

Regards,

Lalit

Read only

Former Member
0 Likes
1,281

hi studyabap,

after reading your code i can understand ur problem.The first problem i.e., is there any problem in refresh t3. yes problem is there better you can use the below statement.

delete t3 where XBLNR = Space

and i think now it will work.and automatically your other problems also solved if u use this statement.

kindly reward me if it's ok

Read only

Former Member
0 Likes
1,281

YOU CAN MAKE USE OF THIS STATEMENT

delete t3 where XBLNR = Space.

Read only

0 Likes
1,281

Hi,

Thank you for your advice.

How can i write the coding?

Please guid!!

thank you

Read only

0 Likes
1,281

Hi,

You can use the below code :

delete itab where field = space.

Thanks,

Sri.