Extracting a Part from the given String

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

rkdatastage
Participant
Posts: 107
Joined: Wed Sep 29, 2004 10:15 am

Post by rkdatastage »

Hi ameyvaidya

Thanks for your response

The Routine works fine but it is not Full filling my requirement

ex1:

My String : ANSY, 3/4" SQ. DR., P/N 251-A626A,
Routine Output : P/N 251
My Desired Output has to be : P/N 251-A626A

Ex 2:

My String : BE PON AY, P/N 436A90-A602, FOR
Routine Output : P/N 436
My Desired Output has to be : P/N 436A90-A602

Can you guide me what are the necessary changes i had to do with the Code .

Thanks in Advance
RK
ameyvaidya
Charter Member
Charter Member
Posts: 166
Joined: Wed Mar 16, 2005 6:52 am
Location: Mumbai, India

Post by ameyvaidya »

This line is the Key:

Code: Select all

IF NUM(InString[PnEndTester,1]) AND InString[PnEndTester,1]<>" " THEN 
What i am doing here is checking for a pure numeric part number.

If the Part number can also have "-" then add

Code: Select all

AND InString[PnEndTester,1]="-"
Add more conditions to this line to test for more cases. Everything else signifies the end of the part number.
Thats all
Amey Vaidya<i>
I am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand.</i>
<i>- Douglas Adams</i>
dprasanth
Charter Member
Charter Member
Posts: 90
Joined: Fri Oct 07, 2005 7:55 am

Post by dprasanth »

rkdatastage wrote:Hi ameyvaidya

Thanks for your response

The Routine works fine but it is not Full filling my requirement

ex1:

My String : ANSY, 3/4" SQ. DR., P/N 251-A626A,
Routine Output : P/N 251
My Desired Output has to be : P/N 251-A626A

Ex 2:

My String : BE PON AY, P/N 436A90-A602, FOR
Routine Output : P/N 436
My Desired Output has to be : P/N 436A90-A602

Can you guide me what are the necessary changes i had to do with the Code .

Thanks in Advance
RK
Hi,
Try adding this to ameyvaidya code . This one will just extract the P/N bit
Total_length=Len(InString)
PnStart=INDEX(InString,"P/N",1)
Start=(Length1-PnStart)+1
Pnbefore=Field(Right(InString, Start),",",1)
Ans=Pnbefore
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Anyone try the MatchField() function suggestion?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Apparently, the preference is for a more brute force method. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Actually if you look at my routine, its fairly simple. Its not working because its not complete. You need an 'Ans' line. I left that upto you so that you can decide what delimiter should come between 'Part' and 'RestOfData'.

Code: Select all

Desc=TRIM(Arg1) 
RestOfData='' 
Part='' 
EndForLoop=LEN(Desc) 
FOR n = 1 TO EndForLoop 
     IF Desc[n,4] = 'P/N ' 
     THEN 
          Part=Field(Desc[n,EndForLoop-n+1],1,2) 
          RestOfData=Desc[1,n-1]:Desc[n+Len(Part),EndForLoop-Len(Part)] 
     END 
NEXT n 
Ans=Part:"|":RestOfData

I delimited the two parts with a pipe.
In the transformer you can use a Field() function to get 'Part' which is before the Pipe and 'RestOfData' which is after the Pipe.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

'Brute Force' does not imply complexity, per se... just relates more to the fact that the routine is iterating through the string a character at a time. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Mine is 4 characters at a time :wink:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Um... no, you slide over one character at a time checking for four each time. :P
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Darn, i thought id sly by without you noticing it. But you got me :o
The OP should really come back and let us know if it worked or not. I dont have access to DS at the moment and thus cannot test out my routine :(
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
Post Reply