Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Removing Leading Spaces and Removing Trailing zeros

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Removing Leading Spaces and Removing Trailing zeros
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: 331
Location: USA

PostPosted: Fri Sep 04, 2015 5:26 am    Post subject: Reply to: Removing Leading Spaces and Removing Trailing zeros
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    Post subject: Reply to: Removing Leading Spaces and Removing Trailing zeros
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: 7914
Location: Bellevue, IA

PostPosted: Fri Sep 04, 2015 6:02 am    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am
No new posts Join key - Populate Zeros when Unpair... rexx77 DFSORT/ICETOOL 6 Thu May 12, 2016 12:22 am
No new posts Removing the MODETAB field in a VTAM ... rcwing All Other Mainframe Topics 1 Fri Feb 19, 2016 7:11 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us