Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Error in Rand function

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Error in Rand function
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    Post subject:
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    Post subject: Reply to: Error in Rand function
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    Post subject: Reply to: Error in Rand function
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    Post subject: Reply to: Error in Rand function
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    Post subject: Re: Reply to: Error in Rand function
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    Post subject: Reply to: Error in Rand function
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts IDC2902I Error tzeche ABENDS & Debugging 2 Tue Mar 28, 2017 11:39 am
No new posts Need help with below DB2 error ashek15 DB2 3 Sat Mar 18, 2017 5:56 am
No new posts FINDREP Syntax Error seahawk789 DFSORT/ICETOOL 4 Thu Mar 09, 2017 10:11 pm
No new posts INVOKE WEBSERVICE error danik56 CICS 11 Thu Mar 09, 2017 11:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us