Regarding String truncation

Hello all,
I have got a small problem. Hope you will help me.
I have got a text String which contains both single byte characters and multi-byte characters mixed up(English characters and non-english characters) which i need to insert into database table. Now the database column is set to store a text of maximum length of 100 bytes so it is required to truncate the string before insertion. Now the problem is when i extract the first 100 bytes from the string, the last character of the string sometimes gets changed( due to extracting only first byte of multi-byte character). The dumbest solution I thought to get around this is something like this:
                //Here remarks contains the string value
     if (null!= remarks && remarks.getBytes().length > 100 ) {
                      while (remarks.getBytes().length > 100) {
                           remarks = remarks.substring(0, remarks.length()-1 );
                 }I am wondering is there any other elegant solution for this as the loop part is time-consuming and moreover, i am inserting the records in a count of thousands.

Thanks for your reply
Why do you have to do that on your own? It's the databases task to correctly truncate a String, if necessary (and inform you of the fact by issuing a Warning).
But when i insert a string of size greater than 100 bytes i am getting an SQL Exception.
Also, is the size of the text field really restricted by the number of bytes instead of the number of characters? I've seen that in some DBs (can't remember which ones), but it's a pretty bad idea and fortunately not all do it that way.
I am using Oracle9i and the size of text field is restricted by the number of bytes.
Also, your code assumes that the database uses the same encoding as the default locale of the machine running your code. Workaround: find out the encoding of the Database and use that when calling getBytes().Points taken. Thanks.

