Author |
Message
|
Blomman |
Posted: Wed May 19, 2010 3:37 am Post subject: Build string in ESQL |
|
|
Master
Joined: 31 Oct 2006 Posts: 230
|
Hi
I have an simple problem buildning an string with its current value + a new value in ESQL(Newbie on ESQL).
MyString2 never gets any value...
Something like this:
Code: |
DECLARE "all variables"
SET integer k=1
SET integer j=5
WHILE k<j DO
SET MyString="NewStringValueEachTurnInLoop";
SET MyString2 = MyString2 || MyString || ".";
SET k = k + 1;
END WHILE;
|
MyString2 should look for example like this when loop is done:
"value1.value2.value3.value4.value5."
Best Regards!
//Blomman |
|
Back to top |
|
 |
Svp |
Posted: Wed May 19, 2010 4:16 am Post subject: |
|
|
Apprentice
Joined: 18 Feb 2010 Posts: 40
|
|
Back to top |
|
 |
vmcgloin |
Posted: Wed May 19, 2010 4:25 am Post subject: |
|
|
Knight
Joined: 04 Apr 2002 Posts: 560 Location: Scotland
|
Try using single quotes instead of double quotes e.g. around '.' |
|
Back to top |
|
 |
Svp |
Posted: Wed May 19, 2010 4:28 am Post subject: |
|
|
Apprentice
Joined: 18 Feb 2010 Posts: 40
|
Declare MyString2 character '';
As concatenation will not accept Null values .
Concatenating data types should be unique. |
|
Back to top |
|
 |
Blomman |
Posted: Wed May 19, 2010 4:29 am Post subject: |
|
|
Master
Joined: 31 Oct 2006 Posts: 230
|
vmcgloin wrote: |
Try using single quotes instead of double quotes e.g. around '.' |
Ahh sorry i have single quotes around, just posted it wrong here... |
|
Back to top |
|
 |
Blomman |
Posted: Wed May 19, 2010 4:47 am Post subject: |
|
|
Master
Joined: 31 Oct 2006 Posts: 230
|
Svp wrote: |
Declare MyString2 character '';
As concatenation will not accept Null values .
Concatenating data types should be unique. |
Ahhh so stupid of me of course.....
Just an simple WMB admin not really an developer...
//Blomman |
|
Back to top |
|
 |
Blomman |
Posted: Thu May 20, 2010 8:19 am Post subject: |
|
|
Master
Joined: 31 Oct 2006 Posts: 230
|
What about the function TRIM?
If i have an string were i want to trim more then one singleton both TRAILING and LEADING.
In psuedo this is the "Trimming" i want to do the the string:
Code: |
var = 'abc abc=abd.'
SET var2 = TRIM(LEADING ' ' var);
SET var2 = TRIM(LEADING '=' var);
SET var2 = TRIM(TRAILING '.' var);
|
Perhaps trimming whitspace should be like this?
SET var2 = TRIM(LEADING var);
//Blomman |
|
Back to top |
|
 |
fatherjack |
Posted: Thu May 20, 2010 9:17 am Post subject: |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
Blomman wrote: |
Code: |
var = 'abc abc=abd.'
SET var2 = TRIM(LEADING ' ' var);
SET var2 = TRIM(LEADING '=' var);
SET var2 = TRIM(TRAILING '.' var);
|
//Blomman |
But var doesn't have a leading space or a leading =, so I'm unclear what you're trying to do and what you expect the result of the TRIMs to be.
By default TRIM will remove all leading and trainling spaces e,g,
Code: |
SET var2 = TRIM(var);
|
_________________ Never let the facts get in the way of a good theory. |
|
Back to top |
|
 |
Blomman |
Posted: Thu May 20, 2010 10:54 am Post subject: |
|
|
Master
Joined: 31 Oct 2006 Posts: 230
|
fatherjack wrote: |
Blomman wrote: |
Code: |
var = 'abc abc=abd.'
SET var2 = TRIM(LEADING ' ' var);
SET var2 = TRIM(LEADING '=' var);
SET var2 = TRIM(TRAILING '.' var);
|
//Blomman |
But var doesn't have a leading space or a leading =, so I'm unclear what you're trying to do and what you expect the result of the TRIMs to be.
By default TRIM will remove all leading and trainling spaces e,g,
Code: |
SET var2 = TRIM(var);
|
|
Ok then i missunderstood the TRIM function, i thought it was the first/last occurance of the singleton, not the first/last.
//Blomman |
|
Back to top |
|
 |
Blomman |
Posted: Fri May 21, 2010 12:04 am Post subject: |
|
|
Master
Joined: 31 Oct 2006 Posts: 230
|
Ok i havent managed to trim whitepace in an string that isnt leading or trailing.
The string is an FILEDVALUE from InputRoot.MQRFH.usr
I tried something like this...Im not sure if ctrl is the way to go.
Code: |
Mystring = '2dfshf734; =483495';
TEST = CAST(X'0d' AS CHARACTER CCSID 819);
SET Mystring2 = TRANSLATE(Mystring,TEST,'_');
|
|
|
Back to top |
|
 |
fatherjack |
Posted: Fri May 21, 2010 12:19 am Post subject: |
|
|
 Knight
Joined: 14 Apr 2010 Posts: 522 Location: Craggy Island
|
Blomman wrote: |
Ok i havent managed to trim whitepace in an string that isnt leading or trailing.
The string is an FILEDVALUE from InputRoot.MQRFH.usr
I tried something like this...Im not sure if ctrl is the way to go.
|
Not sure what you're trying to do here. Do you just want to remove all spaces from your string. If so, read about the TRANSLATE function in the documentation. _________________ Never let the facts get in the way of a good theory. |
|
Back to top |
|
 |
Blomman |
Posted: Fri May 21, 2010 1:03 am Post subject: |
|
|
Master
Joined: 31 Oct 2006 Posts: 230
|
fatherjack wrote: |
Blomman wrote: |
Ok i havent managed to trim whitepace in an string that isnt leading or trailing.
The string is an FILEDVALUE from InputRoot.MQRFH.usr
I tried something like this...Im not sure if ctrl is the way to go.
|
Not sure what you're trying to do here. Do you just want to remove all spaces from your string. If so, read about the TRANSLATE function in the documentation. |
Problem already solved, and yes i used the TRANSLATE function. |
|
Back to top |
|
 |
Blomman |
Posted: Wed Jun 16, 2010 2:01 am Post subject: |
|
|
Master
Joined: 31 Oct 2006 Posts: 230
|
Hi again!
Using the same thread for another question.
How to use an UDP as an variable in an function?
Something like this..
Code: |
DECLARE myExternal EXTERNAL CHARACTER '';
SET myResult = FIELDVALUE(InputRoot.MQHRF.usr. || myExternal);
|
Perhaps this may work:
Code: |
DECLARE myExternal EXTERNAL CHARACTER '';
SET myResult = FIELDVALUE(InputRoot.MQHRF.usr.{myExternal});
|
//Blomman |
|
Back to top |
|
 |
|