Application Development 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: 

Delete records without loop comparing two internal table...

Former Member
0 Kudos

Hi Experts,

I have written two select statement shown below. In it_vbap the whole data is comming apart from auart = 'ZBEO' or auart = 'ZBOR' or auart = 'ZOLD' or auart = 'ZOEO' . In it_vbak it is comming O.K. I want to delete records apart from ZBEO,ZBOR,ZOLD, & ZBEO comparing from it_vbap without loop comparing it_vbap and it_vbak. How to write ? Pl. help me.

SELECT * FROM vbap client specified

INTO CORRESPONDING FIELDS OF TABLE it_vbap

WHERE mandt = sy-mandt and

erdat IN dt1 AND

matnr IN matnr1 AND

gsber = 'HIP' AND

vstel = 'BSP'.

SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE it_vbak

FOR ALL ENTRIES IN it_vbap WHERE vbeln = it_vbap-vbeln

and ( auart = 'ZBEO' or auart = 'ZBOR'

or auart = 'ZOLD' or auart = 'ZOEO' ) .

Yusuf

4 REPLIES 4

former_member195698
Active Contributor
0 Kudos

Instead of writing different queries on VBAP and VBAK .. you can use JOIN On the two tables.

Other Option is loop at the interal table VBAK and prepare a range ra_vbeln for the Document Number (VBELN). Then you can use the statement

delete it_vbap where vbeln in ra_vbeln.

Reward if useful

Regards,

Abhishek

Former Member
0 Kudos

Hi,

Delete it_vabk where auart NE 'ZBEO' or auart NE 'ZBOR' or auart NE 'ZOLD' or auart NE 'ZOEO'.

Delete it_vabk where auart NE 'ZBEO' or auart NE 'ZBOR' or auart NE 'ZOLD' or auart NE 'ZOEO'.

Or best one is :

SELECT * FROM vbap client specified

INTO CORRESPONDING FIELDS OF TABLE it_vbap

WHERE mandt = sy-mandt and

erdat IN dt1 AND

matnr IN matnr1 AND

gsber = 'HIP' AND

vstel = 'BSP' and

AUART = 'ZBEO' and auart = 'ZBOR' and auart = 'ZOLD' and auart = 'ZOEO'.

Regards,

Vijay Mekala.

0 Kudos

Hello Vijay,

The document type is not present in VBAP.

Regards,

Abhishek

0 Kudos

> Delete it_vabk where auart NE 'ZBEO' or auart NE

> 'ZBOR' or auart NE 'ZOLD' or auart NE 'ZOEO'.

Just a small annotation. This code would result in deleting the compete table. If you want to delete all entries with keys other than the 4 stated you have to use AND insteat of OR.

NOT ( a OR b OR c OR d) is becomming NOT a AND NOT b AND NOT c AND NOT d when elimination the ( ) .

Rgds.

Roman