Trim() with options L, T and B.

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

I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Trim() with options L, T and B.

Post by I_Server_Whale »

Hi All,

Say I have a string as follows:

Code: Select all

xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBBxxxxxxxx
I need to trim out the leading and trailing 'x's. The output being:

Code: Select all

AAAAAAAxxxxxBBBBBBBBBB

So, I used

Code: Select all

Trim(InCol, 'x','B')
, where only leading 'x's are trimmed which is not right.

When I use,

Code: Select all

Trim(InCol,'x','L')
, the leading 'x's are trimmed which is correct.

And When I use,

Code: Select all

Trim(InCol,'x','T')
, none of 'x's are trimmed, which is absolutely wrong.

Do these 'L', 'T' and 'B' options work in parallel version or is it behaving oddly because it version 7.5x2?

Please advise,

Thanks,
Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Not DataStaging today, so I can't check. First step would be to check whether it's documented as behaving the same way, or whether different control codes are used for familiar (from server jobs) functionality.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

Tested with both B and L and this is what I got :

Trim(InCol,'x','B') "AAAAAAAxxxxxBBBBBB"
Trim(InCol,'x','L') "AAAAAAAxxxxxBBBBBB"

:shock:
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

I got the following result:

Trim(DSLink2.Col1,'x','B') = AAAAAAAxxxxxBBBBBBBBBB
Trim(DSLink2.Col1,'x','L') = AAAAAAAxxxxxBBBBBBBBBBxxxxxxxx

What is your OS?
You are in 7.5x2 which is datastage EE for windows but you had posted you are working in UNIX.

I am using datastage 7.5.1.A in AIX.

I had similar problems with TrimB and TrimF function in the past. Manual specifies that TrimB and TrimF removes tab but as far as i tried it does not remove tabs.
rafik2k
Participant
Posts: 182
Joined: Wed Nov 23, 2005 1:36 am
Location: Sydney

Post by rafik2k »

Hi,
I tested following scenario and got result which is perferctly fine for me.

Code: Select all

Ans=Trim(Arg1,'x','B') 

Arg1 = xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBBxxxxxxxx

Result = AAAAAAAxxxxxBBBBBBBBBB
-------------------------------------------

Code: Select all

Ans=Trim(Arg1,'x','L') 

Arg1 = xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBBxxxxxxxx

Result = AAAAAAAxxxxxBBBBBBBBBBxxxxxxxx


------------------------------------------

Code: Select all

Ans=Trim(Arg1,'x','T') 

Arg1 = xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBBxxxxxxxx


Result = xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBB
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Re: Trim() with options L, T and B.

Post by sachin1 »

input value val=xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBBxxxxxxxx
trim(val,'x')
got a result as
AAAAAAAxBBBBBBBBBB.

i have server edition 7.2 with following string functions

syntax Trim(%string%,[%stripchar%],[%option%])
TrimB(%string%)
TrimF(%string%)
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Server edition is completely irrelevant here.

Whale, if this is in a Transformer stage can you take a look at the generated C++ code? For job number xxxx this will be in a sub-directory called RT_SCxxxx in the project directory on the server.

I'll see if I can find a 7.5x2 system tomorrow or Friday.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

I tested all scenarios of Trim. It works for me on parallel. I am on 7.5.1A on HP-UX.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

DSGuru2B,

Can you please check whether TrimB and TrimF function removes tab?
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Unfortunately that does not work. Thats really odd. But the following works to remove tabs.

Code: Select all

Trim(DSLink17.Num1,'	','L')
Trim(DSLink17.Num1,'	','T')
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

ray.wurlod wrote:Server edition is completely irrelevant here.

Whale, if this is in a Transformer stage can you take a look at the generated C++ code? For job number xxxx this will be in a sub-directory called RT_SCxxxx in the project directory on the server.

I'll see if I can find a 7.5x2 system tomorrow or Friday.
Hi All,

Sorry for the delay. My bad about the OS. It was an accident. It is in fact 7.5x2 on Windows.


Ray,

I'll check and post the C++ code. Many thanks,

Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
thamark
Premium Member
Premium Member
Posts: 43
Joined: Thu Jan 29, 2004 12:12 am
Location: US

Character datatype

Post by thamark »

I noticed this kind of behavior if the input column is character data type column , by which length of field is not exactly same as field length defined and it pads spaces at the end. Last example works fine since i am triming trailing spaces and then trimming again...

Means

Col1 Char 2000

Col1 ='xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBBxxxxxxxx'

Trim(InCol, 'x','B')

AAAAAAAxxxxxBBBBBBBBBBxxxxxxxx

Trim(InCol,'x','L')

AAAAAAAxxxxxBBBBBBBBBBxxxxxxxx

Trim(InCol,'x','T')

xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBBxxxxxxxx

Trim(Trim(DSLink32.Col1), 'x','B')

AAAAAAAxxxxxBBBBBBBBBB
Hmm i will fill this when ever i get one
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Post by I_Server_Whale »

