Declaring data types

I often see declarations where the type on the left side of = new is different from the type on the right side.
- e.g.
Collection whatever = new Vector();
or
Container whatever = new Window();
What advantages are gained by doing this?
Are there any dis-advantages?
Thank you.

The advantages are considerable, and numerous. One of the most often mentioned is the ability to change the underlying class without affecting ANYTHING else. Using your example,
Collection whatever = new Vector();
Everything that depends on this is using the Collection interface, so you are free to change the Vector to anything else that implements the interface, without disruption of the external code.
The Sun Collection tutorial has a good discussion of this topic, much more than I'm willling to type. See it here:
http://java.sun.com/docs/books/tutorial/collections/intro/index.html
There are no significant disadvantages.

Similar Messages

  • In ECC 6 , I AM  GETTING ERROR WHILE DECLARING DATA TYPE OF BAPI

    HI,
    IN ECC 6 , i AM  GETTING ERROR" NO READ ACESS RETURN"
    EVENTHOUGH   I DECLARED  DATA TYPE   FOR EXAMPLE
    DATA: RETURN TYPE BAPIRET2.AND USING IN RFC.
    HOW TO CORRECT THE ERROR.
    pLZ HELP ME.
    REGARDS,
    RANI

    Hi Rani,
    Could you please post the piece of coding where the error comes from? Maybe we can help you then.
    Regards,
    John.

  • How to declare data type for DATE format

    Hi,
    I need the data format in this format  DD-MM-YYYY HH:MI:SS
    So, I m using    select TO_CHAR(Date_Column, 'DD-MM-YYYY HH:MI:SS')  from dual;
    Now, In my procedure I need to assign this to a OUT  variable, what should be the Data type of out variable.
    My OUT variable is used by other program.
    Thanks

    You can use VARCHAR2. Try the below
    CREATE OR REPLACE PROCEDURE proc_test(p_indate DATE, p_outdate OUT VARCHAR2) 
    AS 
    BEGIN 
       p_outdate:= TO_CHAR(p_indate,'DD-MON-YYYY HH:MI:SS'); 
    END; 
    SET SERVEROUTPUT ON
    DECLARE 
       v_date  VARCHAR2(50); 
    BEGIN 
       proc_test(SYSDATE,v_date);
       DBMS_OUTPUT.PUT_LINE(v_date);  
    END; 
    OUTPUT:-
    anonymous block completed
    15-JAN-2014 12:13:46

  • How to declare a bind variable with 'date' data type in command prompt?

    how to declare a bind variable with 'date' data type in command prompt?
    sql>variable q date;
    when i execute it show list of datatypes

    Hi,
    As Lokanath said, there are no DATE bind variables.
    You can use a VARCHAR2 bind variable, and convert it to a DATE in your SQL statment.
    If you're using SQL*Plus, consider a substitution variable. It won't be as efficient as a bind variable, but it will be as convenient.
    For example:
    DEFINE  first_entrry_date = "DATE '2010-06-20''
    SELECT   ...
    WHERE   entry_date >= &first_entry_date
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Source XML data type declaration querry

    Hi all,
    I am very confused in below XML data type declaration.
    I am dealing first time with this type of XML.
    In source XML header items are mentioned in header node(address).
    <address addressline1="6th & Hunt" addressline2="" city="Pryor" state="OK" country="Sun" zip="74361">
    - <phoneinfo>
      <phone type="work">9999999999</phone>
      </phoneinfo>
    - <faxinfo>
      <fax>100000001</fax>
      </faxinfo>
    </address>
    Please Help in the "Data type declaration" of above source XML????
    How can i use this data type in message mapping????
    Thanks & Regards

    Hi Umesh,
    You can use Data types with Attributes in XI.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/3b/d2a3f7a166514abb8cf5635b71974f/frameset.htm
    And you can even try with the External Definition also.
    Hope this helps,
    regards,
    Moorthy

  • [svn] 3571: Update SWFLoader ASDoc comment to remove &emdash and data type declaration .

    Revision: 3571
    Author: [email protected]
    Date: 2008-10-10 11:07:09 -0700 (Fri, 10 Oct 2008)
    Log Message:
    Update SWFLoader ASDoc comment to remove &emdash and data type declaration. ASDoc adds that automatically.
    Doc the new types in IndexChangedEvent.as
    Checkin Test Passed: Yes
    QA: No
    Bug:
    Doc: No
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/SWFLoader.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/events/IndexChangedEvent.as

    lunke you shoude change svn update http://svn.foo-projects.org/svn/xfce/modules/trunk to svn up $startdir/src/trunk
    hers a PKGBULID for thunar
    pkgname=thunar
    pkgver=0.0.2.r17470
    pkgdesc="Thunar is a file manager designed for Xfce. It is currently under development."
    url="http://thunar.xfce.org/wiki/"
    depends=('exo-svn')
    makedepends=('subversion')
    source=()
    md5sums=()
    build() {
    if [ ! -d $startdir/src/thunar ]; then
    echo "Fetching sources..."
    svn checkout http://svn.foo-projects.org/svn/xfce/thunar/trunk/ /thunar
    else
    echo "Updating sources..."
    svn up $startdir/src/thunar/
    fi
    cd $startdir/src/thunar
    ./autogen.sh --prefix=/opt/xfce4-svn
    make || return 1
    make DESTDIR=$startdir/pkg install
    find $startdir/pkg -name '*.la' -exec rm {} ;
    you will need exo from svn as well
    pkgname=exo-svn
    pkgver=r17470
    pkgdesc="Extensions to Xfce by os-cillation"
    url="http://libexo.os-cillation.com/"
    conflicts=(exo)
    provides=(exo)
    depends=('xfce4-svn')
    makedepends=('subversion')
    source=()
    md5sums=()
    build() {
    if [ ! -d $startdir/src/trunk ]; then
    echo "Fetching sources..."
    svn checkout http://svn.foo-projects.org/svn/xfce/libexo/trunk/
    else
    echo "Updating sources..."
    svn up $startdir/src/trunk
    fi
    cd $startdir/src/trunk
    ./autogen.sh --prefix=/opt/xfce4-svn
    make || return 1
    make DESTDIR=$startdir/pkg install
    find $startdir/pkg -name '*.la' -exec rm {} ;
    "Operation libtool-slay" compliant

  • URGENT:data type declaration of container within the method

    Hi
    My requirement is when the user revceives mail to approve/reject invoice ,the user attaches an attachmnet in the workitem stating the reson for approval/rejection of invoice.The attached attachement should be uploaded to invoice as an attachment.
    I have observed that the attachment attached by the user is stored in the container "office_document" and the type of the container is SOFM.
    To capture the attachment and send it to invoice i have created new task and new method in ZBUS2081.
    i created a container "office_doc_atta" in the workflow .the type of office_doc_atta is SOFM .
    in the method  as well as task i also declared parameter "office_doc_atta" of type sofm.
    to fetch the data from Task to method i have declared following table
    data:office_doc_atta type swc_object occurs 0 with header line.
    swc_get_table container 'office_doc_atta' office_doc_atta.
    I think that data type of "office_doc_atta" decalred within the method
    is wrong and i am unable to fetch data from the container.
    If anyone know what should be the data type of office_doc_atta within the method and how to fetch data from the task kindly let me know.
    Points will be rewarded.

    Try using SWOTOBJID instead of SWC_OBJECT.
    SWOTOBJID is the data type for a persistent object ID, while SWC_OBJECT is the data type for a runtime object ID (or reference or handle, if you are more familiar with any of those terms).
    Normally, an object will be passed by the persistent object ID. As the name reveals, the ID is persistent, i.e. remains the same. Therefore it can be stored in a database, and passed to the next step in a workflow - even if this step is executed by a different person another day.
    <i>Message was edited by Kjetil Kilhavn:</i>
    Please don't use the word urgent in your subject (or in the question for that matter). There are many reasons for this, some of which are:
    1) This is not a help desk or service organization, there are no response time guarantees based on how important a problem is for you.
    2) Most people visit SDN when time permits.
    3) Due to the previous 2 that particular word annoys more than it inspires.
    4) It is specifically mentioned in the guidelines that you should not use that word.
    5) It is a word with no accuracy. It would be better if you wrote (in the question, not the subject) that you need to solve this within 2 days - then we know your deadline.
    6) If I'm in the right mood I will ignore all questions marked as urgent for at least one day. Just for the heck of it.

  • Unicode Program : # is appearing for data types declared as char type

    Hi friends,
    I have copied one program on unicode system to unicode system. As only char type data types are allowed, i converted structure EP to char type only. Now during execution it is giving dump because it is showing value as '#' for 2 fields whos original data type was P and currency. How shall i convert them? Any suggession will helpful.
    Abhijit

    Hi Sandeep,
    This is my piece of code : Initially structure EP was used in read dataset which is of different datatypes. so i created similar structure ep_c with data type as char. As u suggested, i  tried to declare field BETRG as type currency. Then also it gave dump. (Runtime errors: UC_OBJECTS_NOT_CHARLIKE). For 2 fields BETRG and POHRS which is of currency and dec type originally, i am getting values as '#' causing in dump. In non unicode program both fields have values as '0.00' If i put these values in debugging then after execution, program comes to selection screen! Kindly advise.
    Data : komok(2) type c,
           betrg(18) TYPE c,
             betrg type betrg,
             pohrs(10) type c.
    open dataset seq-in for input in text mode encoding default ignoring conversion errors.
          if sy-subrc = 0.
            do.
              read dataset seq-in into ep_c.
              case sy-subrc.
                when 0.
                  move :ep_c-id to ep-id,
                        ep_c-text to ep-text,
                        ep_c-abkrs to ep-abkrs,

  • Difference between DEclaring Itab with DATA & TYpe Statement?

    HI Friends,
      What is the Difference between Declaring Itab with DATA & TYpe Statement?

    Hi,
    The Statements TYPES and DATA
    Each ABAP program define its own data types using the statement.
    TYPES dtype TYPE type ...
    and declare its own variables or instance attributes of classes using the statement
    DATA var {TYPE type} ...
    Within the program or a class, you can also define local data types and variables within procedures. Local variables in procedures obscure identically-named variables in the main program or class.
    When creating data types and data objects, there are a number of naming convention that also apply for other local program definitions, such as procedures. These are described in detail in the keyword documentation.
    The Additions TYPE and LIKE
    The additions TYPE type and LIKE dobj are used in various ABAP statements. The additions can have various meanings, depending on the syntax and context.
    ·        Definition of local types in a program
    ·        Declaration of data objects
    ·        Dynamic creation of data objects
    ·        Specification of the type of formal parameters in subroutines
    ·        Specification of the type of formal parameters in methods
    ·        Specification of the type of field symbols
    TYPES: BEGIN OF struct,
             number_1 TYPE i,
             number_2 TYPE p DECIMALS 2,
           END OF struct.
    DATA:  wa_struct TYPE struct,
           number    LIKE wa_struct-number_2,
           date      LIKE sy-datum,
           time      TYPE t,
           text      TYPE string,
           company   TYPE s_carr_id.
    This example declares variables with reference to the internal type STRUCT in the program, a component of an existing data object wa_struct, the predefined data object SY-DATUM, the predefined ABAP type t and STRING, and the data element S_CARR_ID from the ABAP Dictionary.
    Reward Points if found helpfull..
    Cheers,
    Chandra Sekhar.

  • Declare Variable Data Types

    From my understanding, there is no need to declare variables
    data type like String, Number, Array for it to function. For
    example:
    var abc:String = "abcde";
    var abc:Number = 1234;
    var abc:Array = new Array();
    We can write it in easier way and it is still working.
    abc = "abcde";
    abc = 1234;
    abc = new Array();
    So, what is the purpose and benefit to declare the variable
    specific data type?

    i mean that as3 (= actionscript 3) requires variable typing
    in most situations or the flash compiler will throw an error.
    and no, failing to use strict typing won't cause any
    debugging problems.
    there's also some "feeling" that strict typing enhances code
    efficiency, but i haven't seen anything convincing on this.

  • Need to convert long data type to varchar2

    I need to convert a long datatype in an existing table to a
    varchar2, in either another table or view. I have a 3rd party
    application which needs to query the data in the long data type,
    but it can "handle" the long.
    What is the best way to do this? I tried to make a trigger, but
    I must be missing something. Here is the trigger.
    CREATE OR REPLACE TRIGGER "PROD".SV_GET_RTG_COMNT
    BEFORE INSERT OR UPDATE ON PROD.RELS_RTG_SEQ_COMNT
    FOR EACH ROW
    WHEN (OLD.rels_rtg_no = NEW.rels_rtg_no)
    DECLARE
    -- DECLARE VARIABLES
    RTG_COMNT_VAR VARCHAR2(32);
    RTG_COMNT_LONG LONG;
    BEGIN
    Select COMNT_TXT into RTG_COMNT_LONG
    from rels_rtg_seq_comnt;
    RTG_COMNT_VAR := 'TEXT' || substr(RTG_COMNT_LONG,1,32);
    -- If INSERTING
    Insert into SV_RTG_SEQ_COMNT (print_cd, comnt_no,
    seq_no, rtg_no, comnt_txt) values
    (:new.print_cd, :new.comnt_no, :new.seq_no, :new.rels_rtg_no,
    rtg_comnt_var);
    END;
    I tried to use the substr command on the comnt_txt in view but
    received an invalid datatype error.
    Any help would be greatly appreciated.
    Doug

    create another table with clob datatype
    1)create table clob_tab(pkval number,clob_col clob);
    2) insert into clob_tab (select pkval,to_lob(long_col) from
    long_tab);
    3) use dbms_lob package to do string manipulation using
    substr,instr functions on clob column.

  • PLEASE HELP!!!  Problem with Java and SQLServer Text data type

    Hi there,
    I have a java app. that reads from an MS SQLServer database. Originally, all long text fields were declared as NVARCHAR(200). The program worked fine.
    Someone then advised that I change all long text fields to the TEXT data type. The program now crashes out with the following Exception:
    "java.sql.SQLException: [JRun][SQLServer JDBC Driver]This ResultSet can not re-read row data for column 25."
    Basically, I have a method that retrieves a resulset and iterates through it. The resultset is passed to another method during each iteration. In the example below, the 'specialNote' field used to be NVARCHAR(200). The code worked fine. Then when it was changed to TEXT, the program no longer works with the above Exception thrown.
    Anyone know any special way SQLServer TEXT data types need to be handled?
    Thanks for any advice!
    The code looks something like this in functionality:
    <CODE>
    public void method1 (Connection conn)
    Resultset rs = conn.createStatement().executeQuery("SELECT * FROM ProductBB");
    while (rs.next())
    method2(rs);
    public void method2 (ResultSet rs)
    String str = rs.getString("specialNote");
    </CODE>

    Hi JWoods,
    Thanks for the suggestion. I originally had the code do what you suggested, ie, get the resultset then retrieve the data all within the same method. The data is then used to set properties in an object.
    When I had to create another method that also retrieved a resultset but using a different primary key, then also use the returned data to set the properties in the same type of object, I didn't want to repeat the setter code. That's why I decided to pass the resultsets to the same method that did the property setting.
    Unfortunately, it stopped working with the data type change.
    Any other thoughts?

  • Difference b/w DATA TYPE and DATA OBJECT & differences b/w TYPE and LIKE

    hai
    can any one say the differences between Data type and Data Object.
    And also differences between TYPE and LIKE
    thanks
    Gani

    hi,
    _Data Types and Data Objects_
          Programs work with local program data – that is, with byte sequences in the working memory. Byte sequences that belong together are called fields and are characterized by a length, an identity (name), and – as a further attribute – by a data type. All programming languages have a concept that describes how the contents of a field are interpreted according to the data type.
          In the ABAP type concept, fields are called data objects. Each data object is thus an instance of an abstract data type. There are separate name spaces for data objects and data types. This means that a name can be the name of a data object as well as the name of a data type simultaneously.
    Data Types
       As well as occurring as attributes of a data object, data types can also be defined independently. You can then use them later on in conjunction with a data object. The definition of a user-defined data type is based on a set of predefined elementary data types. You can define data types either locally in the declaration part of a program using the TYPESstatement) or globally in the ABAP Dictionary. You can use your own data types to declare data objects or to check the types of parameters in generic operations.
         All programming languages distinguish between various types of data with various uses, such as ….. type data for storing or displaying values and numerical data for calculations. The attributes in question are described using data types. You can define, for example, how data is stored in the repository, and how the ABAP statements work with the data.
    Data types can be divided into elementary, reference, and complex types.
    a. Elementary Types
    These are data types of fixed or variable length that are not made up of other types.
    The difference between variable length data types and fixed length data types is that the length and the memory space required by data objects of variable length data types can change dynamically during runtime, and that these data types cannot be defined irreversibly while the data object is being declared.
    Predefined and User-Defined Elementary Data Types
    You can also define your own elementary data types in ABAP using the TYPES statement. You base these on the predefined data types. This determines all of the technical attributes of the new data type. For example, you could define a data type P_2 with two decimal places, based on the predefined data type P. You could then use this new type in your data declarations.
    b.  Reference Types
    Reference types are deep data types that describe reference variables, that is, data objects that contain references. A reference variable can be defined as a component of a complex data object such as a structure or internal table as well as a single field.
    c. Complex Data Types
    Complex data types are made up of other data types. A distinction is made here between structured types and table types.
    Data Objects
          Data objects are the physical units with which ABAP statements work at runtime. The contents of a data object occupy memory space in the program. ABAP statements access these contents by addressing the name of the data object and interpret them according to the data type.. For example, statements can write the contents of data objects in lists or in the database, they can pass them to and receive them from routines, they can change them by assigning new values, and they can compare them in logical expressions.
           Each ABAP data object has a set of technical attributes, which are fully defined at all times when an ABAP program is running (field length, number of decimal places, and data type). You declare data objects either statically in the declaration part of an ABAP program (the most important statement for this is DATA), or dynamically at runtime (for example, when you call procedures). As well as fields in the memory area of the program, the program also treats literals like data objects.
            A data object is a part of the repository whose content can be addressed and interpreted by the program. All data objects must be declared in the ABAP program and are not persistent, meaning that they only exist while the program is being executed. Before you can process persistent data (such as data from a database table or from a sequential file), you must read it into data objects first. Conversely, if you want to retain the contents of a data object beyond the end of the program, you must save it in a persistent form.
    Declaring Data Objects
          Apart from the interface parameters of procedures, you declare all of the data objects in an ABAP program or procedure in its declaration part. These declarative statements establish the data type of the object, along with any missing technical attributes. This takes place before the program is actually executed. The technical attributes can then be queried while the program is running.
         The interface parameters of procedures are generated as local data objects, but only when the procedure is actually called. You can define the technical attributes of the interface parameters in the procedure itself. If you do not, they adopt the attributes of the parameters from which they receive their values.
    ABAP contains the following kinds of data objects:
    a.  Literals
    Literals are not created by declarative statements. Instead, they exist in the program source code. Like all data objects, they have fixed technical attributes (field length, number of decimal places, data type), but no name. They are therefore referred to as unnamed data objects.
    b.  Named Data Objects
    Data objects that have a name that you can use to address the ABAP program are known as named objects. These can be objects of various types, including text symbols, variables and constants.
    Text symbols are pointers to texts in the text pool of the ABAP program. When the program starts, the corresponding data objects are generated from the texts stored in the text pool. They can be addressed using the name of the text symbol.
    Variables are data objects whose contents can be changed using ABAP statements. You declare variables using the DATA, CLASS-DATA, STATICS, PARAMETERS, SELECT-OPTIONS, and RANGESstatements.
    Constants are data objects whose contents cannot be changed. You declare constants using the CONSTANTSstatement.
    c.  Anonymous Data  Objects
    Data objects that cannot be addressed using a name are known as anonymous data objects. They are created using the CREATE DATAstatement and can be addressed using reference variables.
    d.  System-Defined Data Objects
    System-defined data objects do not have to be declared explicitly - they are always available at runtime.
    e.  Interface Work Areas
    Interface work areas are special variables that serve as interfaces between programs, screens, and logical databases. You declare interface work areas using the TABLES and NODESstatements.
    What is the difference between Type and Like?
    Answer1:
    TYPE, you assign datatype directly to the data object while declaring.
    LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.
    Answer2:
    Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object.
    Answer3:
    type refers the existing data type
    like refers the existing data object
    reward if useful
    thanks and regards
    suma sailaja pvn

  • Problem with pl/sql table data type

    hai friends,
    i have one procedure it has some in parameters and one out parameter which fetches values to front end.
    But the out parameter will be pl/sql table data type.
    if it is ref cursor
    then i declared as
    var x refcursor;
    exec procedure_name(1,:x);
    it is ok.
    but for pl/sql table data type is out parameter then what i will do in the prompt .
    give me syntax and clarify my doubt.
    advanced thanks...
    madhava

    The SQL*Plus VARIABLE statement does not support user-defined types, hence it cannot support nested tables. It can support cursors because they can be weakly typed (so we can use the one SQL*Plus VAR to hold any shape of resultset). Nested tables are strongly typed; SQL*Plus is a relatively stupid interface and cannot be expected to understand UDT.
    So, it you want to use nested tables as output you'll need to code a wrapping procedure that can understand your nested table type and handle it accordingly.
    Sorry.
    Cheers, APC

  • Problem in F data type

    Hi experts...
    I am using F data type and it gets value 5.50000000000E+10.
    but I want value like 5.500.
    I don't want to use P data type.
    Please Help me.
    thanks in advance.

    Ankita,
    Try declaring it as type quann and check.
    Some additional info:-
    Type F values range from /- 2.2250738585072014E-308 to 1.7976931348623157E308, as well as the number 0, with an accuracy of at least 15 decimal places.
    You cannot enter floating point numbers directly in your programs. Instead, you must use text literals that can be interpreted as floating point numbers. You may use the following formats:
    Decimal numbers with or without sign, with or without decimal point. The form <mantissa> E<exponent>, where the mantissa is a decimal. The exponent may be specified either with or without sign. You may also use spaces before or after the number. Examples of text literals with "floating point numbers":
    '1', '-12.34567', '-765E-04', '1234E5', '12E34', '+12.3E-4', '1E160'.
    Use floating point arithmetic if you need a very large value range or you are making decimal calculations, but be aware of the following features of floating point arithmetic.
    Internally, the exponent and the mantissa of floating point numbers are stored separately, each in two parts. This can lead to unexpected results, despite the high degree of intrinsic accuracy. These occur mainly when performing conversions from and to type F.
    For example, the number 1.5 can be represented exactly in this notation, since 1.5 = 120 + 12**(-1), but the number 0.15 can only be represented approximately by the number 0,14999999999999999. If you round 0.15 up to 1 valid digit, the result is 0.1 rather than 0.2 as you would expect. On the other hand, the number 1.5E-12 is represented by the number 1.5000000000000001E-12, which would be rounded to 2E-12.
    Another example which actually occurred is the calculation of 7.27% of 73050 to an accuracy of 2 decimal places. The intermediate result 5.3107349999999997E+03, since the correct result, 5310.735, cannot be represented exactly in two parts with 53 bits. (If the hardware cannot represent a real number exactly, it uses the next representable floating point number. After rounding, you therefore get 5310.73 rather than 5310.74 as you would expect.
    The ABAP runtime system calculates commercially and not "numerically" like the underlying machine arithmetic. According to the rounding algorithm of the latter, the end digit 5 must always be rounded to the nearest even number (not the next largest number), i.e. from 2.5 to 2, 3.5 to 4.
    You should also note that multiplication using powers of 10 (positive or negative), is not an exact operation. For example, although 100.5 can be represented exactly in two parts, after the operation
    F = F / 100 * 100
    F has the value 100.49999999999999.
    As well as rounding errors, the restricted number of decimal places for the mantissa can lead to the loss of trailing digits. For example, 1 - 1.0000000000000001 results in zero.
    This means that you cannot rely on the last digits in floating point arithmetic. In particular, you should not usually test two floating point numbers for equality; instead, you should check whether the relative difference abs((a - b)/a) is less than a predefined limit, e.g. 10**(-7).
    K.Kiran.

Maybe you are looking for