‎2008 Mar 10 10:07 AM
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.
‎2008 Mar 10 10:14 AM
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.
‎2008 Mar 10 10:10 AM
‎2008 Mar 10 10:10 AM
Hi,
if u use INTO CORREESPONDING FIELDS OF TABLE itab u can avoid the endselect.
rgds,
bharat.
‎2008 Mar 10 10:12 AM
Hi,
For First its perfectly ok.
For second you may try out and see...
HTH
Regards,
Dhruv Shah
‎2008 Mar 10 10:14 AM
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.
‎2008 Mar 10 10:14 AM
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.
‎2008 Mar 10 10:14 AM
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
‎2008 Mar 10 10:24 AM
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