Use of index function

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Use of index function

Post by sjordery »

Hi all,

I am not getting the proper output while using index function.
My source data contains data like this

-------------------------
file_name,file_type

abcd.txt,txt
efgh.csv,csv
--------------------------

I want the output like this

------------------------------
file_name,file_type,occurence

abcd.txt,txt,5
efgh.csv,csv,5

------------------------------------

the value of occurence is calculated by calaculating the the position of " . " in the file_name column

for this I have used a stage variable whose derivation is set to
index(input.file_name,'.',1)and mapped to the occurence column.
But every time I am getting the value as 0.

Can anybody suggest?
rafik2k
Participant
Posts: 182
Joined: Wed Nov 23, 2005 1:36 am
Location: Sydney

Post by rafik2k »

Is your job parallel or server?


0 means it is not finding "." in the input string.

For server job, try writing small subroutine and check like

findDot

Code: Select all

Position = Index(Arg1, ".", 1) 
Ans = Position
call the subroutine in column derivation of occurance as findDot(file_name), though ur code and this routine are same, just for checking.
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post by sjordery »

Thanks rafique
As I have mentioned on the top job type is parallel.
If the function is avaliable in the transformer do I need to go for the subroutine?
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

What is your source?

Can you replace your source with row generator stage and generate these values and post the result?
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

index(input.file_name,'.',1) or index(input.file_name,".",1) is right. Stage variable type also does not matter even if you are using the default type. Now you need to debug yourself with different sample records.
Last edited by JoshGeorge on Mon May 28, 2007 7:00 am, edited 1 time in total.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post by sjordery »

my job design is like this

seqfile------->transformer----->sequential_file

If I will use rowgenerator please suggest how I will generate data for the column having .(dot)extension?
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post by sjordery »

josh,

I have put the same syntax on the top what you have specified,but I am getting 0 as output.
I have used the stage varibale like this

input.filename stagevar1
index(stagevar1,'.',1) stagevar2

The data type I have specified as varchar for both the stage variables,I tried with specifying integer also but nt able to get the output as required.
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

Have column datatype as varchar in row generator. Have a test job with only one column and generate value for that column alone.

Also, Try writing the sequential file to peek to check what you receive is what you expect.

Do you get any warnings when you run the job?

Were you able to view data in the sequential file?
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post by sjordery »

The job is running sucessfully.
In the output I mean in the occurance column I am supposed to get values 5,5(Please check the 1st post) but,I am getting 0,0.
If I will use rowgenerator stage as source it will produce random values which maynt contain . part.
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

If I will use rowgenerator stage as source it will produce random values which maynt contain . part.
Not true.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Then there is something fishy in the data.
Try the following and see what the following shows in your output

Code: Select all

Field(in.Data, ".", 1)
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post by sjordery »

Code:

Field(in.Data, ".", 1)

I tried this one,but getting 0,0 values.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Index should be fine. What are the data types of stage variables? You will need Integer of some kind for the result of Index().
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
sjordery
Premium Member
Premium Member
Posts: 202
Joined: Thu Jun 08, 2006 5:58 am

Post by sjordery »

The data type of both the stage variables are Varchar.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You will need Integer of some kind for the result of Index().
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply