Methods that return more than one object.
Hello everyone,
I don't know if this has ever been proposed or if there's an actual solution to this in any programming language. I just think it would be very interesting and would like to see it someday.
This is the thing: why isn't it possible for a method to return more than one object. They can receive as many parameters as wanted (I don't know if there's a limit), but they can return only 1 object. So, if you need to return more than one, you have to use an auxiliary class...
public class Person {
private String name;
private String lastName;
public Person(String name, String lastName) {
this.name = name;
this.lastName= lastName;
public String getName() {
return name;
public String getLastName() {
return lastName;
}So if you want to get the name of somebody you have to do this, assuming "person" is an instance of the object Person:
String name = person.getName();And you need a whole new method (getLastName) for getting the person's last name:
String lastName = person.getLastName();Anyway, what if we were able to have just one method that would return both. My idea is as follows:
public class Person {
private String name;
private String lastName;
public Person(String name, String lastName) {
this.name = name;
this.lastName= lastName;
public String name, String lastName getName() {
return this.name as name;
return this.lastName as lastName;
}And you would be able to do something like:
String name = person.getName().name;and for the last name you would use the same method:
String lastName = person.getName().lastName;It may not seem like a big deal in this example, but as things get more complicated simplicity becomes very useful.
Imagine for example that you were trying to get information from a database with a very complex query. If you only need to return 1 column you have no problem, since your object can be an array of Strings (or whatever type is necessary). But if you need to retrieve all columns, you have three options:
- Create 1 method per column --> Not so good idea since you're duplicating code (the query).
- Create and auxiliary object to store the information --> Maybe you won't ever use that class again. So, too much code.
- Concatenate the results and then parse them where you get them. --> Too much work.
What do you think of my idea? Very simple, very straight-forward.
I think it should be native to the language and Java seems like a great option to implement it in the future.
Please leave your comments.
Juan Carlos García Naranjo
It's pretty simple. In OO, a method should do one thing. If that thing is to produce an object that contains multiple values as part of its state, and that object makes sense as an entity in its own right in the problem domain--as opposed to just being a way to wrap up multiple values that the programmer finds it convenient to return together--then great, define the class as such and return an instance. But if you're returning multiple values that have nothing to do with each other outside of the fact that it's convenient to return them together, then your method is probably doing too much and should be refactored.
As for the "if it increases productivity, why not add it?" argument, there are lots of things that would "increase productivity" or have some benefit or other, but it's not worth having them in the language because the value they add is so small as to no be worth the increase in complexity, risk, etc. MI of implementation is one great example of something that a lot of people want because it's convenient, but that has real, valid utility only in very rare cases. This feature is another one--at least in the domain that Java is targetting, AFAICT.
Similar Messages
-
How to return more than one object from SwingWorker
I am using a SwingWorker to call 3 different methods of another class (data fetch class). Each of these 3 methods returns a String array. I am able to get the first array outside the thread code using the get() method of the SwingWorker class,
final String tmpOrdNum = OrderNum;
SwingWorker worker = new SwingWorker() {
DATA_FETCH_TO_ARRAY data_fetch = new DATA_FETCH_TO_ARRAY(tmpOrdNum);
public Object construct(){
String [] orderArr = data_fetch.getHeaderArray();
//String [] detailArr = data_fetch.getDetailArray();
//String [] storeArr = data_fetch.getStoreArray();
return orderArr;
//Runs on the event-dispatching thread.
public void finished(){ }
worker.start() ;
String[] testArr = (String[])worker.get(); //gets the header array
/* HOW DO I GET THE DETAIL AND STORE ARRAYS HERE?*/I want to be able to call the other 2 methods of the data fetch class - getDetailArray() and getStoreArray() shown commented in the above code one by one.
Can someone please suggest a way of doing this? Thank you.Return String[][] from construct method.
Here is an example (observe test method):
import java.util.*;
public class ArrayTest{
public static void main(String[] args){
String[][] result=(String[][])new ArrayTest().test();
System.out.println("result1: "+Arrays.toString(result[0]));
System.out.println("result2: "+Arrays.toString(result[1]));
System.out.println("result3: "+Arrays.toString(result[2]));
public Object test(){
String[] str1={"A","B","C"};
String[] str2={"M","N","O"};
String[] str3={"X","Y","Z"};
String[][] out=new String[3][];
out[0]=str1;
out[1]=str2;
out[2]=str3;
return out;
}Thanks,
Mrityunjoy -
Can a method return more than one value?
I was studying for my biology exam and I got bored and I started thinking and then I wandered if a method can return more than one value...?
For example, if I want a method to return a row a column, I make a method that returns an int. But what if I want to return two ints? Or what If I want to return an integer and a string? Is it possible or do I have make two methods, each returning one thing?
What I always did until now is is I want for example to return a few integers, I would store them in a String and then when I return the string, I parse the numbers out using stringtokenizer... but it doesn't look like the best way... and it's pretty annoying...I'm weak on terminology, hence I don't even know what
AFAIK means...As Far As I Know
This doesn't really make sense for me. It's more
efficient to make a whole class just for two
integers, than having two methods? Efficiency is not the point. The flow is.
If you have two methods, the caller must be aware of both of them. The other way it's up to the callee.
Just because the
two integers are related to each other? Doesn't
making a class require more memory usage than just
making two one-line methods?The memory usage is not wholly irrelevant, but there are ways to handle that (caching, inlining, etc.).
It's a bit hard to counter your point for me, but if you had done a lot of GUI painting stuff, you'd see all those Points, Dimensions, Rectangles, you name it, are quite invaluable. -
Can a function return more than one item or object?
Hi I am trying to move text movies and textfields around a stage. This is a learning curve for me. I am confused by an example I have found on the internet.
http://forums.adobe.com/community/flash/flash_actionscript
What type of object is
var letter:Object = getLetterObject(_text.charAt(i)); // in the draw function
as it has properties
letter.stepDegrees = _totalAngle / numOfLetters;
getLetterObject()
seems to return lotts of stuff which would not be done in other languages like C
return
movie:movie,
field:field,
widthInDegrees:0,
fieldWidth:field.width,
fieldHeight:field.height
I would like to get my head around this as this is a good example of what I need. Well parts of it actualy.
I understand that the text field is added as a child to the Movieclip. I would have expected just a MovieClip object returned.
full code including the function getLetterObject()
=======
package
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
public class CurvedText extends MovieClip
public static const DIRECTION_UP:String = "up";
public static const DIRECTION_DOWN:String = "down";
public var showLetterBorder:Boolean = false;
public var showCurve:Boolean = false;
private var _letterHolder:MovieClip;
private var _text:String;
private var _radius:Number;
private var _letters:Array;
private var _widthOfText:Number = 0;
private var _startAngle:Number = 0;
private var _endAngle:Number = 360;
private var _totalAngle:Number = 0;
private var _textFormat:TextFormat;
private var _direction:String;
public function CurvedText(text:String = "", radius:Number = 200, startAngle:Number = 0, endAngle:Number = 360, direction:String = "up", textFormat:TextFormat = null)
_text = text;
_radius = radius;
_startAngle = startAngle;
_endAngle = endAngle;
_direction = direction;
_textFormat = textFormat;
_letters = [];
_totalAngle = Math.abs(_startAngle) + Math.abs(_endAngle);
public function draw():void
// checking if there is any text set
if(_text == "")
return;
// clearing the letters' holder
if(_letterHolder && contains(_letterHolder))
removeChild(_letterHolder);
_letterHolder = new MovieClip();
addChild(_letterHolder);
// adding letters
var numOfLetters:int = _text.length;
for(var i:int=0; i<numOfLetters; i++)
var letter:Object = getLetterObject(_text.charAt(i));
letter.stepDegrees = _totalAngle / numOfLetters;
_letters.push(letter);
_widthOfText += letter.fieldWidth;
_letterHolder.addChild(letter.movie);
// positioning
position();
// draw the curve
if(showCurve) {
_letterHolder.graphics.lineStyle(1, 0xFF0000, 1);
_letterHolder.graphics.drawCircle(0, 0, _radius);
private function getLetterObject(letter:String):Object
// setting default text format
if(!_textFormat)
_textFormat = new TextFormat();
_textFormat.align = TextFormatAlign.CENTER;
_textFormat.font = "Verdana";
_textFormat.size = 12;
_textFormat.color = 0x000000;
// creating the field
var movie:MovieClip = new MovieClip();
var field:TextField = new TextField();
field.width = 10;
field.defaultTextFormat = _textFormat;
field.embedFonts = true;
field.multiline = false;
field.autoSize = TextFieldAutoSize.CENTER;
field.text = letter;
field.x = -field.width / 2;
field.y = -field.height / 2;
if(showLetterBorder)
field.border = true;
movie.addChild(field);
return // RETURNS more than one value?
movie:movie,
field:field,
widthInDegrees:0,
fieldWidth:field.width,
fieldHeight:field.height
private function position():void
// position the letters
var numOfLetters:int = _letters.length;
var degrees:Number = _startAngle;
for(var i:int=0; i<numOfLetters; i++)
var angle:Number = _letters[i].stepDegrees + degrees;
if(_direction == DIRECTION_DOWN)
angle -= 180;
_letters[i].movie.scaleY = -1;
} else {
xValue = _radius * Math.cos((angle-90)/180*Math.PI);
yValue = _radius * Math.sin((angle-90)/180*Math.PI);
var xValue:int = _radius * Math.cos((angle-90)/180*Math.PI);
var yValue:int = _radius * Math.sin((angle-90)/180*Math.PI);
_letters[i].movie.x = xValue;
_letters[i].movie.y = yValue;
_letters[i].movie.rotation = angle;
degrees += _letters[i].stepDegrees;
// position the holder
var bounds:Rectangle = _letterHolder.getBounds(this);
_letterHolder.x = -bounds.x;
_letterHolder.y = -bounds.y;
if(_direction == DIRECTION_DOWN)
_letterHolder.scaleX = -1;Hi
I still think I need an Object parent child linkage diagram on this to get my head around it.
It seems that things are reversed so that it is Object:value. Kind of confusing to see movie:movie.
var letter:Object = getLetterObject(_text.charAt(i));
letter holds the following objects
MovieClip:Movie
TextField:field
widthInDegrees:0 // What is this. What type is a widthInDegrees
fieldWidth:field.width // Same as above
fieldHeight:field.height // Same as above
And to cap it all, back in the calling function draw()
letter.stepDegrees = _totalAngle / numOfLetters; // What is stepDegrees a property of? MovieClip,TextField,widthInDegrees,fieldWidth or fieldHeight
I can understand the first two but not the last three
For example widthInDegrees is not mentioned anywhere in the code. and
letter.stepDegrees // implies that stepDegrees is a property of Object:letter.
Do you throw a property and value blindly at the letter object and let flash work out which object it is a property of?
MovieClip & TextField do not have this property. Searched the web for this information. We need an equivelent of MSDN.
Desmond. -
Hi,
Sorry for that long title, but that's my question.
Can Vision track more than one object in a same area - objects that might cross?
Because I'm able to do it, extracting XY, but it looks like "IMAQ Count Objects" doesn't track object frame after but frame, but extract the XY coordinates always in the same way, like example starting from top and everytime he sees an object, he extracts the XY, but if the objects cross (then he will extract XY without caring which objects was the previous one but just based on "scan from top to bottom").
This is why I opened this topic in the non Vision forum part : http://forums.ni.com/t5/LabVIEW/Sort-XY-by-closest/td-p/2440428
Thank you,
Sébastien
Solved!
Go to Solution.Hi,
In fact, IMAQ count object order the object regarding their top most and left most pixel, but not regarding their gravity center point.
Axis origin of an image is situated on the left top corner.
You need to refer to other caracteristics such as shape or color to identify your objects.
Regards -
Making an int() return more than one method?
hey people. i need an int, for example,
public int someInt(){
return 1000;
}to return more than one number. To clarify, i need to be able to call the int() and it return me three different values. Is this possible?BigDaddyLoveHandles wrote:
Word origins: guru
Hmmm... "Heavy, weighty"
Reminds me of a t-shirt my brother has. He's a rather portly gentlemen. The shirt has a picture of Buddha and the caption, "I have the body of a god." -
GetSelectedRowKeys() returns more than one on Single Selection Tree Table
Hi,
I found that this issue occurring after PS3 (I think.)
I have a tree table component, which allows single row selection. There is a listener on a column of the tree table as follows:
public void listenPackageUnit(ValueChangeEvent valueChangeEvent)
Object oldKey = getTreeComponent().getRowKey();
try
* Retrieve index of selected package unit
* NOTE: Subtract 1 to remove no selection value. This only
* needs to be done if attached LOV has No Selection option set.
if (valueChangeEvent.getNewValue() != null)
Row row = null;
String selectedPackageUnit = null;
int packageUnitIndex = (Integer) valueChangeEvent.getNewValue();
packageUnitIndex--;
* Due to the no selection item, we need to prevent search of regular
* iterator if index is < 0. In this case we know the user selected
* the no selection (blank) value.
if (packageUnitIndex >= 0)
* Using index, determine the value of the selected package unit
DCIteratorBinding packageUnitsIterator =
(DCIteratorBinding) PasUiADFUtil.resolveExpression("#{bindings.PackageUnitsIterator}");
Row newRow =
packageUnitsIterator.getRowAtRangeIndex(packageUnitIndex);
selectedPackageUnit = (String) newRow.getAttribute("LookupCode");
RowKeySet selection = this.getTreeComponent().getSelectedRowKeys();
if (selection != null && selection.getSize() > 0)
for (Object facesTreeRowKey: selection)
this.getTreeComponent().setRowKey(facesTreeRowKey);
JUCtrlHierNodeBinding rowData =
(JUCtrlHierNodeBinding) this.getTreeComponent().getRowData();
row = rowData.getRow();
setSelectedLabel((String) row.getAttribute("Label"));
setSelectedLabelType((String) row.getAttribute("LabelType"));
row.setAttribute("PackageUnit", selectedPackageUnit);
getTreeComponent().setRowKey(oldKey);
finally
getTreeComponent().setRowKey(oldKey);
The issue is that getSelectedRowKeys() returns more than one when the user selects a child row in the tree table.
It seems to be returning the total number counting from the top parent through the child.
(For example, if the child is the second generation, it returns 2, and if the third generation, it returns 3.)
This is causing the issue that the method tries to update the attribute of the parent row with a value for the child row. (And it fails, because the attribute is updateable only while new.)
I remember getSelectedRowKeys() always returned one, the selected child itself, when I coded this around October, 2010.
Is this a design change after PS3? Why does it return more than one though the tree table is for single selection?
How can I get around this issue?
It would be truly appreciated if we can get any quick help, since we are at final testing phase of our product.
Thank you,
TomoHi Vinod,
I found the solution. Thank you very much for your suggestions. :)
Now my listenSelection (custom listener of the tree table) looks like below:
public void listenSelection(SelectionEvent selectionEvent)
Row currentRow;
PasUiADFUtil.invokeEL("#{bindings.TransactionLabelTopLevelVO1.collectionModel.makeCurrent}",
new Class[] { SelectionEvent.class },
new Object[] { selectionEvent });
Object oldKey = getTreeComponent().getRowKey();
try
if (this.getTreeComponent() != null)
RowKeySet rks = this.getTreeComponent().getSelectedRowKeys();
Iterator keys = rks.iterator();
while (keys.hasNext())
List key = (List) keys.next();
this.getTreeComponent().setRowKey(key);
JUCtrlHierNodeBinding node =
(JUCtrlHierNodeBinding) this.getTreeComponent().getRowData();
if (node != null)
currentRow = node.getRow();
if (currentRow != null)
this.setSelectedRow(currentRow);
setSelectedLabel((String) currentRow.getAttribute("Label"));
setSelectedLabelType((String) currentRow.getAttribute("LabelType"));
String shippedItemFlag =
(String) currentRow.getAttribute("ShippedItemFlagValue");
if (shippedItemFlag != null && shippedItemFlag.equals("1"))
setDisableAdd(true);
else
setDisableAdd(false);
finally
getTreeComponent().setRowKey(oldKey);
/* Refresh Action menu and buttons */
RequestContext.getCurrentInstance().addPartialTarget(this.getActionMenu());
RequestContext.getCurrentInstance().addPartialTarget(this.getToolbar());
And my tree table is like below:
<af:treeTable value="#{bindings.TransactionLabelTopLevelVO1.treeModel}"
var="node" rowSelection="single" id="tt1"
contentDelivery="immediate" fetchSize="25"
emptyText="#{bindings.TransactionLabelTopLevelVO1.viewable ? commonFoundationMsgBundle.NO_DATA_TO_DISPLAY : commonFoundationMsgBundle.ACCESS_DENIED}"
selectionListener="#{pageFlowScope.MaintainTransactionSerialAssociationBean.listenSelection}"
binding="#{pageFlowScope.MaintainTransactionSerialAssociationBean.treeComponent}"
summary="#{maintainAssociationUiBundle.CONTAINER_SERIAL_HIERARCHY}">
<!-- Row Header -->
The listener is now always getting the currently selected row only.
Tomo -
Can a Method listen to more than one event in ABAP OO ?
Hi,
is it possible to prepare/register a handler method for e.g two events of two different classes ?
Or can a method generally listen to only one event ?
It seems that the syntax allows only one event ?
methods event_handler for event my_event of my_class.
Thanks for help in advance
OlafAn event can refer to more than one object but you have to instantiate the objects
for example I have 2 grids and want to handle events depending on which grid
the user is selecting / requesting actions on. (I've just posted the relevant bits coded here as data extraction etc you can code normally).
FORM instantiate_grid
* Create Grid container
* Instantiate Grid class
* Instantiate Event Handler class
* Display the Grid
USING grid_container TYPE REF TO cl_gui_custom_container
class_object TYPE REF TO cl_gui_alv_grid
container_name TYPE scrfname.
* create the container
CREATE OBJECT grid_container
EXPORTING container_name = container_name.
* Create the ALV grid object using
* container just created
CREATE OBJECT class_object
EXPORTING
i_parent = grid_container.
* Exclude the SUM function from the GRID toolbar
ls_exclude = cl_gui_alv_grid=>mc_fc_sum.
APPEND ls_exclude TO lt_exclude.
* Instantiate our handler class
* lcl_event_handler
CALL METHOD class_object->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
CREATE OBJECT g_handler.
SET HANDLER g_handler->handle_double_click FOR class_object.
SET HANDLER g_handler->handle_hotspot_click FOR class_object.
SET HANDLER g_handler->handle_toolbar FOR class_object.
SET HANDLER g_handler->handle_user_command FOR class_object.
SET HANDLER g_handler->handle_data_changed FOR class_object.
SET HANDLER g_handler->handle_data_changed_finished FOR class_object.
ENDFORM. "instantiate_grid
MODULE status_0100 OUTPUT.
IF grid_container IS INITIAL.
PERFORM instantiate_grid
USING grid_container
grid1
'CCONTAINER1'.
* Grid title Primary Grid
struct_grid_lset-grid_title = 'Delimit Old org Units - Selection'.
struct_grid_lset-edit = 'X'.
struct_grid_lset-sel_mode = 'D'.
PERFORM display_grid
USING
grid1
<dyn_table>
it_fldcat.
ENDIF.
SET PF-STATUS '001'.
SET TITLEBAR '000' WITH 'Delimit Old Org Units'.
ENDMODULE. "status_0100 OUTPUT
* PAI module
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANC'.
LEAVE PROGRAM.
WHEN 'RETURN'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. "user_command_0100 INPUT
MODULE status_0200 OUTPUT.
IF grid_container1 IS INITIAL.
PERFORM instantiate_grid
USING grid_container1
grid2
'CCONTAINER2'.
* Grid title secondary grid
struct_grid_lset-grid_title = 'Delimited Objects'.
struct_grid_lset-edit = ' '.
PERFORM display_grid
USING
grid2
<dyn_table1>
it_fldcat1.
SET PF-STATUS '001'.
SET TITLEBAR '000' WITH 'Org Units Delimited'.
endif.
ENDMODULE. "status_0200 OUTPUT
In your local event handling class use the variable SENDER to determine which grid / object triggered the event
for example
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
**Hot spot Handler
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id es_row_no,
**Double Click Handler
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column es_row_no
sender,
** Toolbar handler.
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive
sender,
* button press
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm
sender,
* data changed
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed,
*data changed finished
handle_data_changed_finished
FOR EVENT data_changed OF cl_gui_alv_grid,
download_to_excel.
ENDCLASS. "lcl_event_handler DEFINITION
* Implementation methods for lcl_event_handler
CLASS lcl_event_handler IMPLEMENTATION.
*Handle Hotspot Click
* When a "hotspotted"cell is double clicked
* Hotspot indicatore needs to be set in
* the field catalog.
* Not required for this application.
METHOD handle_hotspot_click .
PERFORM mouse_click
USING e_row_id
e_column_id.
CALL METHOD grid1->get_current_cell
IMPORTING
e_row = ls_row
e_value = ls_value
e_col = ls_col
es_row_id = ls_row_id
es_col_id = ls_col_id
es_row_no = es_row_no.
CALL METHOD grid1->refresh_table_display.
CALL METHOD grid1->set_current_cell_via_id
EXPORTING
is_column_id = e_column_id
is_row_no = es_row_no.
ENDMETHOD. "lcl_event_handler
*Handle Double Click
METHOD handle_double_click.
CASE sender.
WHEN grid1.
* returns cell double clicked FROM GRID 1
* Ignore any event from GRID 2
PERFORM double_click
USING e_row
e_column.
ENDCASE.
ENDMETHOD. "handle_double_click
* Add our buttons to standard toolbar
METHOD handle_toolbar.
CASE sender.
* Only add functionality to PRIMARY GRID (GRID 1)
WHEN grid1.
* append a separator to normal toolbar
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
* Delimit Org
CLEAR ls_toolbar.
MOVE 'PROC' TO ls_toolbar-function.
MOVE icon_railway TO ls_toolbar-icon.
MOVE 'DELIMIT' TO ls_toolbar-quickinfo.
MOVE 'DELIMIT ORG UNIT' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
* Select All Rows
MOVE 'SELE' TO ls_toolbar-function.
MOVE icon_select_all TO ls_toolbar-icon.
MOVE 'ALL CELLS' TO ls_toolbar-quickinfo.
MOVE 'ALL CELLS' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
* Deselect all Rows.
MOVE 'DSEL' TO ls_toolbar-function.
MOVE icon_deselect_all TO ls_toolbar-icon.
MOVE 'DESELECT ALL' TO ls_toolbar-quickinfo.
MOVE 'DESELECT ALL' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDCASE.
move 0 to ls_toolbar-butn_type.
move 'EXCEL' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move icon_xxl to ls_toolbar-icon.
move 'Excel' to ls_toolbar-quickinfo.
move 'EXCEL' to ls_toolbar-text.
append ls_toolbar to e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command.
* Entered when a user presses a Grid toolbar
* standard toolbar functions processed
* normally
g_sender = sender.
CASE e_ucomm.
WHEN 'PROC'. "Process selected data
PERFORM get_selected_rows.
WHEN 'SELE'.
PERFORM select_all_rows.
WHEN 'DSEL'.
PERFORM deselect_all_rows.
WHEN 'EXCEL'.
call method me->download_to_excel.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "handle_user_command
METHOD handle_data_changed.
* only entered on data change Not req for ths app.
PERFORM data_changed USING er_data_changed.
ENDMETHOD. "data_changed
METHOD handle_data_changed_finished.
* only entered on data change finished Not req for ths app.
PERFORM data_changed_finished.
ENDMETHOD. "data_changed_finished
* Interactive download to excel
method download_to_excel.
field-symbols:
<qs0> type standard table,
<qs1> type standard table.
data: G_OUTTAB1 type ref to data,
g_fldcat1 type ref to data,
LS_LAYOUT type KKBLO_LAYOUT,
LT_FIELDCAT type KKBLO_T_FIELDCAT,
LT_FIELDCAT_WA type KKBLO_FIELDCAT,
L_TABNAME type SLIS_TABNAME.
case g_sender.
when grid1.
get reference of <dyn_table> into g_outtab1.
get reference of it_fldcat into g_fldcat1.
when grid2.
get reference of <dyn_table1> into g_outtab1.
get reference of it_fldcat1 into g_fldcat1.
endcase.
assign g_outtab1->* to <qs0>.
assign g_fldcat1->* to <qs1>.
call function 'LVC_TRANSFER_TO_KKBLO'
exporting
it_fieldcat_lvc = <qs1>
* is_layout_lvc = m_cl_variant->ms_layout
is_tech_complete = ' '
importing
es_layout_kkblo = ls_layout
et_fieldcat_kkblo = lt_fieldcat.
loop at lt_fieldcat into lt_fieldcat_wa.
clear lt_fieldcat_wa-tech_complete.
if lt_fieldcat_wa-tabname is initial.
lt_fieldcat_wa-tabname = '1'.
modify lt_fieldcat from lt_fieldcat_wa.
endif.
l_tabname = lt_fieldcat_wa-tabname.
endloop.
call function 'ALV_XXL_CALL'
exporting
i_tabname = l_tabname
is_layout = ls_layout
it_fieldcat = lt_fieldcat
i_title = sy-title
tables
it_outtab = <qs0>
exceptions
fatal_error = 1
no_display_possible = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endmethod.
ENDCLASS. "lcl_event_handler IMPLEMENTATION
The sender instance is a variable such as g_sender type ref to cl_gui_alv_grid. "Sender instance.
The above example is for OO ALV grids but should work for other interactive cases where a User presses a key or does a mouse action.
Cheers
jimbo -
Subquery returned more than one value
Hi,
I have this statement which has been working fine - not I get a 'Subquery returned more than one value" error:
SELECT
'WAS3' AS 'Rec ID',
E.EecEEID AS 'Emp ID',
eepNameFirst AS 'First Name',
eepNameLast AS 'Last Name',
EecDateOfOriginalHire AS 'Service Date',
(SELECT DATEDIFF(YEAR, EecDateOfOriginalHire, getdate()) from empcomp EC WHERE EC.EecEEID = E.EECEEID) as 'Yrs of Serv'
FROM
EmpPers
JOIN EmpComp E
ON E.eecEEID = eepEEID
JOIN Company
ON eecCoID = cmpCoID
WHERE
EecDateOfTermination IS NOT NULL
AND EXISTS
(SELECT 1
FROM EmpComp e2
WHERE e2.EecEEID = E.EecEEID
--AND e2.eecEmplStatus <> 'A')-- changed to <> ...this WAS/is to filter out anyone that was termed then re-hired
--AND E.EecTermReason NOT IN ('I01','I02','I03','I14','I22','V05','V07','V09','V12','V22','V13', 'TRO')
AND E.eecDateOfTermination
IN (SELECT (EC.eecDateOfTermination)
FROM EMPCOMP EC
WHERE EC.EecEEID = E.EECEEID
AND EC.eecDateOfTermination IS NOT NULL
AND eC.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
AND EC.eecDateOfTermination <=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)
AND e.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
AND E.eecDateOfTermination <= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)))
--AND eC.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,('12/30/2007')),0)
-- AND EC.eecDateOfTermination <=DATEADD(wk,DATEDIFF(wk,0,('12/30/2007')),6)
-- AND e.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,('12/30/2007')),0)
-- AND E.eecDateOfTermination <= DATEADD(wk,DATEDIFF(wk,0,('12/30/2007')),6)
-- AND E.eecDateOfTermination IS NOT NULL ))
--added below per Paul Cottle to exclude employeess less than four years
AND E.eecdateoforiginalhire >=dateadd(year,-4, CURRENT_TIMESTAMP)
qeqwCheck this, if it works:
SELECT
'WAS3' AS 'Rec ID',
E.EecEEID AS 'Emp ID',
eepNameFirst AS 'First Name',
eepNameLast AS 'Last Name',
EecDateOfOriginalHire AS 'Service Date',
DATEDIFF(YEAR, EecDateOfOriginalHire, getdate()) as 'Yrs of Serv'
FROM EmpPers
JOIN EmpComp E ON E.eecEEID = eepEEID
JOIN Company ON eecCoID = cmpCoID
WHERE EecDateOfTermination IS NOT NULL
AND EXISTS
(SELECT 1
FROM EmpComp e2
WHERE e2.EecEEID = E.EecEEID
AND E.eecDateOfTermination
IN (SELECT (EC.eecDateOfTermination)
FROM EMPCOMP EC
WHERE EC.EecEEID = E.EECEEID
AND EC.eecDateOfTermination IS NOT NULL
AND eC.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
AND EC.eecDateOfTermination <=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)
AND e.eecDateOfTermination >= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
AND E.eecDateOfTermination <= DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)))
AND E.eecdateoforiginalhire >=dateadd(year,-4, CURRENT_TIMESTAMP)
If this post answers your query, please click "Mark As Answer" or "Vote as Helpful". -
Selecting more than one object at a time
Hi guys and girls
I am trying to select more than one object on my artboard and Shift+clicking on the next one isn't working...
I am creating an interactive form in Indesign and realised that I have everything on one layer... I have radio buttons for yes/no questions and I wanted to move them to a new layer for ease of selection and editing...
I have tried selecting one and then Shift+Click on the next but it just moves which one is selected...?
I even tried creating a new layer and dragging them up to the new layer...no Dice?
Has anyone any ideas....Please!
bookie56
P.S. Just realised that the radio buttons are part of the text? Could this be the reason why I can't move them. Doesn't solve the question about selection thoughHi AnshulJain19
OK! sort of guessed that....thanks for coming by.
I am still on this form and have created multiline text boxes for two of my text boxes.... have checked the positioning of the boxes - but when I write in the box in Adobe Acrobat the text is quite a long way above the line...this is only happening with the multiline boxes.
Is there a way to export a font colour for the boxes or does this need to be done in Acrobat Reader...?
I have a standard dark background for my page and that needs a White font...when I fill the form in it is black...
bookie56 -
Function - Return More than One Value in a Concatenated String
Hi,
Is it possible for a function to return a concatenated string(combining more than one number). I am trying to return the PO number by inputting and invoice_id and code number but an invoice_id can have more than one PO with the same code number. I would like to concatenate the PO numbers with commas e.g.
10124, 10090, 10987
At the moment the function returns null for these cases that have more than one PO number.
ThanksAlso is is possible to create another function that can be called in the same script using the PO number as an IN parameter in SQL. See SQL below:
select cck.concatenated_segments as "Segment" ,
cc.code_combination_id,
NVL ( src . user_je_source_name , '**********' ) AS "Source" ,
NVL ( cat . user_je_category_name , '**********' ) AS "Category" ,
jel . period_name as "Period Name" ,
i.invoice_id as "Invoice ID",
s.vendor_name as "Vendor Name",
s.segment1 as "Supplier No",
jeb . name as "Batch Name" ,
func_get_po(i.invoice_id, cc.code_combination_id) "PO No",
jeh . name AS "Header Name" ,
jel . description AS "Description" ,
jel.accounted_dr AS "Debit" ,
jel.accounted_cr AS "Credit" ,
NVL(jel.accounted_dr, 0) - NVL(jel.accounted_cr, 0) AS "Net Amount"
FROM apps.gl_code_combinations cc ,
apps.gl_code_combinations_kfv cck,
apps.gl_je_lines jel ,
apps.gl_je_headers jeh ,
apps.gl_je_batches jeb ,
apps.gl_je_categories cat ,
apps.gl_je_sources src,
apps.gl_import_references r,
apps.xla_ae_lines al,
apps.xla_ae_headers ah,
apps.xla_events e,
xla.xla_transaction_entities te,
apps.ap_invoices_all i,
apps.ap_suppliers s
WHERE ( cck.concatenated_segments BETWEEN '23.83545.141.000.00.23.000.000' AND '23.83545.141.000.00.23.000.000'
AND cc.CHART_OF_ACCOUNTS_ID = 50328
AND jeh.LEDGER_ID IN
(select acc.ledger_id
FROM apps.gl_access_set_ledgers acc
WHERE acc.access_set_id = 1000
AND jel.code_combination_id = cc.code_combination_id
AND cck.code_combination_id = cc.code_combination_id
AND jel.status
|| '' = 'P'
AND ( jel.accounted_dr != 0
OR jel.accounted_cr != 0 )
AND jeh.je_header_id = jel.je_header_id
AND jeh.actual_flag = 'A'
AND 1 = 1
AND jeh.currency_code != 'STAT'
AND jeb.je_batch_id = jeh.je_batch_id
AND jeb.average_journal_flag = 'N'
and src.je_source_name = jeh.je_source
and cat.je_category_name = jeh.je_category
and r.je_header_id(+) = jel.je_header_id
and r.je_line_num(+) = jel.je_line_num)
AND ( :period_name = jel.period_name
and al.gl_sl_link_id(+) = r.gl_sl_link_id
and al.ae_header_id = ah.ae_header_id(+)
and al.application_id = ah.application_id(+)
and ah.application_id = e.application_id(+)
and ah.event_id = e.event_id(+)
and e.application_id = te.application_id(+)
and e.entity_id = te.entity_id(+)
and nvl(te.source_id_int_1,-99) = i.invoice_id(+)
and i.vendor_id = s.vendor_id(+) )
AND ( jel.ledger_id = 2041)
ORDER BY src.user_je_source_name ,
cat.user_je_category_name ,
jeb.name ,
jeh.name ,
cck.concatenated_segments ,
jel.je_line_num
I am using func_get_po(i.invoice_id, cc.code_combination_id), I would like to call another function in this script that uses the PO number as an IN parameter.
For example func_get_po_requester(i.invoice_id, cc.code_combination_id, func_get_po(i.invoice_id, cc.code_combination_id))
Would this work?
Thanks -
Can Function Return more than One Values ??
Hi Experts,
I would like to ask you Can Function Return more than one values. I Used Function with Out and In out parameter and its working Fine..
1. what is harm using Out and In out parameter in function
2. if we can use Out and In out parameter in Function so what is deffernce between procedure and Function.
3. Is there any Other Way Though which we can return more the One values in Function.
Please advice me...
Thanks
Umesh GoelYes/No.
You can return multiple value from function. But, in PL/SQL and not in a SQL.
The following examples demonstrate that -
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Mar 28 17:41:15 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create or replace package glob
2 as
3 b varchar2(20);
4 c varchar2(20);
5 end;
6 /
Package created.
SQL>
SQL> create or replace function test_mul_out(a in number)
2 return number
3 is
4 cursor c1(eno in number)
5 is
6 select ename,job,sal
7 from emp
8 where empno = eno;
9
10 rec c1%rowtype;
11 d number(10);
12 begin
13 open c1(a);
14 loop
15 fetch c1 into rec;
16 exit when c1%notfound;
17 glob.b:= rec.ename;
18 glob.c:= rec.job;
19 d:= rec.sal;
20 end loop;
21 close c1;
22 return d;
23 end;
24 /
Function created.
SQL> set serveroutput on
SQL>
SQL> declare
2 zz number(10);
3 begin
4 select test_mul_out(7777)
5 into zz
6 from dual;
7
8 dbms_output.put_line('Ename: '||glob.b);
9 dbms_output.put_line('Job: '||glob.c);
10 dbms_output.put_line('Sal: '||zz);
11 end;
12 /
Ename: Avik
Job: CLERK
Sal: 3456
PL/SQL procedure successfully completed.
SQL> Regards.
Satyaki De. -
How to return more than one record through OUT parameter in procedure
Hi,
I want to create a procedure which accepts one input and returns more than one record as output.
example:
Input = DeptNo
Output= Empno,ename,sal,comm,job
Scenario:
There can be more than one employee in department we pass as the IN parameter. OUT parameter has to return all the records of the corresponding employee details in that department.
Thanks in advance for your help
Regards,
K.Vijay-- I think you can try something like this using ref cursor:
-- create a package for the type ref cursor and execute
CREATE OR REPLACE PACKAGE PACK_REFCURSOR_FOR_TABLES AS
TYPE DATA_TableRows IS REF CURSOR;
END;
-- after executing the package above, create your procedure:
CREATE OR REPLACE PROCEDURE GET_EMP (
IN_nDeptNo IN number,
OUT_Emp OUT PACK_REFCURSOR_FOR_TABLES.DATA_TableRows)
IS
BEGIN
-- leave query open (implicit) as this will return data
OPEN OUT_Emp FOR
SELECT *
FROM tblEmp
WHERE DeptNo = IN_nDeptNo;
END;
--execute the procedure and you're done -
Possible to return more than one value?
If I have a somethign like this:
public int test()
return 5;
}Is it possible to have test() return more than one value? And if it can, can you post an example showing how?Could you post an example of how to do this?If you do not know how to define a class, you need to start from the very beginning.
Sun's basic Java tutorial
Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's Thinking in Java (Available online.)
Joshua Bloch's Effective Java
Bert Bates and Kathy Sierra's Head First Java.
James Gosling's The Java Programming Language. Gosling is
the creator of Java. It doesn't get much more authoratative than this. -
Can oracle function return more than one value
Hi All
please answer can oracle function return more than one value
need one schenario
regardsCan any function, irrespective of the language, return multiple values?
OF COURSE NOT!!
So why do you think Oracle will now suddenly do it differently than all other languages? Never mind that it is impossible for a function (a unit/module of code) returning a memory address, to return multiple memory addresses. The machine code that does that, has not been yet been designed/implemented.
I am continually amazed that this question is asked. It is about something so fundamental in almost every single 3rd and 4th generation language... something that is taught right at the start... the definition of what a procedure and what a function is.
Sorry, but I simply cannot pull punches on this subject and smooth it over. There is something fundamentally wrong with your training as a programmer if you have to ask such a question about a function.
And whatever programming skills you build on such a foundation, will be seriously lacking.
I kindly suggest that you get back to the very basics of programming - and review and revisit until you fully understand it. There are no shortcuts in becomming a good programmer.
Message was edited by:
Billy Verreynne
Maybe you are looking for
-
I'm trying to create an easy way of inputting data in a JTextField. I have a column of textfields, each requiring fixed-length data-input, and the idea is that the user types series of two digits continuously, without having to press ENTER or TAB bet
-
NoLogging mode and System Change Number
Hi, We are working on migration project from our application currently into 5.3 version to 6.0 version. once EDB is transformed into 6.0 version there is a datawarehouse to which data needs to be pushed. There is a Oracle CDC sitting on top of EDB th
-
How Do I Free-hand Cut an Object Out of a Pic With PSE 8?
I want to completely free-hand cut a horse out of one pic and then save it into another pic with a different background. I can't figure out how to do this with PSE 8. It is my first time using this program. The only picture editing program I have use
-
I have looked every where!
-
Proper Port Name Mini-DVI or Micro-DVI or Mini-DisplayPort
Hello. I have got a new Macbook Pro but the connection for external monitors on it does not fit with my DVI connections for my old macbook pro. What connection do I need to connect to a DVI cable coming from my monitor? Is there a cable that works fo