any other way to get trim functionality without transformer

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
Nripendra Chand
Premium Member
Premium Member
Posts: 196
Joined: Tue Nov 23, 2004 11:50 pm
Location: Sydney (Australia)

any other way to get trim functionality without transformer

Post by Nripendra Chand »

Hi,

Is there any other way to get trim functionality without using transformer?I checked in modify stage but i couldn't find.

Regards,
Nripendra
djm
Participant
Posts: 68
Joined: Wed Mar 02, 2005 3:42 am
Location: N.Z.

Post by djm »

Hi Nripendra,

I suspect you may have posed a question that is too broad. For example, if you are trying to trim all trailing spaces from all fields where the fields are separted by perhaps a comma, possibilities exist in to do this very efficiently on the unix command line. If you are trying to trim non-printable characters, other options may be more suitable.

It may be helpful if you were to post slightly more details e.g. details what are you trying to trim and other useful info such as the source of your data (e.g. flat file, database, ...).

David
Nripendra Chand
Premium Member
Premium Member
Posts: 196
Joined: Tue Nov 23, 2004 11:50 pm
Location: Sydney (Australia)

Post by Nripendra Chand »

Source file is a flat file. I need to perform lookup against it. But before lookup I want to trim all spaces in the lookup keys in this file.


Regards,
Nripendra
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Within DS I think you will have to use the TRIM() function in a transform stage to do this. There are string handling capabilities in the sequential file stage, but they won't work for all types of strings (for instance no implicit trimming will be done when reading quoted strings withi embedded trailing spaces).
djm
Participant
Posts: 68
Joined: Wed Mar 02, 2005 3:42 am
Location: N.Z.

Post by djm »

Another possibility is, as mentioned, to pre-process the file in unix, though it will depend a bit on the field content. For example, if the field to be used in the lookup is the second field (I could pick the first but have conciously chosen the second to illustrate the point) and the fields in the file are separated by a known character, such a comma, you could pre-process the file very, very (did I mention very?) quickly with "sed"

Thus, with the second field the lookup and comma as a record separator:

Code: Select all

sed 's/\([^,]*,[^,]*\) *,/\1,/' your_file_name_here


This approach is dependent on being able to define a regular expression that will enable you to match all the characters that form the fields up to and including the lookup field. If your field separator character can appear within one of the fields preceeding the look-up field, another approach may be easier.

David
Nripendra Chand
Premium Member
Premium Member
Posts: 196
Joined: Tue Nov 23, 2004 11:50 pm
Location: Sydney (Australia)

Post by Nripendra Chand »

Hi ArndW,

can u please tell me through some example how to use string handling capabilities in the sequential file stage. I've defined the quotes as none for input file.

Regards,
Nripendra
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

If you right-mouse click on a column in the input sequential stage and go to "edit row" you will get a window that lets you set many different attributes on a per-column basis. Click on the string attributes at the lower half of the window to see your options, then you can use the online help and/or the .pdf documentation to additional information if you need it.
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

There is a modify function called string_trim which is not documented in any DataStage documentation. It does show up in the old Orchestrate manual:

stringField=string_trim [character, direction, justify](string)

You can use this function to remove the characters used to pad variable-length strings of greater length. By default, these characters are retained when the fixed-length string is then converted back to a variable-length string.

The character argument is the character to remove. It defaults to NULL. The value of hte direction and justify arguments can be either begin or end; direction defaults to end, and justify defaults to begin. Justify has no affect when the target string has variable length.

Examples:
name: string = string_trim[NULL, begin](name)
removes all leading ASCII NULL characters from the beginning of name and places the remaining characters in an output variable-length string with the same naem
Nripendra Chand
Premium Member
Premium Member
Posts: 196
Joined: Tue Nov 23, 2004 11:50 pm
Location: Sydney (Australia)

Post by Nripendra Chand »

For trimming null it worked fine. But when i tried to trim spaces, i gave following expression:
C1: string[4] = string_trim[' ', begin](C1)

But it gave following error:
Error in binding: Parsing parameters " , begin" for conversion "string=string_trim[NULL,end,begin](string)": Only one character, or NULL expected, got:
Expected destination field selector, got: ")"; input:
C1: string[4] = string_trim[' ', begin](C1

What should i give to trim spaces?

-Nripendra
Nripendra Chand
Premium Member
Premium Member
Posts: 196
Joined: Tue Nov 23, 2004 11:50 pm
Location: Sydney (Australia)

Post by Nripendra Chand »

I tried " " instead of ' ', then it worked. Sorry for the last post.
Thanks for all your help.

Regards,
Nripendra
Post Reply