field function

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
sri75
Premium Member
Premium Member
Posts: 132
Joined: Thu Sep 09, 2004 12:42 pm

field function

Post by sri75 »

HI,

one of columns values from seq file look like this

SolditemYear
CAR 3 (3 spaces between 2 fileds)
CAR 50 (4 spaces between 2 fileds)
MD - 71(No space)
ASSO 82(No Space)
3 YE 95(No space)

I need to split the item and year into 2 separate fields
I used 2 stage variables

FIELD(LkInXfm.SOLDITEMYEAR," ",1)
FIELD(LkInXfm.SOLDITEMYEAR," ",2)

it can split correctly only 'ASSO 82'

I want to split remaing values also like
car 3
car 50
MD - 71
3 YE 95

can you please help me how to do ?
few records has two sapces and few records has 3 spaces.Actually there is no consistencey.

I think client entered manully these values


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

Post by DSguru2B »

In the field "CAR 3", is 3 the year? Or is it supposed to be 03 and you did not include the 0. Where I am getting to is that if the last two places are always going to be the year then you can use Right(in.Link, 2) for the year part and LEFT(in.Link, LEN(in.Link)-2) for the Type.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
sri75
Premium Member
Premium Member
Posts: 132
Joined: Thu Sep 09, 2004 12:42 pm

Post by sri75 »

Thanks for your reply DSGuru

Data looks exactly like this

CAR 3 (3 spaces between 2 fileds)
CAR 50 (4 spaces between 2 fileds)
MD - 71(No space) ' here I need to put 'MD -' in one filed and 71 in another filed
ASSO 82(No Space)
3 YE 95(No space)

Thanks
sri75
Premium Member
Premium Member
Posts: 132
Joined: Thu Sep 09, 2004 12:42 pm

Post by sri75 »

I forgot to mention in my previous mail,few records have
just type , no year mentioned.

like

MAT
NAT no year mentioned here

when I use

LEFT(LkInXfm.SOLDYEAR, LEN(LkInXfm.DEGRYEAR)-2)
right(LkInXfm.SOLDYEAR,2)

when I use these functions , it is splitting previus record like M AT
can you please suggest me what needs to be done
OttMAdpttch
Charter Member
Charter Member
Posts: 6
Joined: Thu Mar 27, 2003 1:55 pm
Contact:

Post by OttMAdpttch »

It appears that your source data can have several different formats but basically representing two separate fields. I'd suggest that you create a simple DS routine that uses the MATCH[ES] command in a case structure.

If the extraneous spaces are not required for the output then I'd first Trim the string and then use the following logic:

begin case
*** 3X2N stands for 3 char and 2 numbers ***
case string matches '3X2N'
field1 = string[1,3] or Left(string,1,3)
field2 = string[4,2] or Right(string,4,2)
*** 4X1N stands for 4 char and 1 number ***
case string matches '4X1N'
field1 = ...
field2 = ...
case ...
end case

Ans = field1:"|":field2

Then you can parse the returned value based on the "|" character within the target column's derivation or within stage variables. This logic is not fool proof but can be customized to handle your non-standard data formats.
Mark Ott
DataStage Architect
Adept Technologies, Inc.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

See if the following custom routine helps you.

Code: Select all

      FUNCTION SplitRecord(Arg1)
      FieldToSplit = TRIM(Arg1)
      Type = ""
      Year = ""
      tmpType = ""
      tmpYear = ""
      FLAG = @TRUE

      FieldLength = Len(FieldToSplit)

      FOR n = FieldLength To 1 STEP -1
         asciiCode = SEQ(FieldToSplit[n,1])
         IF (asciiCode >= 48 AND asciiCode <= 57 AND FLAG)
         THEN
            tmpYear = FieldToSplit[n,1]
            Year = tmpYear:Year
         END
         ELSE
            tmpType = FieldToSplit[n,1]
            Type = tmpType:Type
            FLAG = @FALSE
         END
      NEXT n

      Ans = Type:"^":Year

Run this in the stage variable. THe values for Type and Yearwill be split by a ^. For 'Type' do FIELD(STGVar, "^", 1) and for 'Year' do FIELD(STGVar, "^", 2).

I chose ^ as a delimiter as its unlikely to show up in the data. If your data consists of this field then use a delimiter which will not show up.

Go through the code and understand it well. Do through testing.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
sri75
Premium Member
Premium Member
Posts: 132
Joined: Thu Sep 09, 2004 12:42 pm

Post by sri75 »

Thanks MATT and DSGuru for your suggestions.
let me take a look and get the clear picture of the code you send.
Just now I put these 2 derivations in stage variables.I checked for few records , It looks fine.but I am not sure this derivation works if I get different data formats in future.


if alpha(LkInXfm.DEGRYEAR) then LkInXfm.DEGRYEAR else LEFT(LkInXfm.DEGRYEAR, LEN(LkInXfm.DEGRYEAR)-2)

if alpha(LkInXfm.DEGRYEAR) then '' else right(LkInXfm.DEGRYEAR,2)

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

Post by ray.wurlod »

So there appears to be a need for a PEPC (predict every possible contingency) stage?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Nisusmage
Premium Member
Premium Member
Posts: 103
Joined: Mon May 07, 2007 1:57 am

Post by Nisusmage »

ray.wurlod wrote:So there appears to be a need for a PEPC (predict every possible contingency) stage?
Now THAT Would be perfect ..! :D
That way there will be no need for developers.. hey sri75?

sri75: You cannot predict the future. What I suggest is place a transformation with rejects on and push all exceptions to a file and cater for the different data as it comes in.
~The simpliest solutions are always the best~
~Trick is to understand the complexity to implement simplicity~
Post Reply