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

Problem with ENDSELECT

Former Member
0 Likes
908

Hi,

Is it possible not to put an Endselect to the below 2 examples. Thanks a lot!

1. SELECT matnr

werks

lgort

labst

FROM mard INTO i_mard

FOR ALL ENTRIES IN i_stpo

WHERE matnr = i_stpo-idnrk

AND werks = i_stpo-pswrk

AND lgort = i_stpo-lgort.

2. SELECT stko~bmeng

stpo~idnrk

stpo~menge

stpo~lgort

FROM stko INNER JOIN stpo

ON stkostlnr = stpostlnr

INTO i_stpo

WHERE stko~stlnr = v_stlnr

AND stpo~pswrk = p_werks

AND stpo~stlnr = c_1.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
885

Hi,

IF NOT i_stpo[] IS INITIAL.

SELECT matnr

werks

lgort

labst

FROM mard INTO TABLE i_mard

FOR ALL ENTRIES IN i_stpo

WHERE matnr = i_stpo-idnrk

AND werks = i_stpo-pswrk

AND lgort = i_stpo-lgort.

2. SELECT stko~bmeng

stpo~idnrk

stpo~menge

stpo~lgort

FROM stko INNER JOIN stpo

ON stkostlnr = stpostlnr

INTO *TABLE * i_stpo

WHERE stko~stlnr = v_stlnr

AND stpo~pswrk = p_werks

AND stpo~stlnr = c_1.

ENDIF.

When you are using FOR ALL ENTRIES it is compulsory to check initial or not

IF NOT i_stpo[] IS INITIAL.

7 REPLIES 7
Read only

former_member188827
Active Contributor
0 Likes
885

in 1) u cant write endselect but for 2) u hav to

Read only

Former Member
0 Likes
885

Hi,

if u use INTO CORREESPONDING FIELDS OF TABLE itab u can avoid the endselect.

rgds,

bharat.

Read only

dhruv_shah3
Active Contributor
0 Likes
885

Hi,

For First its perfectly ok.

For second you may try out and see...

HTH

Regards,

Dhruv Shah

Read only

Former Member
0 Likes
885

Hi,

In the first statement there is no need for an ENDSELECT.

In the second one you need to have ENDSELECT. You can avoid this , if you put SELECT SINGLE, but this will fetch only one record for you.

Just check which one is appropriate for your requirement.

Reward if helpful.

Regards.

Read only

Former Member
0 Likes
886

Hi,

IF NOT i_stpo[] IS INITIAL.

SELECT matnr

werks

lgort

labst

FROM mard INTO TABLE i_mard

FOR ALL ENTRIES IN i_stpo

WHERE matnr = i_stpo-idnrk

AND werks = i_stpo-pswrk

AND lgort = i_stpo-lgort.

2. SELECT stko~bmeng

stpo~idnrk

stpo~menge

stpo~lgort

FROM stko INNER JOIN stpo

ON stkostlnr = stpostlnr

INTO *TABLE * i_stpo

WHERE stko~stlnr = v_stlnr

AND stpo~pswrk = p_werks

AND stpo~stlnr = c_1.

ENDIF.

When you are using FOR ALL ENTRIES it is compulsory to check initial or not

IF NOT i_stpo[] IS INITIAL.

Read only

Former Member
0 Likes
885

Hi Mark

In first its not possible to write endselect

when we use

select

endselect.

It means we are executing a loop which retrieves records one by one but in (1) you are using caluse "for all entries" which is used to avoid looping. So here all the records come from database at a single time.

In second you can use endselect but for performance point of view no one recommend to use endselect because it is costlier as it retrives all records one by one from database.

regards

Aditya

Read only

JozsefSzikszai
Active Contributor
0 Likes
885

hi Mark,

in both cases, instead of INTO itab you have to use like: INTO TABLE itab. Than you don't need ENDSELECT. (INTO puts the selected lines one by one into a structure, INTO TABLE puts the selected lines into an internal table in one go.)

hope this helps

ec