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

Zero Suppression in Cobol


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

New User


Joined: 06 Jun 2007
Posts: 83
Location: anada

PostPosted: Mon Nov 17, 2008 5:07 pm
Reply with quote

Hi,

Want to know if this is possible in cobol.


The requirement is:-

Ex 1

Input is 00125.1300

then the output should be 125.13 [ zero suppressed in both the ends ].

Ex2

Input is 130.2300

then the output is 130.23


How can i acheive this output through Cobol program ? Is it possible to use Edit fields here?
Back to top
View user's profile Send private message
nartcr

New User


Joined: 06 Jun 2007
Posts: 83
Location: anada

PostPosted: Mon Nov 17, 2008 5:45 pm
Reply with quote

Any help is appreciated for this. I tried with Z(5).Z(4)
But the zeroes after the decimal is not getting suppressed.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Nov 17, 2008 5:47 pm
Reply with quote

the picture clauses are used for output usually,
having misaligned decimal points/commas is unpleasant for reading the numbers
Back to top
View user's profile Send private message
nartcr

New User


Joined: 06 Jun 2007
Posts: 83
Location: anada

PostPosted: Mon Nov 17, 2008 6:00 pm
Reply with quote

Thats fine.

First of all,How do we suppress as you said?
I am not able to suppress the leading zeroes as well as trailing zeroes [ together].
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Nov 17, 2008 6:06 pm
Reply with quote

here is a thread on the same subject
ibmmainframes.com/viewtopic.php?t=35934&highlight=
Back to top
View user's profile Send private message
nartcr

New User


Joined: 06 Jun 2007
Posts: 83
Location: anada

PostPosted: Mon Nov 17, 2008 6:11 pm
Reply with quote

I read this thread before posting this. The above thread doesnt talk about trailing zero suppression which is what i require.
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: Mon Nov 17, 2008 6:18 pm
Reply with quote

Trailing zeroes, unlike leading zeroes, are significant -- they specify the number of digits of accuracy for the decimal value. The only way I know of to remove trailing zeroes is to move the field with the correct number of digits after the decimal specified -- either via a set of IF and MOVE statements or REDEFINES on the variable.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Nov 17, 2008 6:23 pm
Reply with quote

but if You had used a bit of ingenuity
the forward loop with the reference should have given You a hint

use reference modification in a backward loop

first loop to find out the first non zero digits

then two alternatives
a couple of computations to carry on the offset and a length for a move
or a loop to do the move backwards
( anyway two loops are better than one loop and a flag )
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Mon Nov 17, 2008 6:26 pm
Reply with quote

I don't know of a way it can be done using a numeric edited picture clause all by itself, but it could be accomplished using a "move 1 byte at a time" method or with a combination of inspect and reference modification. If the rule is that there will always be only 2 significant digits to the right of the decimal, it can be done using compute and truncation using only a numeric edited picture clause. Your example wasn't specific about that.
Back to top
View user's profile Send private message
nartcr

New User


Joined: 06 Jun 2007
Posts: 83
Location: anada

PostPosted: Mon Nov 17, 2008 6:36 pm
Reply with quote

Thanks for the suggestion. What i had in my mind is same as the reply from enrico-sorichetti. So i am assuning there is no other way around!!!
Back to top
View user's profile Send private message
Auryn

New User


Joined: 11 Jan 2006
Posts: 83
Location: Lower Saxony (DE)

PostPosted: Mon Oct 28, 2013 6:36 pm
Reply with quote

Some years later...

Didn't try yet but probably this may help you:
Code:
 01   division-resault         PICTURE 9(7)V9(4).
 
 01   numeric-as-string.
      05  numeric-edited       PICTURE Z,ZZZ,ZZ9.9999.

******************************************************

     MOVE division-result    TO numeric-edited
*         0001234.1200       =» _,__1,234.1200

     COMPUTE numeric-as-string
             = FUNCTION REVERSE (numeric-as-string)
*            _,__1,234.1200  =» 0021.432,1__,_

     INSPECT numeric-as-string
             REPLACING  LEADING ZERO
                             BY SPACE
*            0021.432,1__,_  =» __21.432,1__,_

     COMPUTE numeric-as-string
             = FUNCTION REVERSE (numeric-as-string)
*            __21.432,1__,_  =» _,__1,234.12__

     DISPLAY numeric-as-string
Back to top
View user's profile Send private message
Auryn

New User


Joined: 11 Jan 2006
Posts: 83
Location: Lower Saxony (DE)

PostPosted: Mon Oct 28, 2013 8:36 pm
Reply with quote

[quote="Auryn"]Some years later...

Didn't try yet but probably this may help you:
Code:
*    (...)

     COMPUTE numeric-as-string
             = FUNCTION REVERSE (numeric-as-string)
*            _,__1,234.1200  =» 0021.432,1__,_

*    (...)

     COMPUTE numeric-as-string
             = FUNCTION REVERSE (numeric-as-string)
*            __21.432,1__,_  =» _,__1,234.12__

*    (...)


Grrr, COMPUTE and FUNCTION REVERSE does not work, computing with alphanumeric values is not possible. My fault, sorry for that.
But the phrase
Code:
MOVE FUNCTION REVERSE (numeric-as-string)
           TO          numeric-as-string

works. - And, all together, these statements provide the desired result.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Oct 28, 2013 8:41 pm
Reply with quote

Hello,

It is best to reply to currently actiove topics rather than topics that have been dormant for 4+ years.

Additionally, i believe the original request might not have been exactly what was wanted . . .

For example (just guessing the the field is $). suppressing the trailing zeros from 00345.60000 or 023.0000 would be incorrect. If my $ guess is correct. . .
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Mon Oct 28, 2013 11:44 pm
Reply with quote

You mean my 5-yr old suggestion was of no use? icon_lol.gif
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top