Prematurely exit enumeration loop
i am enumerating thru a loop
upon a certain condition, i want to exit the loop, while keeping the object of the current enumeration in tact.
Foo foo = null;
Enumeration = fooVector.elements();
while(Enumeration.hasMoreElements())
foo = (Foo) enumeration.nextElement(); // get a foo
if (some condition is met)
// exit loop, but keep object foo in tact
// that is, don't do foo = nextElement()
}I suppose i could do the following, but is there anything more graceful?
Foo foo = null;
Foo foundFoo = null;
boolean found = false;
Enumeration = fooVector.elements();
while(Enumeration.hasMoreElements())
foo = (Foo) enumeration.nextElement(); // get a foo
if ((some condition is met) && (! found))
foundFoo = new Foo(foo);
found = true;
// use foundFoo
Foo foo = null;
Enumeration = fooVector.elements();
while(Enumeration.hasMoreElements())
foo = (Foo) enumeration.nextElement(); // get a
a foo
if (some condition is met)
{break; //This is what you want to do
// exit loop, but keep object foo in tact
// that is, don't do foo = nextElement()
/Kaj
Similar Messages
-
Hi every body
i have a procedure that execute a loop.What i want that to allow user to exit from loop before it finished(by using keyboard), i do that by pressing ctrl+alt+del which end the program it self.One could try putting the call to the procedure in a loop on the front end. Then check within the loop (in the front end ) whether the user has pressed a pre-defined button. If pressed, one could disconnect the connection or take some similar action that would stop processing the call to the stored procedure.
May be something like this is workable ... ?
Narayan.
null -
Set a container element inside class to exit a loop
Hi,
I want to set a container element inside a class to exit a loop.
The element is marked as import/export parameter and the binding from the task to the container exists as well.
The loop has a condition &finish& = X but I cannot exit the loop. Looks like the value gets never updated in the container.
When i am using a container operation to set the element its working but i want to do this out of my method in the class.
Is it not possible to change a container element inside a loop without using a container operation?
Thanks,
ChristophHi,
Using the container operation is a good method to solve the problem. But if you intend to do that in the method coding itself then you will have to have it as the export parameter of the method. You can view all the import and export parameters of a method by going to the Business Object Builder (SWO1) and then choose the method and click on the "Parameters" Button. Once you are done with the interface of the method use that method in the workflow builder as a task and in the binding there are two rows. One for the import that occurs just below the container elements and the export parameters appear below the import in a separate window. Make sure you have the binding set there too as this is where you can transfer the container elements back to the workflow container from the task container and it should work. Maybe you are missing that in the binding.
Hope it helps,
Sudhi -
How to exit from loop after 3 time
hi
how to exit from loop after 3 time
loop at itab.
<exit after 3 time>
endloop.
thanksHi,
You can check the value of SY_TABIX inside loop,
For Example:
Loop at itab.
if sy-tabix = 3.
Exit.
endif.
Endloop.
Hope it helps
Regrds
Mansi -
if in a loop iam checkin a condition n if the condition satisfies then which is the best way to exit the loop.
Hi Sushant,
Use EXIT in the LOOP after the condition .If u use STOP it will exit from the Program.
Try this example creating a Program by uncommending EXIT and STOP.
DATA: t_mara TYPE STANDARD TABLE OF mara.
DATA: w_mara TYPE mara,
sum TYPE i.
SELECT matnr mtart FROM mara INTO CORRESPONDING FIELDS OF TABLE t_mara
WHERE mtart EQ 'KMAT' OR mtart EQ 'FERT' OR mtart EQ 'LGUT'.
sum = 0.
IF sy-subrc EQ 0.
SORT t_mara BY mtart.
LOOP AT t_mara INTO w_mara.
IF w_mara-mtart EQ 'LGUT'.
sum = sum + 1.
EXIT.
*STOP.
ENDIF.
ENDLOOP.
ENDIF.
WRITE : sum.
Reward Points if useful.
Regards
Avi... -
Exit a loop when the condition in if succeed
Hello everbody:
LOOP ....
IF ...
"If the sentence here succeed I want to exit of the loop.
ENDIF.
ENDLOOP.
Some ideas pleaseHi
Try this
Loop ....
if 1=1
begin
goto ExitLoop
end
ExitLoop:
Regards -
How to exit infinite loop when using gotopage( )
I have 10 Pages in one script. At page 9, I want to call page 2 , page 3 and page4
The method is : RSWApp.GotoPage (2)
At page 9 it will run infinite loop page2-page4, How can I stop this loop at Page4
Thanks
JuliaHi, I have a question follow up on this.
For example:
I have 5 pages:
Page 1
Page 2
Page 3
Page 4
Page 5
In Page 1, I have an VBA that look like this:
if something then GoToPage 2
if otherthing then GoToPage 4.
But I only want when the page get to Page 3, then this iteration is finished and don't want to keep going to Page 4 and Page 5.
How do I stop it or restart another iteration, start all over from Page 1?
I have tried "RSWApp.StopIteration", look up some end, exit, etc, doesn't seems work.
Thanks -
Exit the loop of screen in Module pool
Hi,
My requirement is : in my screen i have Table control. When i select any line (the value of select coloum will be 'X' ) and click on one button (Detail is button in my screen) the loop - endloop should exit at that line.
for example : if i select 5th line of table control then the data of 5th line will be in the header of internal table and the value of select coloum will be 'X'. i want to exit at that point itself. i dont want internal table to loop in PAI.
my code is :
PROCESS AFTER INPUT.
LOOP AT IT_ZINVH.
MODULE EXIT_LOOP.
ENDLOOP.
MODULE EXIT_LOOP INPUT.
IF IT_ZINVH-SEL = 'X'.
EXIT .
ENDIF.
ENDMODULE. but here if i use EXIT it is only comming out of IF-ENDIF contidion.
Thanks & RegardsHi,
Try this way.
<li>Code PAI like below
PROCESS AFTER INPUT.
LOOP AT it_zinvh.
MODULE read_table_control.
ENDLOOP.
MODULE user_command_1001.
<li>Module read_table_Control should be like below.
*& Module READ_TABLE_CONTROL INPUT
MODULE read_table_control INPUT.
MODIFY it_nfal INDEX tchkbox-current_line.
"The above Modify statement modifies the table for the column SEL = 'X'.
ENDMODULE. " READ_TABLE_CONTROL INPUT
<li>Write action when you click on DETAIL button. Lets say DETAIL is the function code for Details screen button.
*& Module USER_COMMAND_1001 INPUT
MODULE user_command_1001 INPUT.
CLEAR ok_code.
ok_code = sy-ucomm.
CASE ok_code.
WHEN 'DETAIL'.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
LOOP AT it_zinhv WHERE sel = 'X'.
WRITE:it_zinhv.
EXIT.
ENDLOOP.
ENDCASE.
ENDMODULE. " USER_COMMAND_1001 INPUT
Thanks
Venkat.O -
Im struggling to think of the most appropriate exit criteria. I want the cursor to exit once all the records matching the criteria in the cursor have been extracted, yet for some reason it runs four times and I don't want it to.
ThanksThe easiest way is to use a CURSOR FOR loop which will take care of all that stuff for you. You can do this in several ways, but the most common are:
DECLARE
CURSOR my_cur IS
SELECT *
FROM emp
WHERE dept_no = 10;
BEGIN
FOR my_rec IN my_cur LOOP
IF my_rec.column_name = some_value THEN
do_something
ELSE
do_something_else
END IF;
END LOOP;
END;
or, even easier
BEGIN
FOR my_rec IN (SELECT *
FROM emp
WHERE dept_no = 10) LOOP
IF my_rec.column_name = some_value THEN
do_something
ELSE
do_something_else
END IF;
END LOOP;
END;If you absolutely need to use a DECLARE OPEN FETCH CLOSE structure for some reason then the corerct structure is something like:
DECLARE
CURSOR my_cur IS
SELECT *
FROM emp
WHERE dept_no = 10;
v1 my_cur.col1%TYPE;
v2 my_cur.col2%TYPE;
v3 my_cur.col3%TYPE;
BEGIN
OPEN my_cur;
LOOP
FETCH my_cur INTO v1, v2, v3;
EXIT WHEN my_cur%NOT_FOUND;
IF my_rec.column_name = some_value THEN
do_something
ELSE
do_something_else
END IF;
END LOOP;
CLOSE my_cur;
END;TTFN
John -
How 2 exit the Loop..?
Hello all,
Can any tell me how to get out of this Loop in case of changing the range registered or stored in the db on update in a reange smaller than rang_to i got the message and the raise poped up i need the following logic 2 covers all possible ranges so can any boady help me, sorry 4 the cap locks and sorry that i have to leave 2 4 a vacation..)) reallly..!
Well the following code describes my case is as follows:
=========================================
--------------------------------RANGE VALIDATION----------------------
DECLARE
V_MESSAGE NUMBER(2);
V_RANGE_TO DATE ;
V_RANGE_FROM DATE;
--V_TANK_COUNT NUMBER;
CURSOR RANGE_CURSOR IS
SELECT TANK_CODE,RANGE_TO,RANGE_FROM
FROM PLN_TANK_DEPTH_RANGE
WHERE TANK_CODE= :PLN_TANK_DEPTH_RANGE.TANK_CODE;
BEGIN
FOR I IN RANGE_CURSOR LOOP
--- INSIDE THE RANGE
IF ((:PLN_TANK_DEPTH_RANGE.RANGE_FROM >= I.RANGE_FROM ) AND(:PLN_TANK_DEPTH_RANGE.RANGE_TO <= I.RANGE_TO ) ) OR ((:PLN_TANK_DEPTH_RANGE.RANGE_FROM > I.RANGE_FROM ) AND (:PLN_TANK_DEPTH_RANGE.RANGE_FROM <= I.RANGE_TO )) THEN
V_MESSAGE := FUNC_MSG(1,'not within the range);
RAISE FORM_TRIGGER_FAILURE;
ELSIF (:PLN_TANK_DEPTH_RANGE.RANGE_FROM > I.RANGE_FROM ) AND (:PLN_TANK_DEPTH_RANGE.RANGE_FROM < I.RANGE_TO ) AND (:PLN_TANK_DEPTH_RANGE.RANGE_TO > I.RANGE_TO ) THEN
V_MESSAGE := FUNC_MSG(1,'not within the range);
RAISE FORM_TRIGGER_FAILURE;
ELSIF (:PLN_TANK_DEPTH_RANGE.RANGE_FROM < I.RANGE_FROM ) AND (:PLN_TANK_DEPTH_RANGE.RANGE_TO > I.RANGE_FROM ) THEN
V_MESSAGE := FUNC_MSG(1,'not within the range); RAISE FORM_TRIGGER_FAILURE;
ELSIF (:PLN_TANK_DEPTH_RANGE.RANGE_FROM < I.RANGE_FROM ) AND (:PLN_TANK_DEPTH_RANGE.RANGE_TO > I.RANGE_TO ) THEN
V_MESSAGE := FUNC_MSG(1,'not within the range); RAISE FORM_TRIGGER_FAILURE;
END IF;
END LOOP;
END;
===========================================================
Any suggestions will be welcomed,
Regards,
Abdetu..
===========================================================Exit;
-
Hello,
I am having a problem with looping to the next element. I'm not too familar with how enumeration works so that's why I'm not sure why I keep getting an error. The code I have now works until it gets to the 5th "IF" sstatement. I get a "Server Caught Unhandled exception". The reason it crashes on the 5th "IF" statement is because there are no more elements to be displayed. Now, how do I check to where it loops through each element and if there is an element then display it in the drop-down else it won't be displayed.
Thanks...
<SELECT NAME="address_code" WIDTH="25%">
<OPTION VALUE="">2Select Address</OPTION>
<%
for (Enumeration eAddress = bidProposalRequestBean.getAddressV().elements()
;eAddress.hasMoreElements();) {
if (eAddress != null) {
strAddress_Array = (String[])eAddress.nextElement();
%>
<OPTION VALUE="P"><%=strAddress_Array[0]%></OPTION>
<%
strAddress_Array = (String[])eAddress.nextElement();
if (eAddress != null) {
%>
<OPTION VALUE="S"><%=strAddress_Array[0]%></OPTION>
<%
strAddress_Array = (String[])eAddress.nextElement();
if (eAddress != null) {
%>
<OPTION VALUE="C1"><%=strAddress_Array[0]%></OPTION>
<%
strAddress_Array = (String[])eAddress.nextElement();
if (eAddress != null) {
%>
<OPTION VALUE="C2"><%=strAddress_Array[0]%></OPTION>
<%
strAddress_Array = (String[])eAddress.nextElement();
if (eAddress != null) {
%>
<OPTION VALUE="C3"><%=strAddress_Array[0]%></OPTION>
<%
%>I am having a problem with looping to the next
element.Really hard to tell what you should be doing. But regardless the code you have will not work.
Probably your enumeration should look like the following (there are some details that are different)...
java.util.Enumeration e = v.elements();
String s;
while (e.hasMoreElements())
// Do NOT call e.hasMoreElements() here!
s = (String)e.nextElement();
if (s != null)
System.out.println("P=" + s);
if (!e.hasMoreElements()) break;
s = (String)e.nextElement();
if (s != null)
System.out.println("S=" + s);
if (!e.hasMoreElements()) break;
s = (String)e.nextElement();
if (s != null)
System.out.println("c1=" + s);
if (!e.hasMoreElements()) break;
s = (String)e.nextElement();
if (s != null)
System.out.println("c2=" + s);
if (!e.hasMoreElements()) break;
s = (String)e.nextElement();
if (s != null)
System.out.println("c3=" + s);
The above presumes that you really do want to call the enumeration five times for each loop. If what you really want to do is access the String array then the above would have to be simplified to do that. -
Exiting the loop.....
I am writing an app that reads an arbitrary # of int's ranging from 0 to 50 inclusive and counts how many times each number is entered. After the input has been processed - prints all the values and number of occurances for each number.
Here is what I have so far. I am having trouble exiting the do..while loop without getting errors. I don't want the user to have to reply "y" or "n" after each entry. Any ideas?????
import cs1.Keyboard;
public class IntegerCount
public static void main (String[] args)
final int MIN = 0;
final int MAX = 50;
int[] numbers = new int[MAX];
int[] numbers2 = new int[MAX];
int index = 0;
int num = 0;
char stop;
System.out.println ("Enter a number between 0 and 50: ");
System.out.println ("To summarize your values enter the = ");
do
stop = Keyboard.readChar();
num = Keyboard.readInt();
numbers[index] = num;
index++;
while ((num>=0 && num<=50) && stop != '=');
index = 0;
for (int i = index; index < numbers.length; index++)
if (numbers[index] != 0)
System.out.println (index + " " + numbers[index]); //test numbers[]
numbers2[numbers[index]] = numbers2[numbers[index]] + 1;
index = 0;
for (int i = index; index < numbers2.length; index++)
if (numbers2[index] != 0)
System.out.println (index + " " + numbers2[index]);It looks like the limitation requiring the entry of a y or an
n is contained in the Keyboard class. If you will
substitute this code for the do loop, it will take care of
the problem:
String s = "";
int num = 0;
int total = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
do {
try {
s = br.readLine().trim();
catch (IOException ioe) {
ioe.printStackTrace();
if (s.charAt(0) != '=') {
try {
num = Integer.parseInt(s);
catch(NumberFormatException nfe) {
System.out.println("Invalid number. Zero substituted.");
num = 0;
total += num;
while(s.charAt(0) != '=' && (num >= 0 && num <= 50));Mark -
My custom xslt is as follows which I am using in my map:
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var"
exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:s0="http://Students.Student.SourceSchema"
xmlns:ns0="http://Students.Student.DestinationSchema"
xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<xsl:template match="/">
<xsl:apply-templates select="/s0:Students" />
</xsl:template>
<xsl:template match="/s0:Students">
<ns0:DestinationDetails>
<xsl:for-each select="StudentTransactions">
<xsl:if test="FName='H'">
<xsl:variable name="var:v104" select="ID"/>
<xsl:for-each select="/s0:Students/StudentTransactions[FName='D' and ID_Detail=$var:v104]">
<xsl:variable name="Detail_String" select="string(GL_String/text())"/>
<xsl:if test="$Detail_String!=''">
<Details>
<HeaderSegment>
</HeaderSegment>
</Details>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</ns0:DestinationDetails>
</xsl:template>
<msxsl:script language="C#" implements-prefix="userCSharp">
<![CDATA[
public string StringConcat(string param0)
return param0;
]]>
</msxsl:script>
</xsl:stylesheet>
I want to break the following loop :
<xsl:for-each select="/s0:Students/StudentTransactions[FName='D' and ID_Detail=$var:v104]">
when <xsl:if test="$Detail_String!=''"> condition is true.
Any kind of help would be appreciated.
PrakashGot your point. The counter is not incrementing because, varialbes are immutable in XSLT, i.e. they can't be changed. I think what you need to do is use the position(). With the
resultset of For-each, using position()=1 in <xsl:if test="position() =1 , you would just access the first record of the resultset
from for-each
If my understanding of your problem is correct, then the following XSLT shall work for you.
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:s0="http://CallTemplate_Increment.StudentSchema" xmlns:ns0="http://CallTemplate_Increment.DestinationStudentSchema" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<xsl:template match="/">
<xsl:apply-templates select="/s0:Students" />
</xsl:template>
<xsl:template match="/s0:Students">
<ns0:DestinationDetails>
<xsl:for-each select="StudentTransactions">
<xsl:if test="FName='H'">
<xsl:variable name="var:v104" select="ID"/>
<xsl:variable name="count" select="0"/>
<xsl:for-each select="/s0:Students/StudentTransactions[FName='D' and ID_Detail=$var:v104]">
<xsl:variable name="Detail_String" select="string(GL_String/text())"/>
<!--<xsl:if test="$Detail_String!='' and $count=0">-->
<xsl:if test="position() =1 and $Detail_String!=''" >
<xsl:variable name="var:v1" select="userCSharp:StringConcat(string(FName/text()) , string(LName/text()))" />
<Details>
<ID>
<xsl:value-of select="ID/text()" />
</ID>
<FullName>
<xsl:value-of select="$var:v1" />
</FullName>
<Cost>
<xsl:value-of select="Cost/text()" />
</Cost>
</Details>
<!--<xsl:value-of select="$count + 1"/>-->
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</ns0:DestinationDetails>
</xsl:template>
<msxsl:script language="C#" implements-prefix="userCSharp">
<![CDATA[
public string StringConcat(string param0, string param1)
return param0 + param1;
]]>
</msxsl:script>
</xsl:stylesheet>
If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply. -
Based on sap's documentation, loop in bpm works as While, Can anybody explain how to exit a loop in bpm similar to break statement in While loop? Is cancel the right step to use? will it cause potential issues then terminte the bpm normally(Stop)?
Thanks,Hi,
The "cancel process" option of the control step abruptly terminates the entire process and sets the status to "logically deleted" as per the documentation. Moorthy - if you have found a way to limit the scope of the control step to a block please advise - it does not work for me nor to I see any option for it (I am on SP16 so maybe it is in later SP).
Anyway - when a bpm completes normally the status is set to "completed".
I would suggest that the use of the "cancel process" in a control step is an extreme reaction to a catastrophic failure in your BPM that is unrecoverable. Not the situation that you have. Surely you can make use of local variables, switch statements and loop control to define the proper logical path through your BPM without resorting to canceling the process.
Anyway - the short answer to your original question is this - There is nothing similar to a break statement in a loop control. Cancel process (or cancel step) is not the right way to terminate a loop or step in normal behaviour. It will most likely NOT cause any problems and it WILL terminate the BPM. -
hie guys
i am looping at two internal tables and want to exit through an if statement when a condition specified is not met however the code exits both loops.
loop at itab1.
loop at itab2.
if itab2-value eq 0.
exit.
else.
process.
endif.
endloop.
endloop.
however its not behaving as such..i have tryed to use return statement but it still wont work. i have verified my entries and the conditions exist to be true for some entries ie itab2-value ne 0 but the program exists. please assist.
regards.
Isaac PrinceYOU CAN USE IT
BUT THE SECOND TABLA MUS BE SORTED
LOOP AT T_DOCTOS_WORK.
T_DOCTOS_FINAL-BELNR_PAGO = T_DOCTOS_WORK-BELNR.
T_DOCTOS_FINAL-BUDAT_CONCILIA = T_DOCTOS_WORK-AUGDT.
T_DOCTOS_FINAL-BUDAT_PAGO = T_DOCTOS_WORK-BUDAT.
Se tratan las partidad del proveedor
READ TABLE T_DOC_BSIK_BSAK WITH KEY
AUGGJ = T_DOCTOS_WORK-GJAHR
AUGBL = T_DOCTOS_WORK-BELNR
BINARY SEARCH.
IF SY-SUBRC EQ 0.
INDEXK = SY-TABIX.
DO .
READ TABLE T_DOC_BSIK_BSAK INDEX INDEXK.
IF T_DOC_BSIK_BSAK-AUGGJ NE T_DOCTOS_WORK-GJAHR OR
T_DOC_BSIK_BSAK-AUGBL NE T_DOCTOS_WORK-BELNR OR
SY-SUBRC NE 0.
EXIT.
ELSE.
INDEXK = INDEXK + 1.
*MAKE YOUR CODE
ENDIF.
ENDDO.
ENDIF.
ENDLOOP
Maybe you are looking for
-
Wireless Photosmart 7515 No Longer Recognized by Window
My printer worked wirelessly just fine for over a year. Then one day both my desktop and laptop comuter stopped printing wirelessly. The Wireless Network Test Results show that the printer in "Connected" to the network, but Windows 7 fails to recog
-
A couple weeks back my Illustrator software became so slow that most of the time it would close if I just opened a document. I've tried uninstalling the program and reinstalling it. Which worked for a little while and then the same problem happened.
-
Microsoft Word API for Mac OS: Troubleshooting the Find/Replace function
In my previous topic at http://discussions.apple.com/thread.jspa?threadID=2623068&tstart=0 we found out the way to connect to the Ms-Word from Objective-C through ScriptingBridge. The connection works and the given text can be found and replaced usin
-
Show/Hide DVT Admin Menu Based on Entitlements
Hi, We're using the DVT framework provided in Weblogic Portal 10.3.2 to create My Page functionality within our portal project. Part of the requirement is to offer limited functionality to non-admin users. For example: Portal Level Customization Menu
-
Need to copy files from multiple machine to multiple locations on server in daily basis
My scenario is below: 1. I have 20 machines and data for backup would be on only in one folder of each machine. 2. Need to create 20 folders in server and copy the corresponding machine's data to the respective folder daily. 3. Data copy should be ap