Page 1 of 2

Trim() with options L, T and B.

Posted: Tue Jun 12, 2007 1:15 pm
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.

Posted: Tue Jun 12, 2007 3:29 pm
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.

Posted: Tue Jun 12, 2007 11:12 pm
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:

Posted: Wed Jun 13, 2007 12:03 am
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.

Posted: Wed Jun 13, 2007 4:04 am
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

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

Posted: Wed Jun 13, 2007 5:18 am
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%)

Posted: Wed Jun 13, 2007 5:52 am
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.

Posted: Wed Jun 13, 2007 8:01 am
by DSguru2B
I tested all scenarios of Trim. It works for me on parallel. I am on 7.5.1A on HP-UX.

Posted: Wed Jun 13, 2007 8:06 am
by balajisr
DSGuru2B,

Can you please check whether TrimB and TrimF function removes tab?

Posted: Wed Jun 13, 2007 8:45 am
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')

Posted: Wed Jun 13, 2007 12:28 pm
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.

Character datatype

Posted: Wed Jun 13, 2007 1:04 pm
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

Posted: Wed Jun 13, 2007 1:08 pm
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.

Char datatype problem

Posted: Wed Jun 13, 2007 1:18 pm
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')

Re: Character datatype

Posted: Wed Jun 13, 2007 1:20 pm
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.