| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| edkir98 Beginner
 
  
 Joined: 27 Aug 2007
 Posts: 102
 Topics: 42
 Location: Chennai
 
 | 
			
				|  Posted: Wed Apr 22, 2009 1:19 pm    Post subject: Type Casting |   |  
				| 
 |  
				| not sure if this is a very basic question..but suppose i have a variable VAR1 defined as X(12) which extracts data from the table stored as a number value 9(8)V9(4). So in my program can i use the following 
 
  	  | Code: |  	  | 01 WS-CAST-AS-NUMBER. 10 WS-NUMBER-X                     PIC X(8).
 10 WS-NUMBER      REDEFINES WS-NUMBER-X      PIC 9(8).
 10 WS-DOT                         PIC X(01).
 10 WS-DEC-X                   PIC X(04).
 10 WS-DEC         REDEFINES WS-DEC-X    PIC 9(04).
 | 
 
 
  	  | Code: |  	  | MOVE VAR1 TO WS-CAST-AS-NUMBER | 
 
 So WS-NUMBER have the whole number part and WS-DEC have the decimal part correctly?
 Will this work..
 _________________
 Thanks
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Nic Clouston Advanced
 
 
 Joined: 01 Feb 2007
 Posts: 1075
 Topics: 7
 Location: At Home
 
 | 
			
				|  Posted: Wed Apr 22, 2009 1:21 pm    Post subject: |   |  
				| 
 |  
				| What happened when you tried it? _________________
 Utility and Program control cards are NOT, repeat NOT, JCL.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| edkir98 Beginner
 
  
 Joined: 27 Aug 2007
 Posts: 102
 Topics: 42
 Location: Chennai
 
 | 
			
				|  Posted: Wed Apr 22, 2009 1:47 pm    Post subject: |   |  
				| 
 |  
				| Its working.. because all values in the table are having 8 whole numbers/4 decimal numbers and i'm not authorised to edit a value in the table. but i just wanted to confirm if it would work for others as well... such as when it is 123.44 i would want WS-NUMBER to have 123 and WS-DEC to have 44 _________________
 Thanks
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| kolusu Site Admin
 
  
 
 Joined: 26 Nov 2002
 Posts: 12394
 Topics: 75
 Location: San Jose
 
 | 
			
				|  Posted: Wed Apr 22, 2009 2:54 pm    Post subject: |   |  
				| 
 |  
				|  	  | edkir98 wrote: |  	  | I have a variable VAR1 defined as X(12) which extracts data from the table stored as a number value 9(8)V9(4) | 
 
 Does the table store explicit decimal point? You are retrieving 12 bytes but if it has an explicit decimal point, the length is 13 (8+1+4). Also you are retrieving the table data into a character field it is left justified.
 
 what happens if your your input is
 
 
  	  | Code: |  	  | 1.1234
 12.1234
 123.1234
 1234.1234
 12345.1234
 123456.1234
 1234567.1234
 
 | 
 
 Does your redefine work for it?
 _________________
 Kolusu
 www.linkedin.com/in/kolusu
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| Terry_Heinze Supermod
 
 
 Joined: 31 May 2004
 Posts: 391
 Topics: 4
 Location: Richfield, MN, USA
 
 | 
			
				|  Posted: Sat Apr 25, 2009 2:29 pm    Post subject: |   |  
				| 
 |  
				| If VAR-1 is defined as a DB2 data type DECIMAL (12,4), then you need to MOVE VAR-1 TO WS-NUMBER where You need to study the PICTURE and USAGE clauses and MOVE statements in the Language Reference manual. 	  | Code: |  	  | 01. 05  WS-NUMBER              PIC S9(8)V9(4).
 05  redefines WS-NUMBER.
 10  WS-NUMBER-INTEGER  PIC  9(8).
 10  WS-NUMBER-DECIMAL  PIC S9(4).
 | 
 _________________
 ....Terry
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  | 
	
		|  |