Wednesday, 6 February 2013

Type Conversion Functions


Hi friends Hear i am listing some Type conversion functions which are mostly used in our transformation logic's have a look on ............. 

DateToString:

Returns string representation of given date.
Here we can give or specify whatever date we want.

Ex:       dd-mm-yyyy,mm-dd-yyyy,yyyy-dd-mm
Syntax:  DateToString(%date%,[%yyyy%mm%dd%])

Ex :
1)DateToString( currentdate,”%yyyy\%mm\%dd”)
o/p:2008\10\08

2)DateToString( currentdate,”%yyyy-%mm-%dd”)
o/p:2008-10-08

3)DateToString( currentdate,”%yyyya%mma%dd”)
o/p:2008a10a08

4)DateToString( ‘2010-10-08’,”%yyyy-%mm-%dd”)
o/p:2010-10-08

5)DateToString(‘2010-10-08’,”%mm-%dd-%yyyy”)
o/p:10-08-2010

6)DateToString(‘10-08-2010’,”%dd-%mm-%yyyy”)

7)DateToString( currentdate,”%dd-%mm-%yyyy”)
o/p: 08-oct-2010

8)DateToString( currentdate,”%mm-%dd-%yyyy”)
o/p: oct-08-2010


DecimalToDecimal:

Syntax:   DecimalToDecimal(%Decimal%,%rounding%)

Ex:
1) DecimalToDecimal(12.345)
o/p: 12.35

2) DecimalToDecimal(12.342)
o/p: 12.34

3) DecimalToDecimal(1.3) ------>(2,1)   [length(9),scale(2)]
o/p: 0000001.30

4) DecimalToDecimal(289.347)-------> (6,3)
o/p: 0000289.35

5) DecimalToDecimal(299999999.007) -------->(12,3)
o/p: 0000000.00

6) DecimalToDecimal(2999999.3) ----->(8,1)
o/p: 2999999.30

7) DecimalToDecimal(1.7) ------>(2,1)   [length(9),scale(1)]
o/p: 00000001.7

8) DecimalToDecimal(1.7) ------>(2,1)   [length(9),scale(2)]
o/p: 0000001.70

9) DecimalToDecimal(1.78) ------>(3,2)   [length(9),scale(1)]
o/p: 0000001.8

10) DecimalToDecimal(000000110.00000) ------>Datatype(integer)
o/p: 110

StringToDate:

Returns a date from the given string in the given format.

Syntax:
StringToDate(%DateString%,[%”yyyy-%mm-%dd”%])

Ex:
1)StringToDate(“10201008”,”%mm%yyyy%dd”)
o/p:  2010-08-10

2)StringToDate(“10-2010-08”,”%mm-%yyyy-%dd”)
o/p:  2010-08-10

3)StringToDate(“10/08/2010”,”%mm/%yyyy/%dd”)
o/p:  not support(format is different)

IsValid:

Syntax:   IsValid(%typestring%,%valuestring%)



Ex:

1)IsValid(“Date”,”currentdate”)
o/p: 1

2)IsValid(“Date”,”0000:00:00”)
o/p: 0

3)IsValid(“Date”,”1999-13-11”)
o/p: 0

4)IsValid(“Date”,”1999-12-32”)
o/p: 0

5)IsValid(“Date”,”1999-12-12”)
o/p: 1

6)IsValid(“Decimal”,”12.3.345”)
o/p: 0

7)IsValid(“String”,”3.345”)
o/p: 1

8)IsValid(“Decimal(6,3)”,”123.345”)
o/p: 0

9)IsValid(“Decimal(7,3)”,”123.345”)
o/p: 0

10)IsValid(“String”,”GHJ123”)
o/p: 1

11)IsValid(“String”,”GHJ”)
o/p: 1

StringToDecimal:

Returns the given string in decimal representation

Syntax:
StringToDecimal(%String%,%rtype%)

Ex:
1)StringToDecimal(“34.56”)---->(4,2)  length(8), scale(2)
o/p: 000034.56



                                                                          ---Sudheerkumar

Tuesday, 5 February 2013

String Function in Transformer


Hear i am giving  regularly used string functions in Transformaer with examples ........

1.  AlNum(%string%)

Allnum(“12345”) --- output-1
Allnum(“abcd”) --- output-1
Allnum(“ab125”) --- output-1
Allnum(“@a12345”) --- output-0
Allnum(“@a1 2345”) --- output-0

Except Special Symbols (Letters & Numbers) it will give output as “1”

2. Alpha(%string%)

Alpha (“abcd”) --- output-1
Alpha (“12345”) --- output-0
Alpha (“ab125”) --- output-0
Alpha (“@a12345”) --- output-0
Alpha (“@a1 2345”) --- output-0

3. Compactwhitespace(%string%)

     It reduces or replaces multiple spaces into single space.

Ex: CompactWhiteSpace("sud hee                  r") 

            Out Put: sud hee r


4. Space(length):

     Inserts no.of white spaces given in lengthy parameters.

        Ex:-Space(6):’Brahma’
       Output: Brahma


5 . Len(string):

