Page 1 of 1

MOVE COMP-3 OR COMP field to CHAR

PostPosted: Thu Sep 28, 2017 5:33 pm
by oerdgie
Hi Folks,

when I move a negative COMP-3 or a COMP field to a CHAR field, I missing the negative sign in the CHAR field.
Is it possible to get the sign in the CHAR field only with the MOVE below (e.g. using a special Compiler Option)?

We use COBOL 6.1

Exampel :

028010      05 VALUE-P              PIC S9(09)      COMP-3            
028020                                              VALUE -123456789.
028021      05 VALUE-C              PIC S9(09)      COMP              
028022                                              VALUE -123456789.
028200                                                                
028300      05 OUT-P                PIC X(20).                        
028310      05 OUT-C                PIC X(20).    
 


Result :

004601        MOVE VALUE-P                  TO OUT-P                    
004602        MOVE VALUE-C                  TO OUT-C      

000280 K 05 VALUE-P                         >  -123456789                PACKED
000282 K 05 VALUE-C                         >  -123456789              FULLWORD
                                               ----+----1----+----2            
000285 K 05 OUT-P                           >  123456789                      
                                               ----+----1----+----2            
000286 K 05 OUT-C                           >  123456789                                    
 


Thanks in advance for help

Re: MOVE COMP-3 OR COMP field to CHAR

PostPosted: Thu Sep 28, 2017 9:15 pm
by Terry Heinze
Not with a compiler option that I know of. I'd do it like this:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
       WORKING-STORAGE SECTION.
       01.
           05 VALUE-P                  PIC S9(09)      COMP-3
                                                    VALUE -123456789.
           05 VALUE-C                  PIC S9(09)      COMP
                                                    VALUE -123456789.
           05  OUT-P-X.
               10 OUT-P                PIC S9(18).
           05  OUT-C-X.
               10 OUT-C                PIC S9(18).
       PROCEDURE DIVISION.
           MOVE VALUE-P                TO OUT-P
           MOVE VALUE-C                TO OUT-C
           DISPLAY 'OUT-P-X: >' OUT-P-X '<'
           DISPLAY 'OUT-C-X: >' OUT-C-X '<'
           GOBACK
           .

COMMAND INPUT ===> set hex on                                 SCROLL ===> CSR
---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8-
OUT-P-X: >00000000012345678R<
DEE6D6E746FFFFFFFFFFFFFFFFFD4444444444444444444444444444444444444444444444444444
6430707A0E000000000123456789C000000000000000000000000000000000000000000000000000
 ------------------------------------------------------------------------------
OUT-C-X: >00000000012345678R<
DEE6C6E746FFFFFFFFFFFFFFFFFD4444444444444444444444444444444444444444444444444444
6430307A0E000000000123456789C000000000000000000000000000000000000000000000000000
 ------------------------------------------------------------------------------

If the result needs to be in a 20-byte field and/or left justified, you'd have to manipulate the result.

P.S. I'm using COBOL for z/OS 4.2.0