View previous topic :: View next topic
|
Author |
Message |
saravanakumar N
New User
Joined: 24 Mar 2010 Posts: 5 Location: Chennai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
saravanakumar N
New User
Joined: 24 Mar 2010 Posts: 5 Location: Chennai
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
Back to top |
|
|
|