Page 1 of 1

Move data value from VAR 9(9) to VAR 9(9) COMP-3

PostPosted: Sun Sep 10, 2017 5:59 pm
by arya_starc
Hi All,

What is the o/p if I move a var 'A' which is 9(09) to other var 'B' which is S9(09) comp-3 and to var 'C' which is 9(09) comp-3.
And suppose the value in var 'A' is
000000000.

I am getting value which seems to be junk in the variable C.!!!

Re: Move data value from VAR 9(9) to VAR 9(9) COMP-3

PostPosted: Sun Sep 10, 2017 6:55 pm
by Akatsukami
And what does that "junk" look like in hexadecimal?

Re: Move data value from VAR 9(9) to VAR 9(9) COMP-3

PostPosted: Sun Sep 10, 2017 9:35 pm
by arya_starc
don't know exactly it is hexadecimal or not?

Re: Move data value from VAR 9(9) to VAR 9(9) COMP-3

PostPosted: Sun Sep 10, 2017 9:56 pm
by Akatsukami
Arya-chan, you have been a member of this board for two years, which implies that you have at least that much experience, plus some sort of training. You should know by now, if you didn't already on your first day on your first job, that all computer data are binary, which can be converted to hexadecimal by the simple expedient of grouping four binary digits (or bits; that is where the name comes from) into one hexadecimal digit.

Re: Move data value from VAR 9(9) to VAR 9(9) COMP-3

PostPosted: Mon Sep 11, 2017 2:30 am
by Robert Sample
arya_starc, one thing you apparently have not yet learned in your career but need to is that there is NO such thing as "junk" to a computer. The mainframe uses EBCDIC, which allows 256 possible character values (from X'00' to X'FF') and none of them are "junk" -- every one of them is defined to be something. So when you call something "junk" you are exposing your EXTREME ignorance to the world. Furthermore, why do you not show us what the value of C is instead of calling it "junk"? It is trivial to bring up the data in ISPF edit, use the command HEX ON, and then copy the display to a Coded display on this forum. Then we will be able to tell you why the data you are seeing is not "junk".

Re: Move data value from VAR 9(9) to VAR 9(9) COMP-3

PostPosted: Mon Sep 11, 2017 9:10 pm
by Terry Heinze
The Language Reference Manual contains everything you need to know about pictures and values.
A simple test program would have answered your question:
      WORKING-STORAGE SECTION.
       01.
           05  A-X.
               10  A                   PIC  9(09) VALUE 000000000.
           05  B-X.
               10  B                   PIC S9(09) COMP-3.
           05  C-X.
               10  C                   PIC  9(09) COMP-3.
       PROCEDURE DIVISION.
           MOVE A TO B
-001-I No Report Writer data entries were found in this program.
           MOVE A TO C
           DISPLAY 'A-X: >' A-X '<'
           DISPLAY 'B-X: >' B-X '<'
           DISPLAY 'C-X: >' C-X '<'
           GOBACK
           .


A-X: >000000000<
B-X: >     <
C-X: >     <


COMMAND INPUT ===> set hex on

COMMAND INPUT =
---+----1----+--
A-X: >000000000<
C6E746FFFFFFFFF4
107A0E000000000C
 ---------------
B-X: >     <
C6E7460000044444
207A0E0000CC0000
 ---------------
C-X: >     <
C6E7460000044444
307A0E0000FC0000

Re: Move data value from VAR 9(9) to VAR 9(9) COMP-3

PostPosted: Tue Sep 12, 2017 12:00 am
by arya_starc
Thanks Robert and Akatsukami for more details on EBCDIC.
Actually I am not using termival 3270 or any black green screen for spool, because of that I am not able to change the output value into hexadecimal.Otherwise I will put the output in the forum post.

Hi Terry,
Thanks for the output as I can see the output for B-X and C-X when we see in the hex mode on format, there is different in the last position for B it is 0-C and for C it is 0-F.

Could you please more clarify on the output difference in the value of B-X and C-X for last zero.
As per my understanding it is because as B is stored signed bit and C is not stored any value for signed bit.And in terms of cobol these value should be equal. Please tell me if my understanding is correct.

Re: Move data value from VAR 9(9) to VAR 9(9) COMP-3

PostPosted: Tue Sep 12, 2017 12:29 am
by Terry Heinze
Mathematically, they are equal as far as COBOL is concerned. X'0C' is a signed packed zero. X'0F' is an unsigned packed zero. Again, the Manual explains this.

Re: Move data value from VAR 9(9) to VAR 9(9) COMP-3

PostPosted: Tue Sep 12, 2017 12:32 am
by Akatsukami
Your understanding is not correct.

A packed decimal number (COBOL COMP-3; other languages use other terms) will have a decimal digit (0-9) in each half-byte (a nybble) except in the least significant nybble (the sign nybble). By convention going back to the introduction of the System 360 in 1964, a value of (hexadecimal) A, C, or E is considered positive (although you will only ever see C these days), and a value of B or D is considered negative (again you will only see D used). A value of F is considered unsigned (and is treated as positive for almost purposes).

In Mr. Heinze's example, moving zero to B causes it to have the value of x'0000C', whilst moving zero to C causes it to have the value x'0000F'; an arithmetic comparison will find these equal, but a bitwise comparison will not. Note that none of these values produce EBCDIC glyphs, which is likely why you mistook them for junk.