Adding two generic number types
Hi all,
As a small exercise I am trying to devise a generic maths class that can add two numbers together either Integer, Float and Double types.
I have written the following code
class Test {
public static void main(String args[]) {
MathClass<Integer> integers = new MathClass<Integer>();
Integer i= new Integer(2);
System.out.println(integers.add(i,i));
class MathClass<T> {
public T add(T a, T b) {
return a + b;
public T subtract(T a, T b) {
return a - b;
public T multiply(T a, T b) {
return a * b;
public T divide(T a, T b) {
return a / b;
}But I get a compile error which says that I can't use the + - * / operators on T.
Yet something like the following code works
public class Test2 {
public static void main(String[] args) {
Integer i = new Integer(2);
Integer o = new Integer(2);
System.out.println(i + o);
}Is there a way to make the generic maths class work as I would like?
Even with the UpperBound as Number it will not be able to work as the compiler will not be able to apply autoboxing feature with Number. Number class has byteValue(), intValue(), floatValue() and doubleValue() as method, so Number class is not a spefic datatype class.
This will work because of the feature autoboxing.
public Integer addInteger(Integer a, Integer b) {
return a + b;
This will not work...
public Number addInteger(Number a, Number b) {
return a + b;
}
Similar Messages
-
What is the point of Precision and Scale in Number Type?
Version :11.2
What is the point in having PRECISION and SCALE in number type? If you create the column with just NUMBER ie.without
specifying precision or scale , you can enter numbers with any precision and scale.
SQL> select * From v$version where rownum < 2;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
SQL> create table t1 (col1 number);
Table created.
SQL> insert into t1 values (223.9939394);
1 row created.
SQL> insert into t1 values (88.228384);
1 row created.
SQL> insert into t1 values (9.34);
1 row created.
SQL> insert into t1 values (000.00);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t1;
COL1
223.993939
88.228384
9.34
0Did you ever have a business scenario where a Numerical column should store values only with a fixed precision and scale ?Omega3 wrote:
Version :11.2
What is the point in having PRECISION and SCALE in number type? If you create the column with just NUMBER ie.without
specifying precision or scale , you can enter numbers with any precision and scale.
SQL> select * From v$version where rownum < 2;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
SQL> create table t1 (col1 number);
Table created.
SQL> insert into t1 values (223.9939394);
1 row created.
SQL> insert into t1 values (88.228384);
1 row created.
SQL> insert into t1 values (9.34);
1 row created.
SQL> insert into t1 values (000.00);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t1;
COL1
223.993939
88.228384
9.34
0Did you ever have a business scenario where a Numerical column should store values only with a fixed precision and scale ?Lots of business requirements for specific precisions and scales.
A persons Age may required to be stored as whole numbers of no more than 3 digits.
A sum of money may required to be stored with no more than 2 decimal places of accuracy e.g. GB Pounds and Pence or US Dollars and Cents
A unit of length may required to be stored in metres with 2 decimal places for centimetres
A shoe size may be required to be stored with one decimal place for half sizes
etc.
etc.
Yes, you may just create all of them as generic NUMBER datatype, but creating them with precision and scale can provide additional information about the limitations expected for the values stored, especially for things like reporting tools that may use the specified precision and scale to determine how to display the values automatically (by default).
If you start questioning "what's the point?" then you may as well say what's the point in having a NUMBER datatype when we can store numbers in a VARCHAR2 datatype? or what's the point in having a DATE datatype when we can stored dates as VARCHAR2 datatype? etc.
No point in asking such a question because there's almost always a point to these things (and if there isn't they get deprecated in later versions). -
How to update the null values to some number on the NUMBER type of column
Hello All,
I have one NUMBER type of column in DB table. It has some (null) values. I want to update with value 1. I tried to run the Update statement , It gives 0 rows updated.
SELECT objectid,attr20 FROM table;
object id attr20
====== ====
fff70b67-8d54-4ad7-bc57-7b40a0d8b219 (null)
cac5264a-b363-487b-bfe6-6b84d60064e9 (null)
2fc2a626-51d8-401c-9495-18aacd4c35c8 (null)
1b60bfa4-ff68-4488-adf6-2a83528c0e20 (null)
1c662829-24c1-4b3c-9289-0128e170c043 5
74f11331-545b-435f-bf4b-f57c7a6b4500 2
c941c1ac-a18e-47ec-843c-dbe2a5b51001 0
d7eba203-93c0-48ea-a109-9b06015ef387 0
eba72fa3-21d8-4489-bb93-917ebbd67de2 0
I ran following query but no success.
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 = NULL
0 rows updated
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 = null
0 rows updated
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 = ''
0 rows updated
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 =' '
Error starting at line 1 in command:
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 =' '
Error report:
SQL Error: ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause:
*Action:
can some one help me out to update such values ????Hi,
"=" will not work for NULL values. Please remeber two NULL values are NOT same. Try IS operator.
UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 IS NULLRegards,
Avinash -
Generic cursor type // generic datatype
Hi,
I would like to dynamically declare a cursor in my procedure and retrieve rows from it for firing insert / update statements on another table. The procedure should take a table_name in VARCHAR2 and use it to declare a cursor like:
procedure thisProcedure (table_name in VARCHAR2) is
cursor thisCursor is select * from <table_name>;
thisRow thisCursor%ROWTYPE;
begin
loop
fetch thisCursor into thisRow
-- exit when empty
-- do sth. with this record (insert or update on another table depending on data in thisRow)
end loop;
end thisProcedure;
I have been around in several forums and have got as far as declaring a weak cursor variable (one declared without return clause) and then opening this cursor with dynamic SQL. However, the moment I want to fetch a row of that cursor into a record, I would fail as weak cursor variables do not know their ROWTYPE. So in that case, I would have the cursor correct, but I would not have the corresponding - generically and dynamically declared - datatype:
procedure thisProcedure (table_name in VARCHAR2) is
type thisCursorType is ref cursor;
thisCursor thisCursorType;
thisRow <table_name>%ROWTYPE;????
begin
open thisCursor for 'my dynamic SQL';
loop
fetch thisCursor into WHAT???????
-- exit when empty
-- do sth. with this record (insert or update on another table depending on data in thisRow)
end loop;
end thisProcedure;
Anybody know a solution or a workaround? Anything?
Cheers
SebastianMaybe you can use object types and ANYDATA/ANYTYPE types. For example:
CREATE TYPE dept_obj_type AS OBJECT (
deptno NUMBER (2),
dname VARCHAR2 (20)
CREATE TABLE dept_obj_table OF dept_obj_type
CREATE TYPE emp_obj_type AS OBJECT (
empno NUMBER (4),
ename VARCHAR2 (20),
deptno NUMBER (2)
CREATE TABLE emp_obj_table OF emp_obj_type
-- procedure inserts a "generic object type" variable
CREATE OR REPLACE PROCEDURE gen_insert1 (
p_table VARCHAR2,
p_anydata ANYDATA)
IS
l_statement VARCHAR2 (32000);
BEGIN
l_statement :=
' DECLARE' ||
' l_anydata ANYDATA := :p_anydata;' ||
' l_object ' || p_anydata.GetTypeName || ';' ||
' l_result_code PLS_INTEGER;' ||
' BEGIN ' ||
' l_result_code := l_anydata.GetObject (l_object);' ||
' INSERT INTO ' || p_table || ' VALUES (l_object);' ||
' END;';
EXECUTE IMMEDIATE l_statement USING IN p_anydata;
END;
-- unnamed PL/SQL block for testing
DECLARE
l_dept dept_obj_type;
l_emp emp_obj_type;
BEGIN
-- creates objects
l_dept := dept_obj_type (10, 'dept 10');
l_emp := emp_obj_type (2000, 'emp 2000', 10);
-- inserts objects
gen_insert1 (
p_table => 'dept_obj_table',
p_anydata => ANYDATA.ConvertObject (l_dept));
gen_insert1 (
p_table => 'emp_obj_table',
p_anydata => ANYDATA.ConvertObject (l_emp));
END;
/For (very complicated) relational version see
Inserting a "Generic Record Type" Using ANYDATA/ANYTYPE Types
http://www.quest-pipelines.com/pipelines/plsql/tips04.htm#MARCH
Regards,
Zlatko Sirotic -
BOM explosion with Two Material Number
Hi
How can i Explosion in BOM with two material number, if any Fm is there in sap or any othre options
Please tell me
Regards
ManiYour question is not complete.
There are two types of bom explosion. from child to parent and parent to child.
You have to pass one material at a time. Please search in sdn for the fm's. This question ihas been widely discussed here. -
Two different document types in MIRO
Hi Gurus,
Can we have two different FI document types in MIRO for Service PO and Normal PO?
Standard is RE but we want one more.
Can you please suggest something?
Regards,You can work with your own document types but I do not hink you can have two different document types for Standard and Service PO.
The effect of MIRO is still the same whether its Service PO or Standard PO - GR/IR debit and Vendor credit.
If it is just for reporting, you can always take the PO number from RSEG table.Then drill down to EKKO/EKPO and get all the details. -
How to define field of number type in ecs file
Hi B2B Experts,
I need some help. In the detail record of my ecs file, i need to define a filed as number. Basically the data coming in the data file is a dollar amount. It is a number type.
The number length maximum length is 6, The spec file says that field should be like below....
9(04)V99
The data came in the text file as 013100, so according to the business it is like 131.00 but as i defined the field as string, it is taking it as 13100. I want to define that field as a number type and it should consider keeping that number with two digits precision i.e.,decimal part. Please help me in this regard.
I believe i should define the type as number and the i dont know what to keep for the format ?
Thanks,
NNaresh,
What are your requirements? If I understood it correctly, you will be getting data without decimal and you want B2B to add decimal accordingly. If this is the case then I don't think it should be done at B2B rather this should be performed at middleware.
Please let us know your exact requirement if I interpreted it incorrectly.
Regards,
Anuj -
Adding two leading zeroes infront of a variable(both character and numeric)
Hi Experts,
I have a variable v_data. Whatever is the value of the v_data, two leading zeroes should get added to it.
v_data may be numeric or charachter type.
I am using FM CONVERSION_EXIT_ALPHA_INPUT for adding two preceding zeroes for numeric types but for character types what logic I should use?
Currently I am doing:
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_data
IMPORTING
OUTPUT = v_data.
if v_data CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
SHIFT v_data BY 2 PLACES right.
v_data+0(1) = '0'.
v_data+0(2) = '0'.
endif.
But the above code is giving output like this: 0 P0001 but I want output like 00P0001.
How to fix it?
Regards,
Sangeeta.
Edited by: Sangeeta on Nov 11, 2008 6:22 AMCALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_data
IMPORTING
OUTPUT = v_data.
if v_data CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
SHIFT v_data BY 2 PLACES right.
v_data+0(1) = '0'.
v_data+1(1) = '0'. " change this
endif. -
Adding new Batch Number to AP Invoice
i am working on adding new batch number to an existing AP IN by SDK function. I try the following codes, no errors prompt but also nothing updated. Can anyone advise me how to add new batch number to AP Invoice? Many Thanks!
Dim ErrMsg As String
Dim ErrCode As Integer
Dim opch As SAPbobsCOM.Documents
opch = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseInvoices)
opch.GetByKey(5)
opch.Lines.BatchNumbers.Add()
opch.Lines.BatchNumbers.BatchNumber = "3"
opch.Lines.BatchNumbers.Quantity = 3
ret = opch.Update
If ret <> 0 Then
oCompany.GetLastError(ErrCode, ErrMsg)
MsgBox(ErrCode & " " & ErrMsg)
End IfHi ,
Steps to do:
1.Create an User Defined Field on Document Row Level:
Name: Serial / Batch Details
Type: Alphanumeric
Structure: Text
- Create a Formatted Search which will populate the data from Delivery note.
- Put the UDF into the Print Layout of Delivery Order.
Displaying Batch Details
2. Decide with information is needed from Batch details to be printed out on A/R Invoice
On Bacth Details form (Inventory\Item Management\Batches\Batch Details) we can see all the possible details.
- Batch Number
- Delivered Quantity
- Expiration Date
3. Build the formatted search SQL command.
By a SQL cursor driven result set we can build a text which contains the list of the delivered batch details separated by new lines. The relations between A/R Invoice and Delivery note is defined on A/R Invoice Form. in columns 45, 46, and 43
declare @batch as nvarchar(100)
declare @txt nvarchar(max)
set @txt = ''
declare P cursor for SELECT T0.[BatchNum] + space(1)
+ cast(cast(T1.[Quantity] as decimal(19,2)) as nvarchar)
+ space(1) + case when T0.[ExpDate] is null then '' else convert(nvarchar,T0.[ExpDate],102) end
FROM OIBT T0 INNER JOIN IBT1 T1 ON T0.ItemCode = T1.ItemCode and T0.WhsCode = T1.WhsCode
and T0.BatchNUm = T1.BatchNum
WHERE T1.[BaseEntry] =$[$38.45.0] and T1.[BaseLinNum] =$[$38.46.0]
open P
fetch next from P into @batch
while @@fetch_status = 0
begin
set @txt = @txt '\n'@batch +','
fetch next from P into @batch
end
close P
deallocate P
select @txt
4. Defined the formatted search on the A/R Invoice. -
Hello,
While adding a new phone number in Iphone 5S, when you hit 'add phone', it displays the phone number types in this sequence - home fax, radio, home and then mobile. Is there a way to configure this sequence to see mobile as the very first option? i save only mobile numbers and dont see much use in home fax and other options. I know we can delete other phone number types, but i want to save few cliks for convinience
Thanks...When you add a new phone number, I think you are talking about the Contacts app.
Click "home fax" in that display that comes up. You should be able to change it to something else; e.g., home.
Then home would come up first. -
I accidentally added two .doc files by dragging and dropping into itunes, under my device, then the app tab, then file sharing for Adobe Reader, they show in iTunes file sharing window, but don't show on iPad 3, and I cannot delete them on iTunes screen? Please help!
First, I would advise you to apply Tao philosophy to this. Given the dysfunction of most software, if this was just an accidental copy and you don't want them on iPad and they are not showing up anyway, what's the problem? Forget it. It's not worth the hassles. I'm more concerned that you have psychological issues you need to be dealing with, not this. You are making much too unnecessary work and stress for yourself.
As for deleting them, I'm assuming you highlighted them and hit delete and it didn't work. If not, it should. Works for me. But if it doesn't, my advice is also not to worry about it, as annoying as the clutter is. It will eventually resolve itself (like when your data files corrupt or your iPad crashes, LOL. (I apologize for my cynicism but I am fed up with dysfunctional software). It's not worth the hassles of trying to figure out petty issues.
As for me, I have the opposite, and very serious problem. I've got Reader on my iPad too. But I can't move the pdfs out of it and onto my laptop with iTunes' dysfunctional file sharing. I get the error "file cannot be copied because you do not have permission to see its contents." I have hundreds of pdfs on my iPad that I converted from web surfing with other programs that also don't work and I can't get them off the iPad for backup and to have a synced library I can access from both laptop and iPad.
I called iTunes twice and both times they blamed it on the app, saying iTunes file sharing doesn't support third party apps and that I should call Adobe and talk them into writing the code that will work with iTunes. Yeah, right. And Reader is not the only problem. This is happening with iAnnotate and Write PDF and other apps.
I suspect that both of us have the root problem, perhaps Apple's greedy refusal to support the apps that it sells in the app store and are quasi-integrated enough to show up in the file sharing documents list, but can't be moved or deleted; and the apps that don't bother to make their apps fully work with iTunes file sharing.
If anyone has any solutions ...... -
Loading custom Generic Loader type extracts broken after patch 7616161
Before applying 7616161, we could perform full ETL operations within iSetup using custom apis for a seeded .lct file. After applying this patch, extracts still work using the same custom apis, but loads fail with the following error:
Validating Primary Extract...
Parsing driver.xml
Time taken to parse the Driver file and construct setup objects:25 milliseconds
Sorting Apis based on their dependency...
null
java.lang.NullPointerException
at oracle.apps.az.r12.api.APISorter.sortBySeqNum(APISorter.java:599)
at oracle.apps.az.r12.loader.cpserver.APILoader.groupApis(APILoader.java:449)
at oracle.apps.az.r12.loader.cpserver.APILoader.loadAPIs(APILoader.java:226)
at oracle.apps.az.r12.loader.cpserver.APILoader.callAPIs(APILoader.java:141)
at oracle.apps.az.r12.loader.cpserver.LoaderContextImpl.load(LoaderContextImpl.java:66)
at oracle.apps.az.r12.loader.cpserver.LoaderCp.runProgram(LoaderCp.java:65)
at oracle.apps.fnd.cp.request.Run.main(Run.java:157)
Concurrent program completed.
Any help would be most appreciated.In an instance that was cloned with 12.0.6 after applying 7616161, then upgrading the instance to 12.1.1, still getting this problem, specifically the nullpointerexception error in the APISorter class. Will the patch 8871713 work under this upgraded instance as well? Or do I need different code to patch up iSetup to get the Generic Loader type extensions working in 12.1.1?
-
Does the Number type in Oracle always map to the Java BigDecimal object
We have noticed that whenever we create a column in a table of type smallint, integer, real, etc. that the type in sqlplus always shows up as number(x). Our problem is that this type always seems to map to java.math.BigDecimal through JDBC. Is this a bug in the JDBC drivers???
Put another way when I create a column of type smallint I expect that after performing a query I should be able to call the getShort method on the result set in order to get the value from the afore mentioned column. But instead I get a ClassCastException because the Java type for the column is actually a java.math.BigDecimal.
Thanks,
Keith
[email protected]<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Keith Nielsen:
We have noticed that whenever we create a column in a table of type smallint, integer, real, etc. that the type in sqlplus always shows up as number(x). Our problem is that this type always seems to map to java.math.BigDecimal through JDBC. Is this a bug in the JDBC drivers???
Put another way when I create a column of type smallint I expect that after performing a query I should be able to call the getShort method on the result set in order to get the value from the afore mentioned column. But instead I get a ClassCastException because the Java type for the column is actually a java.math.BigDecimal.
Thanks,
Keith
[email protected]<HR></BLOCKQUOTE>
~~~
The possible Java types to which SQL NUMBER type can be materialized to include
oracle.sql.NUMBER
java.lang.Byte
java.lang.Short
java.lang.Integer
java.lang.Long
java.lang.Float
java.lang.Double
java.math.BigDecimal
byte,short, int, long, float, double
For a complete listing for all datatypes mappings refer the Oracle8i JDBC Developer's guide and reference. -
Two different condition types in one report
Hello,
i have a problem with the conditional display of a report.
I want to use two different condition types for one report.
For example I want to show the report only when the page is not in printer friendly mode and when the value of an item is NULL.
Is that possible?
Has anyone a solution for this problem?
Thank you,
TimTim,
you can use
IF V('PRINTER_FRIENDLY') = 'YES' AND :P1_ITEM IS NOT NULL THEN RETURN FALSE;
ELSE RETURN TRUE;
END IF;
in the Conditional Display picking PL/SQL Function Body returning a Boolean.
Denes Kubicek -
Problem araised in adding two custom fields to ksb1 tcode.
hi experts,
I added tow fields vendor no, vendor name to Tcode:KSB1.
i used user-exit : coomep01 .
in this exit i added two fields to ci_rkpos (include table) . i.e zlifnr,zname1.
but that problem is ci_rkpos is not appearing in green color it means it is not transported .
in development client is working properly .
using sm34 i added fields names.
error is coming like this.
The following syntax error occurred in the program SAPLXKAEP :
"The data object "CS_RECORD" has no component called "ZLIFNR", but ther"
Error in ABAP application program.
The current ABAP program "SAPLKAEP" had to be terminated because one of the
here wat ever we add the zfields will appear in kaep_coac ,so in this structure two added fields are appeared in dev client
but,the same zfields when transported to quality is not appearing .
please suggest how to do??hi breakpoint.
yes i attached in transport.
in quality client.
wat ever i wriiten code in user exit it is coming ,but
incldue table structure is not coming ,and even that fields are appearing in v_tkalv ,but in structure kaep_coac
blank include strcuture CI_RKPOS is appearing ,but
in dev client is working properly, and in quality first of all report is going to dump.
here this tvode is using all 3 plants,how can i restrict to specified plant so that ,it will not affect others plant.
suggest me how to do??
Edited by: kamalsac on Aug 18, 2010 10:57 AM
Maybe you are looking for
-
FW will not open due to an Internal Error
I have reinstalled FW and Flash after a crash and its not opening due to an Internal error....I tried to remove a utility called DlgXRSizer by Gajits but the website is gone....tried completely removing all MM programs and still no luck. Any ideas? T
-
I am receiving flat file in SFTP Server which need to be posted into SAP (No mapping involved) What will be the best approach ? 1. I tried using IDOCFlatToXmlConvertor (The limitation in the format of source file. The parent and child node relationsh
-
Oracle Spatial LRS point X and Y.
I’m having some problems with LRS points. Two tables: A and b. Table A contains valid LRS linestrings; table B (non spatial) is a list of points with stated eastings and northings columns that exist in close proximity to the linestrings. Points are a
-
Hi, I would like to know if there's another possible way in SAP to check the vendor's delivery accuracy (on time delivery) but via statistical delivery date and the goods receipt. Up until now I use the transaction MC$6 to get the needed information.
-
WGA 600N and using it for internet on a Windows 7 PC
Hello I am trying to use my WGA 600N to get internet in my PC. I have previously configured this unit and used it with my Xbox 360 with no problems. I can get on the ip address of 192.168.1.250 and connect to my wifi. The problem i am having is getti