MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Convert external floating point number to COMP-2

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
jathampy
Beginner


Joined: 21 Dec 2007
Posts: 18
Topics: 7
Location: UK

PostPosted: Wed Aug 02, 2023 11:13 am    Post subject: Convert external floating point number to COMP-2 Reply with quote

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 ?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Wed Aug 02, 2023 5:08 pm    Post subject: Reply with quote

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

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jathampy
Beginner


Joined: 21 Dec 2007
Posts: 18
Topics: 7
Location: UK

PostPosted: Sat Aug 05, 2023 3:47 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu Aug 10, 2023 10:06 am    Post subject: Reply with quote

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             

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jathampy
Beginner


Joined: 21 Dec 2007
Posts: 18
Topics: 7
Location: UK

PostPosted: Mon Aug 14, 2023 9:29 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group