View previous topic :: View next topic
|
Author |
Message |
rahulpala
New User
Joined: 30 Apr 2008 Posts: 3 Location: CA
|
|
|
|
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 |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
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 |
|
|
rahulpala
New User
Joined: 30 Apr 2008 Posts: 3 Location: CA
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
rahulpala
New User
Joined: 30 Apr 2008 Posts: 3 Location: CA
|
|
|
|
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 |
|
|
|