Hi Ray,

This is what I got from RT_SCxxxx folder. I'm pasting the C++ code (contents of the TRX file) generated for each case:

Case 1: Trim() with 'B' option,

Code: Select all


//
// Generated file to implement the V0S1_repos_Transformer_1 transform operator.
//

// define our input/output link names
inputname 0 DSLink2;
outputname 0 DSLink3;

initialize {
	// define our row rejected variable
	int8 RowRejected0;

	// define our null set variable
	int8 NullSetVar0;

	// declare our intermediate variables for this section
	string InterVar0_0;
	string InterVar0_1;

	// initialise constant values which require conversion
	InterVar0_0 = "x";
	InterVar0_1 = "B";
}

mainloop {
	// initialise our row rejected variable
	RowRejected0 = 1;

	// evaluate columns (no constraints) for link: DSLink3
	DSLink3.col1 = trimc_string(DSLink2.col1 , InterVar0_0 , InterVar0_1);
	writerecord 0;
	RowRejected0 = 0;
}

finish {
}
Case 2: Trim() with 'L' option,

Code: Select all

//
// Generated file to implement the V0S1_repos_Transformer_1 transform operator.
//

// define our input/output link names
inputname 0 DSLink2;
outputname 0 DSLink3;

initialize {
	// define our row rejected variable
	int8 RowRejected0;

	// define our null set variable
	int8 NullSetVar0;

	// declare our intermediate variables for this section
	string InterVar0_0;
	string InterVar0_1;

	// initialise constant values which require conversion
	InterVar0_0 = "x";
	InterVar0_1 = "L";
}

mainloop {
	// initialise our row rejected variable
	RowRejected0 = 1;

	// evaluate columns (no constraints) for link: DSLink3
	DSLink3.col1 = trimc_string(DSLink2.col1 , InterVar0_0 , InterVar0_1);
	writerecord 0;
	RowRejected0 = 0;
}

finish {
}
Case 2: Trim() with 'T' option,

Code: Select all

//
// Generated file to implement the V0S1_repos_Transformer_1 transform operator.
//

// define our input/output link names
inputname 0 DSLink2;
outputname 0 DSLink3;

initialize {
	// define our row rejected variable
	int8 RowRejected0;

	// define our null set variable
	int8 NullSetVar0;

	// declare our intermediate variables for this section
	string InterVar0_0;
	string InterVar0_1;

	// initialise constant values which require conversion
	InterVar0_0 = "x";
	InterVar0_1 = "T";
}

mainloop {
	// initialise our row rejected variable
	RowRejected0 = 1;

	// evaluate columns (no constraints) for link: DSLink3
	DSLink3.col1 = trimc_string(DSLink2.col1 , InterVar0_0 , InterVar0_1);
	writerecord 0;
	RowRejected0 = 0;
}

finish {
}

In every case, it uses the trimc_string function with the respective options. What does this trimc_string function do? What is its usage syntax?

Anyways, that's the content of the C++ code.

Thanks again. Appreciate it.

Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
thamark
Premium Member
Premium Member
Posts: 43
Joined: Thu Jan 29, 2004 12:12 am
Location: US

Char datatype problem

Post by thamark »

I_Server_Whale wrote: Whale.
I guess this is problem due to the Data Type of the column.

Following function should give you correct answer, if that is the case

Trim(Trim(Column), 'x','B')
Hmm i will fill this when ever i get one
I_Server_Whale
Premium Member
Premium Member
Posts: 1255
Joined: Wed Feb 02, 2005 11:54 am
Location: United States of America

Re: Character datatype

Post by I_Server_Whale »

thamark wrote:I noticed this kind of behavior if the input column is character data type column , by which length of field is not exactly same as field length defined and it pads spaces at the end. Last example works fine since i am triming trailing spaces and then trimming again...

Means

Col1 Char 2000

Col1 ='xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBBxxxxxxxx'

Trim(InCol, 'x','B')

AAAAAAAxxxxxBBBBBBBBBBxxxxxxxx

Trim(InCol,'x','L')

AAAAAAAxxxxxBBBBBBBBBBxxxxxxxx

Trim(InCol,'x','T')

xxxxxxxxxAAAAAAAxxxxxBBBBBBBBBBxxxxxxxx

Trim(Trim(DSLink32.Col1), 'x','B')

AAAAAAAxxxxxBBBBBBBBBB
thamark,

I have my input and output columns defined as Varchar(100). So that's not what is causing it. I even tried

Code: Select all

	Trim(Trim(InCol), 'x','B')

But it still returns:

Code: Select all

AAAAAAAxxxxxBBBBBBBBBBxxxxxxxx
Whale.
Anything that won't sell, I don't want to invent. Its sale is proof of utility, and utility is success.
Author: Thomas A. Edison 1847-1931, American Inventor, Entrepreneur, Founder of GE
Post Reply