Compare values in an ArrayList to another int variable
Hi all i'm just starting to use and understand ArrayList's, however i've come upon a problem and am a bit stuck! I want to compare an int variable, say int num to the values in an arrayList to see if the arrayList contains a match to num. I've looked through several tutorials and haven't found anything that talks about this, so is it possible and if so how?
@Keith: Hey, I was only reading the question ;)!
is there a way of adding multiple ints to an array list in one statementAdding to a list, not creating one...
@OP: Run this. And weep. (Or, at least be aware of the problem.)
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class AddAllEg {
public static void main(String[] args) {
test1();
test2();
public static void test1() {
List<Integer> list = new ArrayList<Integer>();
list.addAll(Arrays.asList(1, 42, -1));
System.out.println(list);
// later...
list.add(0);
System.out.println(list);
public static void test2() {
List<Integer> list = Arrays.asList(new Integer[] {1, 42, -1});
System.out.println(list);
// later...
list.add(0);
System.out.println(list);
}[Arrays.asList()|http://java.sun.com/javase/6/docs/api/java/util/Arrays.html#asList(T...)] does more than merely "make" a list.
Similar Messages
-
Need to compare values in two columns of one table against values in two columns in another table
Hi, as the title reads, I'm looking for an approach that will allow me to compare values in two columns of one table against values in two columns in another table.
Say, for instance, here are my tables:
Table1:
Server,Login
ABCDEF,JOHN
ABCDEF,JANE
FEDCBA,SEAN
FEDCBA,SHAWN
Table2:
Server,Login
ABCDEF,JOHN
ABCDEF,JANE
FEDCBA,SHAWN
In comparing the two tables, I'd like my query to report the rows in table1 NOT found in table2. In this case, it'll be the 3rd row of table one:
Server,Login
FEDCBA,SEAN
Thanks.create table Table1([Server] varchar(50), Login varchar(50))
Insert into Table1 values ('ABCDEF','JOHN'),('ABCDEF','JANE'),('FEDCBA','SEAN'),('FEDCBA','SHAWN')
create table Table2([Server] varchar(50), Login varchar(50))
Insert into Table2 values ('ABCDEF','JOHN'),('ABCDEF','JANE'), ('FEDCBA','SHAWN')
select [Server] ,Login from Table1
Except
select [Server] ,Login from Table2
select [Server] ,Login from Table1 t1
where not exists(Select 1 from Table2 where t1.[Server] = t1.[Server] AND Login=t1.Login)
drop table Table1,Table2 -
Problem getting arraylist from another class
I am trying to call information about an arraylist from another class. I am using this code to call the size of an arraylist:
import java.io.*;
public class Test
public static void main(String argv[]) throws IOException
Echo03 thing = new Echo03();
int y=thing.value();
System.out.println(y);
Echo03 thing2 = new Echo03();
int x=thing2.percent.size();
System.out.println(x);
}from another file which starts like this:
public class Echo03 extends DefaultHandler
static ArrayList<String> percent = new ArrayList<String>();
static ArrayList<String> text = new ArrayList<String>();
int a;
public int value(){
return percent.size();
public static void main(String argv[]) throws IOException
{The second file is based on an example piece of code from the Java website. I havent posted the whole thing, but if it is relevant then please ask.
Anyway when I run Echo03 by itself, the arraylist has a size of 2. But when I run it from the Test file, it says a size of 0. Is this because the data is not being transferred between the classes? Or is the Echo03 program not executing (and hence the arraylist is not filling up)?
How can I fix this? I have tried 2 ways of calling the data (As seen in my Test file). Neither work.I didnt post the full bit of the code for the second one. Here it is:
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import java.util.ArrayList;
import java.awt.*;
import javax.swing.*;
public class Echo03 extends DefaultHandler
static ArrayList<String> percent = new ArrayList<String>();
static ArrayList<String> text = new ArrayList<String>();
int a;
public static void main(String argv[]) throws IOException
if (argv.length != 1) {
System.err.println("Usage: cmd filename");
System.exit(1);
// Use an instance of ourselves as the SAX event handler
DefaultHandler handler = new Echo03();
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter(System.out, "UTF8");
// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(argv[0]), handler);
for (int b=0; b<percent.size();b++){
System.out.println(percent.get(b+1));
} catch (Throwable t) {
System.exit(0);
static private Writer out;
public void startElement(String namespaceURI,
String lName, // local name
String qName, // qualified name
Attributes attrs)
throws SAXException
if (attrs != null) {
StringBuffer sb = new StringBuffer (250);
for (int i = 0; i < attrs.getLength(); i++) {
nl();
emit(attrs.getValue(i));
sb.append (attrs.getValue(i));
String sf = sb.toString ();
percent.add(sf);
System.out.println(" String: "+sf); a++;
public void characters(char buf[], int offset, int len)
throws SAXException
emit(" ");
String s = new String(buf, offset, len);
if (!s.trim().equals("")) {text.add(s); emit(s);}
//===========================================================
// Utility Methods ...
//===========================================================
// Wrap I/O exceptions in SAX exceptions, to
// suit handler signature requirements
private void emit(String s)
throws SAXException
try {
out.write(s);
out.flush();
} catch (IOException e) {
throw new SAXException("I/O error", e);
// Start a new line
private void nl()
throws SAXException
String lineEnd = System.getProperty("line.separator");
try {
out.write(lineEnd);
} catch (IOException e) {
throw new SAXException("I/O error", e);
} -
ArrayList e .RangeCheck(int)line 546
Hi guys I am working on this project
in few word
I have to draw different shape on a panel
moreover when two similar shapes collide ( 2 circles ) they make a bigger circle
when st change direction
almost everything works
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import javax.swing.JPanel;
class ShapePanel extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
public static ArrayList <Shape>shapes;
private javax.swing.Timer animationTmr;
int speed;
PlaySound audioClip = new PlaySound();
private float heigth;
private float width;
private int shape1;
private int shape2;
public ShapePanel() {
shapes = new ArrayList<Shape>();
animationTmr = new javax.swing.Timer(80, this); //interval, ActionListener
animationTmr.start();
public ArrayList<Shape> getShapes()
return shapes;
public void addSquare(int x, int y,int w,int h, int shapeType) {
shapes.add(new Square(this,x, y,width, heigth, shapeType));
repaint();
System.out.println(shapes.size());
public void addCircle(int x, int y,int w,int h, int shapeType) {
shapes.add(new Circle(this, x, y,width, heigth, shapeType));
repaint();
System.out.println(shapes.size());
public void addRectangle(int x, int y,int w,int h, int shapeType) {
shapes.add(new Rectangle(this, x, y,width, heigth, shapeType));
repaint();
System.out.println(shapes.size());
public void addStar(int x, int y,int w,int h, int shapeType) {
shapes.add(new Star(this, x, y,width, heigth, shapeType));
repaint();
System.out.println(shapes.size());
public void paintComponent(Graphics g) { //called Whenever panel needs
super.paintComponent(g); //re-displaying:
Iterator<Shape> it = shapes.iterator(); //Iterate through Balls calling
g.setColor(Menu.getColor());
g.fillRect(0, 0, this.getWidth(), this.getHeight());
while (it.hasNext()) { //each one's paint method
it.next().paint(g);
public void actionPerformed(ActionEvent ev) {
//On timer tick,
Iterator<Shape> it = shapes.iterator(); //Iterate through Balls calling
while (it.hasNext()) { //each one's updatePos() method
it.next().updatePos();
checkTypeCollision();
handleCollision();
repaint();
private void checkTypeCollision()
//we iterate through all the balls, checking for collision
for(int i=0;i<shapes.size();i++)
for(int j=0;j<shapes.size();j++)
if(i!=j)
if(collide(shapes.get(i), shapes.get(j)))
shape1=shapes.get(i).shapeType;
shape2=shapes.get(j).shapeType;
if(shape1==shape2)
/* int newX = (int) ((shapes.get(i).getCenterX() + (shapes.get(j).getCenterX()/2))/2);
int newY = (int) ((shapes.get(i).getCenterY() + (shapes.get(j).getCenterY() /2))/2);
float newWidth = shapes.get(i).getWidth()+(shapes.get(j).getWidth()/2);
float newHeigth = shapes.get(i).getHeigth()+(shapes.get(j).getHeigth()/2);
int newShapeType = shapes.get(i).shapeType;
if(shapes.get(i).getShapeType()==1)
shapes.remove(j); //remove shape element at j
shapes.remove(i); //remove shape element at j
System.out.println("SIZE IS==="+ shapes.size());
System.out.println("newx====="+newX);
System.out.println("newy====="+newY);
System.out.println("newWidth====="+newWidth);
System.out.println("newx====="+newHeigth);
// shapes.add(new Rectangle(this,newX,newY,530,530,newShapeType));
System.out.println("SIZE IS==="+ shapes.size());
// repaint();
if(shapes.get(i).getShapeType()==2)
shapes.remove(j); //remove shape element at j
shapes.remove(i); //remove shape element at j
// shapes.add(new Circle(this,newX,newY,newWidth,newHeigth,newShapeType));
// repaint();
if(shapes.get(i).getShapeType()==3)
shapes.remove(j); //remove shape element at j
shapes.remove(i); //remove shape element at j
shapes.add(new Square(this,newX,newY,newWidth,newHeigth,newShapeType));
if(shapes.get(i).getShapeType()==3)
shapes.remove(j); //remove shape element at j
shapes.remove(i); //remove shape element at j
//shapes.add(new Star(this,newX,newY,newWidth,newHeigth,newShapeType));
// repaint();
private void handleCollision()
//we iterate through all the balls, checking for collision
for(int i=0;i<shapes.size();i++)
for(int j=0;j<shapes.size();j++)
if(i!=j)
if(collide(shapes.get(i), shapes.get(j)))
shapes.get(i).hit(shapes.get(j));
shapes.get(j).hit(shapes.get(i));
boolean collide(Shape b1, Shape b2)
double wx=b1.getCenterX()-b2.getCenterX();
double wy=b1.getCenterY()-b2.getCenterY();
//we calculate the distance between the centers two
//colliding balls (theorem of Pythagoras)
double distance=Math.sqrt(wx*wx+wy*wy);
if(distance<b1.shapeSize)
audioClip.playRectangle();
return true;
else return false;
public static int vectorSize()
return shapes.size();
}the drawing stops and
i have this error after a while
arrayList<e>.RangeCheck(int)line 546
moreover it doesn t draw a bigger shape as i want with the line
shapes.add(new Circle(this,newX,newY,newWidth,newHeigth,newShapeType));
help please the deadline is Tomorrow;Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
at java.util.ArrayList.RangeCheck(ArrayList.java:546)
at java.util.ArrayList.get(ArrayList.java:321)
at ShapePanel.checkTypeCollision(ShapePanel.java:156)
at ShapePanel.actionPerformed(ShapePanel.java:77)
at javax.swing.Timer.fireActionPerformed(Timer.java:271)
at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
it doesn t compile because is part of a bigger project -
Move value from one listbox to another listbox
Hi,
I have two list boxes with list of values in it. Can anyone help me to move values from one listbox to another listbox on click of a button in AWT. It will be of great help if i can get any sample code.
Thanks a lot in advancehi,
do u want to move a specific item that is selected or all of the items?
anyway the logic is very simple!:)
if u want to transfer the currently selected itme form the first List box,
use the method getSelectedItem() to get the currently selected item.
then keep this value in a String variable (item)
and use getItemSelected() to get the Index of it in int.
keep this value in an int variable (index)
then delete the item from the first list using the method remove(index) on the first list object.
then add the item to the second list using
add(item) on the second list object.
hope u can work it out urself from here!
rgds
JP -
Required UDF for comparing values within same context
I have to compare values within the same context.I am getting boolean values for that field.If all the values in the same context are true,then the result should be true .Otherwise false should be passed.
If input is-
<context>
true
false
true
<context>
true
true
<context>
Output should be as-
<context>
false
<context>
true
<context>
Please suggest how to acheive this?..its urgentHi,
Check with this UDF
Src>UDF>target
public void context1(String[] a,ResultList result,Container container)
int k = 0;
int arrayLength = a.length;
if (arrayLength > 0)
String firstElement = a[0];
for (int i = 1; i < arrayLength; ++i)
if(!(a<i>.equalsIgnoreCase(firstElement)))
k = 0;
break;
else
k = 1;
if(k == 1)
result.addValue("true");
else
result.addValue("false"); -
Values added into arraylist are override with the last value
Hi,
I am running a very simple java program.
Here is the sample program.
CustProfAccountFid fid = new CustProfAccountFid();
for(int i=0;i<cp104Result.size();i++ ){
Hashtable cp104ht = (Hashtable)cp104Result.get(i);
fid.setFidSeqNumber((String)cp104ht.get("x"));
fid.setFidType((String)cp104ht.get("z"));
fid.setFidName((String)cp104ht.get("c"));
fid.setFidText((String)cp104ht.get("v"));
custProfAccountFidList.add(fid);
Here cp104Result and custProfAccountFidList, both are arraylist.
I want to get all the values added to the arraylist.But the problem is when loop continues the arraylist values get
override by the last value.
As a result i get 5 or 6 same values in the arraylist.
Please help me out for the solution.
Thanks in advance.for(int i=0;i<cp104Result.size();i++ ){
CustProfAccountFid fid = new CustProfAccountFid();
Hashtable cp104ht = (Hashtable)cp104Result.get(i);
fid.setFidSeqNumber((String)cp104ht.get("x"));
fid.setFidType((String)cp104ht.get("z"));
fid.setFidName((String)cp104ht.get("c"));
fid.setFidText((String)cp104ht.get("v"));
custProfAccountFidList.add(fid);
} -
Passing value from one jsp to another?
how to pass value from one jsp to another? i have a value assigned in the link, i want to pass that value to another jsp page?
please help with code?Instead of the value being passed, i am getting a null value.
Here is my calendar code:
<%@page import="java.util.*,java.text.*" %>
<html>
<head>
<title>Print a month page.</title>
</head>
<body bgcolor="white">
<%
boolean yyok = false;
int yy = 0, mm = 0;
String yyString = request.getParameter("year");
if (yyString != null && yyString.length() > 0)
try
yy = Integer.parseInt(yyString);
yyok = true;
catch (NumberFormatException e)
out.println("Year " + yyString + " invalid" );
Calendar c = Calendar.getInstance( );
if (!yyok)yy = c.get(Calendar.YEAR);
mm = c.get(Calendar.MONTH);
%>
<table align="center">
<tr>
<td>
<form method=post action="calendar.jsp">
Enter Year : <select name="year">
<%
for(int i= yy;i<=2010;i++)
%>
<OPTION VALUE= <%=i%> > <%=i%> </option>
<%
%>
</select>
<input type=submit value="Display">
</form>
</td>
</tr>
<tr>
<table>
<%!
String[] months = {"January","February","March",
"April","May","June",
"July","August","September",
"October","November", "December"
int dom[] = {
31, 28, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31
%>
<%
int leadGap =0;
%>
<div id="t1" class="tip"><table border="4" cellpadding=3 cellspacing="3" width="250" align="center" bgcolor="lavender">
<tr>
<td halign="centre" colgroup span="7" style="color:#FF0000;">
</colgroup>
<tr>
<td>
<%
GregorianCalendar calendar =null;
for(int j=0;j<12;j++)
calendar = new GregorianCalendar(yy, j, 1);
int row = 1 ;
row = row + j;
%>
<table>
<tr>
<colgroup span="7" style="color:#FF0000;">
</colgroup>
</tr>
<tr align="center">
<th colspan=7>
<%= months[j] %>
<%= yy %>
</th>
</tr>
<tr>
<td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td>
</tr>
<%
leadGap = calendar.get(Calendar.DAY_OF_WEEK)-1;
int daysInMonth = dom[j];
if ( calendar.isLeapYear( calendar.get(Calendar.YEAR) ) && j == 1)
++daysInMonth;
out.print("<tr>");
out.print(" ");
for (int h = 0; h < leadGap; h++)
out.print("<td>");
out.print("</td>");
for (int h = 1; h <= daysInMonth; h++)
out.print("<td>");
out.print("<a href=desc.jsp>" + h + "</a>" );
out.print("</td>");
if ((leadGap + h) % 7 == 0)
out.println("</tr>");
out.println("</tr></table></div>");
if( row%3 != 0)
out.println("</td><td>");
else
out.println("</td></tr>\n<tr><td>");
%>
</html>I need to pass the value in 'h' to the desc.jsp page.
my code for desc.jsp is :
<html>
<head>
</head>
<body bgcolor="lightblue">
<form method=post action="Calenda.jsp">
<br>
<%= request.getParameter("h") %>
<h2> Description of the event <INPUT NAME="description" TYPE=TEXT SIZE=20> </h2>
<BR> <INPUT TYPE=SUBMIT VALUE="submit">
</form>
</body>
</html>But i am not able to pass the value. The 'h' value contains all the date. i want to pass only a single date, the user clicks to the other page. please help -
Comparable[] items, Comparable value
how can I change this
public static boolean search(Comparable[] items, Comparable value, int low, int high) {
if (low > high) return false;
int middle = (low + high) / 2;
if (items[middle].equals(value)) return true;
if (value.compareTo(items[middle]) < 0) {
// recursively search the left part of the array
return search(items, value, low, middle-1);
else {
// recursively search the right part of the array
return search(items, value, middle+1, high);
TO
public static boolean binarySearch(int[] nums, int value, int low, int high) {
}By simply changing the method signature and the code?
-
Calling arraylist from another class - help please!!
Hey, I need some help calling my arraylist from my GUI class, as the arraylist is in the 'AlbumList' class and not in the 'GUI' class i get the error 'cannot find symbol', which is pretty obvious but i cannot figure how to get around this problem. help would be greatly appreciated.
i have written ***PROBLEM*** next to the bad line of code!
Thanks!!
public class Album
String artist;
String title;
String genre;
public Album(String a, String t, String g)
artist = a;
title = t;
genre = g;
public String getArtist()
return artist;
public String getTitle()
return title;
public String getGenre()
return genre;
public class AlbumList
public ArrayList <Album> theAlbums;
int pointer = -1;
public AlbumList()
theAlbums = new ArrayList <Album>();
public void addAlbum(Album newAlbum)
theAlbums.add(newAlbum);
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GUI extends JFrame
public int max = 5;
public int numAlbums = 4;
public int pointer = -1;
public GUI ()
super("Recording System");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel main = new JPanel();
JPanel panel1 = new JPanel();
panel1.setLayout(new GridLayout(3,2,0,0));
JPanel panel2 = new JPanel();
panel2.setLayout(new GridLayout(1,2,20,0));
final JLabel artistLBL = new JLabel("Artist: ");
final JLabel titleLBL = new JLabel("Title: ");
final JLabel genreLBL = new JLabel("Genre: ");
final JTextField artistFLD = new JTextField(20);
final JTextField titleFLD = new JTextField(20);
final JTextField genreFLD = new JTextField(20);
final JButton nextBTN = new JButton("Next");
nextBTN.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
pointer++;
artistFLD.setText(theAlbums.get(pointer).getArtist()); ***PROBLEM***
titleFLD.setText("NEXT");
genreFLD.setText("NEXT");
final JButton prevBTN = new JButton("Prev");
prevBTN.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
pointer--;
artistFLD.setText("PREVIOUS");
titleFLD.setText("PREVIOUS");
genreFLD.setText("PREVIOUS");
panel1.add(artistLBL);
panel1.add(artistFLD);
panel1.add(titleLBL);
panel1.add(titleFLD);
panel1.add(genreLBL);
panel1.add(genreFLD);
panel2.add(prevBTN);
panel2.add(nextBTN);
main.add(panel1);
main.add(panel2);
setVisible(true);
this.getContentPane().add(main);
setSize(500, 500);
-----------------------------------------------------------------------Thanks!!
Edited by: phreeck on Nov 3, 2007 8:55 PMthanks, it dosnt give me a complication error but when i press the button it says out of bounds error, and i think my arraylist may be empty possibly even though i put this data in.. this is my test file which runs it all.
any ideas? thanks!!
public class Test
public static void main(String []args)
AlbumList a = new AlbumList();
String aArtist = "IronMaiden";
String aTitle = "7thSon";
String aGenre = "HeavyMetal";
Album newA = new Album(aArtist, aTitle, aGenre);
a.addAlbum(newA);
aArtist = "LambOfGod";
aTitle = "Sacrament";
aGenre = "Metal";
Album newB = new Album(aArtist, aTitle, aGenre);
a.addAlbum(newB);
aArtist = "JohnMayer";
aTitle = "Continuum";
aGenre = "Guitar";
Album newC = new Album(aArtist, aTitle, aGenre);
a.addAlbum(newC);
aArtist = "StillRemains";
aTitle = "TheSerpent";
aGenre = "Metal";
Album newD = new Album(aArtist, aTitle, aGenre);
a.addAlbum(newD);
GUI tester = new GUI();
} -
Copy values from a filed to another in different blocks in same table
Hi All,
How to copy value from a filed to another field in different blocks in same form ?
example if i change value in Field A of block 1 it should reflect in Field B block 2 and again if i change in Field B block 2 it should reflect in Field A of block 1.
values will change twice or thrice then it will not change. It is happening like that.
how to do this ?
RegardsSame table / different blocks
I guess, both blocks will be marked for update, and when your user presses commit, the same table will be updated twice!
Are you sure that this is what you want to do? Is the same record current in both blocks? If so, you better use 1 block (it can be spread over several canvases and windows) and synchronize the items with the "synchronize item" property.
Anyway: If you can't apply the synchronize-property bcos the items are in different blocks, you can synchronize with 2 when-validate-item triggers.
Wolfram -
How to get a value from one item into another
How can i get value from one item into another item.
Ex: I have a report, in there i have check boxes, and when i have checked some rows, and press submitt, a prosses computates it into a item on another page, and a branche redirects to page 3. Then i'm going to use the value in the item into a PL/SQL script in an report to show the submittet items.
How can i do this?
Computation script, pages and all that is fixed. But i dont know which PL/SQL statement to use to get th value from the item.Hi Fredr1k,
Use the V() function from pl/sql.
e.g. V('P3_MY_ITEM')
will return the value of that page item.
As long as the pl/sql is called from within the Apex environment.
Regards
Michael -
How we can get the values from one screen to another screen?
hi guru's.
how we can get the values from one screen to another screen?
we get values where cusor is placed but in my requirement i want to get to field values from one screen to another screen.
regards.
satheesh.Just think of dynpros as windows into the global memory of your program... so if you want the value of a field on dynpro 1234 to appear on dynpro 2345, then just pop the value into a global variable (i.e. one defined in your top include), and you will be able to see it in your second dynpro (assuming you make the field formats etc the same on both screens!).
-
Copying value from one cursor to another
Hi,
I have a problem while copying values from one cursor to another cursor.
The code looks like below.
PROCEDURE XYZ
TransactionResultSet OUT NOCOPY types.ref_cursor,
IS
temp_cursor types.ref_cursor;
wip_rec types.ref_cursor;
BEGIN
DECLARE
CURSOR temp_cursor IS
SELECT ...........
END;
BEGIN
FOR wip_rec IN temp_cursor
LOOP
update tinsagr set something
where {the condition}
IF SQL%ROWCOUNT = 0 THEN
dbms_output.put_line('this is test ');
Fetch wip_rec into TransactionResultSet;
END IF;
END LOOP;so basically i want to iterate the "temp_cursor" and depending on the values i get it from here i shall update a table. Actually i want to exclude few records from "temp_cursor" and add it/copy rest of the records to "TransactionResultSet"
That means say initially " temp_cursor" has 100 records and i updated 5 records in a table and same number of records should be excluded and rest should be added to the output cursor TransactionResultSet.
How do i achieve it?
while saving i am getting
(1): PLS-00456: item 'WIP_REC' is not a cursor.
Do any one has any idea what to do in such scenario?There are options like....
SQL> CREATE OR REPLACE TYPE emp_obj AS OBJECT (ename VARCHAR2(50), dept NUMBER);
2 /
Type created.
SQL> CREATE OR REPLACE TYPE emp_tbl IS TABLE OF emp_obj;
2 /
Type created.
SQL> set serverou on
SP2-0158: unknown SET option "serverou"
SQL> set serverout on
SQL> DECLARE
2 rc sys_refcursor;
3 v_ename emp.ename%TYPE;
4 v_dept emp.deptno%TYPE;
5 ---End Of Local Varriable Declaration
6 --Procedire declaration !
7 PROCEDURE TEST_CUR(pi_out_ref_cur IN OUT sys_refcursor) IS
8 emp_rec emp_tbl;
9 BEGIN
10 /* This BULK COLLECT can be done with explicit cursor,Ref Cursor
11 with some simple modification, Here I have used implicit cursor! */
12 SELECT emp_obj(ename, deptno) --Casting as the object
13 BULK COLLECT
14 INTO emp_rec
15 FROM emp
16 WHERE deptno = 10;
17
18 dbms_output.put_line('Records selected are:');
19 FOR i in 1 .. emp_rec.COUNT LOOP
20 dbms_output.put_line(emp_rec(i).ename || '--' || emp_rec(i).dept);
21 END LOOP;
22 --Now we are filtering the record and may be doing some operation with each record.
23 FOR i in 1 .. emp_rec.COUNT LOOP
24 IF emp_rec(i).ename = 'KING' THEN
25 --You can change this IF according to your need.
26 emp_rec.DELETE(i);
27 END IF;
28 END LOOP;
29 OPEN pi_out_ref_cur FOR
30 SELECT * FROM TABLE(emp_rec); --Using the TYPE AS table.
31 END TEST_CUR;
32 /* Main execution or procedure calling section*/
33 BEGIN
34 --Actual calling
35 TEST_CUR(rc);
36 dbms_output.new_line;
37 dbms_output.put_line('Now in Ref Cursor');
38 dbms_output.put_line('****************');
39 LOOP
40 FETCH rc
41 INTO v_ename, v_dept;
42 dbms_output.put_line(v_ename || '--' || v_dept);
43 EXIT WHEN rc%NOTFOUND;
44 END LOOP;
45
46 END;
47 /
Records selected are:
CLARK--10
KING--10
MILLER--10
Now in Ref Cursor
CLARK--10
MILLER--10
MILLER--10
PL/SQL procedure successfully completed.
SQL> -
Passing the values from one pgm to another pgm (Calling pgm has no sel scr)
Hi gurus,
In my requirement i need to pass the values from one program to another program.
I am using SUBMIT statement . But , the program which i am calling has no selection screen.
So how can i pass the values?
Please help me ASAP.
Regards,
Bhanu.RExport your internal tables or work areas to a memory id in ur program before u use submit.
Then in second pgm you have to import from memory id given above.
example.
EXPORT gs_header FROM gs_header to memory id 'HEADER'.
EXPORT gt_item FROM gt_item to memory id 'ITEM'.
SUBMIT YFIIN_DISHC_MAILREPORT EXPORTING LIST TO MEMORY AND RETURN.
In your second pgm you can write
import gs_header TO gs_header from MEMORY id 'HEADER'.
import gt_item TO gt_item from MEMORY id 'ITEM'.
Maybe you are looking for
-
Total Settlement Value field not getting populated in IW38 Transaction
Dear all PMCS group Members, I have a list of Maintenance Orders on which Actual Costs are posted and also periodic settlements done before TECO. When i list these Maintenance Orders in IW38 transaction the system is bringing in the values in Tot
-
ERROR WHILE POSTING THE STOCK OF MATERIAL
Dear experts while posting the stock of material iam getting the error 'number ranges for transevent type WA in year 2011 does not exist. what transaction should be used . Thanks & Regards. Erfan.
-
"This game cannot be played" Texas Hold'Em
I have found a lot of questions on this - but no responses. I've even tried deleting it and re-purchasing it, which also gave the same error. I've played this before on my iPod, but I think one of the newer games has corrupted something. I have a mod
-
Need help with a report design- 11.1.1.5(11g)
Hello Experts I have a report with Category(Electronics, Home App..), Brand(Philips, samsung,..), products(TV, Laptop, Lamps..), % Expenses, % Profit and now the users want this report in such a way that Category, Brand and Products has to come under
-
MTO " PROCESS AFTER SALES ORDER .
hi all , can any one xplain MM integration n MTO Make To Order) , can u pl let me as am into SD module . It would be of gr8 help if you can provide config steps . MM01 views required for MTO . Regards, jerry.