Author |
Message
|
lung |
Posted: Fri Feb 06, 2004 6:45 pm Post subject: Making a STRING Field PACKED |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
Hi all.
I need to make a conversion from a String field to a packed field. In other words, for example if FieldA is 'ABC', I want FieldB to be x'ABC'. How can I accomplish this?
Thanks! |
|
Back to top |
|
 |
EddieA |
Posted: Fri Feb 06, 2004 7:04 pm Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
Are you saying that the input field is the actual hex you want, but in characters. If so, then ABC is invalid because you would need an even number of charaters.
Or do you want to convert the characters ABC into their hex equivalent.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
lung |
Posted: Fri Feb 06, 2004 7:48 pm Post subject: |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
Thanks for the prompt reply.
I want it to be in actual hex, in characters. Thus 'ABC' would become x'0ABC' (zero in front, since it is in hex format)
Of course there won't be any instance where the character i want to convert is later than the character F, since it is not supported in hex format.
To put the matter in simpler terms, let's just assume I want to convert '123456' in STRING to x'123456' (hex), which would turn up as '4V' in STRING.
I could use the code
SET Field2 = x'123456'
But what if the value I want to set is in a variable?
Hope you get what I mean here.  |
|
Back to top |
|
 |
EddieA |
Posted: Fri Feb 06, 2004 10:56 pm Post subject: |
|
|
 Jedi
Joined: 28 Jun 2001 Posts: 2453 Location: Los Angeles
|
In which case, a CAST(string AS BLOB) should do it.
Cheers, _________________ Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
kspranava |
Posted: Sun Feb 08, 2004 6:14 pm Post subject: Concatenate |
|
|
 Centurion
Joined: 27 Apr 2003 Posts: 124
|
Hi,
Did u try concatenation ? This might be silly, still if it serves ur problem then u can use it very well.
Pranava. |
|
Back to top |
|
 |
lung |
Posted: Sun Feb 08, 2004 10:25 pm Post subject: |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
My mistake...
Actually, the code
SET Field2 = x'123456';
Itself doesn't work because I've declared Field2 as a STRING.
So how can I assign a hexadecimal value into a STRING?
I've tried this code here
SET Field2 = CAST(x'123456' AS CHAR);
But then Field2 ends up as 'X'123456' instead of '4V'! This really stumps me because the 'X' itself appears in the STRING! The same happens when I try to use a BLOB variable in place of the x'123456', eg.
DECLARE temp AS BLOB;
SET temp = x'123456';
SET Field2 = CAST(temp as CHAR);
Please help!
kspranava, what do you mean by using concatenation? Please provide an example if possible... Thanks!  |
|
Back to top |
|
 |
kirani |
Posted: Sun Feb 08, 2004 10:56 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Lung,
You need to use CCSID parameter in your code, for example,
Code: |
DECLARE temp AS BLOB;
SET temp = x'123456';
SET Field2 = CAST(temp as CHAR CCSID InputProperties.CodedCharSetId);
|
_________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
kspranava |
Posted: Sun Feb 08, 2004 11:37 pm Post subject: try this... |
|
|
 Centurion
Joined: 27 Apr 2003 Posts: 124
|
Hi Lung,
Forget abt concatenation. Try this code.
Declare temp CHAR;
SET temp= cast(cast(strToConvert as BLOB ) as char ccsid InputProperties.CodedCharSetId);
strToConvert is the string to be converted.
Pranava. |
|
Back to top |
|
 |
lung |
Posted: Mon Feb 09, 2004 12:38 am Post subject: |
|
|
 Master
Joined: 27 Aug 2002 Posts: 291 Location: Malaysia
|
Thanks for the replies, kirani and kspranava.
The CCSID thing works!
Problem solved. |
|
Back to top |
|
 |
|