View previous topic :: View next topic |
Author |
Message |
prog_mario Beginner
Joined: 08 Sep 2007 Posts: 86 Topics: 27
|
Posted: Thu Jan 20, 2011 6:16 am Post subject: Removing Leading Zeros. |
|
|
I have a field PIC 9(17) VALUE 00000001234567890.
I need to move that to an alpha field but first I have to remove the leading zeros and the target field must have the data justified left with no spaces on the left.
Any help?
Thanks. _________________ The more I learn, the more I want to learn. |
|
Back to top |
|
|
prog_mario Beginner
Joined: 08 Sep 2007 Posts: 86 Topics: 27
|
Posted: Thu Jan 20, 2011 6:54 am Post subject: |
|
|
I need to do that in a Cobol program. _________________ The more I learn, the more I want to learn. |
|
Back to top |
|
|
Anuj Dhawan Intermediate
Joined: 19 Jul 2007 Posts: 298 Topics: 7 Location: Mumbai,India
|
Posted: Thu Jan 20, 2011 7:20 am Post subject: |
|
|
Quote: | target field must have the data justified left | What is the PIC clause for the target field? _________________ Regards,
Anuj |
|
Back to top |
|
|
prog_mario Beginner
Joined: 08 Sep 2007 Posts: 86 Topics: 27
|
Posted: Thu Jan 20, 2011 8:20 am Post subject: |
|
|
target field is a PIC X(15). _________________ The more I learn, the more I want to learn. |
|
Back to top |
|
|
RonB Beginner
Joined: 02 Dec 2002 Posts: 93 Topics: 0 Location: Orlando, FL
|
Posted: Thu Jan 20, 2011 8:33 am Post subject: |
|
|
Try this:
1) DEFINE a tally-field with a PIC of S9(2) COMP.
2) REDEFINE source-field as source-field-X with a PIC of X(17).
3) MOVE SPACES TO target-field.
4) MOVE ZERO TO tally-field.
5) INSPECT source-field-X TALLYING tally-field FOR LEADING ZEROS
6) ADD 1 TO tally-field.
7) MOVE source-field-X (tally-field:) to target-field. _________________ A computer once beat me at chess, but it was no match for me at kick boxing. |
|
Back to top |
|
|
prog_mario Beginner
Joined: 08 Sep 2007 Posts: 86 Topics: 27
|
Posted: Thu Jan 20, 2011 10:50 am Post subject: |
|
|
Thanks RonB, it works perfectly. _________________ The more I learn, the more I want to learn. |
|
Back to top |
|
|
aquarian Beginner
Joined: 28 Sep 2005 Posts: 66 Topics: 17 Location: Mars
|
Posted: Wed Sep 17, 2014 7:26 am Post subject: |
|
|
Just curious !!
What if the target field is
Z.ZZZ.ZZZ.ZZZ.ZZZ.ZZ9,99-
I did tried it and its moving to right? Is there any way we can move it toleft without hurting the declaration _________________ cheers,
Aquarian |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Wed Sep 17, 2014 11:02 am Post subject: |
|
|
aquarian,
Unless that is trick question isn't it removing the leading spaces instead of zeroes?
Right now you get this
Code: |
----+----1----+----2----+
1,23-
12,34
123,45
1.234,56
12.345,67
123.456,78
1.234.567,89
12.345.678,90
|
and you want it like this ?
Code: |
1,23-
12,34
123,45
1.234,56
12.345,67
123.456,78
1.234.567,89
12.345.678,90
|
If so define another field X(24) and follow the procedure above _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
William Collins Supermod
Joined: 03 Jun 2012 Posts: 437 Topics: 0
|
Posted: Wed Sep 17, 2014 12:33 pm Post subject: |
|
|
Since the field can only contain leading blanks (and you should ensure there is at least one, putting an extra leading Z on if necessary) then you can use UNSTRING with DELIMITED BY ALL SPACE. You'll need two target fields, the first just a dummy field (it will receive the content before the leading spaces) and the second field being the one you want.
This solution is not possible for the leading zeros, as within an number there can easily be one or more significant zero. |
|
Back to top |
|
|
|
|