Similar Messages

  • Warning - 1241024 - Possible string truncation in column #

    I am running the following command in a simple MaxL script, the output of which is sent to a text file:
    display variable App.DB.SubVar;
    The text file appears to have generated fine, with the substitution variable value displayed. However, the following warnings are returned each time from the stderr output. Should I be concerned? Is there any way to rectify this?
    WARNING - 1241024 - Possible string truncation in column 3.
    WARNING - 1241028 - Output column defined with warnings.
    WARNING - 1241024 - Possible string truncation in column 4.
    WARNING - 1241028 - Output column defined with warnings.

    Hi John,
    Many thanks for your response. The problem is a little confusing, as I cannot see how anything is being truncated here - indeed there are characters to spare! Could it be because the potential size of the substitution variable name is 320 bytes and the potential size of the substitution variable value is 256 bytes (11.1.2.1)? Could this be the cause of the warnings here?
    Adding "set column_width 10;" does not appear to remove the warnings either unfortunately. Do you please have any other thoughts on how I might remove the warnings? It might allay the fears of the client later on!
    James

  • Regarding String Replacing ....

    Hi Friends,
    I have some problem regarding String replacing.
    ex.
    I have following string ::
    =================================================
    This is the java manager the main purpose for the jasper is used to create reports.
    And the Java language is very extensible.
    Is this the proper string functions provided by java isn't it ?
    *================================================*
    *i want to replace word "is"  with "IS". but that word is not connected to word like  Th{color:#ff00ff}is{color}*
    *differ from simple separate "{color:#ff0000}is{color}" so Word should not be replaced in This only separate "is"*
    *must be replaced. ?*
    *Any Idea ?*
    *{color}*
    Edited by: Ghanshyam on Sep 14, 2007 4:27 PM

    How about just searching for and replacing
    " is "
    instead of
    "is"
    So, using this code from the Java Developers Almanac 1.4 (2002 Addison-Wesley):-
    static String replace(String str, String pattern, String replace) {>    int s = 0;>    int e = 0;>    StringBuffer result = new StringBuffer();> >    while ((e = str.indexOf(pattern, s)) >= 0) {>       result.append(str.substring(s, e));>       result.append(replace);>       s = e+pattern.length();>  result.append(str.substring(s));
    return result.toString();
    }Your would use:-
    String newStr = replace(originalStr, " is "," IS ");
    Edited by: mad_scientist on Sep 14, 2007 4:16 AM (Sorry about all the edits, just getting used to the formatting on here)
    Edited by: mad_scientist on Sep 14, 2007 4:22 AM
    Edited by: mad_scientist on Sep 14, 2007 4:24 AM

  • Regarding data truncation

    Hello,
    I have a currency field in the backend ( CURR 13 ). The data stored in the table is say 34.838.839,00.
    Now when I extract this field to BW, I can see the data in PSA as required.
    But when it gets loaded to the master data infoobject, the data is seen as 3483884.
    The infoobject corresponding to this field is of type NUMC 14. I cannot make it of type CURR as it is should be a characteristic, not a key figure.
    I believe this is because of a conversion routine problem.
    Could someone help me out pls?
    Regards,
    Suraj

    Thanks for your reply
    Why do you have to do that on your own? It's the databases task to correctly truncate a String, if necessary (and inform you of the fact by issuing a Warning).
    But when i insert a string of size greater than 100 bytes i am getting an SQL Exception.
    Also, is the size of the text field really restricted by the number of bytes instead of the number of characters? I've seen that in some DBs (can't remember which ones), but it's a pretty bad idea and fortunately not all do it that way.
    I am using Oracle9i and the size of text field is restricted by the number of bytes.
    Also, your code assumes that the database uses the same encoding as the default locale of the machine running your code. Workaround: find out the encoding of the Database and use that when calling getBytes().Points taken. Thanks.

  • String Truncation Exception in SQL Server

    I get an error when issuing an updateRow() after updateString("String Field", "Test"). My exception is:
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]String data
    , right truncation
    at sun.jdbc.odbc.JdbcOdbcResultSet.setPos(JdbcOdbcResultSet.java:5068)
    at sun.jdbc.odbc.JdbcOdbcResultSet.updateRow(JdbcOdbcResultSet.java:4053
    at exuberance.remote.JDBCClient.setFieldValue(JDBCClient.java:446)
    I believe this occurs because Java stores strings in Unicode (2 bytes), but I'm not positive. Any help would be much appreciated.

    You are passing a string that is too big.
    Possibilities:
    -String you are passing is bigger than field it is being inserted into.
    -Total length of SQL call exceeds the max len limit (8000?, 2174?)
    -The string is a actually a 'blob' type of string (greater than 8000 on MS SQL?) and you need to use the same sort of handling for blobs to pass it.

  • Odd String Truncation Issue

    Hello all,
    I am having the strangest problem with a crystal report truncating a text field when reading records from the DB.  Basically, I have a varchar(6) string field in my Oracle database that holds batch numbers for credit card transactions.  The report worked fine until some users started getting into batches numbered higher than 999.  Anytime a 4th character is added (ie, 1004), my report will read the string as '100'.  All of the other fields in the record are being read fine.
    Oddly enough, this only happens on some databases/machines and not others.  For instance, a DB dump of this data to a local machine will work fine and the report reads '1004'.  I have captured the SQL the report is using to obtain records and pasted it in an Oracle client (TOAD) and the record pulls fine with the batch number being '1004'.  The width of the field on the report is long enough to display much more than 4 characters, so that's not the issue.  Anyone seen this type of issue before or have any ideas on how to troubleshoot it?
    We are using Crystal Reports XI R2 to design the report.

    Hi Chuck Reed,
    Can you add that field through Add Command and see all digets are coming in ?
    Go in Datbase expert --Under you datbase connection click on Add Command and write sql like
    Select BatchNumber from Table and link the batchnumber with your table batch number and place command batchnumber in report and check.
    Thanks,
    Sastry

  • String truncation

    is there an easy way to remove x ammount of characters from a
    string value??
    IE:
    var greeting = "hello";
    (truncate 3 char from the end);
    trace(greeting) // "he"

    you can use the substr() or substring() methods of
    strings.

  • Regarding string

    Hi frnds,
                  I have a requirement where i have to find the position numbers of '#' in the complet string.
    can anyone help me how to approach.
    <code>
    REPORT  ZTEST_POSITIONFINDER.
    data : var1 type string .
    var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K  WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.
    </code>
    help me frnds
    regards,
    satish

    Satish,
      I forgot to add one more line in my earlier mail.Check now this.
    DATA : v_cnt TYPE I,
    v_num TYPE I,
    v_num1 TYPE I,
    v_pos(100).
    var1 = '210651#WHA-588QV#11/26/2007 10:58#527.02#526.99#526.99#17640207#ALLEN K WITHRAW J#1000#CVGOGG20071118NL02#Approved on link to booking.#'.
    v_cnt = strlen( var1 ).
    DO v_cnt TIMES.
    v_count = v_count + 1.
    IF var1+v_num1(v_count) EQ '#' .
    concatenate v_count ',' INTO v_pos.
    v_count  =  v_count + 1.*
    ENDIF.
    ENDDO.
    Write : v_pos.
    Here you can see the # position numbers seperated by coma(,).

  • Regarding string operations and value alignment below heading

    Hi all,
    I have a requirement of sending the data in the form of table in mail thought me program.
    Am sending the mail content form int table.
    The issue is the table getting displayed like this(I used internal table of strings for this)-
    Name            |          Old value               |       New value                              -->Heading string
    Description     |          Material for production of tractors  |  Material for tractors  -->value string1
    weight               |       123   | 124                                                                   -->value string2
    Value 124 should have been well below New value.
    In short am not able to arrange the values (Because of variable length of values)well below table field so that i can distinguish  various values in same row.Please guide me for this issue .
    Thank you,
    Edited by: sanu debu on Mar 22, 2009 1:43 PM

    hi,
    use UNDER option.
    like
    write:
      / 5 text-001(give text ele as carrid)
        10 text-002(give as connid)
    loop at itab into fs_itab.
    write: / fs_itab-carrid under text-001,
               fs_itab-connid under text-002.
    endloop.
    Regards,
    jaya

  • Workflow and Task Description String truncate

    Hello,
    When i start the workflow,
    I see the field Url in the container correctly filled.
    URL= htpp://www.bwptestAAA
    But, in the log of the workflow, i see in Task Description:
    Please select the URL = http://www.bwptestA (lack info)
    In fact the URL is truncated to 68 chars ....
    Any Idea ?
    Thanks

    Hi,
    Try using type SOLI in that container this will Help you.
    Regards,
    Purvesh Patel.

  • XSL and string truncation

    Hello
    i am creating a XSL to transform some XML information into a CiscoIPPhoneMarkupLanguage document (CIPML). CIPML's schema restricts several element's lenght. For instance, a CiscoIPPhoneMenu/MenuItem/Name must be no more than 64 characters long. I would like that the XSL stylesheet handle the truncation of (eventual) extra characters, but I did not see how it is possible in the w3c TRs. Do you know how?
    THx

    I don't see the Java connection in this question, but XSL does have a substring function.

  • Regarding string functions

    hi all,
    i have a text file as following
    linkstable
    linkname,linkpage
    linkpage
    xxxxxxxxxxxxnow i have to read the file ,ie., i have to get Strings in between the "#" ie.,
    i have to find the occurance of the "# " and then the string between them how can i do this
    do we have any method to find the repeated occurance of a string in java
    could any one help me
    thanks in advance

    A lot of this is going to depend on your definition of "between"
    Text1
    Text2
    Text3
    #Text4#
    In the previous example Text3 is the only answer, Text4 is the only answer, or all of the Texts are the answer, which is it? If you don't know, go back to your teacher and find out--you cannot code for a problem that does not have a known outcome. You need much better problem definition before an algorithm can be developed to provide a solution to code.

  • A question regarding String

    One String problem confused me.
    String s = "aacc";
    Now, i want to insert "bb" between "aa" and "cc", The result would be that s equals "aabbcc". I had thought to implement it by using insert method. but I was surprised that Class String do not support this method. Could anyone give me a simple way that can do this. thanks a lot.

    Use the StringBuffer class instead. The String class is imutable. It will create a new string when modified.
    StringBuffer b = new StringBuffer("aacc");
    b.insert(2, "bb");

  • Regarding string operations

    Hi All,
    i've a string holding the value as given below.
    AA,17,2/19/2003,"9,999.00",USD,00,10,318,"193,275.31"
    by performing some string operations i want the result string in the format as given below:
    AA,17,2/19/2003,"9999.00",USD,00,10,318,"193,275.31"
      i.e., i want to remove all the commas(,)that are included in between a pair of " " only.
    can anyone provide me a sample code for the same

    Hi vijay,
    A bit complex but works for sure, check the following logic,
    REPORT zsritest.
    DATA: gs_string TYPE string.
    gs_string = 'AA,17,2/19/2003,"9,999.00",USD,00,10,318,"193,275.31"'.
    WRITE: / gs_string.
    PERFORM string_trim CHANGING gs_string.
    *       FORM string_trim                                              *
    *  -->  LS_STRING                                                     *
    FORM string_trim CHANGING ls_string.
      DATA: lt_string TYPE string OCCURS 0 WITH HEADER LINE,
            lv_tabix TYPE i,
            lv_start.
      SPLIT gs_string AT '"' INTO TABLE lt_string.
      CHECK sy-subrc EQ 0.
      CLEAR gs_string.
      LOOP AT lt_string.
        lv_tabix = sy-tabix MOD 2.
        IF lv_tabix EQ 0.
          TRANSLATE lt_string USING ', '.
          CONDENSE lt_string NO-GAPS.
        ENDIF.
        IF lv_tabix EQ 0 OR lv_start EQ 'X'.
          CONCATENATE gs_string lt_string INTO gs_string SEPARATED BY '"'.
          IF lv_start EQ 'X'.
            CLEAR lv_start.
          ELSE.
            lv_start = 'X'.
          ENDIF.
        ELSE.
          CONCATENATE gs_string lt_string INTO gs_string.
        ENDIF.
      ENDLOOP.
      IF lv_start EQ 'X'.
        CONCATENATE gs_string '"' INTO gs_string.
      ENDIF.
      WRITE: / gs_string.
    ENDFORM.
    Hope this helps..
    Sri

  • Basic Doubt regarding string comparision

    I have the following code:
    RegisterForm rf = (RegisterForm)form;
    String user = rf.getUsername();
    DTO ourdto = DBconnection.getDTO();               
    String pass = ourdto.getPword();When I print user,*pass* both the strings print "*pojo*"
    Now the condition I have to satisfy is
    pseudo code ---- if(*user* isequal to pass) { proceed forward }.
    I have used .equals but it is returning false,used equalsIgnoreCase and isContentEquals both are returning false.
    Could someone tell me if there is any method that can compare "pojo" to "pojo" and return a true.
    .

    sidster wrote:
    I have used .equals but it is returning false,used equalsIgnoreCase and isContentEquals both are returning false.Then they're not equal.
    Could someone tell me if there is any method that can compare "pojo" to "pojo" and return a true.
    String str = getUserInputOrWhatever();
    if ("pojo".equals(str)) {
      // the string was "pojo"
    }

Maybe you are looking for

  • Two different schedulelines

    Hai friends, My issue is my line item number is same but I have two schedulelines for the same line item number.I have created two delivery document numbers with one order number.How do I know that which line item number belongs to which scheduleline

  • Saved sequences in Premiere Pro CC acting oddly, striped clips, green clips, blue clips...

    Rather new user to PP. Can't even find this question asked anywhere. 1. The other day, I created some sequences. Each sequence has its own bin and the source footage is in the bin. 2. Today I open up the sequences and though the source footage is int

  • My iphone is not charging?

    even when is connected to the power, of course...

  • Connecting to Oracle 8i.7 Database on Application Server 10g (10.1.2)

    Hi Dear All i have gust installed Oracle Application Infrastructure & middle tire 10g(10.1.2) and i am asking for the capability to connect (After Configuring Tnsname) to Oracle Database 8i(8.1.7.0.0) the message after trying to connect is : Connecti

  • Join query

    I have 2 tables initially. Now I have written a query creating a table/view based on those two tables using inner join based on a condition involving 1 column from either of the two tables. Now the requirement is as such where the data has been distr