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
 

 

Zero Suppression in Cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
nartcr

New User


Joined: 06 Jun 2007
Posts: 78
Location: anada

PostPosted: Mon Nov 17, 2008 5:07 pm    Post subject: Zero Suppression in Cobol
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: 78
Location: anada

PostPosted: Mon Nov 17, 2008 5:45 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10292
Location: italy

PostPosted: Mon Nov 17, 2008 5:47 pm    Post subject: Reply to: Zero Suppression in Cobol
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: 78
Location: anada

PostPosted: Mon Nov 17, 2008 6:00 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10292
Location: italy

PostPosted: Mon Nov 17, 2008 6:06 pm    Post subject: Reply to: Zero Suppression in Cobol
Reply with quote

here is a thread on the same subject
http://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: 78
Location: anada

PostPosted: Mon Nov 17, 2008 6:11 pm    Post subject:
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: 8132
Location: East Dubuque, Illinois, USA

PostPosted: Mon Nov 17, 2008 6:18 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10292
Location: italy

PostPosted: Mon Nov 17, 2008 6:23 pm    Post subject: Reply to: Zero Suppression in Cobol
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    Post subject:
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: 78
Location: anada

PostPosted: Mon Nov 17, 2008 6:36 pm    Post subject:
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: 45
Location: Lower Saxony (DE)

PostPosted: Mon Oct 28, 2013 6:36 pm    Post subject: suppressing trailing zeroes - another hint
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: 45
Location: Lower Saxony (DE)

PostPosted: Mon Oct 28, 2013 8:36 pm    Post subject: Re: suppressing trailing zeroes - another hint
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

Site Director


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

PostPosted: Mon Oct 28, 2013 8:41 pm    Post subject:
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    Post subject:
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    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 ALPHABETIC check in COBOL vidyaa COBOL Programming 8 Thu Aug 17, 2017 7:13 pm
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am


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