Spliting Strings - Stage Variable or Routine
Moderators: chulett, rschirm, roy
Spliting Strings - Stage Variable or Routine
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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().
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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
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
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.
Nick.
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: