Determine data type of string field

I am trying to determine the data type of input strings in a data flow task.  For each column in the input (all of which are strings) I want to sample X number of records, try to cast them as money, date, boolean, etc and if 100% of X records pass then
use the first data type that passes the test.  I looked into row sample but this doesn't appear to be the right data flow task.  Can anyone point me in the right direction?
Thanks!

You have two tasks:  find the datatype by looking at X rows; cast all rows to the popular datatype.
What I use is the TryParse method that occurs on several datatypes in .Net (http://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx).  It returns true if it parses
and false if it doesn't.  I have used this in a profiling package that reads a CSV and stores counts of values that can be converted to different datatypes.
The second piece is trickier.  If you can afford, I would add a second dataflow.  The first dataflow looks at a sample of the data and determines the datatype. You assign that to a variable.  Then the second one has a derived column that has
a set of derived columns, each with a formula like this:
@DataType == "Int"?(DT_I4)[Column]:NULL(DT_I4)
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

Similar Messages

  • Problem in using a structure with a field of  data type 'RAW STRING'

    Friends
    I have written a ZBAPI that imports a structure which has 5 fields. I have defined this in the IMPORT tab of Tr.Code <SE37>.  One of the field of this structure is of data type 'RAW STRING'.
    When I try to activate this BAPI, I get an error message as follows:
    Function Module ZBAPI_ADD_CONFIG_DNA
    "ZDAMPER_CON_DNA" Must be a flat structure. You cannot use internal table
    strings, references, or structures as components.
    Where ZDAMPER_CON_DNA is the table name that I am using.
    FOR TESTING PURPOSE, WHEN I CHANGE THE DATA TYPE FROM 'RAW STRING' TO JUST A CHAR OF LENGHT 5, IT WORKS FINE.
    Here is the source code of the simple BAPI that i am trying to activate.
    FUNCTION ZBAPI_ADD_CONFIG_DNA.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(CONFIG_DNA_DATA) TYPE  ZCONFIG_DNA_STRUCTURE
    *"  EXPORTING
    *"     VALUE(MESSAGE) TYPE  ZRETURNMESSAGE
    tables: ZDAMPER_CON_DNA.
        ZDAMPER_CON_DNA-CONFIG_ID       =     CONFIG_DNA_DATA-CONFIG_ID.
        ZDAMPER_CON_DNA-STRING_NAME     =     CONFIG_DNA_DATA-STRING_NAME.
        ZDAMPER_CON_DNA-STRING_FORMAT   =     CONFIG_DNA_DATA-STRING_FORMAT.
        ZDAMPER_CON_DNA-STRING_VALUE    =     CONFIG_DNA_DATA-STRING_VALUE.
        ZDAMPER_CON_DNA-OBJECT_NAME     =     CONFIG_DNA_DATA-OBJECT_NAME.
        INSERT ZDAMPER_CON_DNA.
        MESSAGE-SUBRC = sy-subrc.
        if sy-subrc = 0.
            MESSAGE-RETURNMESSAGE = 'SuccessfullyInserted'.
        else.
            MESSAGE-RETURNMESSAGE = 'Insert Failed'.
        endif.
    =============
    ANY KIND OF FEED BACK WILL BE HIGHLY APPRECIATED.
    THANKS
    RAM

    Hi ram,
    there is no data element exists with the name RAW STRING ,
    but check one of these names..
    Data element                   Short text
    C2S_RAWSTRING                  C2-Server: Data Element of Type Rawstring
    N2_RAWSTRING                   Byte String of Variable Length
    QISRDRAW_STRING                Data in Format RAW Character String
    RCF_RAWSTRING                  Rawstring
    RPAP_TEMPLATE_RAWSTRING        Blob of Template File
    RSRAWSTRING                    Raw String
    RSRD_RAWSTRING                 Binary Content in the Broadcasting Framework
    SWH_RAWSTRING                  Workflow: Data Type RAWSTRING
    WDR_RAWSTRING                  Byte Sequence of Variable Length
    <REMOVED BY MODERATOR>
    venkat.
    Edited by: Alvaro Tejada Galindo on Mar 7, 2008 5:15 PM

  • How can I read the data type of a field in an MS Access database

    I need to be able to determine if a field in an Access database is of a certain data type, and if it isn't, to change it to what it should be.
    I can't seem to find any way of reading the data type of any field in any table - can anyone give me a metod of getting this info?
    Thanks
    ..Bob

    Does <cfdbinfo> work for Access DBs?
    You might be better off asking this on a MS Access forum.  It's more of an Access issue than a CF one.
    Adam

  • Determine data type

    Hi all,
    I've got procedure for inserting data into value1 column of table1.
    My need is to determine data type entered by user.
    If data type is not number then user should receive error.
    How do I perform it?

    The easiest and most reliable way would be to declare the formal parameter as a number like:
    SQL> create procedure p (p_num in number) as
      2  begin
      3     null;
      4  end;
      5  /
    Procedure created.
    SQL> exec p('a');
    BEGIN p('a'); END;
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    ORA-06512: at line 1If you cannot do that, or want to be more "user friendly", then the only alternative is to test it and raise an error like:
    SQL> create procedure p (p_str in varchar2) is
      2     l_num number;
      3  begin
      4     l_num := to_number(p_str);
      5  exception
      6     when value_error then
      7        raise_application_error(-20001, 'I know I said it was a string, but I really want a number');
      8  end;
      9  /
    Procedure created.
    SQL> exec p('a');
    BEGIN p('a'); END;
    ERROR at line 1:
    ORA-20001: I know I said it was a string, but I really want a number
    ORA-06512: at "OPS$ORACLE.P", line 7
    ORA-06512: at line 1John

  • How to coerce data types to strings in a SELECT statement?

    ABAPers,
    I need to coerce column outputs to strings in a SELECT statement. Here is a pseudo example:
    select ConvertToString(count(*)) from MARA
    On help.sap.com, I could not find enough information on the functions that are supported within SELECT statement. I would appreciate it if someone can enlighten me on how to achive this.
    Note that my real problem is that I do not know the return type of the specified columns. The columns are passed as a user-specified parameter. As I do not know the column types, I am mandating that customers specify columns that return only string type data.
    Thank you in advance for your help.
    Pradeep

    Hi Pradeep,
    Convert to string wont be possible in the SELECT statement.
    What you can do is use Field Symbols. This allows to assign data types dynamically.
    Field-Symbols
    Best regards,
    Prashant
    Pls. mark points for helpful answers

  • Can we change the data type of a field based on the value of the field

    HI Gurus,
    My Requirement is as below -- Could you please guide me
    in the Printable Adobe form -- for ex - as usual for dates fields in the Object Pallette the object type is a date/time field  and for quantity/currency fields corresponding fields are taken
    now in case the either the date, quantity or currency is initial in place of displaying 0.00 or empty date we need to display N/A (Not Applicable)
    for this I would like to change the data type of the field
    to put it simply --
    we need to change the data type of date field from DATE&TIME to Char type to hold N/A or  Quantity field to Char field to hold N/A
    how can we realize this in SAP adobe forms
    Thanks in Advace
    Ramchander Rao.K

    Hello Ramchander,
         You cannot change the data type of the field at run time in Adobe forms because the type of field you choose at the time of design level is associated with the data type itself.
    If you want to achieve your requirement, then your main idea should be to set the data type as CHARACTER itself while designing the field in the adobe form itself. CHAR field will comfortably hold the value of Calculation/amount field, Currency field, Amount, Date, Time HHMMSS, Unit Accuracy, Currency key, Floating point number, Numeric text, Client, Language and many other data types.
    After designing the field as TEXT field in Adobe form you have two options.
    Option 1:
    Select the Date field initially as type TEXT field or CHAR field in Adobe forms.
    Suppose the name of the field is TEXTFIELD1, then write the Javascript code on this field in Initialize event as below.
    if ( this.rawvalue == null )
         this.rawvalue = "N/A";
    If the field is not blank, then it will show the date. Else it will show "N/A".
    Option 2:
    Select the Date field initially as type TEXT field or CHAR field in Adobe forms. Do the formatting part in ABAP itself. It will increase the performance. Avoid Javascript as much as possible.
    Suppose you have a DATE variable l_dats of type DATS. Then take another variable l_date of type CHAR. Then write the below ABAP code.
    MOVE l_dats TO l_date.
    IF l_date IS INITIAL.
         l_date = 'N/A'.
    ENDIF.
    Bind the l_date to the TEXT field in the form.
    Even in this case, if the field is not blank, then it will show the date. Else it will show "N/A".
    But I will suggest you to use Option 2 of keeping the AMOUNT, QUANTITY, DATE, TIME fields etc as CHAR or TEXT fields in Adobe form and do the required formatting in ABAP itself.

  • Activation error while changing the data type of a field of a table

    hi friends,
    i am facing one problem while changing a data type of a field of a table.
    i just created one table(Yqm32) .i have assigned charcter data type to one field(ztotal_count) .now i want to change this charcter data type to numeric data type.
      while changing to NUMC data type activation error is comming as below.
    Table is not yet classified                           
    Field ZTOTAL_COUNT: Type change                       
      ALTER TABLE is not possible                         
    Structure change at field level (convert table YQM32) 
    Check on table YQM32 resulted in errors   
    Table YQM32 could not be activated                       
    (E- Structure change at field level (convert table YQM32)
    plz suggest.i need to change the data type from char to numc.
    Thanks & Regards

    Hi Pabitra......
    From the SE11 change the table as u wanted and then from menubar select
    UTILITIES--> DATABASE UTILITY
    It will open database utility
    there u select the Activate and adjust database button.
    then the database table will get adjusted.
    just try it once.........
    Suresh......

  • Impact of changing data type of a field in Database table

    Hi All,
    I need to change the data type of a field(which is not a key field and it has no dependency with any other field) from NUMC to CHAR by maintaining the same length. Please let me know if there will be any impact in doing this. Hope the following things need to be taken care:
    - Take backup of entire data in the table before doing the change
    - After changing the data type, I need to set the option 'Save Data' and then 'Activate and Adjust Database' in 'Database Utility'.
    - Use 'Where Used List' to check the related objects.
    Please let me know if there is any impact or any thing else need to be taken care apart from the above things.
    Thanks in advance.
    Regards
    Vidhya.

    Hi,
    even if the length is same there would be no impact.
    just v need to adjust the database in the database utility.
    check the table maintenence generator also. if not reflected there u need to delete it and create it again.
    reward if useful,
    teja

  • How to check data type of the field symbol at run time

    Hi,
    My code is as following:
          LOOP AT <fs> ASSIGNING <wa_covp_ext>.
            ASSIGN COMPONENT 86 OF STRUCTURE <wa_covp_ext> TO <f_zzname>.
            IF sy-subrc = 0.
              ASSIGN COMPONENT 158 OF STRUCTURE <wa_covp_ext> TO <f_pernr>.
              IF sy-subrc = 0.
                  SELECT SINGLE sname INTO <f_zzname> FROM pa0001
                                WHERE pernr = <f_pernr>
                                AND endda GE sy-datum
                                AND begda LE sy-datum.
             ENDIF.
          ENDIF.
        ENDLOOP.
    This query is giving dump when <f_zzname> is type P length 8 and decimals 2, because it tries to put PA0001-sname into it which is type C length 30. So I want to check the type of <f_zzname> before the select statement. If it is character 30, then I will write the select statement else not.
    How to check data type of the field symbol at run time? If it's not possible, then can somebody suggest a workaround? Thanks.

    check this ...
    write describe statement  ...
    field-symbols : <f_zzname> .
    data : sname like pa0001-sname,
           typ(10).
    assign sname to  <f_zzname>.
    describe  field <f_zzname> type typ.
    write : typ. <-- typ contains character type in this case ..
    U can check if typ is of character(C) if so .. write the select statement ...

  • How to determine data type of cell in Excel file

    I have a company standard Excel file that needs to be read to determine what tests to run.  I have no control over its format.  I need to be able to tell what the data type is in order to read it using the LabView sample code.  It is a hodge poge of numbers and strings.  Some of the numeric fields are formated as hex while some are floating point.  There does not appear to be a vi that I can call to determine info about the cell formating.  As I remember it, the Windows Active X control for accessing Excel support that.  I really was hoping to avoid dealing with the Active X control for Excel directly.
    Any help/ideas?
    Outputting it in CSV or similar is not an option.
    Solved!
    Go to Solution.

    If you have to deal with Excel directly, I don't see how you're going to get around using Active X.
    MSDN page on using ActiveX

  • What should be the data type for a field in ztable?

    i am desing a ztable , wht should be the datatype for a field if i want to enter values like -1.5 and -2.5 , negative values with decimals what should be the data type???

    declare as P type. TYPE P DECIMALS 1
    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.
    Also check this link.
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb2fd9358411d1829f0000e829fbfe/content.htm
    Regards,
    Maha

  • Determining the type of a field-symbol

    Hi!
    I want to create a logical expression that determines the type of field-symbol that was passed in to a function.
    i want to do something like this:
    IF imported_fieldsymbol IS OF TYPE some_type
    ENDIF
    how do you create such an expression in ABAP?
    regards

    Hi,
      You can use the RTTS - Run Time Type Service.
      Try the sample code
    TYPES my_type TYPE i.
    DATA: my_data   TYPE my_type,
          descr_ref TYPE ref to cl_abap_typedescr.
    START-OF-SELECTION.
      descr_ref = cl_abap_typedescr=>describe_by_data( my_data ).
    The hierarchy of RTTS classes are as follows,
    CL_ABAP_TYPEDESCR
      |
      |--CL_ABAP_DATADESCR
      |   |
      |   |-- CL_ABAP_ELEMDESCR
      |   |--CL_ABAP_REFDESCR
      |   |--CL_ABAP_COMPLEXDESCR
      |       |
      |       |--CL_ABAP_STRUCTDESCR
      |       |--CL_ABAP_TABLEDESCR
      |
      |--CL_ABAP_OBJECTDESCR
         |
         |--CL_ABAP_CLASSDESCR
         |--CL_ABAP_INTFDESCR
    Regards,
    Mustajab

  • Need to determine data type of free characteristic in multiprovider

    Hi,
    I need to determine the data type (e.g. numeric vs alpha numberic) of a free characteristic in a multiprovider.  Can this be accomplished in BEx Query Designer? 
    If not, can it be accomplished in RSA1?  How?
    Thanks,
    Kevin

    its not possible via Query designer..
    give that object name if it is infoobject then you can get via RSD1

  • How to Find the Data Type of the Field In a Database Table

    Hi Experts,
    I'm currently working on a program which needs to find out the data type of the given field in a database table. In addition to accessing DD03L directly, is there any other workaround such as function module to help me achieve this? It would be helpful if a demo example could be provided.
    Thanks a lot.

    Hi,
    Use this..
    DESCRIBE FIELD dobj  TYPE typ.
    write typ.
    type will contain the data type of the object.
    and check this thread also....
    Re: How to get datatype of fields in dynamic structures
    Cheers,
    Simha.
    Reward all the helpful answers..

  • Determining data type of existing column in table

    Hi
    I've done some googling on this, and I know I've done it before, but i cant find/remember how to determine the data type of a column in an existing table..... i tried select dump(column_name) from table but it didnt work.
    any suggestions?
    Thanks in advance

    Hi try this
    SQL> select data_type from user_tab_columns
      2  where COLUMN_NAME='EMPNO'
      3  and table_name='EMP';
    DATA_TYPE
    NUMBER

Maybe you are looking for