IBM Sterling Transformation Extender

Sterling Transformation Extender

Come for answers, stay for best practices. All we're missing is you.


#Sterling
#Supplychain
 View Only
  • 1.  substr function in WTX 8.2

    Posted 09/01/09 04:17 PM

    Originally posted by: MyScreen-Laks


    Here is my requirement:

    Check the number of decimal places and if it is equal to 3 then move the digit one place to right and if it is equal to 4 then move the digit two places to the right.For ex: a=123.456 returns a=1234.56 and if a=123.4567 then returns a=12345.67

    I already did this in Java but I don't know how to implement the same functionality in WTX. Please advice:
    Here is the equivalent Java Code:

    public String MyAbs(String a,Container container){
    int i = a.indexOf(".");
    if(i != -1)
    {
    String subStr = a.substring(i+1);
    String substr1 = a.substring(0,i);
    String substr2 = a.substring(i+1);
    if(subStr.length() ==3)
    {
    a = substr1 + substr2.charAt(0)+ "." + substr2.substring(1,3);
    }
    else if(subStr.length() == 4)
    {
    a = substr1 + substr2.substring(0,2)+ "." + substr2.substring(2,4);
    }
    else if(subStr.length() == 5)
    {
    a = substr1 + substr2.substring(0,3)+ "." + substr2.substring(3,5);
    }
    else if(subStr.length() == 6)
    {
    a = substr1 + substr2.substring(0,4)+ "." + substr2.substring(4,6);
    }
    }
    return a;
    }
    #IBMSterlingTransformationExtender
    #DataExchange
    #IBM-Websphere-Transformation-Extender


  • 2.  Re: substr function in WTX 8.2

    Posted 09/01/09 05:12 PM

    Originally posted by: repanzer


    IF(count(word(a,".",-1))>3, a X 10, a X 100)

    The above statement assumes you will always have 3 or 4 decimal places to the right. If you need to check for more;

    IF(SIZE(WORD(a,".",-1))=3, a X 10,
    ..IF(SIZE(WORD(a,".",-1))=4, a X 100
    ...IF(SIZE(WORD(a,".",-1))=5, a X 1000
    ....IF(SIZE(WORD(a,".",-1))=6, a X 10000
    .....IF(SIZE(WORD(a,".",-1))=7, a X 100000
    )))))

    etc

    WORD does on the fly delimiting, in this case the decimal, size returns the size of any given string, multiplying any number by 10, moves the decimal to the right by 1 place, 100 moves it by two, etc.
    #IBM-Websphere-Transformation-Extender
    #DataExchange
    #IBMSterlingTransformationExtender


  • 3.  Re: substr function in WTX 8.2

    Posted 09/01/09 05:13 PM

    Originally posted by: repanzer


    IF(count(word(a,".",-1))>3, a X 10, a X 100)

    should be;

    IF(size(word(a,".",-1))>3, a X 10, a X 100)
    #IBM-Websphere-Transformation-Extender
    #DataExchange
    #IBMSterlingTransformationExtender


  • 4.  Re: substr function in WTX 8.2

    Posted 09/01/09 05:14 PM

    Originally posted by: repanzer


    Oh, and -1 in the word function returns the value in the last delimited field, in this case, always the characters to the rigth of the last decimal.
    #DataExchange
    #IBM-Websphere-Transformation-Extender
    #IBMSterlingTransformationExtender


  • 5.  Re: substr function in WTX 8.2

    Posted 09/02/09 10:19 AM

    Originally posted by: MyScreen-Laks


    Works like a charm. Thank you so much for your help.
    #DataExchange
    #IBMSterlingTransformationExtender
    #IBM-Websphere-Transformation-Extender