String Operation

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
saugat_1982
Participant
Posts: 29
Joined: Mon Nov 20, 2006 7:17 am
Location: Melbourne

String Operation

Post by saugat_1982 »

Hi ,
I ve a input column which can give a integer value from 1 to 10 or NULL.
I am interested to create a string of char(20) where I will like to put a 'X' on position value provided by input col , and rest as empty space delimited by |.

For example , if input is 2
then output should look like '|X|||||||||'
if input is 5 then output should be '||||X||||||'

Please help , thanks in advance .

PS : For testing I am saying input will be 1 to 10 , but in real time it will be 1 to 500. So if I can successfully can do for 10 , my next step will be for 500.


Thanks Again
Saugat Dey
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

Str("|", InLink.Pos - 1) : "X" : Str("|", svMaxLen - InLink.Pos - 1)
I've used svMaxLen as a stage variable rather than using 10 or 500 as a constant. Set its value in the initialization step and do not include a per-row derivation for it.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
saugat_1982
Participant
Posts: 29
Joined: Mon Nov 20, 2006 7:17 am
Location: Melbourne

Post by saugat_1982 »

Thanks Ray for the reply.
But I guess , it is not the requirement .

from input I will get a number (integer) .Lets say 'a'.
value of 'a' can be anything between 1 to 'n'(Max Value, in this case I m saying 10).

Now in output I want to generate a string (2n length).
Lets call the output string as 'outputstr'
And the shape of output will be like this

for i 1 to 2*n
if i%2 =0 then outputstr='|'
if i=2*a-1 then outputstr='X'
else output is NULL

Can you please suggest , Thanks Again.
Saugat Dey
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

saugat_1982 wrote:Thanks Ray for the reply.
But I guess , it is not the requirement .

from input I will get a number (integer) .Lets say 'a'.
value of 'a' can be anything between 1 to 'n'(Max Value, in this case I m saying 10).

Now in output I want to generate a string (2n length).
Lets call the output string as 'outputstr'
And the shape of output will be like this

for i 1 to 2*n
if i%2 =0 then outputstr='|'
if i=2*a-1 then outputstr='X'
else output is NULL

Can you please suggest , Thanks Again.



Read carefully what Ray is suggesting. It will give you the desired result or may be you have to change it a bit to get the result you want.

If you want to generate the string of length 2n then you might have to pad a space between pipes. Str function will do that. Try it first.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Your requirement appears incomplete.

Who is be using your output? With so many pipes, the receiving party will have an heck of translation to do.
saugat_1982
Participant
Posts: 29
Joined: Mon Nov 20, 2006 7:17 am
Location: Melbourne

Post by saugat_1982 »

why "the receiving party will have an heck of translation" ?
output is expected to 'n' numbers of characters/NULL separted by each pipe
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

It is not possible to include NULL in a string. As soon as you use NULL as an operand, the result is necessarily NULL. What did you have in mind here?
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