04-03-2006 3:17 PM
HI,
I have two nested select statements. In the inner select statement if the retrieved value does not correspond to a specific criteria then I have to come out of both the select statments. How do I do that ?
Regards,
Varun.
04-03-2006 3:25 PM
use a flag.
set that flag.
based on that flag exit the second select also.
select.....
select......
if condition fails.
flag = 'x'.
exit.
endif.
endselect.
if flag = 'x'.
exit.
endif.
endselect.
Regards,
Ravi
04-03-2006 3:21 PM
04-03-2006 3:22 PM
Hi,
In the innermost select set a flag = 'X' and then exit.
in the outer select check for this flag and if it is 'X'
(say) then exit.
select
select
if <specific criteria> " inner select
flag = 'X'.
exit.
endif. " inner select
if flag = 'X'. " outer select
clear flag.
exit.
endif. " outer select
Regards,
GSR.
04-03-2006 3:25 PM
HI,
This is what I have done.
CLEAR : w_recnroot.
SELECT recnroot INTO w_recnroot
FROM estmj
WHERE matnr = t_outtab-matnr
AND delflg = space.
IF sy-subrc EQ 0.
SELECT subid subcat
INTO (t_outtab-subid, w_subcat)
FROM estrh
WHERE recnroot = w_recnroot
AND delflg = space.
if w_subcat in s_subcat.
w_value = 0.
else.
w_value = -1.
clear t_outtab-subid.
exit.
endif.
ENDSELECT.
ENDIF.
if w_value < 0.
exit.
endif.
ENDSELECT .
CLEAR : w_value.
Buytthis doesn't work for me.
Regards,
Varun.
04-03-2006 4:37 PM
Try this code
TABLES: KNA1.
DATA: L_FIRST,
L_KUNNR LIKE KNA1-KUNNR,
L_KUNNR2 LIKE KNB1-KUNNR.
SELECT-OPTIONS: S_KUNNR FOR KNA1-KUNNR.
first
SELECT KUNNR
FROM KNA1
INTO L_KUNNR
WHERE KUNNR IN S_KUNNR.
CLEAR L_FIRST.
L_FIRST = '1'.
Second
SELECT KUNNR
FROM KNB1
INTO L_KUNNR2
WHERE KUNNR IN S_KUNNR.
L_FIRST = '2'.
ENDSELECT.
check - still flag is 1 then exit....
IF L_FIRST = '1'.
EXIT.
ENDIF.
ENDSELECT.
Regards,
Naimesh Patel
04-03-2006 3:22 PM
HI Varun,
In the inner select update a flag & EXIT.. in the outer select check for this flag & EXIT if necessary..
Regards,
Suresh Datti
04-03-2006 3:25 PM
use a flag.
set that flag.
based on that flag exit the second select also.
select.....
select......
if condition fails.
flag = 'x'.
exit.
endif.
endselect.
if flag = 'x'.
exit.
endif.
endselect.
Regards,
Ravi
04-03-2006 3:27 PM
Remove the sy-subrc check after the first select.. it si not necessary as you are already inside the SELECT by then..
Suresh
04-03-2006 3:33 PM
HI,
I need that sy-subrc because it is an deoendent query. Only if first select is ok then only I need to work with second query.
REgards,
Varun.
04-03-2006 3:35 PM
then change <i>if sy-subrc eq 0</i> to
<b>if not w_recnroot is initial</b>
Regards,
Suresh Datti
04-03-2006 3:59 PM
No - you don't need it. If the outer select finds nothing, it won't go to the inner select.
Rob
04-03-2006 3:26 PM
Hi,
REPORT ZTEST .
data: x_vbeln like vbak-vbeln,
x_posnr like vbap-posnr.
data: flag .
select vbeln
from vbak
into x_vbeln .
select single posnr
from vbap
into x_posnr
where vbeln = x_vbeln.
if sy-subrc <> 0.
flag = 'X'.
exit.
endif.
if flag = 'X'.
clear flag .
exit.
endif.
endselect.
Regards
vijay
Message was edited by: Vijay Babu Dudla
04-03-2006 3:31 PM
Hi,
Set a flag equal zero. If the innner select statement succeeds, then set it to an integer value .
otherwise put exit statement in the inner select and outer select also.
regards.
Rakesh