IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Removing Leading Spaces and Removing Trailing zeros


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rahulpala

New User


Joined: 30 Apr 2008
Posts: 3
Location: CA

PostPosted: Fri Sep 04, 2015 4:58 am
Reply with quote

Hi All,

Its my first post. Please find below the output I'm trying to achieve here:

=====O U T P U T=====
NUMBER Inp:<bbbbbbbb67.020>
NUMBER L :<67.02>
NUMBER Inp:<bbbbbbbb2.000>
NUMBER L :<2>
NUMBER Inp:<bbbbbb1,002.000>
NUMBER L :<1,002>
=================

I have coded something like this:
CHAR-W81 is PIC X(18).
MOVE WS-NUM-C TO CHAR-W81.
INSPECT CHAR-W81 TALLYING I-CTR FOR LEADING SPACES.
INSPECT FUNCTION REVERSE(CHAR-W81)
TALLYING ZERO-TRAIL-CNT FOR
LEADING ZEROES.
MOVE CHAR-W81(I-CTR + 1 : LENGTH OF CHAR-W81 - (I-CTR +
ZERO-TRAIL-CNT))
TO L-CHAR-W81.

I know this wont work for my second set of output. But still what made me confused is that the second INSPEECT for Leading Zeroes is failing to count the zeros. I tried LEADING '0', LEADING "0" etc.
Appreciate if anyone could offer any advise on this, what could be wrong with the second INSPECT.
Thanks
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Fri Sep 04, 2015 5:26 am
Reply with quote

First of all, let's have the code tags:
Code:
CHAR-W81 is PIC X(18).
MOVE WS-NUM-C TO CHAR-W81.
INSPECT CHAR-W81 TALLYING I-CTR FOR LEADING SPACES.
INSPECT FUNCTION REVERSE(CHAR-W81)
TALLYING ZERO-TRAIL-CNT FOR
LEADING ZEROES.
MOVE CHAR-W81(I-CTR + 1 : LENGTH OF CHAR-W81 - (I-CTR +
ZERO-TRAIL-CNT))
TO L-CHAR-W81.

I believe Number L is the output you want:
Quote:
NUMBER Inp:<bbbbbbbb67.020>
NUMBER L :<67.02>
NUMBER Inp:<bbbbbbbb2.000>
NUMBER L :<2>
NUMBER Inp:<bbbbbb1,002.000>
NUMBER L :<1,002>

I don't see any leading zeroes in the input. b is blank, isn't it?

And this is how you use code tags:
http://ibmmainframes.com/faq.php?mode=bbcode

.
Back to top
View user's profile Send private message
rahulpala

New User


Joined: 30 Apr 2008
Posts: 3
Location: CA

PostPosted: Fri Sep 04, 2015 5:45 am
Reply with quote

Thanks, <b> is for spaces i have before the string. Yes, L field is the output I want.

I was looking for leading zeros after reversing the string.

Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Sep 04, 2015 6:02 am
Reply with quote

FUNCTION REVERSE will reverse the ENTIRE variable. For an 18-byte variable, that means byte 18 will become byte 1, byte 17 will become byte 2, and so forth. Your sample data is NOT right-justified to 18 bytes so COBOL is reporting exactly what you have -- no leading zeroes. If you had counted leading spaces on the reversed variable, I suspect you would have a non-zero count.
Back to top
View user's profile Send private message
rahulpala

New User


Joined: 30 Apr 2008
Posts: 3
Location: CA

PostPosted: Fri Sep 04, 2015 6:42 am
Reply with quote

Thanks Robert. You are right, I leading spaces in the reversed string was causing me a trouble and it failed the inspect to find count of zeros.

I solved this puzzle now and here is what i did:

Code:
MOVE WS-NUM-C               TO CHAR-W81.                     
INSPECT CHAR-W81 REPLACING ALL SPACES BY ZEROS.             
INSPECT CHAR-W81 TALLYING I-CTR FOR LEADING ZEROS.           
MOVE FUNCTION REVERSE(CHAR-W81)                             
                            TO L-REV-W81.                   
INSPECT L-REV-W81 TALLYING ZERO-TRAIL-CNT FOR LEADING ZEROS.
MOVE CHAR-W81(I-CTR + 1 : LENGTH OF CHAR-W81 - (I-CTR + 
                                         ZERO-TRAIL-CNT))
                            TO L-CHAR-W81.               
INSPECT L-CHAR-W81 REPLACING ALL '. ' BY SPACES.


Here is the output:
Code:

NUMBER     :         67.020   
NUMBER R   :00000000067.020000
NUMBER L   :67.02             
NUMBER     :          2.000   
NUMBER R   :00000000002.000000
NUMBER L   :2                 
NUMBER     :      1,002.000   
NUMBER R   :0000001,002.000000
NUMBER L   :1,002       


Hope this helps someone in the future, Last inspect replace looks for a period and space together to replace it with spaces.
Thanks everyone for the participation.

Code'd
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Cobol program with sequence number ra... COBOL Programming 5
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
Search our Forums:

Back to Top