Separating integer and decimal parts from comp3



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Separating integer and decimal parts from comp3

Postby rajesh m01 » Sun Jun 03, 2012 12:07 pm

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.

ex: A = 234.45 then B=234.00 and C = 045.00

this is what i tried...

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

this is what i got...

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

also i tried below 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...

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

kindly help.
rajesh m01
 
Posts: 1
Joined: Sat Jun 02, 2012 1:36 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Separating integer and decimal parts from comp3

 

Re: Separating integer and decimal parts from comp3

Postby NicC » Sun Jun 03, 2012 1:46 pm

I am sure I saw a long thread on this question last night including several solutions but I cannot find it now on any of the 3 forums I have looked at so here goes...

No forget it I found it on another forum. You have just wasted 1/2 an hour of my time by multi-posting. You SHOULD NOT multi-post. I am going to have to charge you for that lost 1/2 hour. Locked.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post