| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| rajeshm01 Beginner
 
 
 Joined: 01 Jun 2012
 Posts: 8
 Topics: 2
 
 
 | 
			
				|  Posted: Fri Jun 01, 2012 2:01 pm    Post subject: Separating integer and decimal parts from comp3 |   |  
				| 
 |  
				| hi all, 
 This is my requirement.
 FieldA PIC S999V99  COMP-3.
 FieldB PIC 999.99.
 FieldC PIC 999.99.
 
 I need integer part of FieldA in FieldB, decimal part of FieldA in FieldC.
 The value in FieldA may or may not have decimal values in it.
 
 I read thorugh lot of posts and found some Comp3 to alphanumeric and Comp3 to numeric conversions but couldnt find anything related.
 Kindly help.
 
 thanks!
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| papadi Supermod
 
 
 Joined: 20 Oct 2009
 Posts: 594
 Topics: 1
 
 
 | 
			
				|  Posted: Fri Jun 01, 2012 2:14 pm    Post subject: |   |  
				| 
 |  
				| Why does someone believe this is needed? 
 Why not something like:
 
  	  | Code: |  	  | 05 THEFIELDS PIC 9(5). 05 FILLER REDEFINES THEFIELDS.
 10 FIELDB PIC 999.
 10 FIELDC PIC V99.
 | 
 
 Then MOVE FIELDA TO THEFIELDS.
 _________________
 All the best,
 
 di
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| kolusu Site Admin
 
  
 
 Joined: 26 Nov 2002
 Posts: 12394
 Topics: 75
 Location: San Jose
 
 | 
			
				|  Posted: Fri Jun 01, 2012 2:34 pm    Post subject: Re: separating integer and decimal parts from comp3 |   |  
				| 
 |  
				|  	  | rajeshm01 wrote: |  	  | hi all, 
 This is my requirement.
 FieldA PIC S999V99  COMP-3.
 FieldB PIC 999.99.
 FieldC PIC 999.99.
 
 I need integer part of FieldA in FieldB, decimal part of FieldA in FieldC.
 
 
 | 
 
 rajeshm01,
 
 You also need to show a sample of input and desired output.
 
 ex: A = 234.45  then B=234.00 and C = 045.00?
 
 Is that it?
 
 
  	  | rajeshm01 wrote: |  	  | The value in FieldA may or may not have decimal values in it.
 | 
 
 what do you mean by this? There is no decimal dot explicitly in a Packed decimal field.
 
 A value of 234.56 is stored in 3 bytes as
 
 and you can read it into
 
  	  | Code: |  	  | S9(5) as 23456
 S9V9(4) as 2.3456
 S9(2)V9(4) as 23.456
 ...
 
 | 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| papadi Supermod
 
 
 Joined: 20 Oct 2009
 Posts: 594
 Topics: 1
 
 
 | 
			
				|  Posted: Fri Jun 01, 2012 10:50 pm    Post subject: |   |  
				| 
 |  
				| If fielda is 234.56, 
 I suspect that fieldb should be 234 and fieldc  should be 56 after the
 MOVE FIELDA TO THEFIELDS.
 
 Possibly i'm missing something. . .
 
 Possibly TS might clarify. . .
 _________________
 All the best,
 
 di
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| rajeshm01 Beginner
 
 
 Joined: 01 Jun 2012
 Posts: 8
 Topics: 2
 
 
 | 
			
				|  Posted: Sat Jun 02, 2012 2:26 am    Post subject: |   |  
				| 
 |  
				| thanks Kolusu , your example is fine. ex: A = 234.45 then B=234.00 and C = 045.00
 
 thanks papadi, thats what i received as requirement
   
 here is what i tried...
  	  | Code: |  	  | 05 FIELDA PIC S999V99 COPM-3.
 05 FIELDB PIC 9(5).
 05 FILLER REDEFINES FIELDB.
 10 FIELDP PIC 999.
 10 FIELDQ PIC 99.
 05 FIELDC  PIC 999.99
 05 FIELDD  PIC 999.99
 
 
 MOVE  123.45 TO FIELDA
 DISPLAY FIELDA     ----   12345
 MOVE FIELDA TO FIELDB
 DISPLAY FIELDB       --- 00123
 DISPLAY FIELDP       --- 001
 DISPLAY FIELDQ       --- 23
 MOVE FIELDP TO FIELDC
 DISPLAY FIELDC       --- 001.00
 MOVE FIELDQ TO FIELDD
 DISPLAY FIELDD       --- 023.00
 
 
 MOVE  123 TO FIELDA
 DISPLAY FIELDA       ----12300
 MOVE FIELDA TO FIELDB
 DISPLAY FIELDB       ----  00123
 DISPLAY FIELDP       ----  001
 DISPLAY FIELDQ       ----  23
 MOVE FIELDP TO FIELDC
 DISPLAY FIELDC       ---- 001.00
 MOVE FIELDQ TO FIELDD
 DISPLAY FIELDD      ---- 023.00
 
 | 
 please correct me.
 
 thanks again!
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| papadi Supermod
 
 
 Joined: 20 Oct 2009
 Posts: 594
 Topics: 1
 
 
 | 
			
				|  Posted: Sat Jun 02, 2012 12:42 pm    Post subject: |   |  
				| 
 |  
				| My bad. . . .   
 The picture for THEFIELDS should have been 9(3)V99.
 The fields should have been:
 
  	  | Code: |  	  | 05 THEFIELDS PIC 9(3)V99. 05 FILLER REDEFINES THEFIELDS.
 10 FIELDB PIC 999.
 10 FIELDC PIC V99.
 | 
 
 Please try testing again with the new picture and let us know the result.
 
 Also, be aware there is another issue if the value could ever be negative.
 _________________
 All the best,
 
 di
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| rajeshm01 Beginner
 
 
 Joined: 01 Jun 2012
 Posts: 8
 Topics: 2
 
 
 | 
			
				|  Posted: Sun Jun 03, 2012 1:33 am    Post subject: |   |  
				| 
 |  
				| thanks here is what i tried...
 
  	  | Code: |  	  | 05 FIELDA PIC S999V99 COPM-3.
 05 FIELDB PIC 9(3)v99.
 05 FILLER REDEFINES FIELDB.
 10 FIELDP PIC 999.
 10 FIELDQ PIC V99.
 05 FIELDC PIC 999.99
 05 FIELDD PIC 999.99
 
 | 
 this is what i got...
 
  	  | Code: |  	  | MOVE 123.45 TO FIELDA
 DISPLAY FIELDA ---- 12345
 MOVE FIELDA TO FIELDB
 DISPLAY FIELDB --- 12345
 DISPLAY FIELDP --- 123
 DISPLAY FIELDQ --- 45
 MOVE FIELDP TO FIELDC
 DISPLAY FIELDC --- 123.00
 MOVE FIELDQ TO FIELDD
 DISPLAY FIELDD --- 000.45
 
 | 
 
 FIELDC is 123.00 is correct
 FIELDD shud be 045.00
 
 pls suggest
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| rajeshm01 Beginner
 
 
 Joined: 01 Jun 2012
 Posts: 8
 Topics: 2
 
 
 | 
			
				|  Posted: Sun Jun 03, 2012 4:00 am    Post subject: |   |  
				| 
 |  
				| i tried this and it worked. 
  	  | Code: |  	  | 05 FIELDA PIC S999V99 COPM-3.
 05 FIELDB PIC 9(3)v99.
 05 FILLER REDEFINES FIELDB.
 10 FIELDP PIC 999.
 10 FIELDQ PIC V99.
 10 FIELDX REDEIFNES FIELDQ PIC XX.
 05 FIELDC PIC 999.99
 05 FIELDD PIC 999.99
 
 | 
 this is what i got...
 
  	  | Code: |  	  | MOVE 123.45 TO FIELDA
 DISPLAY FIELDA ---- 12345
 MOVE FIELDA TO FIELDB
 DISPLAY FIELDB --- 12345
 DISPLAY FIELDP --- 123
 DISPLAY FIELDQ --- 45
 MOVE FIELDP TO FIELDC
 DISPLAY FIELDC --- 123.00
 MOVE FIELDX TO FIELDD
 DISPLAY FIELDD --- 045.00
 
 | 
 thanks for ur time guys.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| papadi Supermod
 
 
 Joined: 20 Oct 2009
 Posts: 594
 Topics: 1
 
 
 | 
			
				|  Posted: Sun Jun 03, 2012 1:54 pm    Post subject: |   |  
				| 
 |  
				| Good to hear it is working - thank you for posting your solution   
 My misunderstanding of what was wanted was no help to a speedy answer . . .
   
 fwiw - i'd use PIC 99 for FIELDX (rather than PIC XX).
 _________________
 All the best,
 
 di
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| rajeshm01 Beginner
 
 
 Joined: 01 Jun 2012
 Posts: 8
 Topics: 2
 
 
 | 
			
				|  Posted: Mon Jun 04, 2012 2:53 am    Post subject: |   |  
				| 
 |  
				| you are correct. 
 tried pic 99 and it also worked.
 
  	  | Code: |  	  | 05 FIELDA PIC S999V99 COPM-3.
 05 FIELDB PIC 9(3)v99.
 05 FILLER REDEFINES FIELDB.
 10 FIELDP PIC 999.
 10 FIELDQ PIC V99.
 10 FIELDX REDEIFNES FIELDQ PIC 99.
 05 FIELDC PIC 999.99
 05 FIELDD PIC 999.99
 
 | 
 this is what i got...
 
  	  | Code: |  	  | MOVE 123.45 TO FIELDA
 DISPLAY FIELDA ---- 12345
 MOVE FIELDA TO FIELDB
 DISPLAY FIELDB --- 12345
 DISPLAY FIELDP --- 123
 DISPLAY FIELDQ --- 45
 MOVE FIELDP TO FIELDC
 DISPLAY FIELDC --- 123.00
 MOVE FIELDX TO FIELDD
 DISPLAY FIELDD --- 045.00
 
 | 
 thanks again.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| kolusu Site Admin
 
  
 
 Joined: 26 Nov 2002
 Posts: 12394
 Topics: 75
 Location: San Jose
 
 | 
			
				|  Posted: Mon Jun 04, 2012 11:57 am    Post subject: |   |  
				| 
 |  
				| Here is a simple version 
 
  	  | Code: |  	  | 01 FLD-A                       PIC S9(3)V99 VALUE 234.56.
 
 01 TEMP.
 05 TEMP-I                   PIC 999.
 05 TEMP-D                   PIC 99.
 
 01 FLD-B                       PIC 999.99.
 01 FLD-C                       PIC 999.99.
 
 PROCEDURE DIVISION.
 
 MOVE FLD-A                TO TEMP
 MOVE TEMP-I               TO FLD-B
 MOVE TEMP-D               TO FLD-C
 
 | 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| William Collins Supermod
 
 
 Joined: 03 Jun 2012
 Posts: 437
 Topics: 0
 
 
 | 
			
				|  Posted: Mon Jun 04, 2012 4:57 pm    Post subject: |   |  
				| 
 |  
				|  	  | Code: |  	  | 01  w-original-field comp-3 pic s999v99.
 
 01  w-interger-part-of-original pic 999v99 value zero.
 01  filler redefines w-interger-part-of-original.
 05  w-integer-part-integer pic 999.
 05  filler pic xx.
 
 01  w-decimal-part-as-integer-of-original pic 999v99 value zero.
 01  filler redefines w-decimal-part-as-integer-of-original.
 05  filler pic x.
 05  w-decimal-part-as-integer pic v99.
 05  filler pic xx.
 
 move w-original-field to w-integer-part-integer
 w-decimal-part-as-integer
 
 | 
 
 Note that you started with a signed field. You have lost the sign, but that is your requirement.
 
 By putting the fixed part of the data into the data definition, the procedure becomes very simple.
 
 With the integer part, the final two bytes will always be zero, so define them so.
 
 With the decimal part expressed as an integer, the first byte and the final two bytes will always be zero, so define them so.
 
 If you want to keep the signs, you can have a different story...
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| rajeshm01 Beginner
 
 
 Joined: 01 Jun 2012
 Posts: 8
 Topics: 2
 
 
 | 
			
				|  Posted: Tue Jun 05, 2012 1:28 am    Post subject: |   |  
				| 
 |  
				| thanks guys. 
 kolusu,
 FieldA should be COMP-3. I got s0c7 when moving FieldA(Comp3) to Temp.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| William Collins Supermod
 
 
 Joined: 03 Jun 2012
 Posts: 437
 Topics: 0
 
 
 | 
			
				|  Posted: Tue Jun 05, 2012 6:18 am    Post subject: |   |  
				| 
 |  
				|  	  | rajeshm01 wrote: |  	  | thanks guys. 
 kolusu,
 FieldA should be COMP-3. I got s0c7 when moving FieldA(Comp3) to Temp.
 | 
 
 So
 
 
  	  | Code: |  	  | 01  TOMP PIC 999V99. 01  TEMP REDEFINES TOMP.
 05 TEMP-I                   PIC 999.
 05 TEMP-D                   PIC 99.
 | 
 Change your MOVE to TOMP.
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| jyoung Beginner
 
 
 Joined: 10 Nov 2005
 Posts: 36
 Topics: 2
 Location: Flint, MI
 
 | 
			
				|  Posted: Tue Jun 05, 2012 7:11 am    Post subject: |   |  
				| 
 |  
				| If you don't care about the sign how about this: 
  	  | Code: |  	  | WORKING-STORAGE SECTION.
 01  WS-AMOUNT              PIC S9(3)V99 VALUE +123.45.
 01  WS-AMT                 PIC 9(5)     VALUE ZEROES.
 01  WS-NEW-AMT.
 03  WS-NEW-AMT-1       PIC 9(3) VALUE ZEROES.
 03  WS-NEW-AMT-2       PIC 9(2) VALUE ZEROES.
 01  WS-AMT-1               PIC 9(3)V99 VALUE ZEROES.
 01  WS-AMT-2               PIC 9(3)V99 VALUE ZEROES.
 PROCEDURE DIVISION.
 100-MAIN.
 COMPUTE WS-AMT = WS-AMOUNT * 100.
 MOVE WS-AMT TO WS-NEW-AMT.
 MOVE WS-NEW-AMT-1 TO WS-AMT-1.
 COMPUTE WS-AMT-2 = WS-NEW-AMT-2 / 100
 DISPLAY "FIRST AMOUNT " WS-AMT-1.
 DISPLAY "SECOND AMOUNT " WS-AMT-2.
 
 | 
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		|  | 
	
		|  |