Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in converting from alphanumeric to numeric 1

Status
Not open for further replies.

shaily123

Programmer
Feb 5, 2005
17
US
Hi, I have to move a alphanumeric number to numeric number. What is the impact of it.

Example:

01 number1 pix x(10).
01 number2 pic 9(10).

move number1 to number2.

The problem is number1 can be 7 digits so in that case number2 is not moving 000number1 in number2 field it is moving 7digits.

What should I do for proper move.
 
Take a look at the NUMVAL intrinsic function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Just so it is clear, the MOVE of an alphanumeric to an unsigned integer numeric receiving field is valid - but ONLY if the sending field has no spaces (or other on-digit) values.

As was pointed out above, the NUMVAL (or in some cases the NUMVAL-C) intrinsic functions work "great" for alphanumeric sending fields (possibly with periods, commas, currency signs). However, in the '89 Amendment to the '85 Standard, you need to use the COMPUTE statement not the MOVE statement.

However, in the '02 Standard (and as an extension in many compilers before that) MOVE is also supported.

Bill Klein
 
Bill,

MOVE alphanumeric-to-numeric was in the 1985 standard, and perhaps even 1974, so it was not an extension. Correct behavior was required by the Navy.CCVS tests.

Tom Morrison
 
Sorry if I wasn't clear

MOVE numeric-intrinsic-function

was not in the '89 Intrinsic Function amendment but is in the '02 Standard. In the '89 Amendment, one needed to use COMPUTE receiving-field = numeric-intrinsic-function

However, Micro Focus did allow MOVE - as did some others before then.

Bill Klein
 
Hi shaily123,
Declare the variable,number1, with JUST clause and after you move the data into number1.Use INSPECT on number1 and replace all spaces with zeros and then you move number1 to number2.
01 number1 pix x(10) JUST.
01 number2 pic 9(10).


==> insert INSPECT clause here.
move number1 to number2.
This solution is valid whether number1 is of 1,2..,7,....10 digits provided you have no other character other than spaces and digits.
Thanks
Tushar Johri
 
You can also try the following code:

Code:
:
:
01  i1       pic 99.
01  i2       pic 99.
01  number1  pic x(10).
01  number2  pic 9(10).
01  char2    redefines number2 pic x(10).
:
:
           move zeroes  to char2.
           move 10 to i2.
           perform varying i1 from 10 by -1 until i1 < 1
             if number1(i1:1) is numeric
                move number1(i1:1) to char2(i2:1)
                subtract 1 from i2
             end-if
           end-perform
:
:

Theophilos.

-----------

There are only 10 kinds of people: Those who understand binary and those who don't.
 
>
01 number1 pix x(10).
01 number2 pic 9(10).

move number1 to number2.

The problem is number1 can be 7 digits so in that case number2 is not moving 000number1 in number2 field it is moving 7digits.


This works for me everytime (when the fields are of the same length):
Code:
  01  number1  pix  x(10).
  01  number2   pic 9(10).

  move  number1(1:10)  to number2(1:10).


__________________________________________
Try forum1391 for lively discussions
 
Hi Shaily,

You didn't say what your environment is. The routine below works in an IBM mainframe environment with a COBOL II or later compiler. It's not exactly what you want but you can make it so.

05 JS-TAL-FLD PIC S9(04) COMP.
05 JS-STR-LEN PIC S9(04) COMP.
05 JS-TEST-FLD PIC X(14).
05 JS-JUST-R
JUST RIGHT PIC X(14) VALUE SPACES.
05 JS-JUST-ED
REDEFINES JS-JUST-R
PIC +(11).99.
05 JS-TEST-C3 PIC S9(07)V99 COMP-3.


MOVE '+123.45' TO JS-TEST-FLD
PERFORM 1000-CONVERT-RTN
DISPLAY
'JS-TEST-C3 POS SIGN >' JS-TEST-C3 '<'
MOVE '-123.45' TO JS-TEST-FLD
PERFORM 1000-CONVERT-RTN
DISPLAY
'JS-TEST-C3 NEG SIGN >' JS-TEST-C3 '<'
MOVE ' 123.45' TO JS-TEST-FLD
PERFORM 1000-CONVERT-RTN
DISPLAY
'JS-TEST-C3 NO SIGN >' JS-TEST-C3 '<'
STOP RUN
.

1000-CONVERT-RTN.
IF JS-TEST-FLD(1:1) = SPACE
MOVE '+' TO JS-TEST-FLD
END-IF
MOVE ZERO TO JS-TAL-FLD
INSPECT FUNCTION REVERSE(JS-TEST-FLD)
TALLYING JS-TAL-FLD FOR LEADING SPACES
COMPUTE JS-STR-LEN =
LENGTH OF JS-TEST-FLD - JS-TAL-FLD
MOVE JS-TEST-FLD(1:JS-STR-LEN) TO JS-JUST-R
MOVE JS-JUST-ED TO JS-TEST-C3
.

Process output:

JS-TEST-C3 POS SIGN >000012345<
JS-TEST-C3 NEG SIGN >00001234N<
JS-TEST-C3 NO SIGN >000012345<


Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
In an IBM mainframe envrionment - with any LE-conforming COBOL, then

Compute Recv-Num = Function Numval (sending-alpha)

is a WHOLE lot easier (and VS COBOL II is "long unsupported" - by IBM)

Bill Klein
 
Thank you all of you for reply. I work on VAX/VMS main frame.
I tried function NUMVAL and it worked perfectly.

Thanks Again,.
 
(and VS COBOL II is "long unsupported" - by IBM)

Maybe so, Bill, but it's still being used. That's the "real world" for ye. :)

Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top