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
 

 

How to remove commas from a numeric value

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to remove commas from a numeric value
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: 8120
Location: East Dubuque, Illinois, USA

PostPosted: Tue Dec 20, 2011 6:17 pm    Post subject:
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    Post subject:
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: 8120
Location: East Dubuque, Illinois, USA

PostPosted: Tue Dec 20, 2011 7:14 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Tue Dec 20, 2011 8:47 pm    Post subject: Reply to: How to remove commas from a numeric value
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Dec 20, 2011 9:35 pm    Post subject: Reply to: How to remove commas from a numeric value
Reply with quote

Review this previous post -

http://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    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 Validate if a Value from the file is ... balacsv2 COBOL Programming 8 Mon Jun 19, 2017 11:52 pm
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts Format record to remove Leading zeroes Learncoholic DFSORT/ICETOOL 14 Wed Apr 05, 2017 2:43 pm
No new posts Converting decimal to numeric using I... Balaryan DFSORT/ICETOOL 4 Thu Feb 02, 2017 11:27 pm
No new posts Remove junk values in a file and rite... KP1125 DFSORT/ICETOOL 2 Wed Jan 25, 2017 9:58 pm


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