MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Removing Leading Zeros.

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
prog_mario
Beginner


Joined: 08 Sep 2007
Posts: 86
Topics: 27

PostPosted: Thu Jan 20, 2011 6:16 am    Post subject: Removing Leading Zeros. Reply with quote

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
View user's profile Send private message
prog_mario
Beginner


Joined: 08 Sep 2007
Posts: 86
Topics: 27

PostPosted: Thu Jan 20, 2011 6:54 am    Post subject: Reply with quote

I need to do that in a Cobol program.
_________________
The more I learn, the more I want to learn.
Back to top
View user's profile Send private message
Anuj Dhawan
Intermediate


Joined: 19 Jul 2007
Posts: 298
Topics: 7
Location: Mumbai,India

PostPosted: Thu Jan 20, 2011 7:20 am    Post subject: Reply with quote

Quote:
target field must have the data justified left
What is the PIC clause for the target field?
_________________
Regards,
Anuj
Back to top
View user's profile Send private message
prog_mario
Beginner


Joined: 08 Sep 2007
Posts: 86
Topics: 27

PostPosted: Thu Jan 20, 2011 8:20 am    Post subject: Reply with quote

target field is a PIC X(15).
_________________
The more I learn, the more I want to learn.
Back to top
View user's profile Send private message
RonB
Beginner


Joined: 02 Dec 2002
Posts: 93
Topics: 0
Location: Orlando, FL

PostPosted: Thu Jan 20, 2011 8:33 am    Post subject: Reply with quote

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
View user's profile Send private message
prog_mario
Beginner


Joined: 08 Sep 2007
Posts: 86
Topics: 27

PostPosted: Thu Jan 20, 2011 10:50 am    Post subject: Reply with quote

Thanks RonB, it works perfectly.
_________________
The more I learn, the more I want to learn.
Back to top
View user's profile Send private message
aquarian
Beginner


Joined: 28 Sep 2005
Posts: 66
Topics: 17
Location: Mars

PostPosted: Wed Sep 17, 2014 7:26 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Wed Sep 17, 2014 11:02 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Wed Sep 17, 2014 12:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group