IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Error in Rand function


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
dsarlie
Currently Banned

New User


Joined: 22 Apr 2008
Posts: 5
Location: Chennai

PostPosted: Tue Mar 03, 2009 2:54 pm
Reply with quote

Hi,

I am using the following piece of code in my program.I am getting undefined or unusable host variable.Can someone tell me what is the error in the code.

03 W070-RANDOM-NUMBER1 PIC 9(1)V VALUE ZEROES

EXEC SQL
SELECT DECIMAL(RAND() * 10)
INTO :W070-RANDOM-NUMBER1
FROM SYSIBM.SYSDUMMY1
END-EXEC

DSNH312I E DSNHSMUD LINE 1314 COL 20 UNDEFINED OR UNUSABLE HOST VARIABLE
"W070-RANDOM-NUMBER1"

Thanks
Jeba David
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Mar 03, 2009 3:26 pm
Reply with quote

The result of the RAND function is a double precision floating-point number... ... try changing the PIC clause to accomodate floating point
Back to top
View user's profile Send private message
dsarlie
Currently Banned

New User


Joined: 22 Apr 2008
Posts: 5
Location: Chennai

PostPosted: Tue Mar 03, 2009 3:55 pm
Reply with quote

I checked with the picture clause matching.It is not getting matched.I hope this error may be because of attribute mistach.I dont know the exact length of the output for this query.
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Mar 03, 2009 4:35 pm
Reply with quote

Quote:
03 W070-RANDOM-NUMBER1 PIC 9(1)V VALUE ZEROES
...not sure if it will work..Try defining the variable as USAGE COMP-2.
WTF
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Mar 03, 2009 4:55 pm
Reply with quote

Sorry ..missed out on the DECIMAL part of the query ...
PIC S9(9)V9(2) USAGE COMP-3. should work.
Hope this helps.
WTF
Back to top
View user's profile Send private message
dsarlie
Currently Banned

New User


Joined: 22 Apr 2008
Posts: 5
Location: Chennai

PostPosted: Wed Mar 04, 2009 10:24 am
Reply with quote

Hi,

Thanks.Comp-2 works now.Comp-3 gives the same error.While I am getting the data from the table it is Floating point precision.

For eg:

(blank.20000000000000000E 01 ) this is the output I get from the table.I need only the number 2.

03 ws-num1 usage comp-2
03 ws-num2 redefines ws-num1
05 filler pic x(02)
05 ws-num3 pic 9(1)
05 filler pic 9(17).

This is how I have declared the variables.

in my ouput ws-num3 has blank space and it is not displaying anything.Is there any error over here.How should I get the value 2.
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Wed Mar 04, 2009 12:46 pm
Reply with quote

Jeba,
Lets work on your original request.
I tried the following code ...and it worked for me.
Code:
WORKING STORAGE.
 01 RAN PIC S9(1) USAGE COMP-3.       
 01 RAN-DISP  PIC S9(1) VALUE ZEROES. 
PROCEDURE DIVISION.
 EXEC SQL                           
 SELECT DECIMAL(RAND() * 10)         
 INTO :RAN                           
 FROM SYSIBM.SYSDUMMY1               
 END-EXEC
                           
 MOVE RAN TO RAN-DISP                 
 DISPLAY 'OUTPUT:'RAN                 
 DISPLAY 'OUTPUT DISPLAY :'RAN-DISP
 

Spool Output
OUTPUT:7
OUTPUT DISPLAY :G
I believe this should work for you as well, do let us know otherwise.
WTF
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Error when install DB2 DB2 2
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
Search our Forums:

Back to Top