Checking data type

I know there must be an easy way to do this. Say I want to
have a function
to which you can pass either an integer or a point, or maybe
a list, either
would work. How do I determine what the data type of the data
I've been
given is? In other words, I'd like to be able to say:
if data.type = #integer then <do something>
else if data.type = #point then <do something else>
else if data.type = #list then <do yet another thing>
etc.

> "ilk" is the keyword you're looking for.
Ah, I knew it'd be something simple like that. Thanks.

Similar Messages

  • 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 ...

  • Checking data type compatibility

    Hi,
    Is there a method to check if two data types are compatible with each other? I need to perform this check without any value at hand. With a value it works if I create data references and assign them to field symbols. How do I make the same more generic with just the data type and length given.
    Any help would be greatly appreciated. Thanks.
    regards,
    nithya

    I have extracted the below info from a document that i have with me. Do provide your mail-id if you need the document. I dont mind sharing...:)
    Please check this for more understanding...
    <b>Type Checks and Type Compatibility</b>
    For historical reasons, the types of field symbols and parameters in subroutines or function modules can be defined with the STRUCTURE addition.
      If the types of field symbols are defined with FIELD-SYMBOLS <f> STRUCTURE s DEFAULT wa and they are later assigned a data object wa with ASSIGN wa TO <f> ... , in a NUP both statements are checked to see if wa is at least as long as s and wa satisfies the alignment requirements of s at runtime.
    16
    If parameter types in function modules or subroutines are defined with FORM form1 USING/CHANGING arg STRUCTURE s ... or FORM form2 TABLES itab_a STRUCTURE s ... and the parameters are passed actual parameters with PERFORM form1 USING/CHANGING wa or PERFORM form2 USING/CHANGING itab_b, the NUP also only checks if wa or the line type of itab_b is at least as long as s and wa or the line type of itab_b satisfies the alignment requirements of s. The same is true for function module parameters whose types are defined with STRUCTURE.
    The following extra rules are checked in a UP after defining the type with STRUCTURE when assigning data objects, that is for the DEFAULT addition in the FIELD-SYMBOLS statement, for ASSIGN, and when passing actual parameters.
    1. If wa or the line type of itab_b is a flat or deep structure, the length of s must be the same for the Unicode fragment views of wa or of itab_b and s.
    2. If wa is a single field, only the character-types C, N, D or T are allowed and the structure s must be purely character-type.
    Checking both these rules requires additional runtime. It is therefore recommended that, if possible, you type the parameters using TYPE, since the test for actual compatibility is much faster.
      If the type of an argument in a function module was defined with ... LIKE struc, where struc is a flat structure, the NUP only checks if the argument is a flat structure with the same length when the parameters are passed. In the UP, it also checks that the fragment views of the current and formal parameters are the same. For performance reasons, it is again recommended that you use TYPE to assign types.
      Furthermore, two structures of which one or both contain Includes, are only compatible if the alignment gaps caused by the Include are the same on all platforms. In the following example, struc1 and struc2 are not compatible because a further alignment gap occurs in the US before the INCLUDE:
    BEGIN OF struc1, BEGIN OF struc2, BEGIN OF struc3,
    a(1) TYPE X, a(1) TYPE X. b(1) TYPE X,
    b(1) TYPE X, INCUDE struc3. c(1) TYPE C,
    c(1) TYPE C, END OF struc2. END OF struc3.
    END OF struc1.
    Since the type compatibility can differ in a UP and an NUP, the type compatibility rules of the calling program are valid in an NUS for checking the parameters. This means that if an NUP calls a UP, the type compatibility is defined as in the NUP. Conversely, the Unicode check is activated if a UP calls an NUP.
    Kind Regards
    Eswar

  • Stupid question on checking data types

    Hi
    I want to write a function that can accept a parameter which could be an int or an int array. This is what I have so far:
    void translateParams(Object obj) {
    Class type = obj.getClass();
    if (type.isArray()){
    //do something
    Two questions - firstly am I going about this the right way (i.e. have the parameter be type "object" and then check to see what it is) or is there a better alternative. Secondly how can I do the javascript equivalent of isNumeric()??

    If you need the same method name to accept two parameter types, just overload the method:public void someMethod(int parm){
       // some code
    public void someMethod(int[] parm){
       // some code
    }If you have common functionality between the two methods, one can call the other:public void someMethod(int parm){
       // some code
    public void someMethod(int[] parm){
       for (int i =0;i<parm.length;i++){
          someMethod(parm);

  • SQL - How to check data type definition

    Is it possible to check (inside SQL statement) how particular field is defined. Is it VARCHAR2(5) or VARCHAR2(10)

    If by field you mean column, then use USER_TAB_COLUMNS, ALL_TAB_COLUMNS or DBA_TAB_COLUMNS:
    SELECT  TABLE_NAME || '.' || COLUMN_NAME || ' ' || DATA_TYPE ||
            CASE
              WHEN DATA_TYPE LIKE '%CHAR%' THEN '(' || DATA_LENGTH || ')'
              WHEN DATA_TYPE = 'NUMBER' THEN '(' || DATA_PRECISION  || ',' || DATA_SCALE || ')'
            END X
      FROM  USER_TAB_COLUMNS
      WHERE TABLE_NAME = 'EMP'
      ORDER BY COLUMN_ID
    X
    EMP.EMPNO NUMBER(4,0)
    EMP.ENAME VARCHAR2(10)
    EMP.JOB VARCHAR2(9)
    EMP.MGR NUMBER(4,0)
    EMP.HIREDATE DATE
    EMP.SAL NUMBER(7,2)
    EMP.COMM NUMBER(7,2)
    EMP.DEPTNO NUMBER(2,0)
    8 rows selected.
    SQL>   SY.

  • How to check date type is initial

    there is SQL sentence.
    DATA: BEGIN OF it OCCURS 0,
        matnr LIKE mara-matnr,
        laeda  LIKE mara-laeda,
      END OF it.
    select matnr laeda
    from mara
    where laeda <> space.
    How can I  check the  laead field is initial.
    Regards.

    Hi,
         Try this syntax
    SELECT... WHERE s IS [NOT] NULL...
    SELECT matnr laeda FROM mara INTOTABLE it_itab WHERE
    laeda IS [NOT] NULL.
    Regards
    Bala Krishna

  • Check box with Boolean data type is not behaving properly

    Hi,
    I create a sample application with one entity driven view object with two attributes. One is of String data type [Value will be Y/N] and another (transient) attribute with Boolean data type. I planned to bind this boolean data type attribute to UI. I overridded the view row impl class and included setting of boolean attribute inside the setter of String attribute. Also in the getter of boolean attribute, added code to check the string attribute and return true/false based on that. Everything is working fine in application module tester. But when i test the same in view controller project in a page, it is not working. Always Check box component is not checked eventhough when i explicitly check it.
    [NOTE: I have given the control hint of Boolean attribute as check_box. Also i don't want selected/unselected entries in the page def file. That's why followed this approach]
    Have i missed out anything? Why this behaviour.
    Thanks in advance.
    Raguraman

    what is the value that is going in when u check it.. did u debug it.. is the viewRowimps setter and getter getting called.. and is it having the right value set and got.. and ur sure that ur using selectBooleanCheckBox..
    ur binding the checkbox to the transient value right??

  • How to check the data type dynamically

    hi all
    my requirement is like this  in one screen field which is of character type user is inputing data .
    now while saving to the database i have to apply one external check for this data if it is integer type or not
    as this data on the screen is refrenced to the database so i can not change the data type on the screen itself .
    i have to check it externally from PAI ....... would any one please help on this
    Thanks and regards
    Papps

    Hi
    Thanks again you are right i missed the space one ..
    but Now another problem...
    I have tried that but in that case even user can input data by mistake like this
    123 4  but this is not an integer it should also give error as this is also not a correct integer ...
    as par asi think . we have to aain check if there is any spaces in the data provided i guess or
    is there any other procedure ?

  • Checking table columns and data type before inserting

    I have some data coming from different sources and want to insert the data from those files into multiple tables.
    Before inserting the data I like to perform a check on data type, length, null etc so that I can avoid errors at the time of insert. If there is any problem with the data then I do not want to perform the insert and report the problems.
    Thanks

    If you have 10gR2 (10.2.0.4) you could use DML_ERROR_LOGGING.
    Read about it here, see the examples: http://tkyte.blogspot.com/2005/07/how-cool-is-this.html
    In short: it avoids errors during your transactions, afterwards you know which records failed and why.
    It's more or less the same functionality:
    your goal:
    check before transactions and avoid the insert of 'bad' records. (extra code, extra maintenance, more chance of bugs)
    dml_err_logging:
    insert 'bad' records during transaction automatically into a dedicated error table including error message.
    Edited by: hoek on Mar 24, 2009 6:56 PM

  • Check data load or not in subtype of table type

    Hi friends,
    Using global collection variable vt_product_tab.
    created record tr_product_tab.
    type tt_product_tab is table of tr_product_tab index by binary integer.
    vt_product_tab tr_product_tab;
    when the package loaded first time data loded into vt_product_tab. Now I would like to write a procedute to check data loded or not into vt_product_tab.
    Venkat.

    Hi,
    have a managed bean that has a JSF binding reference (table property) for th etable. Then on the table you can call getSelecteRowKeys, which returns a rowk key set
    Frank

  • How do I do a data type check?

    Hi.
    I was trying to do a hashtotal for a table column. It is necessary that the table column only contains numeric values. Is there a way to do a data type check, before I compute the hashtotal value? Thanks.
    LOOP AT itab INTO hash_value.
      IF hash_value = NUMC. " (==> Cannot)
        hash_total = hash_total + hash_value.
      ENDIF.

    you can try this
    data : text(50),
           dtyp like DD01V-DATATYPE,
           bef(15),
           aft(15).
    data : dtype(1).
    text = '1,234.60'.
    if text co '0123456789.,'.
    write : / 'numeric'.
    endif.
    split text at '.' into bef aft.
    replace all occurrences of ',' in bef with space.
    condense bef.
    CALL FUNCTION 'NUMERIC_CHECK'
      EXPORTING
        STRING_IN        = bef
    IMPORTING
    *   STRING_OUT       =
       HTYPE            = dtyp
    if dtyp cs 'NUMC'.
    write : / 'Befor decimal Numeric'.
    else.
    write : / 'Befor decimal Character'.
    endif.
    clear dtyp.
    CALL FUNCTION 'NUMERIC_CHECK'
      EXPORTING
        STRING_IN        = aft
    IMPORTING
    *   STRING_OUT       =
       HTYPE            = dtyp
    if dtyp cs 'NUMC'.
    write : / 'After decimal Numeric'.
    else.
    write : / 'After decimal Character'.
    endif.
    regards
    shiba dutta

  • Check table in data type AFNAM (Name of Requisitioner/Requester)

    Hello,
    To satisfy a customer's requirement, I changed data type AFNAM so that it would have a search help. The search help name of this data type now points to the ZAFNAM view - this view is based on table ZQQPVS001, where I keep the valid entries for the field.
    Here.'s my problem: at least in one of the standard transactions ( ME5A - List Display of Purchase Requisitions), I can get help pressing F4 on the field but I cannot see the help button on the right side of the field. In other transactions (namely ME22n ), I can see the small round button.
    Any clues?
    Regards,
    Joã

    Hello,
    Problem solved.

  • JDBC MS Access--- cannot extract entry with null value with data type Meta

    I'm trying to extract a data entry with null value by using JDBC. The database is MS Access.
    The question is how to extract null entry with data type memo? The following code works when the label has data type Text, but it throws sqlException when the data type is memo.
    Any advice will be appreciated! thanks!
    Following are the table description and JDBC code:
    test table has the following attributes:
    Field name Data Type
    name Text
    label Memo
    table contents:
    name label
    me null
    you gates
    Code:
    String query = "SELECT name, label FROM test where name like 'me' ";
    ResultSet rs = stmt.executeQuery(query);
    while (rs.next())
    String name = rs.getString("name");
    rs.getString("val");
    String label = rs.getString("label");
    System.out.println("\t"+name+"\t"+label);
    catch (SQLException ex)
    System.out.println(ex.getSQLState());
    System.out.println(ex.getErrorCode());
    System.out.println("in sqlexception");
    output:
    C:\Temp\SEFormExtractor>java DBTest
    yet SELECT name, label FROM test
    null
    0
    in sqlexception

    The question is how to extract null entry with data type memo?Okay, what you need to do is this:
    if (rs.getString("val") == null)
      // do something
    }This way, when it's a null value, you can check it first, and then handle it how you want, rather than getting an exception.

  • 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

  • Issue when SelectOneChoice is used with Domain data type in JDev 11.1.2.0.0

    Hi,
    I am facing one issue while working with SelectOneChoice along with Custom Domain data type. Sample app to simulate the issue is available at http://www.filejumbo.com/Download/6FDF6ECF2922BD24
    Issue Details.
    Base view object’s attribute is of type CustomString, for which another static VO’s attribute is attached as LOV. LOV attribute is of type String. Because of this data type mismatch between LOV VO attribute and Base VO attribute, while working in screen, initially we were facing Class cast exception.
    Cannot convert <<LOV Attr. Val.>> of type class java.lang.String to class model.domain.common.CustomString This is not only for this type of SelectOneChoice but also for InputText field whose underlying VO attribute is of type CustomString (i.e. any Custom Domain type)
    On raising this in Jdeveloper forum, I came to know that adding a default oracle converter against the UI Component will take care of converting to respective data type. After added the converter for InputText and SelectOneChoice components, this issue got resolved. This was our lesson while working in Jdeveloper version 11.1.1.3.0. Converter we used,
    <f:converter converterId="oracle.genericDomain"/> When we try the same scenario in Jdev Version 11.1.1.4.0, without having the oracle converter itself, SelectOneChoice started working fine!! (i.e. it is able to set the base attribute with LOV attribute’s value but with proper base attribute’s domain data type). Anyhow, converter is required for InputText.
    When we try the same scenario in Jdeveloper new version 11.1.2.0.0, it started giving class cast exception when we don’t have oracle converter for SelectOneChoice. But by adding it, though it didn’t give such class cast exception message, though a selection is made in SelectOneChoice, VO attribute has not been updated with the new value. Instead it is updated with null value (Checked the setter method of view row impl by having break point) . Because of this, after a selection is made, when we try to read the attribute value from VO on button click, VO attribute always returns null.
    We have also tried our own converters but there is no change in the behavior.
    The above misbehavior can be tested either by having SOP programmatically or by refreshing the SelectOneChoice by giving its id as Partial trigger to itself with autosubmit set to true, so that the selected value will be reset to null irrespective of the selection made.
    For convenience, Issue details with Sample application is shared. Shared link : http://www.filejumbo.com/Download/6FDF6ECF2922BD24
    Shared folder contains
    1. Sample App developed on Jdev 11.1.1.4.0 to ensure it didn’t give this error.
    2. Sample App developed on Jdev 11.1.2.0.0 to simulate this error.
    3. Error details in a document.
    Can anybody have a look at this and tell me why this misbehavior and is it a bug? If so, any workaround available to continue the development?
    Thanks in Advance.
    Raghu
    Edited by: Raguraman on Sep 10, 2011 10:31 AM

    Sorry for the late reply John and Frank. Ya i did. Thank you.
    One more detail:
    I tested the behavior in Jdeveloper 11.1.2.0.0. The recent surprise is Select One Choice is behaving perfectly when it used in Grid layout and fail to work when it is form layout. I am getting surprised why behavior of component varies based on the way it refers the binding.
    for form layout,
    value=#{bindings.
    for grid layout,
    value=#{row.bindings.
    The bug details (#/title) are Bug 12968871 - RUNTIME CONVERSION FAILURE WHEN USING CUSTOM DOMAIN OBJECT VALIDATION IN EO
    Edited by: Raguraman on Sep 12, 2011 8:23 PM
    Edited by: Raguraman on Sep 12, 2011 8:31 PM

Maybe you are looking for