Convert external floating point number to COMP-2
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Application Programming

#1: Convert external floating point number to COMP-2 Author: jathampyLocation: UK PostPosted: Wed Aug 02, 2023 11:13 am
    —
I have an input file that contain amount fields in exponential form like "-2.2204462782314e-16". I want to convert this into COMP-2 format.

Tried NUMVAL-F intrinsic function and the cobol compiler (Z/OS 4.2.0) giving compilation error "expected a function name, but found NUMVAL-F". However NUMVAL and NUMVAL-C intrinsic functions are working.

Any idea how to convert the exponential representation of numbers to COMP-2 internal floating point ?

#2:  Author: kolusuLocation: San Jose PostPosted: Wed Aug 02, 2023 5:08 pm
    —
jathampy,

Try this

Code:

WORKING-STORAGE SECTION.                             
01 WS-INP-FLNUM                PIC +V9(16)E+99 GLOBAL.
01 WS-INP-FLCHAR     REDEFINES WS-INP-FLNUM.         
   05 A                        PIC X(20).             
01 WS-OUT-FL                   COMP-2.               
                                                     
PROCEDURE DIVISION.                                   
      MOVE "-2.2204462782314E-16"         TO A.       
      DISPLAY 'CHAR VALUE : ' A                       
      MOVE WS-INP-FLNUM TO WS-OUT-FL                 
      DISPLAY 'COMP VALUE : ' WS-OUT-FL               
      GOBACK.                                         


Result from 6.xx compiler
Code:

CHAR VALUE : -2.2204462782314E-16   
COMP VALUE : -.22204462782314002E-15

#3:  Author: jathampyLocation: UK PostPosted: Sat Aug 05, 2023 3:47 am
    —
Thanks Kolusu for providing the solution. I tried the solution but job failed with
Quote:
"IGZ0040S An invalid separate sign was detected in program"
while executing the move statement " MOVE WS-INP-FLNUM TO WS-OUT-FL"

We are using the old cobol compiler (Z/OS 4.2.0) and this will be upgraded only next year post Z/OS upgrade.

#4:  Author: kolusuLocation: San Jose PostPosted: Thu Aug 10, 2023 10:06 am
    —
jathampy,

Can you give this a try ?
Code:

WORKING-STORAGE SECTION.                             
01 WS-INP-FLNUM                PIC +V9(16)E+99 GLOBAL.
01 WS-INP-FLCHAR     REDEFINES WS-INP-FLNUM.         
   05 A                        PIC X(21).             
01 WS-OUT-FL                   COMP-2.               

PROCEDURE DIVISION.                           

    MOVE "-2.2204462782314E-16"         TO A. 
    DISPLAY 'CHAR VALUE A : ' A               

    COMPUTE WS-OUT-FL  = FUNCTION NUMVAL-F(A) 
    DISPLAY "COMP-2 Value is : " WS-OUT-FL             

#5:  Author: jathampyLocation: UK PostPosted: Mon Aug 14, 2023 9:29 am
    —
I tried NUMVAL-F before also and it's not working. The Other intrinsic functions NUMVAL and NUMVAL-C are working fine with the compiler version 4.2.0 V4R2 . When I use NUMVAL-F,it's giving compilation error:

Code:
IGYPS2130-S   Expected a function-name, but found "NUMVAL-F".  The "COMPUTE" statement was discarded.



MVSFORUMS.com -> Application Programming


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group