View previous topic :: View next topic
|
Author |
Message |
gvvjags
New User
Joined: 27 Feb 2020 Posts: 1 Location: INDIA
|
|
|
|
Hi , I have defined COBOL Variable as below.
03 VARIABLE-A PIC S9(04)
03 FILLER REDEFINES VARIABLE A.
05 VARIABLE-B S9(02).
05 VARIABLE-C S9(02).
Is this redefinition correct. I mean for example 24 is moved to VARIABLE-B
and 40 is moved to Variable-C .
Where does Sign stored in Variable-a, Variable-b and Variable-c.
Does variable-a exactly store values in b and c together. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
It took me a few minutes to write the following program:
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. MYTEST.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIABLE-A PIC S9(4).
01 FILLER REDEFINES VARIABLE-A.
03 VARIABLE-B PIC S9(2).
03 VARIABLE-C PIC S9(2).
PROCEDURE DIVISION.
MOVE 1357 TO VARIABLE-A *> NO SIGN
DISPLAY 'VARIABLE-A= ' VARIABLE-A
' VARIABLE-B=' VARIABLE-B
' VARIABLE-C=' VARIABLE-C
MOVE -9876 TO VARIABLE-A *> NEGATIVE
DISPLAY 'VARIABLE-A= ' VARIABLE-A
' VARIABLE-B=' VARIABLE-B
' VARIABLE-C=' VARIABLE-C
MOVE +2468 TO VARIABLE-A *> POSITIVE
DISPLAY 'VARIABLE-A= ' VARIABLE-A
' VARIABLE-B=' VARIABLE-B
' VARIABLE-C=' VARIABLE-C
GOBACK. |
And another few seconds to write some JCL:
Code: |
//MYTEST JOB NOTIFY=&SYSUID
//STEP001 EXEC PGM=MYTEST
//STEPLIB DD DISP=SHR,DSN=hlq.WHERE.LOAD
//SYSOUT DD SYSOUT=* |
And after a few more seconds, got the result:
Code: |
VARIABLE-A= 135G VARIABLE-B=13 VARIABLE-C=5G
VARIABLE-A= 987O VARIABLE-B=98 VARIABLE-C=7O
VARIABLE-A= 246H VARIABLE-B=24 VARIABLE-C=6H |
|
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
I also added:
Code: |
MOVE 24 TO VARIABLE-B
MOVE 40 TO VARIABLE-C
DISPLAY 'VARIABLE-A= ' VARIABLE-A
' VARIABLE-B=' VARIABLE-B
' VARIABLE-C=' VARIABLE-C |
and the DISPLAY showed:
Code: |
VARIABLE-A= 2D4{ VARIABLE-B=2D VARIABLE-C=4{ |
I guess this answers your question. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Is this redefinition correct. |
Absolutely, categorically no. Will it "work" for COBOL? MAYBE. The Language Reference manual tells us that a zoned decimal variable that is declared as signed stores the sign in the rightmost character's zone bits. Hence variable A will have its sign stored in the zone field of the 4th byte. If you move something to B, it will have a sign stored in the zone of the second byte. What does this mean for A? At a minimum, you've got a sign that will be ignored if A is used as a variable. COBOL allows you to do many things that are not within the purview of the rules. Such things are, typically, creating unpredictable results. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2141 Location: USA
|
|
|
|
gvvjags wrote: |
Hi , I have defined COBOL Variable as below.
03 VARIABLE-A PIC S9(04)
03 FILLER REDEFINES VARIABLE A.
05 VARIABLE-B S9(02).
05 VARIABLE-C S9(02).
Is this redefinition correct. |
Definitely NOT is you are using SIGNED numeric variables (e.g. "decimal unpacked" in IBM environment). It may (or may not) work with UNSIGNED numeric variables...
Unless you are using simple CHARACTER values (e.g. PIC X...), the result of REDEFINES can be unpredictable; one needs to understand well the internal data representation in particular environments. |
|
Back to top |
|
|
|