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: 

is there any other way to do it?

Former Member
0 Kudos
133

hi

is there any other way to do it? if yes please tell me how...

LOOP AT itab.

SELECT SINGLE lgort INTO lv_lgort

FROM zbas

WHERE werks EQ itab-werks

AND lgort EQ itab-lgort.

IF sy-subrc NE 0.

DELETE itab.

ENDIF.

ENDLOOP.

this creates the perforamnce issue that we can not use select inside loop.plz suggest me the other way to do it..

i m tryin to do it this way .. will it work

SELECT SINGLE lgort INTO lv_lgort

FROM zbas

WHERE werks EQ itab-werks

AND lgort EQ itab-lgort.

LOOP AT itab.

IF lv_lgort NE itab-lgort.

DELETE itab.

ENDIF.

ENDLOOP.

thnx

1 ACCEPTED SOLUTION

Former Member
0 Kudos
100

Hi,

Try this


DATA: BEGIN OF ITAB occurs 0,
       werks LIEK zbas-werks,
       lgort LIEK zbas-lgort,
       END OF ITAB.
IF NOT itab[] IS INITIAL.
SELECT werks lgort INTO TABLE i_lgort
             FROM zbas
             FOR ALL ENTRIES in itab
             WHERE werks EQ itab-werks
             AND lgort EQ itab-lgort.
ENDIF.

LOOP AT itab.
Read table i_lgort WITH KEY werks = itab-werks
                            lgort = itab-lgort.
if sy-subrc NE 0.
 DELETE itab.
ENDIF.
ENDLOOP.

Reward points if this olvesur problem.

7 REPLIES 7

gopi_narendra
Active Contributor
0 Kudos
100

U can use FOR ALL ENTRIES instead of using SELECT in a LOOP.

Regards

Gopi

Former Member
0 Kudos
100

TAKE A TABLE LIKE ITAB SAY ITAB1 AND TTABIX LIKE SY-TABIX VARIABLE.

SELECT lgort INTO TABLE ITAB1

FROM zbas

FOR ALL ENTRIES IN ITAB

WHERE werks EQ itab-werks

AND lgort EQ itab-lgort.

LOOP AT ITAB.

TTABIX = SY-TABIX.

READ TABLE ITAB1 WITH KEY werks = itab-werks lgort = itab-lgort.

IF SY-SUBRC NE 0.

DELETE ITAB INDEX TTABIX.

ENDIF.

ENDLOOP.

REGARDS

SHIBA DUTTA

Former Member
0 Kudos
101

Hi,

Try this


DATA: BEGIN OF ITAB occurs 0,
       werks LIEK zbas-werks,
       lgort LIEK zbas-lgort,
       END OF ITAB.
IF NOT itab[] IS INITIAL.
SELECT werks lgort INTO TABLE i_lgort
             FROM zbas
             FOR ALL ENTRIES in itab
             WHERE werks EQ itab-werks
             AND lgort EQ itab-lgort.
ENDIF.

LOOP AT itab.
Read table i_lgort WITH KEY werks = itab-werks
                            lgort = itab-lgort.
if sy-subrc NE 0.
 DELETE itab.
ENDIF.
ENDLOOP.

Reward points if this olvesur problem.

Former Member
0 Kudos
100

Try this:

SELECT lgort from zbas INTO CORRESPONDING FIELDS OF TABLE

ltab_lgort FOR ALL ENTRIES IN itab

WHERE werks EQ itab-werks

AND lgort EQ itab-lgort.

**Now itab_igort will contain all the matching entries from itab.

**compare itab and itab_gort..

Loop at itab.

READ TABLE itab_gort

WITH KEY werks = itab_werks

TRANSPORTING NO FIELDS.

if sy-subrc ne 0.

delete itab[].

endif.

endloop.

Hope this helps.

Former Member
0 Kudos
100

HI NEHA,

WRITE CODE IN THIS WAY .

CREATE INTERNAL TAB IT_TAB .

THIS TAB CONTAIL ONLY ONE FIELD lgort

THEN

SELECT lgort INTO TABLE IT_TAB

FROM zbas

FOR ALL ENTRIES IN ITAB

WHERE werks EQ itab-werks

AND lgort EQ itab-lgort.

THEN IT_TAB CONTAIN ALL MACHING RECORDS

NOW DELETE ALL RECORDS THOSE NOT IN IT_TAB BY COMPAING TWO INTERNAL TABLE IT_TAB ITAB

MUKESH AGGARWAL

Former Member
0 Kudos
100

but on what condition u want to delete the entries in itab ?

only storage location or any combination of plant and lgort + matnr ??

You need to fix this thing up .

1.see the sol'n is first do a select all the entries for the criteria into a internal table say jtab .

and

2. loop at itab .

read table jtab with key <b>jtab-f1 = itab-f1 }

jtab-f2 = itab-f2.</b> "if applies

if sy-subrc eq 0 .

delete the entry where <condition>.

endif.

endloop.

//

ur option :

SELECT SINGLE lgort INTO lv_lgort

FROM zbas

WHERE werks EQ itab-werks

AND lgort EQ itab-lgort.

LOOP AT itab.

IF lv_lgort NE itab-lgort.

DELETE itab.

ENDIF.

ENDLOOP.

the order is not good for this scenario.

vijay

Former Member
0 Kudos
100

SELECT key_field1

key_field2

.............

lgort INTO table it_lv_lgort

FROM zbas

WHERE werks EQ itab-werks

AND lgort EQ itab-lgort.

if not it_lv_lgort[] is initial.

LOOP AT itab.

read it_lv_lgort with key_fiel_1 = itab-key-fiel_1...

DELETE itab.

ENDLOOP.

endif.