Runtime conversion of a string value to a primitive data type in java

can anyone of you give me an idea to convert a string value to a primitive data type during run time...i have the value and the type to which it has to be converted as String values...do you have any idea ,...pls share

String recvalvalue = inputval;
                String recvartype = inputtype;
               if (recvartype.equals("int")){
               value0 = Integer.parseInt(recvalvalue);
         else
         if (recvartype.equals("double")){
                value1  = Double.parseDouble(recvalvalue);
         else
         if(recvartype.equals("float")){
          value2 = Float.parseFloat(recvalvalue);
         else
         if(recvartype.equals("Boolean")){
          value3 = Boolean.parseBoolean(recvalvalue);
         else
         if(recvartype.equals("char")){
           value4 = (char)recvalvalue.charAt(0);
        else
        if(recvartype.equals("String")){
          value5 = recvalvalue;
         else
         if(recvartype.equals("byte")){
           value6 = Byte.parseByte(recvalvalue);
              //listA.add(6, value6);
              //     listA.g = value6;
         else
          if(recvartype.equals("long")){
           value7 = Long.parseLong(recvalvalue);
         else
          if(recvartype.equals("short")){
          value8 = Short.parseShort(recvalvalue);
         } yes i can do this but the resultant value has to be assigned to a variable of a specific type which is here recvartype .....it has to be done dynamically automatically..if we know what type of data is that we can convert and assign to the type but we donot know when we run the program as the program will be supllied by someone and has to be executed

Similar Messages

  • Assigning a string value to a decimal data type field.

    Hi,
    I want to assign a value 'N/A' to an internal table field 'itab-field1' which is of data type dec.
    How can I do this?.
    Your help is really apprieciated
    Thanks & Regards,
    Soumya.

    hi,
    on what condition do u want N/A to be displayed, i hope when ever that field is empty...
    so u can do in this way..in stead of changing in internal table...
    when ever u r writing the values from internal table to output list..
    ther put a check like if  itab- field1 = 0.
                                      write :/ 'N/A'.
                                  else.
                                     write : itab-field1.
    hope this is helpful, because we can not pass char values to internaltable field of type dec..
    Rgds.,
    subash

  • Can't assign a string value to a member of type TEXT in Calculation Manager

    I can assign a string value to that member of type TEXT using a run-time prompt of type StringToNumber.
    Example: "My Text Member" = {string_rtp};
    However, I need to accompllish the same function without using a run-time prompts.
    I have a planning application and I know that text along with all other non-numeric
    values are stored on the relational side in the planning application schema.
    It seems reasonable to assume that if this can can accomplish
    with a run-time prompt that I could do also do it without a run-time prompt.
    What appears to be lacking is a function like:
    "My Text Member" = @StringToNumber(<String Literal>);
    Clearly, this is already being done "under the covers" for run-time prompts. If
    would appear to be a minor enhancement to expose such a function to developers.
    NOTE: I suppose you would also need to add new syntax/function to identify a string
    literal from say a member name. I'm wondering if this is the more difficult challenge
    from a product perspective????

    When executing a Calculation Manager rule in Planning, the run-time prompt (RTP) is populated by looking up the outline information present in the relational Planning application database. If the RTP is of type TEXT, the strings displayed in the member select are from the from the relational Planning application database too. Subsequently when executing the Rule, the RTP's value is in fact the record ID (a number) which is then saved into the appropriate intersection in Essbase.
    You need to bear in mind, the Rule is executed in Essbase. If Essbase needs to "write" a text, it would then need to connect to the Planning relational database to create a new record. The newly created record ID then needs to be feed back to Essbase, in order to store it in the appropriate intersection.
    What you are suggesting, comes with a big overhead causing Essbase and the rule to slow. Thus, the disadvantages outweighs the advantages.

  • Transferring primitive data types via UDP other than a String

    Hi ALL,
    I am new to Socket programming in UDP.
    I need to implement a FTP client-server application.
    Now the packet that I need to transfer using UDP as a DatagramPacket consists of multiple primitive data types, (3short types and 1 byte array of size 265.)
    How do I do that?
    All the samples and examples I managed to find on the Internet illustrated the problem of transferring a String type converted to getBytes and the byteArray is transferred.
    However, in my case i need to pass this structure..(3fields) to the other side. If I convert the 4 fields to a single concatenated string there's this problem of finding out where each of the four fields begin and where do they end.
    Please suggest and help...
    thanks..
    : )

    Just create a class that represents your structure and convert-it to a byte array that can be sended over a DatagramSocket.
    Try this sample code :
    import java.io.*;
    import java.net.*;
    public class DP
        /** Creates a new instance of DP */
        public DP ()
         * @param args the command line arguments
        public static void main (String[] args)
            try
                System.out.println ("Starting server ...");
                DatagramServerThread server = new DatagramServerThread ("Datagram server");
                server.start ();
                System.out.println ("Creating your object ...");
                ByteArrayOutputStream baos = new ByteArrayOutputStream (); // Creating byte array output stream ..
                ObjectOutputStream oos = new ObjectOutputStream (baos);// Creating a object output stream that writes to byte array output stream..
                YourStructure newObject = new YourStructure (); // creating your data structure..
                newObject.setShortField1 ((short)12);// setting values ...
                newObject.setShortField2 ((short)45);
                newObject.setShortField3 ((short)4);
                newObject.setArray (new byte [256]);
                oos.writeObject (newObject); // write your structure to object output stream...
                byte data_to_be_sent[] = baos.toByteArray (); // retrieving equivalent byte array...
                // send data...
                DatagramSocket s = new DatagramSocket ();
                System.out.println ("Sending ...");
                DatagramPacket packet = new DatagramPacket (data_to_be_sent, data_to_be_sent.length);
                packet.setAddress (InetAddress.getByName ("localhost"));
                packet.setPort (8888);
                s.send (packet);
            catch (Exception e)
                e.printStackTrace ();
    class YourStructure implements Serializable
         * Holds value of property shortField1.
        private short shortField1;
         * Holds value of property shortField2.
        private short shortField2;
         * Holds value of property shortField3.
        private short shortField3;
         * Holds value of property array.
        private byte[] array;
         * Getter for property shortField1.
         * @return Value of property shortField1.
        public short getShortField1 ()
            return this.shortField1;
         * Setter for property shortField1.
         * @param shortField1 New value of property shortField1.
        public void setShortField1 (short shortField1)
            this.shortField1 = shortField1;
         * Getter for property shortField2.
         * @return Value of property shortField2.
        public short getShortField2 ()
            return this.shortField2;
         * Setter for property shortField2.
         * @param shortField2 New value of property shortField2.
        public void setShortField2 (short shortField2)
            this.shortField2 = shortField2;
         * Getter for property shortField3.
         * @return Value of property shortField3.
        public short getShortField3 ()
            return this.shortField3;
         * Setter for property shortField3.
         * @param shortField3 New value of property shortField3.
        public void setShortField3 (short shortField3)
            this.shortField3 = shortField3;
         * Getter for property array.
         * @return Value of property array.
        public byte[] getArray ()
            return this.array;
         * Setter for property array.
         * @param array New value of property array.
        public void setArray (byte[] array)
            this.array = array;
        public String toString ()
            StringBuffer buffer = new StringBuffer ();
            buffer.append ("Short field 1 is ");
            buffer.append(this.getShortField1 ());
            buffer.append ("\nShort field 2 is ");
            buffer.append (this.getShortField2 ());
            buffer.append ("\nShort field 3 is ");
            buffer.append (this.getShortField3 ());
            buffer.append ("\nYour array field is ");
            for (int index = 0; index < this.getArray ().length; index++)
                buffer.append ("Index [" + index + "] = " + this.getArray () [index] + "\n");
            return buffer.toString ();
    class DatagramServerThread extends Thread
        protected DatagramSocket socket = null;
        public DatagramServerThread (String name) throws IOException
            super (name);
            socket = new DatagramSocket (8888);
        public void run ()
            try
                byte buffer [] = new byte [socket.getReceiveBufferSize ()];
                DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
                System.out.println ("Server is ready. Waiting for packet ...");
                socket.receive(packet); // waiting for packet ...
                System.out.println ("Packet received! : ");
                byte received_data[] = packet.getData ();
                ByteArrayInputStream bais = new ByteArrayInputStream (received_data); // Creating byte array input stream ..
                ObjectInputStream ois = new ObjectInputStream (bais); // Creting Object input stream
                Object readed_object = ois.readObject ();
                YourStructure your_original_object = (YourStructure)readed_object;
                System.out.println (your_original_object.toString ());
                System.out.println ("Exiting server thread. Bye");
                socket.close ();
            catch (Exception e)
                System.err.println ("Server error");
                e.printStackTrace ();
    }

  • Is string primitive data type?

    - Is String a primitive date type? Elaborate please.
    - How is String object is mutable?

    > It is completely immutable. Once created it cannot be changed.
    import java.lang.reflect.*;
    public class ImmutableStringDemo {
        public static void main(String[] args) throws Exception {
            String string = "foo";
            System.out.println(string);
            new StringChanger().change(string);
            System.out.println(string);
    class StringChanger {
        public void change(String s) throws IllegalAccessException {
            Field[] fields = s.getClass().getDeclaredFields();
            for (Field f : fields) {
                f.setAccessible(true);
                if (f.getType() == char[].class) {
                    f.set(s, "bar".toCharArray());
    }QED. ;o)
    ~

  • Handle null value in char infoobject -data type DATE(ora-01722 invalid num)

    Hi,
    We have a DSO with a info object in the Data fields. The char info object has the data type DATE and most often it has the null value. but some times  it has data in it.
    When ever we were trying to run a report on the DSO it throws a error  as  ORA- 01722 INVALID NUMBER.
    we tried editing PSA data and placing 00000000 for null values - and had a message  invalid date.
    suggestions pls
    Regards.

    Hello,
    Please check the note given below
    https://service.sap.com/sap/support/notes/1327167.
    If null value is the problem,  change the query setting for not to show the null values. Just add a filter in ZDAT to exclude "NULL"
    Thanks
    Nidhi

  • Store the value  in BLOB column data type

    Hi All,
    I have a file of about 5MB. I want to store this in BLOB column data type of a table.
    Can we compress this file to store and when we take uncompress the same...or how do we do it.
    and what is the procedure to store this....
    pls. help me
    Thanks,
    Naresh

    Hi skud
    i juast want to store the agent code to variable.if i did get ur point...
    Why don't u just use a simple assign statment for example...
    DECLARE
    V_VALUE  NUMBER;
    BEGIN
    V_VALUE := LC354 ; -- IF it was a value as LC354 static i mean
    -- or u could use any value
    V_VALUE := :ur_form_item_name; --- if it was dynamic
    END;That's it .
    Hope this helps...
    Regards,
    Ammatu Allah.

  • How to store beyond the range value for a given data type!!!

    Hi all,
    I want to know.Is it possible to create a new data type like int,float in java. which can store any number without any range restrictions.As you know the range of byte data type is -128 - + 127.I don't want any range restrictions.The data type should be able to grow dynamically.
    Regards!!
    Tameshwar Sahu

    The only solution I can think of is to use java objects, Im not sure youll be able to create a new primitive for java !!
    Youd have to put together Integers, posibly in a vector depending on how HUGE a number youd like to create.
    If you reached the max of one, add another to the vector. and then continue with the next.. The problem with this of course is the fact that math operations, will be a bit of a challenge to code. also actuall representation of the value would be a bit tricky as well !! There are however ways to go about this, you just have to think about it a little.

  • Error Message while adding Item in Item Master Data- [Microsoft][SQL Server Native Client 10.0][SQL Server]Conversion failed when converting the nvarchar value 's008 01' to data type int. (CINF)

    Dear Experts
    I am getting the following error message while adding item in Item Master data. I have modified the following SBO_SP_transactionNotification in SQL server after that could not able to add the item
    ALTER proc [dbo].[SBO_SP_TransactionNotification]
    @object_type nvarchar(20),                      -- SBO Object Type
    @transaction_type nchar(1),               -- [A]dd, [U]pdate, [D]elete, [C]ancel, C[L]ose
    @num_of_cols_in_key int,
    @list_of_key_cols_tab_del nvarchar(255),
    @list_of_cols_val_tab_del nvarchar(255)
    AS
    begin
    -- Return values
    declare @error  int                       -- Result (0 for no error)
    declare @error_message nvarchar (200)           -- Error string to be displayed
    select @error = 0
    select @error_message = N'Ok'
    --    IF @OBJECT_TYPE = '59' AND (@TRANSACTION_TYPE = 'A' or @TRANSACTION_TYPE = 'U')
      BEGIN
       IF EXISTS(
        SELECT T0.Price FROM IGN1 T0
        where  IsNull(T0.Price, '0') = '0' and T0.DocEntry = @list_of_cols_val_tab_del)
       BEGIN
        SELECT @ERROR=1,@ERROR_MESSAGE='Please insert the price !'
      END
    end
    -- Select the return values
    select @error, @error_message
    end

    Hi Rathna,
    Just put the SP like this, without the -- before the IF. A -- marks the line as a command therefore you need to uncomment and it will work.
    IF @OBJECT_TYPE = '59' AND (@TRANSACTION_TYPE = 'A' or @TRANSACTION_TYPE = 'U')
      BEGIN
       IF EXISTS(
        SELECT T0.Price FROM IGN1 T0
        where  IsNull(T0.Price, '0') = '0' and T0.DocEntry = @list_of_cols_val_tab_del)
       BEGIN
        SELECT @ERROR=1,@ERROR_MESSAGE='Please insert the price !'
      END
    end
    Hope it helps

  • Flatten Variant to String vs. Flatten Data to String in case of variant data type

    May be a dumb question, but I want just understand what is the principal difference and what are the restrictions for both methods? Also I noticed that in case of "Flatten Variant to String" it looses all its attibutes, and this is not in case of flatten generic data to sting. Where I can find a more detailed info on this?
    LabView Ver. 6.0,6.1

    defuflo,
    See OpenG.org >> Site Docs >> LabVIEW Data 1 of 2.
    On non variant data, "Flatten to String" and "Variant to Flattened String" have the same output.
    On Variant data, "Variant to Flattened String" ouputs the flattened string and type string of the sub-type held in the variant. All variant attributes are lost in the process since they belong to the variant, not to the subtype.
    "Flatten to String" operates on variants like on any other types, returning the type string of a variant and all its flattened data, including any attributes.
    LabVIEW, C'est LabVIEW

  • How to get the values from struct data type using java code..?

    Hi ,
    I am newer to java.
    we are using oracle database.
    How to get the data from struct data type using java code.
    Thanks in Advance.
    Regards,
    kumar

    Hi Rajeev,
    To retrieve a FilterContainer you will need to traverse the report structure:
    ReportStructure boReportStructure = boDocumentInstance.getStructure();
    ReportContainer boReportContainer = (ReportContainer) boReportStructure.getReportElement(0);
    FilterContainer boFilterContainer = null;
    if (boReportContainer.hasFilter()) {
         boFilterContainer = boReportContainer.getFilter();
    } else {
         boFilterContainer = boReportContainer.createFilter(LogicalOperator.AND);
    Calling boDocumentInstance.getStructure() will retrieve the entire structure for the document.
    Calling boReportStructure.getReportElement(0) will retrieve the structure for the first report of the document.
    Hope this helps.
    Regards,
    Dan

  • Getting a Time value from a datetime data type in SQL Server - URGENT!

    Hi guys
    I have an urgent issue here -
    I have a datetime data type in a SQL Server database. The field holds both a time, and a date within it.
    I am able to pull the date out of the field by using:
    Date sDate = Date();
    while (gd.next()) {
    sDate = gd.getDate(2);
    how do this with the time????
    Thanks

    Hi,
    The funny part here is that you have already done it! The API is a great thing to use to help in your programming.
    API: The class Date represents a specific instant in time, with millisecond precision.
    You want time, you got it! How about:
    sDate.getTime();
    sDate.getMinutes();
    sDate.getHours();
    sDate.getSeconds();
    Not enough?

  • Convert String variable value  to an Object referece type

    Hi all,
    I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
    Let's think that there is a string variable name like,
    String name="HelloWorld";
    and there is a class name same to the variable value.
    class HelloWorld
    I am passing this string variable value to a method which is going to make a object of helloworld;
    new convertobj().convert("HelloWorld");
    class convertobj{
    public void convert(String name){
    // in hert it is going to create the object of HelloWorld;
    // HelloWorld hello=new HelloWorld(); just like this.
    now i want to do this from the name variable value.( name na=new name()) like wise.
    please let me know if there any possible way to do that.
    I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
    thanx.

    Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
    Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
    John

  • Creating runtime data types

    Hi
    I need to dynamically create input fields with specified lengths(so that user cannot enter values beyond this length).
    I do it like this.
    IWDAttributeInfo attributeInfo =
        nodeName
        .getNodeInfo()
        .addAttribute(attributeName,
           "ddic:com.sap.dictionary.string");
    IWDInpuField inputField =
       (IWDInpuField)viewHandle
                      .createElement
                      (IWDInputField.class,null);
    int length = getLengthFromSomeMethod();
    inputField.bindValue(attributeInfo);
    inputField.setLength(length);
    The input field added is of specified length, but still the user is able to enter value beyond this length. This i guess is due to the fact that attribute bound to the field is of type "ddic:com.sap.dictionary.string".
    Can i create data types at runtime so that i might add attributes with this data type to a node at run time?
    Is there any other way to solve this problem?

    kaushal,
    Try this:
    attributeInfo.getModifiableSimpleType()
      .setMaxLength(length);
    "Length" of InputField declares (average) width of control in characters.
    VS

  • Find data type from value

    Hi,
    I want to find data type from its value.
    Ex- If value = 1234 then its data type is numeric.
          If value = ABCD then its data type is char.
    So is there any FM which can tell the data type from its value or any way to do it.
    Moderator Message: Offering points is against forum RoE. 
    Regards,
    Ashish Gupta
    Message was edited by: Suhas Saha

    Hai.
    check this.
    the five non-numeric types (text field (C), numeric text field (N), date field (D), time field (T), and hexadecimal field (X)), there are three numeric types, used in ABAP to display and calculate numbers. Data type N is not a numeric type. Type N objects can only contain numeric characters (0...9), but are not represented internally as numbers. Typical type N fields are account numbers and zip codes.
    integers - type I
    The value range of type I numbers is -2*31 to 2*31-1 and includes only whole numbers. Non-integer results of arithmetic operations (e.g. fractions) are rounded, not truncated.
    You can use type I data for counters, numbers of items, indexes, time periods, and so on.
    Packed numbers - type P
    Type P data allows digits after the decimal point. The number of decimal places is generic, and is determined in the program. The value range of type P data depends on its size and the number of digits after the decimal point. The valid size can be any value from 1 to 16 bytes. Two decimal digits are packed into one byte, while the last byte contains one digit and the sign. Up to 14 digits are allowed after the decimal point. The initial value is zero. When working with type P data, it is a good idea to set the program attribute Fixed point arithmetic.Otherwise, type P numbers are treated as integers.
    You can use type P data for such values as distances, weights, amounts of money, and so on.
    Floating point numbers - type F
    The value range of type F numbers is 1x10*-307 to 1x10*308 for positive and negative numbers, including 0 (zero). The accuracy range is approximately 15 decimals, depending on the floating point arithmetic of the hardware platform. Since type F data is internally converted to a binary system, rounding errors can occur. Although the ABAP processor tries to minimize these effects, you should not use type F data if high accuracy is required. Instead, use type P data.
    You use type F fields when you need to cope with very large value ranges and rounding errors are not critical.
    Using I and F fields for calculations is quicker than using P fields. Arithmetic operations using I and F fields are very similar to the actual machine code operations, while P fields require more support from the software. Nevertheless, you have to use type P data to meet accuracy or value range requirements.
    C ---> character
    D ---> date
    P ---> packed
    T ---> time
    X ---> hexadecimal
    I ---> integer.
    N ---> Muneric.
    Possible ABAP/4 data types:
    C: Character.
    D: Date, format YYYYMMDD.
    F: Floating-point number in DOUBLE PRECISION (8 bytes).
    I: Integer.
    N: Numerical character string of arbitrary length.
    P: Amount or counter field (packed; implementation depends on hardware platform).
    S: Time stamp YYYYMMDDHHMMSS.
    T: Time of day HHMMSS.
    V: Character string of variable length, length is given in the first two bytes.
    X: Hexadecimal (binary) storage.
    regards.
    sowjanya.b.

Maybe you are looking for

  • Why is my iphone 4s taking so long to restore my photos from icloud back up

    i restored my phone from factory settings to icloud back up this all worked normally all my apps and everything restored very easily so did my photo streem however on my camera roll it just says downloding and non on my photos are there it just keeps

  • Cisco ISE 1.2 Patch 8 with Roaming User Profiles

    ISE 1.2 with patch 8 has been installed and Works fine. Using AnyConnect Secure Mobility Client (NAM) 3.1.04072 and Cisco NAC Agent version 4.9.1013 Scenario is EAP Chaining which does machine authentication + User Authentication After NAC Agent Pops

  • Getting this error when running a form. HTTP Listner is not available

    I am using windows XP Professional. I have the 9i database running fine. I can launch form developer and connect to my database (which is on the same machine but in different homes.) I get a Http listner error no available when I go to run the form.

  • Offset on exit variables on 0FISCPER?

    Hi, We are having an IP environment here. A copy function is supposed to roll forward values from one period to the next. Originally I had developed an exit variable pointing to the target period, and I have set up the copy like that: From: Target Pe

  • Subgroups disappear after closing project. Is there a subgroup limit?

    I have a program that takes in voltage inputs and converts some to rms current values and some to rms voltage values.  I created subgroups to use scaling factors in two seperate formula steps that would output the scaled rms voltage and currents. Aft