ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » CAST with padding.

Post new topic  Reply to topic
 CAST with padding. « View previous topic :: View next topic » 
Author Message
tbt102
PostPosted: Wed Apr 30, 2003 7:24 am    Post subject: CAST with padding. Reply with quote

Apprentice

Joined: 21 Apr 2003
Posts: 28

Hi all,

In a compute node I have a declared iVar as integer and cVar as char. iVar will be populated with a number no larger than 9999.

I need to cast iVar to cVar with leading 0s when the signifeget digits are less than 4.

I want to do something like this when iVar = 999:
SET cVar = SomePaddingFunction(CAST(iVar AS CHAR))
cVar contains 0999

Can someone help with the SomePaddingFunction?

Thanks in advance for any help.
Back to top
View user's profile Send private message
RamVijayawada
PostPosted: Wed Apr 30, 2003 7:37 am    Post subject: Reply with quote

Novice

Joined: 22 Apr 2003
Posts: 15

First cast iVar to cVar..
Then find length
DECLARE N INTEGER;
DECLARE M INTEGER;
SET N = LENGTH(iVar);
IF N < 4 THEN
SET M = 4 - N;
WHILE M >0 DO
SET iVar = '0' || iVar;
SET M= M-1;
END WHILE;
END IF;
Pull out the iVar, u c the padded iVar....
Hope this helps...
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Apr 30, 2003 9:12 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

You could use the OVERLAY function for this.
Code:
set cVar = cast(iVar as char);
if (length(cVar) < 4) then
    set cVar = overlay('0000' placing cVar from (4 - length(cVar));
end if;

But you don't say what version of WMQI you're running, and what CSD level, so you may not have the OVERLAY function available.
Back to top
View user's profile Send private message
RamVijayawada
PostPosted: Wed Apr 30, 2003 10:00 am    Post subject: Reply with quote

Novice

Joined: 22 Apr 2003
Posts: 15

Jeff, if the value is 99 according to u
the result will be 0990--according my understanding...
but he wants 0099--
It should be
set cVar = cast(iVar as char);
if (length(cVar) < 4) then
set cVar = overlay('0000' placing cVar from (5 - length(cVar));
end if;
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed Apr 30, 2003 11:47 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Ooops. Off by one error.

Too much C recently, sorry.
Back to top
View user's profile Send private message
RamVijayawada
PostPosted: Wed Apr 30, 2003 11:54 am    Post subject: Reply with quote

Novice

Joined: 22 Apr 2003
Posts: 15

Cool, overlay is good if its the matter of 4-5 characters. One has to go for a loop it its the case of a real big long String..
Back to top
View user's profile Send private message
kwelch
PostPosted: Wed May 07, 2003 12:38 pm    Post subject: Reply with quote

Master

Joined: 16 May 2001
Posts: 255

Are you using the MRM? If so you can assign a padding character there.

Karen
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » CAST with padding.
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.