|
|
| Author |
Message |
neelesht
Active User
Joined: 24 Jul 2006 Posts: 79 Location: Milwaukee USA
|
|
|
|
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 |
|
 |
References
|
|
 |
XungoPejcao
New User
Joined: 04 Sep 2008 Posts: 7 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
Senior Member
Joined: 13 Feb 2004 Posts: 354 Location: Bangalore
|
|
|
|
| Code: |
inspect ws-var replacing leading spaces by zero
|
|
|
| Back to top |
|
 |
Sambhaji Warnings : 1 Active User
Joined: 16 Feb 2007 Posts: 268 Location: Pune, India
|
|
|
|
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
Senior Member
Joined: 20 Oct 2006 Posts: 1618 Location: germany
|
|
|
|
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 |
|
 |
Sambhaji Warnings : 1 Active User
Joined: 16 Feb 2007 Posts: 268 Location: Pune, India
|
|
|
|
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
Senior Member
Joined: 13 Feb 2004 Posts: 354 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
Active User
Joined: 24 Jul 2006 Posts: 79 Location: Milwaukee USA
|
|
|
|
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
Senior Member
Joined: 06 Jun 2008 Posts: 892 Location: Atlanta, GA
|
|
|
|
| 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
Senior Member
Joined: 14 Jan 2008 Posts: 333 Location: Orlando, FL, 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
Active User
Joined: 24 Jul 2006 Posts: 79 Location: Milwaukee USA
|
|
|
|
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: 36 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: 1504
|
|
|
|
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 |
|
 |
|
|