Returns length of string in characters

     Ex:- Len(space(6):’Brahma’)
     Output---12

     Ex:- Len(“Brahma”)
      Output—6


6. Compare(String1,String2,[Justification]):       //case sensitive

      Compares String1 & String2,if String1 is greater than String2 it will result 1

            If String1 is less than String2,then it will result 1.
            If both the strings are equal then it will result 0.
            To compare String1 with String2, we give Justification:L
           To compare String2 with String1,we give Justification:R

     Ex:       Compare(“abcd”,”abc”,”L”)---output-1
                  Compare(“abcd”,”abc”,”R”)---output-0
                  Compare(“abc”,”Abc”)---output-1     Default Justification-L
                  Compare(“abc”,”abcd”)---output  -1

7. CompareNoCase(String1,String2):

             Same as Compare,but diff is this function is NOT case sensitive.
          In this function no argument called Justification.

8. CompareNum(String1,String2,length):

           Compares two strings up to the given length.
           Ex:-     CompareNum(“a”,”abc”,1)     output---0
                       CompareNum(“a”,”abcde”,5) output--    -1
           CompareNum(“abcde”,”a”,5) output---1
           CompareNum(“abcde”,”Abcde”,1)    output---1
           CompareNum(“Abcde”,”abcde”,1)    output--   -1


9. CompareNumNoCase(String1,String2,length):

          Same as CompareNum, diff is this function is NOT case sensitive.
          Ex:-     CompareNumNoCase(“Abcde”,”abcde”,5)   output---0
         CompareNumNoCase(“abxye”,”abcde”,5)    output---1
         CompareNumNoCase(“abcde”,”abxde”,5)    output--  -1


10. Upcase(String):

           Change all lowercase letters in a string to uppercase.

           Ex:-     Upcase(“brahma”)       output—BRAHMA
           Upcase(“braHma”)      output----BRAHMA

11. DQuote(String):

          Enclose a string in double quotation marks.

         Ex:-     DQuote(Upcase(“brahma”))   output---“BRAHMA”
        DQuote(‘brahma’)                  output---“brahma”


12. Field(String,delimiter,occurrence,number):

          Returns the substring before delimiter based on occurrence we are given.
            Ex:-     Field(“br_ah_ma_na”,”_”,2)   output---ah

         Here ah is substring before the second occurrence of delimiter ‘_’.
Field(“br_ah_ma_na”,”_”,3)   output---ma
         Here after ma _ is third occurrence.
Field(“br_ah_ma_na”,”_”,1,4)            output---br_ah_ma_na
Field(“br_ah_ma_na”,”_”,1,2)            output---br_ah
Field(“br_ah_ma_na”,”_”,1,3)            output---br_ah_ma
Field(“br_ah_ma_na_a”,”_”,1,5)        output---br_ah_ma_na_a

 Note:-

          Field(“brahmananda”,”a”,2)   output—hm
   Here ‘a’ is delimiter
         Field(“brbhmananda”,”a”,2)   output—n
         Field(“brhhmananda”,”a”,1)   output—brhhm
          Field(“brahmananda”,”a”,1,3)  output—brahman


13. Index(String,substring,occurrence):

        Returns starting character position of substring.
        Ex:-     Index(“brahma”,”a”,1)            output---3
        Index(“brahma”,”a”,2)            output---6
        Index(“brahmananda”,”a”,3)  output---8
        Index(“brahmananda”,”na”,1)  output---7

14. Convert(fromlist,tolist,Expression)

      Converts specified character in a string(given in expression arg) to designated replacement character
      Ex:-  convert(“a”,”y”,”brahma”)
   o/p:byhmy
             convert(“ah”,”y”,”brahma”)
   o/p:brymy
      This function performs character replacement, but not word.
      Ex:  convert(“brahma”,”msrmad”,”brahma”)

15. Count(String,Substring):

      Count number of times a Substring occurs in a String.
      Ex:Count(“brahma”,”a”)
            o/p:2
           Count(“brahmabaabaaba”,”ab”)
            o/p:3
          Count(“brahmabaabaaba”,”ba”)
            o/p:3

16. DCount(String,Delimiter):

      Count number of delimited fields in a string.

     Ex:  DCount(“br-ah-ma-na”,”_”)-------o/p:4
             DCount(“br,ah,ma,na”,”,”)-------o/p:5
             DCount(“br,ah-ma,na”,”,”)-------o/p:4
    ah-ma, treats as one field

17. Downcase(String):

       Change all uppercase letters in a String to lowercase
     Ex:  Downcase(“BRAHMA”)------o/p:brahma
             Downcase(“brHMA”)------o/p:brahma
             Downcase(“BRAhma”)------o/p:brahma

18. Left(String,length)

        Returns leftmost ‘n’ characters of the string, where n is length.
      
       Ex:  Left(“brahmananda”,4) o/p:brah
               Left(“bra__hmananda”,6) o/p:bra_hm

19. Right(String,Length)

      Returns rightmost ‘n’ characters of the string
    
      Ex:   Right(“brahmananda”,4) o/p:anda

20. Num(String)

     Returns 1 if string can be converted to a number.
     
     Ex:    Num(“brah”)    o/p=0
              Num(“369”)     o/p=1