How to edit comp-3 variable in cobol?

I have date 20101010 which is stored as comp-3 . Now I want to change this date to 2010-10-10 format. How to achieve this?. I also believe that we can't split comp-3 variable.Am I rite?..Help folks!!

Questions by Atham

Showing Answers 1 - 6 of 6 Answers

We cant move the variable of type S9(10)V99 COMP-3 to ALPHANUMERIC directly.
Plz declare a intermediate variable of type +9(10).99 and move it to the alphanumeric.. It works.

In your case if we take the exmaple of date and define the variable as
"WS-DATE       PIC 9(8) COMP-3 VALUE 20101010."
"WS-DATE-TEMP   PIC 9(8)."


Then we need to move WS-DATE to WS-DATE-TEMP,

"MOVE  WS-DATE TO WS-DATE-TEMP."

Then if you want the date in DD-MM-YYYY format then define the group variables as below


01 WS-DATE-TEMP1.                              
   05 WS-TEMP-YYYY           PIC 9(4).        
   05 WS-TEMP-MM             PIC 9(2).        
   05 WS-TEMP-DD             PIC 9(2).        
                                               
01 WS-DATE-FORMAT.                             
   05 WS-DD                  PIC X(2).        
   05 FILLER                  PIC X(1) VALUE '-'
   05 WS-MM                 PIC X(2).        
   05 FILLER                  PIC X(1) VALUE '-'
   05 WS-YYYY               PIC X(4).        


Then...


MOVE  WS-DATE-TEMP TO WS-DATE-TEMP1"
MOVE  WS-TEMP-YYYY TO WS-YYYY.
MOVE  WS-TEMP-MM TO WS-MM.   
MOVE  WS-TEMP-DD TO WS-DD.   


DISPLAY "WS-YYYY-" WS-YYYY.             
DISPLAY "WS-MM-" WS-MM.                 
DISPLAY "WS-DD-" WS-DD.                 
DISPLAY "WS-DATE-FORMAT-" WS-DATE-FORMAT.


WS-DATE-FORMAT will have the date in desired format like "10-10-2010"

  Was this answer useful?  Yes

If you have accepted the amount as 126778.12 from user and have to move it in COMP-3 variable then declares a user defined fields as 9(11).99 and accept the above variable into it, then move it into the desired comp-3 variable, For ex
 PIC  9(11)V99 COMP-3.
Amount will get modified.

To again display this amount in some report or so you can again do the reverse of above.
Move PIC  9(11)V99 COMP-3 to  PIC 9(11).99  .

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions