Spliting Strings - Stage Variable or Routine

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
danddmrs
Premium Member
Premium Member
Posts: 86
Joined: Fri Apr 20, 2007 12:55 pm

Spliting Strings - Stage Variable or Routine

Post by danddmrs »

I put this in a resolved topic and probably shouldn't have.

I have a 75 byte field that needs to be split into 3 smaller fields, 25 bytes each. Business rules require that none of the words be split in the middle and that each field begin with a character other than space .

Input
THE HAPPENING STUDIO OF HAIR DESIGN AND GREAT MAKEOVERS INC

Output
THE HAPPENING STUDIO OF
HAIR DESIGN AND GREAT
MAKEOVERS INC

I was able to do this in COBOL using PERFORM VARYING logic. Do I need to set up a Routine to do the same thing using FOR LOOP logic or can this be done within the Transformer using FORMAT or maybe using Stage Variables?

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

Post by ray.wurlod »

Welcome aboard. :D

You can use Fmt(InLink.TheString, "25T")
The "T" format is "text" - it breaks on whole words. The Fmt() function inserts a "text mark" (@TM) at each division - you can convert this to anything you require, for example a newline, using Convert() for single character or Ereplace() for multi-character.

You might also like to investigate the Fold() function, though I don't think this offers the "text break" functionality you can get with Fmt().
Last edited by ray.wurlod on Sat Apr 21, 2007 2:13 am, edited 1 time in total.
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 »

ray.wurlod wrote:You can use Fmt(InLink.TheString, "25T")
Ooooo... New trick for old dog. Thank you Master. :D
-craig

"You can never have too many knives" -- Logan Nine Fingers
danddmrs
Premium Member
Premium Member
Posts: 86
Joined: Fri Apr 20, 2007 12:55 pm

Post by danddmrs »

Thanks Ray.

I'll have to join to see the full reply but I get where you're going. I didn't think this was going to be more difficult than Cobol - nothing else in DS is.

Great forum! If the company won't kick in the $ I'll join myself.

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

Post by ray.wurlod »

:idea: Maybe the fact that you need a small contribution to get full technical information could be used to justify the expense to the company?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
danddmrs
Premium Member
Premium Member
Posts: 86
Joined: Fri Apr 20, 2007 12:55 pm

Post by danddmrs »

Thanks Ray. The text mark and convert worked but with one problem. Names are left justified within each field but the fields are being filled from LAST to FIRST. I would have expected the opposite.

Dicks Diner is
" ", " ", "Dicks Diner "
instead of
"Dicks Diner ", " ", " "

I'm going to load it to the database and see how the Webpage likes it but thought I'd throw this out.

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

Post by ray.wurlod »

Last to first suggests that you're using "25R" rather than "25T".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
danddmrs
Premium Member
Premium Member
Posts: 86
Joined: Fri Apr 20, 2007 12:55 pm

Post by danddmrs »

Code is CONVERT(CHAR(251),"",FMT(L1.ORG_NM,"25T"))

I've tried TrimF(CONVERT(CHAR(251),"",FMT(L1.ORG_NM,"25T"))) and also using TrimF on the field in a second transform. Probably not a great idea but...

I also tried to evaluate the field 25 bytes at a time but that repeated the same 25 bytes 3 times. Maybe the problem isn't spaces but something else?

Not sure if it matters but the output of the transform is an FTP plug-in sending the data to the mainframe. I'm going to make a copy and write to a sequential file to see what happens.

Thanks.
Richard Schneider
nick.bond
Charter Member
Charter Member
Posts: 230
Joined: Thu Jan 15, 2004 12:00 pm
Location: London

Post by nick.bond »

Try this, you may find the field function handy if you want these into 3 separate fields.

Code: Select all

Field1 = Trim(Field(FMT(L1.ORG_NM,"25T"), @TM, 1))
Field2 = Trim(Field(FMT(L1.ORG_NM,"25T"), @TM, 2))
Field3 = Trim(Field(FMT(L1.ORG_NM,"25T"), @TM, 3))
Regards,

Nick.
danddmrs
Premium Member
Premium Member
Posts: 86
Joined: Fri Apr 20, 2007 12:55 pm

Post by danddmrs »

Thanks. The field function worked very nicely. The fields are populating in the correct order.

Remaining issue with justified right appears to be tied to how the FTP Plug-in is set up. When I write to a sequential file the data is left justified as expected.

I will close this thread and search the FTP posts for answers before posting anything else.

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

Post by ray.wurlod »

For efficiency you might evaluate FMT(L1.ORG_NM,"25T") once in a stage variable rather than three times in expressions.
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