convert char to integer

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
rafidwh
Participant
Posts: 179
Joined: Mon Oct 10, 2005 11:30 pm

convert char to integer

Post by rafidwh »

Hi All,
I have a source flat file with one of the column srccol1 char3 and my corresponding column in the database is trgcol1 num3.

If you look at the above description the souce column datatype is char and the target column is number.
Should I need to convert the char to num to populate to table? or will Datastage internally converts the char to num?
If doesn't convert the how I need to convert?
Please suggest me
Thanks in advance

Regards,
Saik.
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Re: convert char to integer

Post by balajisr »

rafidwh wrote:Hi All,
I have a source flat file with one of the column srccol1 char3 and my corresponding column in the database is trgcol1 num3.

If you look at the above description the souce column datatype is char and the target column is number.
Should I need to convert the char to num to populate to table? or will Datastage internally converts the char to num?
If doesn't convert the how I need to convert?
Please suggest me
Thanks in advance

Regards,
Saik.
Datastage will not convert char to num. You need to convert char to num using Int() Function.
Last edited by balajisr on Mon Jun 12, 2006 2:21 am, edited 1 time in total.
rafidwh
Participant
Posts: 179
Joined: Mon Oct 10, 2005 11:30 pm

Post by rafidwh »

But from the help,I found that the int() function is returning the integer portion from the number value like srccol value is 2.3 ,if we use Int it returns as 2,
Now will Int() aslo converts char to integer
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

rafidwh wrote:But from the help,I found that the int() function is returning the integer portion from the number value like srccol value is 2.3 ,if we use Int it returns as 2,
Now will Int() aslo converts char to integer
Indeed. Int() returns integer portion from the number value.

I think i got it totally wrong. For checking whether the string contains only numeric value do not use Alpha() function use Num() function which checks whether the string is numeric.

As for conversion i am not sure that Int() is the right method to use for converting char to integer. Sorry for my mistake.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

DataStage will perform an implicit conversion from a string to a number and vice-versa.

Code: Select all

   x = '123'
   x = x : '4'
   x = x * 2
   x = x[3,2]
rafidwh
Participant
Posts: 179
Joined: Mon Oct 10, 2005 11:30 pm

Post by rafidwh »

Hi Arnd
so that means,I need not use any coding to convert char to integer
Is that you mean to say.

Thanks
Saik
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

If your CHARacter field contains only digits then you do not need to perform any explicit conversions, see the example I gave in the previous post.
If your CHAR fields contains mixed numeric and text then you will need to provide some conversion code to make sure that DataStage interprets this field correctly. There are ICONV() conversions such as "MCN" that you can use to effect this.
rafidwh
Participant
Posts: 179
Joined: Mon Oct 10, 2005 11:30 pm

Post by rafidwh »

what should be done if a character like (A,B,C) occurs,should these rows need to be rejected by using num() or any conversions are possible.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Rafidwh - did you actually read my post? Please look into your BASIC programming PDF file and search for the MCN conversion and that will answer your question on what can technically be done with alphabetic characters in a numeric string. Nobody here can answer what needs to be done according to your business rules.
NBALA
Participant
Posts: 48
Joined: Tue Jul 11, 2006 11:52 am
Location: IL, USA

Post by NBALA »

Hi All,

I have the similar question, I have data which is signed decimal value from source flat file. This field will have -/+ like ' -213.23004'. We need to keep the sign on the target (oracle number). How to do this using DS.
Note: We are using DS 7.5

Please some one help me.

Thanks in advance
-NB
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Please start a new post.
Datastage will take it as a signed decimal. You dont need to worry about it. Negative decimal numbers are preserved.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply