View previous topic :: View next topic
|
Author |
Message |
neelesht
New User
Joined: 24 Jul 2006 Posts: 99 Location: Los Angeles
|
|
|
|
Hi All,
I have an Alphanumeric fields X(6) , i want leading zeroes in it.......e.g if value is E6 it shud be 0000E6 (this field can have any value E8 or ABC or TYRS)
one way is to count how till next space and then do it.
I wanted to know if there are any other ways, more simple ones ?
Thanks Everyone |
|
Back to top |
|
|
XungoPejcao
New User
Joined: 04 Sep 2008 Posts: 5 Location: EspaƱa
|
|
|
|
Hi!
You can try with Inspect sentence:
01 CT-E6 PIC X(6) VALUE ' E6'.
------------------------------------------------
INSPECT CT-E6 REPLACING ALL ' ' BY '0'
CT-E6 = '0000E6' |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Code: |
inspect ws-var replacing leading spaces by zero
|
|
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
I think instead of REPLACING ALL it should be REPLACING LEADING.
if value is 'E 6'
with REPLACING ALL SPACES output will be '000E06'
with REPLACING LEADING SPACES output will be '000E 6'
Now depends on neelesht what he wants.. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
since you might be clobbered by justification problems,
you need to know where your non-space data will be.
If you can insure that the 'significant characters' will be right justified,
then the suggestions about INSPECT REPLACING will be appropriate.
But, if the data is left justified,
you are going to need write some kind of byte manipulation routine;
either with subscripts, indexes or reference modification. |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Sorry Ashimer, i couldnt see your post as i was typing mine...
you were 2 min ahead...
Moderators delete my post if not required |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Quote: |
Sorry Ashimer, i couldnt see your post as i was typing mine...
|
You post does have valid suggestions ... |
|
Back to top |
|
|
neelesht
New User
Joined: 24 Jul 2006 Posts: 99 Location: Los Angeles
|
|
|
|
Hi All,
I guess I was not clear enough.
It wont have leading spaces, it will have trailing spaces like 'E6 '
In this case I cant even say INSPECT CT-E6 REPLACING ALL ' ' BY '0' coze it will make it
'E60000'
'E6 ' should look in file as '0000E6'
Sorry for not being clear.
Thanks everyone. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
neelesht: I haven't tried this but I believe it'll meet your need. Define a variable PIC X(06) JUST RIGHT and move your field to this variable. Do the INSPECT REPLACING LEADING SPACE on this variable. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Give this a try -
Code: |
03 WS-WORK-AREA PIC X(06).
03 WS-CT-E6 PIC X(06) VALUE ' E6'.
03 WS-SUB PIC 9(08) BINARY.
MOVE LENGTH OF WS-WORK-AREA TO WS-SUB.
MOVE WS-SUB TO TALLY.
MOVE ZERO TO WS-WORK-AREA.
*
PERFORM UNTIL TALLY < 1
IF WS-CT-E6 (TALLY:1) > SPACE
MOVE WS-CT-E6 (TALLY:1)
TO WS-WORK-AREA (WS-SUB:1)
SUBTRACT 1 FROM WS-SUB
END-IF
SUBTRACT 1 FROM TALLY
END-PERFORM.
*
* AT THIS POINT, 'WS-WORK-AREA' CONTAINS '0000E6'
*
|
Regards,
Bill |
|
Back to top |
|
|
neelesht
New User
Joined: 24 Jul 2006 Posts: 99 Location: Los Angeles
|
|
|
|
Thanks Bill/Robert and everyone else.
I will try this tomorrow and let you all know.
Thanks for the help.
Regards
Neelesh |
|
Back to top |
|
|
Cristopher
New User
Joined: 31 Jul 2008 Posts: 53 Location: NY
|
|
|
|
Neelesh,
You can very well use the code been suggested by Bill, it will take care of leading or trailing spaces.
But u need to either move zeroes to WS-WORK-AREA in the begining or
use inspect WS-WORK-AREA replacing leading spaces by zero after the Perform to get the desired result.
Regards,
Cris |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Robert,
The parameter JUSTifies on the difference in the sending/receiving VARIABLE lengths, not the difference between the sending string length and the receiving VARIABLE length. |
|
Back to top |
|
|
|