Conditional in while statement
OK, i know this should be simple stuff.
Imagine i have a while loop. The looping is converned by a statement that is populated by a webservice call inside the loop.
So i have placed this inside the while expression:
xp20:matches(bpws:getVariableData('CheckTransmittalDocs_Output','parameters','/ns1:CheckTransmittalDocumentsResponse/ns1:CheckTransmittalDocumentsResult'),'[OK]') = true()
Basically if the return contains OK then exit the loop.
but this doesn't work and i assume this becuase the initial variable is null and a regex match will just return null on this match no true or false.
I can't use boolean as any value will be true. Any ideas?
Thanks for the quick reply.
I tryed that:
<assign name="Assign_1">
<copy>
<from expression="'null'"/>
<to variable="CheckTransmittalDocs_Output" part="parameters" query="/ns1:CheckTransmittalDocumentsResponse/ns1:CheckTransmittalDocumentsResult"/>
</copy>
</assign>
Which was successful, but when it came to the while, it through this:
XPath expression failed to execute. Error while processing xpath expression, the expression is "(xp20:matches(bpws:getVariableData("CheckTransmittalDocs_Output", "parameters", "/ns1:CheckTransmittalDocumentsResponse/ns1:CheckTransmittalDocumentsResult"), "[OK]") = true())", the reason is . Please verify the xpath query.
I assume here that the error is misleading and it is the regex that is failing, but this should be ok.
Similar Messages
-
Hi,
I have a while statement and within this a return statement, but when i compile this it produces an error -
missing return statement.
This is my code:
public double getResults() { // Open getResults method
while ( i >= 10 ) { // Open while
i++;
return (runs * 10);
} // Close while
} // Close getResults method
What is wrong?
ThanksThe compiler waits for the return statement to be at the end of the method. For example if you put it before your while loop you'll have an error like "unreachable statement". Because the compiler understands the return statement as the end of the method.
In your case:
What happens in any loop or statement is forgot after its end. So if you create a variable inside the loop and your try to change its value after the end of the loop, it will give you an error because any variable created inside the loop is erased from the memory at the end of the loop. The same thing happens to your return statement . If the value is returned in the loop, as the compiler understand it as the end of the method, it creates an error because the method is not finished yet. And as a previous user told you if the condition of the while loop is not met the return will not be executed. But the compiler is not so smart, it just waits for the return statement as the last line of any such method. And as the value you are returning is declared outside the loop, it will keep its new value at the end of the loop, so you will return the value you want. -
Programming a times table with FOR, WHILE & DO WHILE STATEMENTS
Guys,
Help me, I have tried hard, but I didn't find the answer, my problem is that I got difficulties in doing a times table with the FOR, WHILE, and DO WHILE STATEMENTS just using a single index or a single variable.
Guys, is it possible to program a times table with these conditions all together in the same code???
Do I await your suggestions?
Ps: Below, the attempt that I did, but I was not successful.
import javax.swing.JOptionPane;
public class tab
public static void main(String args[])
int i;
String TimesTable= "";
int result=0;
do
for (i=0;i<=10;i++)
result=i*1;
TimesTable +="\n" + i + "x" + i + "=" + result;
//JOptionPane.showMessageDialog(null, "Times tables of " + i + TimesTable);
// TimeTable="";
// i=0;
// i=i+1;
// i=0;
while(i<=10)
i=i+1;
// System.out.println("2 x "+i+"="+2*i);
// i--;
}while(i!=0);
JOptionPane.showMessageDialog(null, "Times Table of " + i + TimesTable);
TimesTable="";
}You can use the if block "if(i%10==9)" in this case.
-
Problem interpreting a while statement
Hello there,
The following code snippet (excerpted from Thinking in Java) has held me down all day. Can anyone tell me what condition evaluated to true in the while statement?
import java.io.*;
public class FormattedMemoryInput
public static void main(String[] args) throws IOException
try
DataInputStream in = new DataInputStream( new
ByteArrayInputStream(BufferedInputFile.read(
"FormattedMemoryInput.java").getBytes()));
while(true)
System.out.print((char)in.readByte());
catch(EOFException e)
System.err.println("End of stream");
} Thanks,
ue_JoeDo not mind me. I am just as confused with the concept as with interpreting the statement. Here's the other half of the code. Might wish to run it to see that it works.
// BufferedInputFile.java
import java.io.*;
public class BufferedInputFile
// Throw exceptions to console:
public static String read(String filename) throws IOException
// Reading input by lines:
BufferedReader in = new BufferedReader(new FileReader(filename));
String s;
StringBuilder sb = new StringBuilder();
while((s = in.readLine())!= null)
sb.append(s + "\n");
in.close();
return sb.toString();
public static void main(String[] args) throws IOException
System.out.print(read("BufferedInputFile.java"));
}ue_Joe. -
I have a Y9 Computer Science Exam next week and I know that this will probably be one of the questions on it so I need to know the answer. What is the difference?
An If statement executes once IF the statement is true:
If 1 = 2/2 Then
Textwindow.writeline("True")
EndIf
A While statement executes WHILE the statement is true:
While 4 = 2+2
'Will keep looping while it is true
EndWhile
A For statement loops a number in increment:
For i = 1 to 10
'Every time through, i gets bigger by one until it equals 10
EndFor
It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11 -
How to manual maintain TAX condition value while creating sales order
Hi
I am creating one Tax condition suppose JLST without access sequence .
while creating sales order I am manually maintain the % value of TAX. suppose it is 1%
then I see It show some value in TAX .
save that sales order & creating delivery document for that but when I create Invoice its show error.
" Tax code in procedure CMTAXP is invalid ".
I know the configuration only for Tax condition with vk11 condition record .
BUT now I want to maintain TAX condition at the time of creating sales order.
so I remove the access sequence of that condition .
but It shows tax code error while billing.
My main question is that If i maintain condition record while creating sales order then how i can assign Tax code .
Can it is possible ?
if yes then How?
please help me.
thank youHi,
The "straight-forward" answer for Tax Code creation is contact the FI consultant. He shall help you, by creating Tax codes.
I have tested, with creating a tax cond type (copy of MWST) & manually entering values. I can create Sorder, Dlv and Bill but I cannot create an Accounting document. That is because of every line (amount) a Tax code is necessary.
I THINK, you can NOT have manually filled tax codes; access sequence is needed to get the tax value (%) and the Tax code from the condition record.
There is lot of material on the web to understand Tax classification, code etc. etc. See a useful link below -
http://www.sapgeek.net/2010/04/sd-determines-tax-code/
In short Tax code is a must and take the help of your FI consultant for the configuration of the same.
BTW - Tax code is already made created for MWST, therefore I suggested that you can use MWST. Furthermore, you can change the values corresponding to Tax codes in FTXP.
But if you are a beginner in these things, better take help. -
Problem with while statement :(
i am having a problem with my while statement, can anyone help me to get it working :(
i am trying to get the while statement to only run when the input hasnt been a yes or a no, can someone please help me.
System.out.print("Are you a Resident? (yes/no): ");
Resident = console.next(); //Requests resident status from user and puts in in Resident
while ((Resident != "yes") && (Resident != "no"))
System.out.print("error - You didnt type yes or no. Try again: ");
Resident = console.next();
}while ((Resident != "yes") && (Resident != "no"))Don't compare Strings with ==, use the equals() method instead.
while(!("yes".equals(Resident) && "no".equals(Resident))) -
Dynamic where condition in Select statement
Hi,
I have 10 fields on selection-screeen. In which ever field the user enters single values or ranges,i should pick that field dynamically and pass that field along with value range to Where condition of Select statement.How can i achieve this? Please help.
Regards
K Srinivassee the following example:
data : begin of itab occurs 0,
matnr like mara-matnr,
end of itab.
ypes: begin of ty_s_clause.
types: line(72) type c.
types: end of ty_s_clause.
data : begin of gt_condtab occurs 0.
include structure hrcond.
data : end of gt_condtab.
FIELD-SYMBOLS <fs_wherecond> TYPE ty_s_clause.
data:
gt_where_clauses type standard table of ty_s_clause
with default key.
gt_condtab-field = 'MATNR'.
gt_condtab-opera = 'EQ'.
gt_condtab-low = '000000000000000111'.
append gt_condtab.
clear gt_condtab.
call function 'RH_DYNAMIC_WHERE_BUILD'
exporting
dbtable = space " can be empty
tables
condtab = gt_condtab
where_clause = gt_where_clauses
exceptions
empty_condtab = 01
no_db_field = 02
unknown_db = 03
wrong_condition = 04.
select matnr from mara into table itab where (gt_where_clauses). -
Checking conditions in SELECT statement
Hi All,
I am relative new to ABAP and I would like to ask a question about checking conditions in SELECT statement in the "WHERE" part.
There are two checkboxes at the selection screen and each should disable one of conditions (marked with two stars) in the SELECT mentioned below.
My question is, whether there exists an option how to solve this problem without using solution like:
IF checkobx1.
SELECT (without one condition)
ELSEIF checkbox2.
SELECT(without other condition).
ELSE.
SELECT (with both conditions)
SELECT qprueflos qherkunft qaufnr qsa_aufnr qmatnr qwerkvorg
qpastrterm qpaendterm
qverid qobjnr vobjnr AS objnr_fa vauart
FROM qals AS q INNER JOIN vkaufk AS v
ON qaufnr = vaufnr
INTO CORRESPONDING FIELDS OF TABLE gt_qals
WHERE q~prueflos IN s_pruefl
AND q~stat35 EQ space
AND q~werk EQ loswk
AND q~herkunft IN s_herk
AND q~offennlzmk EQ 0
AND q~offen_lzmk EQ 0
AND q~pastrterm IN s_startt
AND q~paendterm LE s_endt
AND v~auart IN s_auart. "('ZCPA', 'ZCPK', 'ZCBA').Hi,
With this, I think u can directly read into WHERE clause
IF checkbox1.
v_where = '& BETWEEN ''&'' AND ''&'' '.
REPLACE '&' WITH key_field INTO v_where.
REPLACE '&' WITH field_LOW INTO v_where.
REPLACE '&' WITH field_HIGH INTO v_where.
CONDENSE v_where.
ELSEIF checkbox2.
v_where = '& BETWEEN ''&'' AND ''&'' '.
REPLACE '&' WITH key_field INTO v_where.
REPLACE '&' WITH field_LOW INTO v_where.
REPLACE '&' WITH field_HIGH INTO v_where.
CONDENSE v_where.
ENDIF.
select * into corresponding fields of table ITAB
from (table_name)
where (v_where).
In this key_field is your fieldname in the where clause and field_low, field_high are range of values.
If i write static query it looks like this
RANGES: MATNR1 FOR MARA-MATNR.
MATNR1-LOW = MATNR_LOW.
MATNR1-HIGH = MATNR_HIGH.
MATNR1-SIGN = 'I'.
MATNR1-OPTION = 'BT'.
APPEND MATNR1.
select * into corresponding fields of table itab
from mara where matnr BETWEEN 'M100' AND 'M200'.
Hope it helps u
thanks\
Mahesh
Edited by: Mahesh Reddy on Jan 30, 2009 11:23 AM -
How Do You "Unload" Using a "While" statement?
How do you "Unload" or "Exit" using a "While" statement?
Sample: The console displays "Press Enter to continue".
Description: It a User press the Enter key, then the application would start over. On the other hand, if a User presses the "0" key, the application ends, exits. What code would be used?
THANKS ... signed ... VERY NEW at JAVA ...input=readInput();
while (input!=yourExitKey)
// do stuff here
input=readInput();
// End of code -
URGENT! Having problem with while statement and other syntax errors
I am trying to teach myself JSP for a school project due very soon. But I keep receiving errors surrounding my while statement. The errors are:
Syntax: ";" inserted to complete BlockStatements
Syntax: "}" inserted to complete Block
I have checked it over and over again, comparing against other examples found in this forum and against servlet examples and I can see no difference. This is my file for your information. It is supposed to list all the users in the user table. Is there a simpler way to do this?
regards
rach
<%@ page language="java" import="java.sql.*, java.util.*"%>
<html>
<head>
<title></title>
</head>
<body>
<%! String selected = null; %>
<%
try{
// Connect to the database
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:odbc:dbtest");
catch(ClassNotFoundException e) {
System.out.println("Database driver could not be found.");
System.out.println(e.toString());
throw new UnavailableException(this, "Database driver class not found");
try{
//create SQL statement
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from USER ORDER BY User_lastname, User_firstname");
catch(SQLException e){
System.out.println("Error connecting to the database.");
System.out.println(e.toString());
throw new UnavailableException(this, "Cannot connect to the database");
%>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td width="200" valign="top" align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td><form method="post" action="userupdatedelete.jsp" target="content" name="userlist">
<h2>Users</h2>
</td>
</tr>
<tr>
<td width="10"> </td>
</tr>
<tr>
<td valign="top"><select size="15" name="rec">
<!-- if the resultset is not null -->
<% try {
//if (rs.next()) {
While (rs.next()){
//retrieve data from User table
String userid = rs.getString("User_ID");
String firstname = rs.getString("User_firstname");
String lastname = rs.getString("User_lastname");
out.println("<option value='userid'>lastname + ', ' + firstname</option>");
//<option value="<%=userid%>"><%=lastname + ", " + firstname%></option>
//else {
// out.println("<option> - No Users Entered - </option>");
//<option> - No Users Entered - </option>
stmt.close();
con.close();
catch (SQLException ex){
System.err.print("SQL Exception :");
System.err.println(ex.getMessage());
%>
</select>
</td>
</tr>
<tr>
<td align="center"><input type="submit" value="Update/Delete"></td>
</tr></form>
<tr>
<td><br></td>
</tr>
<tr>
<td align="center">
<form method="post" action="useraddform.jsp" name="addbuttonform">
<input type="submit" value=" Add New " name="addnew">
</tr></form>
</table>
</td>
<td width="10"> </td>
</tr>
</table>
</body>
</html>There is a problem here with the "scope" of variables namely your variables "rs" and "stmt". Variables declared within a try block are available only within that try block. Also, the type for stmt is not even given.
Change:
try{
//create SQL statement
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from USER ORDER BY User_lastname, User_firstname");
catch(SQLException e){
System.out.println("Error connecting to the database.");
System.out.println(e.toString());
throw new UnavailableException(this, "Cannot connect to the database");
}to:
Statement stmt = null;
ResultSet rs = null;
try
//create SQL statement
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * from USER ORDER BY User_lastname, User_firstname");
catch(SQLException e)
System.out.println("Error connecting to the database.");
System.out.println(e.toString());
throw new UnavailableException(this, "Cannot connect to the database"); -
Hey, I'm having a problem with my while statement. I need to be able to have the program stop running when the input is Q. The only problem is that the input should otherwise be a number. I have to convert the user inputed number of dollars to euros using a previously inputed rate. So I can't just put everything as a String because then the equation doesn't work. Any help is welcome.
gdawgrancid wrote:
Hey, I'm having a problem with my while statement. I need to be able to have the program stop running when the input is Q. The only problem is that the input should otherwise be a number. I have to convert the user inputed number of dollars to euros using a previously inputed rate. So I can't just put everything as a String because then the equation doesn't work. Any help is welcome.A handy thing to do when solving ANY programming problem:
1. Understand the problem, and what it is you have to do.
2. Think of a solution in terms of english (or whatever your language may be)
3. Put that solution into pseudo-code, which is often easier than working out what Java classes you might need.
4. Take that pseudocode and code it in Java.
Apply that to your current situation and the while loop should sort itself out. -
Hi All. I am a student in java programming, beginning class. I am having problems with understanding how to make a loop body work properly using a while statement. I have a problem I am working on, and I can't seem to get it to run properly, and I believe its mainly because I don't understand what I am doing. I have been searching the net for examples of while statements, but all I find are mostly the same ones, and they don't help. Here is the code I have so far, which compiles fine, but does not return the value I want, and also it seems to run infinately. Any ideas or help with this concept would be greatly appreciated.
public class StereoPayments
public static final double INTEREST_MONTHLY = 0.015;
public static final int PAYMENT_MONTHLY = 50;
public static void main(String[] args)
//Need variables for monthly interest amount, for amount left over from $50 payment minus inerest(which gets
//subtracted from the principle.
double startMoney = 1000;
double monthsInterest = 0;
double moneyAfterInterestPayment = 0;
double numberOne = 0;
double numberTwo = 0;
System.out.println("Here is your payments");
while (startMoney >= 0)
moneyAfterInterestPayment = (startMoney*INTEREST_MONTHLY);
numberOne = (moneyAfterInterestPayment + startMoney);
numberTwo = (numberOne - PAYMENT_MONTHLY);
monthsInterest++;
System.out.println("Months of payments " + monthsInterest);
System.out.printf("Amount of interest paid " + numberOne);
I am trying to print out how long it took to pay off the stereo, at $50 a month, while adding the interest to it each month, then output the amount of months it took to pay it off, and the total amount of interest paid. I am obviously not doing this right though. Can anyone help me? Thanks in advance! Newbie101.public class StereoPayments
public static final double INTEREST_MONTHLY = 0.015;
public static final int PAYMENT_MONTHLY = 50;
public static void main(String[] args)
//Need variables for monthly interest amount, for amount left over from $50 payment minus inerest(which gets
//subtracted from the principle.
double startMoney = 1000;
double monthsInterest = 0;
double moneyAfterInterestPayment = 0;
double numberOne = 0;
double numberTwo = 0;
double currentAmount = 0;
System.out.println("Here is your payments");
while (startMoney >= 0)
moneyAfterInterestPayment = (startMoney*INTEREST_MONTHLY);
numberOne = (moneyAfterInterestPayment + startMoney);
startMoney = (numberOne - PAYMENT_MONTHLY);
monthsInterest++;
System.out.println("Months of payments " + monthsInterest);
System.out.printf("Amount of interest paid " + moneyAfterInterestPayment);
Here is a revised code. It does end now, thanks to you folks' help! However, I am failing to add up the interest amount. What is does is show how much interest is being paid monthly, but not adding it up to a grand total. So, would I make a statement of "moneyAfterInterestPayment++; ? Newbie101. -
Update Contract conditions in Real State
Hi,
I am working with real state moduel, while creating the contract offer user when selecting the conditions wants to select one condition on the basis of which i through some abap code should populate all the conditions.
The thing is can anyone tell me if there is a BADI or enhancement for this where i can put my code.
ThanksHi
I was able to solve the problem by using BADI_RECD_CONDITION,
I implemented the funtion named as CHECK_ALL.
In this function used the following code
io_object - > method import parameter
*To get Contract details
CALL FUNCTION 'API_RE_OF_GET_DETAIL'
EXPORTING
io_object = io_object "Object containing the
"reference for cont. offer
IMPORTING
et_condition = lt_condition
EXCEPTIONS
error = 1
OTHERS = 2.
*Manipulated the conditions and then updated them using
* update contracts
CALL FUNCTION 'API_RE_OF_CHANGE'
EXPORTING
io_object = io_object
it_condition = lt_condition_change
EXCEPTIONS
error = 1
OTHERS = 2.
These functions provide us with the updated data which the user has entered and not saved, that is the runtime data.
Regards,
Khusro Habib -
Can put condition in read statement for a particular fild please suggest?
hi i have a requirement as belo
1 ) i am reading a table with read statement now i want to read with one more condition like
where status<> Z
to add to this read statement as below can i add the above condition to the below statement?? let me know
how to check on this one more condition in below read statement
loop at itrecord1 into wa_Record
READ TABLE it_main INTO wa_inv_master WITH KEY
/' CUSIP = wa_record-primarykeyfield1 BINARY SEARCH.
here one more condition i need to put whilereading that where statu <>z which is best way todo
IF SY-SUBRC = 0.
APPEND wa_record TO itrecord1.
clear wa_record.
else.
APPEND wa_record TO itrecord2.
clear : wa_record.
ENDIF.
ENDLOOP.
so how to put the condition in above statment can put in the read statement as that is most convinient will that work?
regards
aroraHello arora.
You can restrict the READ to an internal table, using "n" conditions in WITH KEY statement.
Use:
READ TABLE it_main INTO wa_inv_master
WITH KEY cusip = wa_record-primarykeyfield1
field2 = wa_record-field2
fieldn = wa_record-fieldn
BINARY SEARCH.
Remember that if you want restrictions like ">=", "<=", "<" or "<", must use LOOP, not READ.
Regards.
Valter Oliveira.
Maybe you are looking for
-
File Upload, only work in server directory, PLS HELP!!
hi all, my sevlet program work only if the source file is in the server where tomcat is installed. Can I upload the file in pc's local harddisc? The following is my code: import sun.net.ftp.*; import sun.net.*; import java.io.*; import javax.servlet.
-
I have an apple tv box. It has been sest up, but now it says it is not connected. The light on the apple tv box is blinking, the apple logo is on the tv, but nothing is happening.
-
Deleting Duplicate Photos in LR5
How do I delete duplicate photos? I have hundreds of duplicates in the catelog, folders and collections. I must have imported them without checking "Do not import suspected duplicates". Now what? Thanks.
-
Java Web Services Developer Pack 1.3 and JDK 1.3.1
Does anyone know if I can use Java Web Services Developer Pack 1.3 with JDK 1.3.1? The installation instructions only mention JDK 1.4. Thanks, Jerry
-
Where can I test-drive an Ink & Slide?
Where can I test drive an Ink & Slide? I don't want to buy until I have a chance to try. Are there any retailers in the Providence RI area who have an available product set up to test?