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

How to remove commas from a numeric value


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

New User


Joined: 24 Mar 2010
Posts: 5
Location: Chennai

PostPosted: Tue Dec 20, 2011 6:09 pm
Reply with quote

I need to remove commas from a numeric value and move the value in PIC 9(8) variable, (i.e. convert 12,000 as 12000). What is the best way to do this..?
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: Tue Dec 20, 2011 6:17 pm
Reply with quote

If the variable PICTURE is numeric edited, just move it to your PIC 9(8) variable. Otherwise, depending upon how the data is stored in memory, you MIGHT be able to use FUNCTION NUMVAL. If not, you can always use reference modification (or an array) to build the value one byte at a time.
Back to top
View user's profile Send private message
saravanakumar N

New User


Joined: 24 Mar 2010
Posts: 5
Location: Chennai

PostPosted: Tue Dec 20, 2011 6:30 pm
Reply with quote

Thank you Robert.
Here the input field is alphanumric. I thought of using Array...but i want to know, if there any other best ways to do this...?..can explain the FUNCTION NUMVAL ?
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: Tue Dec 20, 2011 7:14 pm
Reply with quote

There is a link to manuals at the top of this page. Click on it, find the Enterprise COBOL Language Reference manual, and read section 7.1.32 on NUMVAL. You might also want to read 1.8.1.10 on Reference Modification.

The "best way" to do this depends -- A LOT -- upon how the specific data values are stored (in other words, there is no single "best way"). If they are justified to the decimal point and the decimal point is fixed in the field, you could use REDEFINES on the alphanumeric variable to define the same area as a numeric edited variable.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Dec 20, 2011 8:47 pm
Reply with quote

If your input is in a standard format, like 99,999,999 then:

Code:
01  W-EDITED-NUMBER.
    05  W-EN-FIRST-TWO-N PIC XX.
    05  W-EN-FIRST-COMMA PIC X.
    05  W-EN-MIDDLE-THREE-N PIC XXX.
    05  W-EN-SECOND-COMMA PIC X.
    05  W-EN-LAST-THREE-N PIC XXX.

01  W-DEEDITED-NUMBER PIC 9(8).
01  FILLER REDEFINES W-DEEDITED-NUMBER.
    05  W-DN-FIRST-TWO-N PIC XX.
    05  W-DN-MIDDLE-THREE-N PIC XXX.
    05  W-DN-LAST-THREE-N PIC XXX.


Check the EN-....-Ns for being NUMERIC, check the -COMMAs for being "," (or COMMA) then move to the respective positions in the REDFINES of W-DEEDITED-NUMBER.

Obviously you'll need to do something which the spec-writer agrees with if the data does not conform to the format you expect. If the spec-writer says it must always be valid, you can safely code an abend for if/when it does happen.

This may see a lot of work, but it doesn't come to much if you know a bit about using the editor. Plus, you can even copy/paste the above and change the datanames for local site conventions...
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Dec 20, 2011 9:35 pm
Reply with quote

Review this previous post -

ibmmainframes.com/viewtopic.php?p=281041&highlight=#281041

Mr. Bill
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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Remove leading zeroes SYNCSORT 4
No new posts Convert HEX to Numeric DB2 3
No new posts Find a record count/numeric is multip... COBOL Programming 1
Search our Forums:

Back to Top